|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.mmbase.bridge.util.Queries
This class contains various utility methods for manipulating and creating query objecs. Most essential methods are available on the Query object itself, but too specific or legacy-ish methods are put here.
Query| Field Summary | |
static int |
OPERATOR_BETWEEN
|
static int |
OPERATOR_IN
|
static int |
OPERATOR_NULL
|
| Constructor Summary | |
Queries()
|
|
| Method Summary | |
static Constraint |
addConstraint(Query query,
Constraint newConstraint)
Adds a Constraint to the already present constraint (with AND). |
static Constraint |
addConstraints(Query query,
java.lang.String constraints)
Adds a 'legacy' constraint to the query, i.e. |
static java.util.List |
addFields(Query query,
java.lang.String fields)
Adds a number of fields. |
static java.util.List |
addPath(Query query,
java.lang.String path,
java.lang.String searchDirs)
Adds path of steps to an existing query. |
static java.util.List |
addSortOrders(Query query,
java.lang.String sorted,
java.lang.String directions)
Adds sort orders to the query, using two strings. |
static void |
addStartNodes(Query query,
java.lang.String startNodes)
Add startNodes to the first step with the correct type to the given query. |
static Constraint |
copyConstraint(Constraint c,
Step sourceStep,
Query query,
Step step)
Takes a Constraint of a query, and takes al constraints on 'sourceStep' of it, and copies those Constraints to the given step of the receiving query. |
static void |
copySortOrders(java.util.List sortOrders,
Step sourceStep,
Query query,
Step step)
Copies SortOrders to a given step of another query. |
static int |
count(Query query)
Takes the query, and does a count with the same constraints (so ignoring 'offset' and 'max') |
static Constraint |
createConstraint(Query query,
java.lang.String fieldName,
int operator,
java.lang.Object value)
Defaulting version of createConstraint(Query, String, int, Object, Object, boolean). |
static Constraint |
createConstraint(Query query,
java.lang.String fieldName,
int operator,
java.lang.Object value,
java.lang.Object value2,
boolean caseSensitive)
Creates a constraint smartly, depending on the type of the field, the value is casted to the right type, and the right type of constraint is created. |
static NodeQuery |
createNodeQuery(Node node)
Returns the NodeQuery returning the given Node. |
static Query |
createQuery(Cloud cloud,
java.lang.String startNodes,
java.lang.String nodePath,
java.lang.String fields,
java.lang.String constraints,
java.lang.String orderby,
java.lang.String directions,
java.lang.String searchDir,
boolean distinct)
Creates a Query object using arguments for Cloud.getList(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) (this function is of course
implemented using this utility). |
static NodeQuery |
createRelatedNodesQuery(Node node,
NodeManager otherNodeManager,
java.lang.String role,
java.lang.String direction)
Returns a query to find the nodes related to the given node. |
static NodeQuery |
createRelationNodesQuery(Node node,
NodeManager otherNodeManager,
java.lang.String role,
java.lang.String direction)
Returns a query to find the relations nodes of the given node. |
protected static java.lang.Object |
getCompareValue(int fieldType,
int operator,
java.lang.Object value)
Used in implementation of createConstraint |
protected static java.lang.Number |
getNumberValue(java.lang.String stringValue)
Used in implementation of createConstraint |
static int |
getOperator(java.lang.String s)
Creates a operator constant for use by createConstraint |
static int |
getRelationStepDirection(java.lang.String search)
Translates a string to a search direction constant. |
static int |
getSortOrder(java.lang.String dir)
Converts a String to a SortOrder constant |
protected static java.lang.String |
removeDigits(java.lang.String complete)
Returns substring of given string without the leading digits (used in 'paths') |
static Step |
searchStep(java.util.List steps,
java.lang.String stepAlias)
Searches a list of Steps for a step with a certain name. |
static Query |
sortUniquely(Query q)
Add a sortorder (DESCENDING) on al the'number' fields of the query, on which there is not yet a sortorder. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int OPERATOR_BETWEEN
public static final int OPERATOR_IN
public static final int OPERATOR_NULL
| Constructor Detail |
public Queries()
| Method Detail |
public static int getRelationStepDirection(java.lang.String search)
null then
'BOTH' is returned.
The same function, only with another return value if String is null
public static Query createQuery(Cloud cloud,
java.lang.String startNodes,
java.lang.String nodePath,
java.lang.String fields,
java.lang.String constraints,
java.lang.String orderby,
java.lang.String directions,
java.lang.String searchDir,
boolean distinct)
Cloud.getList(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) (this function is of course
implemented using this utility). This is useful to convert (legacy) code which uses
getList, but you want to use new Query features without rewriting the complete thing.
It can also be simply handy to specify things as Strings.
public static Constraint addConstraints(Query query,
java.lang.String constraints)
public static Constraint addConstraint(Query query,
Constraint newConstraint)
public static int getOperator(java.lang.String s)
createConstraint(org.mmbase.bridge.Query, java.lang.String, int, java.lang.Object)
protected static java.lang.Number getNumberValue(java.lang.String stringValue)
throws BridgeException
BridgeException
protected static java.lang.Object getCompareValue(int fieldType,
int operator,
java.lang.Object value)
public static Constraint createConstraint(Query query,
java.lang.String fieldName,
int operator,
java.lang.Object value)
createConstraint(Query, String, int, Object, Object, boolean).
Casesensitivity defaults to false, value2 to null (so 'BETWEEN' cannot be used).
public static Constraint createConstraint(Query query,
java.lang.String fieldName,
int operator,
java.lang.Object value,
java.lang.Object value2,
boolean caseSensitive)
query - The query to create the constraint forfieldName - The field to create the constraint on (as a string, so it can include the step), e.g. 'news.number'operator - The operator to use. This constant can be produces from a string using getOperator(String).value - The value to compare with, which must be of the right type. If field is number it might also be an alias.value2 - The other value (only relevant if operator is BETWEEN, the only terniary operator)caseSensitive - Whether it should happen case sensitively (not relevant for number fields)
null it by chance the specified arguments did not lead to a new actual constraint (e.g. if value is an empty set)
public static Constraint copyConstraint(Constraint c,
Step sourceStep,
Query query,
Step step)
sourceStep - The step in the 'source' query.query - The receiving querystep - The step of the receiving query which must 'receive' the sort orders.
java.lang.IllegalArgumentException - If the given constraint is not compatible with the given step.
UnsuporteOperationException - If CompareFieldsConstraints or LegacyConstraints are encountered.Functions are similar
public static void copySortOrders(java.util.List sortOrders,
Step sourceStep,
Query query,
Step step)
sortOrders - A list of SortOrders (for example the result of sourceQuery.getSortOrders()).sourceStep - The step in the 'source' query.query - The receiving querystep - The step of the receiving query which must 'receive' the sort orders.public static int getSortOrder(java.lang.String dir)
public static java.util.List addSortOrders(Query query,
java.lang.String sorted,
java.lang.String directions)
protected static java.lang.String removeDigits(java.lang.String complete)
public static java.util.List addPath(Query query,
java.lang.String path,
java.lang.String searchDirs)
public static java.util.List addFields(Query query,
java.lang.String fields)
public static void addStartNodes(Query query,
java.lang.String startNodes)
(this is essentially a 'bridge' version of the startnodes part)public static int count(Query query)
public static Step searchStep(java.util.List steps,
java.lang.String stepAlias)
java.lang.ClassCastException - if list does not contain only Stepspublic static NodeQuery createNodeQuery(Node node)
public static NodeQuery createRelatedNodesQuery(Node node,
NodeManager otherNodeManager,
java.lang.String role,
java.lang.String direction)
public static NodeQuery createRelationNodesQuery(Node node,
NodeManager otherNodeManager,
java.lang.String role,
java.lang.String direction)
public static Query sortUniquely(Query q)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||