|
||||||||||
| 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 objects. 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,
String constraints)
Adds a 'legacy' constraint to the query, i.e. |
static List |
addFields(Query query,
String fields)
Adds a number of fields. |
static List |
addPath(Query query,
String path,
String searchDirs)
Adds path of steps to an existing query. |
static NodeQuery |
addRelationFields(NodeQuery q,
String role,
String relationFields,
String sortOrders)
|
static Query |
addSortedFields(Query q)
Make sure all sorted fields are queried |
static List |
addSortOrders(Query query,
String sorted,
String directions)
Adds sort orders to the query, using two strings. |
static void |
addStartNodes(Query query,
String startNodes)
Add startNodes to the first step with the correct type to the given query. |
protected static Object |
aggregate(Query query,
StepField field,
int type)
|
static int |
compare(Node node1,
Node node2,
List sortOrders)
Does a field-by-field compare of two Node objects, on the fields used to order the nodes. |
static int |
compare(Node node1,
Node node2,
SortOrder sortOrder)
Compare tho nodes, with a SortOrder. |
static int |
compare(Object value,
Object value2,
SortOrder sortOrder)
|
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(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,
String fieldName,
int operator,
Object value)
Defaulting version of createConstraint(Query, String, int, Object, Object, boolean, int). |
static Constraint |
createConstraint(Query query,
String fieldName,
int operator,
Object value,
Object value2,
boolean caseSensitive)
Defaulting version of createConstraint(Query, String, int, Object, Object, boolean, int). |
static Constraint |
createConstraint(Query query,
String fieldName,
int operator,
Object value,
Object value2,
boolean caseSensitive,
int datePart)
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,
String startNodes,
String nodePath,
String fields,
String constraints,
String orderby,
String directions,
String searchDir,
boolean distinct)
Creates a Query object using arguments for Cloud.getList(String, String, String, String, String, String, String, boolean)
(this function is of course implemented using this utility). |
static NodeQuery |
createRelatedNodesQuery(Node node,
NodeManager otherNodeManager,
String role,
String direction)
Returns a query to find the nodes related to the given node. |
static NodeQuery |
createRelationNodesQuery(Node node,
NodeManager otherNodeManager,
String role,
String direction)
Returns a query to find the relations nodes of the given node. |
static NodeQuery |
createRelationNodesQuery(Node node,
Node otherNode,
String role,
String direction)
Returns a query to find the relations nodes between two given nodes. |
protected static Object |
getCompareValue(int fieldType,
int operator,
Object value)
Used in implementation of createConstraint |
protected static Object |
getCompareValue(int fieldType,
int operator,
Object value,
int datePart)
Used in implementation of createConstraint |
static int |
getDateTimePart(String s)
Creates a part constant for use by createConstraint |
protected static Number |
getNumberValue(String stringValue)
Used in implementation of createConstraint |
static int |
getOperator(String s)
Creates a operator constant for use by createConstraint |
static NodeList |
getRelatedNodes(Node node,
NodeManager otherNodeManager,
String role,
String direction,
String relationFields,
String sortOrders)
Queries a list of cluster nodes, using a NodeQuery (so al fields of
one step are available), plus some fields of the relation step. |
static int |
getRelationStepDirection(String search)
Translates a string to a search direction constant. |
static int |
getSortOrder(String dir)
Converts a String to a SortOrder constant |
static Object |
getSortOrderFieldValue(Node node,
SortOrder sortOrder)
Obtains a value for the field of a sortorder from a given node. |
static void |
main(String[] argv)
|
static Object |
max(Query query,
StepField field)
|
static Object |
min(Query query,
StepField field)
|
protected static String |
removeDigits(String complete)
Returns substring of given string without the leading digits (used in 'paths') |
static Step |
searchStep(List steps,
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(String search)
null then
'BOTH' is returned.
search - string representation of the searchdir constant
The same function, only with another return value if String is null
public static Query createQuery(Cloud cloud,
String startNodes,
String nodePath,
String fields,
String constraints,
String orderby,
String directions,
String searchDir,
boolean distinct)
Cloud.getList(String, String, String, String, String, String, 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.
cloud - startNodes - nodePath - fields - constraints - orderby - directions - searchDir - distinct -
public static Constraint addConstraints(Query query,
String constraints)
query - query to add constraint toconstraints - string representation of constraints
public static Constraint addConstraint(Query query,
Constraint newConstraint)
query - query to add the constraint tonewConstraint - constraint to add
public static int getOperator(String s)
s - String representation of operator
createConstraint(Query, String, int, Object),
createConstraint(Query, String, int, Object, Object, boolean)public static int getDateTimePart(String s)
s - String representation of a datetime part
createConstraint(Query, String, int, Object, Object, boolean, int)
protected static Number getNumberValue(String stringValue)
throws BridgeException
stringValue - string representation of a number
BridgeException - when failed to convert the string
protected static Object getCompareValue(int fieldType,
int operator,
Object value)
fieldType - Field Type constant (@link Field)operator - Compare operatorvalue - value to convert
protected static Object getCompareValue(int fieldType,
int operator,
Object value,
int datePart)
fieldType - Field Type constant (@link Field)operator - Compare operatorvalue - value to convert
public static Constraint createConstraint(Query query,
String fieldName,
int operator,
Object value)
createConstraint(Query, String, int, Object, Object, boolean, int).
Casesensitivity defaults to false, value2 to null (so 'BETWEEN' cannot be used), datePart set to -1 (so no date part comparison)
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.
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 createConstraint(Query query,
String fieldName,
int operator,
Object value,
Object value2,
boolean caseSensitive)
createConstraint(Query, String, int, Object, Object, boolean, int).
DatePart set to -1 (so no date part comparison)
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 createConstraint(Query query,
String fieldName,
int operator,
Object value,
Object value2,
boolean caseSensitive,
int datePart)
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)datePart - The part of a DATETIME value that is to be checked
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)
c - The constrain to be copied (for example the result of sourceQuery.getConstraint()).sourceStep - The step in the 'source' query.query - The receiving querystep - The step of the receiving query which must 'receive' the sort orders.
IllegalArgumentException - If the given constraint is not compatible with the given step.
UnsupportedOperationException - If CompareFieldsConstraints or LegacyConstraints are encountered.Functions are similar
public static void copySortOrders(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(String dir)
dir - string representation of direction of sortorder
public static List addSortOrders(Query query,
String sorted,
String directions)
query - query to add the sortorders tosorted - string with comma-separated fieldsdirections - string with comma-separated directions
protected static String removeDigits(String complete)
complete - string with leading digits
public static List addPath(Query query,
String path,
String searchDirs)
query - extend this querypath - create steps from this pathsearchDirs - add steps with these relation directions
public static List addFields(Query query,
String fields)
query - The query where the fields should be added tofields - a comma separated string of fields
public static void addStartNodes(Query query,
String startNodes)
query - query to add the startnodesstartNodes - start nodes(this is essentially a 'bridge' version of the startnodes part)public static int count(Query query)
query - query as base for the count
protected static Object aggregate(Query query,
StepField field,
int type)
public static Object min(Query query,
StepField field)
public static Object max(Query query,
StepField field)
public static Step searchStep(List steps,
String stepAlias)
steps - steps to search throughstepAlias - alias to search for
ClassCastException - if list does not contain only Stepspublic static NodeQuery createNodeQuery(Node node)
node - Node to create the query from
public static NodeQuery createRelatedNodesQuery(Node node,
NodeManager otherNodeManager,
String role,
String direction)
node - start nodeotherNodeManager - node manager on the other side of the relationrole - role of the relationdirection - direction of the relation
public static NodeQuery createRelationNodesQuery(Node node,
NodeManager otherNodeManager,
String role,
String direction)
node - start nodeotherNodeManager - node manager on the other side of the relationrole - role of the relationdirection - direction of the relation
public static NodeQuery createRelationNodesQuery(Node node,
Node otherNode,
String role,
String direction)
if (Queries.count(Queries.createRelationNodesQuery(node1, node2, "posrel", null)) > 0) {
..
}
node - start nodeotherNode - node on the other side of the relationrole - role of the relationdirection - direction of the relation
public static NodeList getRelatedNodes(Node node,
NodeManager otherNodeManager,
String role,
String direction,
String relationFields,
String sortOrders)
NodeQuery (so al fields of
one step are available), plus some fields of the relation step. The actual node can be got
from the node cache by doing a Node.getNodeValue(java.lang.String) with the NodeList.NODESTEP_PROPERTY property. The fields of the relation can be got by
prefixing their names by the role and a dot (as normal in multilevel results).
node - start nodeotherNodeManager - node manager on the other side of the relationrole - role of the relationdirection - direction of the relationrelationFields - Comma separated string of fields which must be queried from the relation stepsortOrders - Comma separated string of fields of sortorders, or the empty string or null
So, this methods is targeted at the use of 'posrel' and similar fields, because sorting on other fields isn't possible right now.
public static NodeQuery addRelationFields(NodeQuery q,
String role,
String relationFields,
String sortOrders)
public static Query sortUniquely(Query q)
q - query to change
public static Query addSortedFields(Query q)
public static Object getSortOrderFieldValue(Node node,
SortOrder sortOrder)
public static int compare(Node node1,
Node node2,
SortOrder sortOrder)
compare(Node, Node, List)
If node2 is only 'longer' then node1, but otherwise equal, then it is bigger.
public static int compare(Object value,
Object value2,
SortOrder sortOrder)
public static int compare(Node node1,
Node node2,
List sortOrders)
public static void main(String[] argv)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||