wt.rule.util
Class QueryUtils

java.lang.Object
  extended bywt.rule.util.QueryUtils

public class QueryUtils
extends Object

This class provides query utility methods that are used by classes in the wt.rule package.


Field Summary
private static String RESOURCE
           
 
Constructor Summary
QueryUtils()
           
 
Method Summary
static QuerySpec createBasicQuerySpec(Class table, RuleType ruleType, boolean defaultRule, boolean enabled)
          Construct a basic QuerySpec that can be used as the basis for querying for Rules: either InstanceBasedRules or TypeBasedRules (or another Rule subclass).
static WTContainerRef[] getAncestorArray(WTContainerRef container)
          Return an array of WTContainerRefs that includes the specified container plus all of its ancestors.
(package private) static QuerySpec getBasicSpec(RuleType ruleType, Boolean defaultRule, Boolean enabled)
          Return a QuerySpec that queries the TypeBasedRule table for rules that meet the specified criteria.
static Rule[] getRules(RuleType ruleType, Boolean defaultRule, Boolean enabled, WTContainerRef[] containers, String[] typeNames, boolean first_match)
          Return all TypeBasedRules that meet the specified criteria.
(package private) static StatementSpec getTypeHierarchySpec(QuerySpec qs, String[] typeNames)
          Return a StatementSpec that returns the IDs of all TypeBasedRules that meet the conditions in the query spec that is passed in and have their OBJ_TYPE attribute set equal to one of the type names in the typeNames list.
private static StatementSpec getTypeHierarchySpec(QuerySpec qs, WTContainerRef[] containers, String[] typeNames)
          Return a StatementSpec that returns the IDs of all TypeBasedRules that meet the conditions in the query spec that is passed in and are contained in one of the containers in the containers list and have their OBJ_TYPE attribute set equal to one of the typenames in the typeNames list.
static String[] getTypeNames(Class type)
          Return an array of type names that includes the name of the specified type plus the names of all of its parent types.
(package private) static WhereExpression getWhereTypeIs(String typeName)
          Returns a WhereExpression that can be used to filter a query for TypeBasedRules to only return rules whose OBJ_TYPE attribute is equal to the specified type name.
(package private) static WTArrayList inflateIDs(QueryResult ids, boolean first_match)
          Used to expand the results of a query that has only selected the IDs of the objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values
Constructor Detail

QueryUtils

public QueryUtils()
Method Detail

getRules

public static Rule[] getRules(RuleType ruleType,
                              Boolean defaultRule,
                              Boolean enabled,
                              WTContainerRef[] containers,
                              String[] typeNames,
                              boolean first_match)
                       throws WTException
Return all TypeBasedRules that meet the specified criteria.

If any parameter is null then that parameter is not used to filter the results.

Rules that are contained in one of the containers specified in the containers list are returned. Rules whose OBJ_TYPE attribute is equal to one of the type names listed in the typeNames list are returned.

The results are ordered to be consistent with the order of the containers in the containers list. All rules that are contained in the first container in the containers list are first in the result set, followed by the rules that are contained in the second container in the containers list, and so on. Rules that belong to the same container are ordered to be consistent with the order of the type names in the typeNames list. All rules whose OBJ_TYPE attribute is equal to the first type name in the list are first in the result set, followed by the rules whose OBJ_TYPE attribute is equal to the second type name in the list, and so on.

If first_match is true then the rule that would be first in the result set is returned. This is the rule that meets the basic search criteria (ruleType, defaultRule and enabled), is contained in the container closest to the front of the containers list and whose OBJ_TYPE is closest to the front of the typeNames list.

Parameters:
ruleType - the rule type to filter the results on
defaultRule - the defaultRule value to filter the results on
enabled - the enabled value to filter the results on
containers - the containers to search in
typeNames - the type names to search for
first_match - whether only the first result object should be returned
Throws:
WTException
See Also:
wt.inf.container.StandardWTContainerService#orderedQuery

getWhereTypeIs

static WhereExpression getWhereTypeIs(String typeName)
                               throws QueryException
Returns a WhereExpression that can be used to filter a query for TypeBasedRules to only return rules whose OBJ_TYPE attribute is equal to the specified type name.

Parameters:
typeName - the name of the type to filter the query on
Throws:
QueryException

getTypeNames

public static String[] getTypeNames(Class type)
                             throws WTIntrospectionException
Return an array of type names that includes the name of the specified type plus the names of all of its parent types. The type names are ordered from the name of the most specific type to the name of the most general.

Parameters:
type - the type whose parent types should be returned
Throws:
WTIntrospectionException

getAncestorArray

public static WTContainerRef[] getAncestorArray(WTContainerRef container)
                                         throws WTException
Return an array of WTContainerRefs that includes the specified container plus all of its ancestors. The containers are returned ordered from the specified container up to the root container.

Parameters:
container - the container whose ancestors should be returned
Throws:
WTException

getBasicSpec

static QuerySpec getBasicSpec(RuleType ruleType,
                              Boolean defaultRule,
                              Boolean enabled)
                       throws WTException
Return a QuerySpec that queries the TypeBasedRule table for rules that meet the specified criteria.

If any parameter is null then a condition for that attribute is not added to the query specification.

Parameters:
ruleType - the rule type to filter the results on
defaultRule - the defaultRule value to filter the results on
enabled - the enabled value to filter the results on
Throws:
WTException

getTypeHierarchySpec

static StatementSpec getTypeHierarchySpec(QuerySpec qs,
                                          String[] typeNames)
                                   throws WTException
Return a StatementSpec that returns the IDs of all TypeBasedRules that meet the conditions in the query spec that is passed in and have their OBJ_TYPE attribute set equal to one of the type names in the typeNames list.

The statement spec orders the results to be consistent with the order of the type names in the typeNames list: all rules whose OBJ_TYPE attribute is equal to the first type name in the list are first in the result set, followed by the rules whose OBJ_TYPE attribute is equal to the second type name in the list, and so on. NOTE: Use this query with Jon B.'s enhanced lookup function

Parameters:
qs - a query spec for TypeBasedRule
typeNames - a list of type names to use to filter the result set
Throws:
WTException
See Also:
getWhereTypeIs(java.lang.String)

getTypeHierarchySpec

private static StatementSpec getTypeHierarchySpec(QuerySpec qs,
                                                  WTContainerRef[] containers,
                                                  String[] typeNames)
                                           throws WTException
Return a StatementSpec that returns the IDs of all TypeBasedRules that meet the conditions in the query spec that is passed in and are contained in one of the containers in the containers list and have their OBJ_TYPE attribute set equal to one of the typenames in the typeNames list.

The statement spec orders the results to be consistent with the order of the containers in the containers list. All rules that are contained in the first container in the containers list are first in the result set, followed by the rules that are contained in the second container in the containers list, and so on. Rules that belong to the same container are ordered to be consistent with the order of the type names in the typeNames list. All rules whose OBJ_TYPE attribute is equal to the first type name in the list are first in the result set, followed by the rules whose OBJ_TYPE attribute is equal to the second type name in the list, and so on.

NOTE: Use this query with Jon B.'s enhanced lookup function

Parameters:
qs - a query spec for TypeBasedRule
containers - a list of containers to use to filter the result set
typeNames - a list of type names to use to filter the result set
Throws:
WTException
See Also:
getWhereTypeIs(java.lang.String), WTContainerHelper.getWhereContainerIs(wt.inf.container.WTContainer)

createBasicQuerySpec

public static QuerySpec createBasicQuerySpec(Class table,
                                             RuleType ruleType,
                                             boolean defaultRule,
                                             boolean enabled)
                                      throws WTException
Construct a basic QuerySpec that can be used as the basis for querying for Rules: either InstanceBasedRules or TypeBasedRules (or another Rule subclass).

Parameters:
table - the table to query (the class of rule)
ruleType - the desired rule type
enabled - whether only enabled rules should be searched for
Throws:
WTException

inflateIDs

static WTArrayList inflateIDs(QueryResult ids,
                              boolean first_match)
                       throws WTException
Used to expand the results of a query that has only selected the IDs of the objects.

Parameters:
ids - the query result containg only object identifiers
first_match - whether the first result in the query should only be returned
Returns:
a query result containing fully inflated objects
Throws:
WTException