Java Doc for Queries.java in  » Database-ORM » MMBase » org » mmbase » bridge » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » MMBase » org.mmbase.bridge.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.mmbase.bridge.util.Queries

Queries
abstract public class Queries (Code)
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.
author:
   Michiel Meeuwissen
version:
   $Id: Queries.java,v 1.96 2008/02/29 11:00:05 michiel Exp $
See Also:   org.mmbase.bridge.Query
since:
   MMBase-1.7


Field Summary
final public static  intOPERATOR_BETWEEN
    
final public static  intOPERATOR_IN
    
final public static  intOPERATOR_NULL
    


Method Summary
public static  ConstraintaddConstraint(Query query, Constraint newConstraint)
     Adds a Constraint to the already present constraint (with AND).
public static  ConstraintaddConstraints(Query query, String constraints)
     Adds a 'legacy' constraint to the query, i.e.
public static  List<StepField>addFields(Query query, String fields)
     Adds a number of fields.
public static  List<Step>addPath(Query query, String path, String searchDirs)
     Adds path of steps to an existing query.
public static  NodeQueryaddRelationFields(NodeQuery q, String role, String relationFields, String sortOrders)
    
public static  List<SortOrder>addSortOrders(Query query, String sorted, String directions)
     Adds sort orders to the query, using two strings.
public static  QueryaddSortedFields(Query q)
    
public static  voidaddStartNodes(Query query, String startNodes)
     Add startNodes to the first step with the correct type to the given query.
protected static  Objectaggregate(Query query, StepField field, int type)
    
public static  intcompare(Node node1, Node node2, SortOrder sortOrder)
     Compare tho nodes, with a SortOrder.
public static  intcompare(Object value, Object value2, SortOrder sortOrder)
    
public static  intcompare(Node node1, Node node2, List<SortOrder> sortOrders)
     Does a field-by-field compare of two Node objects, on the fields used to order the nodes.
public static  ConstraintcopyConstraint(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. Constraints on different steps then the given 'sourceStep' are ignored.
public static  voidcopySortOrders(List<SortOrder> sortOrders, Step sourceStep, Query query, Step step)
     Copies SortOrders to a given step of another query.
public static  intcount(Query query)
    
public static  ConstraintcreateConstraint(Query query, String fieldName, int operator, Object value)
     Defaulting version of Queries.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)
Parameters:
  query - The query to create the constraint for
Parameters:
  fieldName - The field to create the constraint on (as a string, so it can include the step), e.g.
public static  ConstraintcreateConstraint(Query query, String fieldName, int operator, Object value, Object value2, boolean caseSensitive)
     Defaulting version of Queries.createConstraint(Query,String,int,Object,Object,boolean,int) . DatePart set to -1 (so no date part comparison)
Parameters:
  query - The query to create the constraint for
Parameters:
  fieldName - The field to create the constraint on (as a string, so it can include the step), e.g.
public static  ConstraintcreateConstraint(Query query, String fieldName, int operator, Object originalValue, Object value2, boolean caseSensitive, int datePart)
     Creates a constraint smartly, depending on the type of the field, the value is cast to the right type, and the right type of constraint is created. This is used in taglib implementation, but could be useful more generally.
Parameters:
  query - The query to create the constraint for
Parameters:
  fieldName - The field to create the constraint on (as a string, so it can include the step), e.g.
public static  NodeQuerycreateNodeQuery(Node node)
     Returns the NodeQuery returning the given Node.
public static  QuerycreateQuery(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(StringStringStringStringStringStringStringboolean) (this function is of course implemented using this utility).
public static  NodeQuerycreateRelatedNodesQuery(Node node, NodeManager otherNodeManager, String role, String direction)
     Returns a query to find the nodes related to the given node.
public static  NodeQuerycreateRelationNodesQuery(Node node, NodeManager otherNodeManager, String role, String direction)
     Returns a query to find the relations nodes of the given node.
public static  NodeQuerycreateRelationNodesQuery(Node node, Node otherNode, String role, String direction)
     Returns a query to find the relations nodes between two given nodes.
protected static  ObjectgetCompareValue(int fieldType, int operator, Object value)
    
protected static  ObjectgetCompareValue(int fieldType, int operator, Object value, int datePart, Cloud cloud)
    
public static  intgetDateTimePart(String s)
    
protected static  NumbergetNumberValue(String stringValue)
    
public static  intgetOperator(String s)
    
public static  NodeListgetRelatedNodes(Node node, NodeManager otherNodeManager, String role, String direction, String relationFields, String sortOrders)
     Queries a list of cluster nodes, using a org.mmbase.bridge.NodeQuery (so al fields of one step are available), plus some fields of the relation step.
public static  intgetRelationStepDirection(String search)
     Translates a string to a search direction constant.
public static  intgetSortOrder(String dir)
    
public static  ObjectgetSortOrderFieldValue(Node node, SortOrder sortOrder)
     Obtains a value for the field of a sortorder from a given node.
public static  voidmain(String[] argv)
    
public static  Objectmax(Query query, StepField field)
    
public static  Objectmin(Query query, StepField field)
    
public static  StringremoveDigits(String complete)
    
public static  StepsearchStep(List<Step> steps, String stepAlias)
     Searches a list of Steps for a step with a certain name.
public static  QuerysortUniquely(Query q)
     Add a sortorder (DESCENDING) on al the'number' fields of the query, on which there is not yet a sortorder.

Field Detail
OPERATOR_BETWEEN
final public static int OPERATOR_BETWEEN(Code)



OPERATOR_IN
final public static int OPERATOR_IN(Code)



OPERATOR_NULL
final public static int OPERATOR_NULL(Code)





Method Detail
addConstraint
public static Constraint addConstraint(Query query, Constraint newConstraint)(Code)
Adds a Constraint to the already present constraint (with AND).
Parameters:
  query - query to add the constraint to
Parameters:
  newConstraint - constraint to add The new constraint.



addConstraints
public static Constraint addConstraints(Query query, String constraints)(Code)
Adds a 'legacy' constraint to the query, i.e. constraint(s) represented by a string. Alreading existing constraints remain ('AND' is used).
Parameters:
  query - query to add constraint to
Parameters:
  constraints - string representation of constraints The new constraint, or null if nothing changed added.



addFields
public static List<StepField> addFields(Query query, String fields)(Code)
Adds a number of fields. Fields is represented as a comma separated string.
Parameters:
  query - The query where the fields should be added to
Parameters:
  fields - a comma separated string of fields The new stepfields



addPath
public static List<Step> addPath(Query query, String path, String searchDirs)(Code)
Adds path of steps to an existing query. The query may contain steps already. Per step also the 'search direction' may be specified.
Parameters:
  query - extend this query
Parameters:
  path - create steps from this path
Parameters:
  searchDirs - add steps with these relation directions The new steps.



addRelationFields
public static NodeQuery addRelationFields(NodeQuery q, String role, String relationFields, String sortOrders)(Code)

since:
   MMBase-1.8



addSortOrders
public static List<SortOrder> addSortOrders(Query query, String sorted, String directions)(Code)
Adds sort orders to the query, using two strings. Like in 'getList' of Cloud. Several tag-attributes need this.
Parameters:
  query - query to add the sortorders to
Parameters:
  sorted - string with comma-separated fields
Parameters:
  directions - string with comma-separated directions The new sort orders



addSortedFields
public static Query addSortedFields(Query q)(Code)
Make sure all sorted fields are queried
since:
   MMBase-1.8



addStartNodes
public static void addStartNodes(Query query, String startNodes)(Code)
Add startNodes to the first step with the correct type to the given query. The nodes are identified by a String, which could be prefixed with a step-alias, if you want to add the nodes to another then this found step. Furthermore may the nodes by identified by their alias, if they have one.
Parameters:
  query - query to add the startnodes
Parameters:
  startNodes - start nodes
See Also:   org.mmbase.module.core.ClusterBuilder.getMultiLevelSearchQuery(ListListStringListStringListListint)
See Also:   (this is essentially a 'bridge' version of the startnodes part)



aggregate
protected static Object aggregate(Query query, StepField field, int type)(Code)

since:
   MMBase-1.8



compare
public static int compare(Node node1, Node node2, SortOrder sortOrder)(Code)
Compare tho nodes, with a SortOrder. This determins where a certain node is smaller or bigger than a certain other node, with respect to some SortOrder. This is used by Queries.compare(Node,Node,List) If node2 is only 'longer' then node1, but otherwise equal, then it is bigger.
since:
   MMBase-1.8



compare
public static int compare(Object value, Object value2, SortOrder sortOrder)(Code)

since:
   MMBase-1.8



compare
public static int compare(Node node1, Node node2, List<SortOrder> sortOrders)(Code)
Does a field-by-field compare of two Node objects, on the fields used to order the nodes. This is used to determine whether a node comes after or before another, in a certain query result. -1 if node1 is smaller than node 2, 0 if both nodes are equals, and +1 is node 1 is greater than node 2.
since:
   MMBase-1.8



copyConstraint
public static Constraint copyConstraint(Constraint c, Step sourceStep, Query query, Step step)(Code)
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. Constraints on different steps then the given 'sourceStep' are ignored. CompositeConstraints cause recursion and would work too (but same limitation are valid for the childs).
Parameters:
  c - The constrain to be copied (for example the result of sourceQuery.getConstraint()).
Parameters:
  sourceStep - The step in the 'source' query.
Parameters:
  query - The receiving query
Parameters:
  step - The step of the receiving query which must 'receive' the sort orders.
since:
   MMBase-1.7.1
See Also:   org.mmbase.storage.search.implementation.BasicSearchQuery.copyConstraint
See Also:    Functions are similar
throws:
  IllegalArgumentException - If the given constraint is not compatible with the given step.
throws:
  UnsupportedOperationException - If CompareFieldsConstraints or LegacyConstraints are encountered. The new constraint or null



copySortOrders
public static void copySortOrders(List<SortOrder> sortOrders, Step sourceStep, Query query, Step step)(Code)
Copies SortOrders to a given step of another query. SortOrders which do not sort the given 'sourceStep' are ignored.
Parameters:
  sortOrders - A list of SortOrders (for example the result of sourceQuery.getSortOrders()).
Parameters:
  sourceStep - The step in the 'source' query.
Parameters:
  query - The receiving query
Parameters:
  step - The step of the receiving query which must 'receive' the sort orders.
since:
   MMBase-1.7.1



count
public static int count(Query query)(Code)
Takes the query, and does a count with the same constraints (so ignoring 'offset' and 'max')
Parameters:
  query - query as base for the count number of results



createConstraint
public static Constraint createConstraint(Query query, String fieldName, int operator, Object value)(Code)
Defaulting version of Queries.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)
Parameters:
  query - The query to create the constraint for
Parameters:
  fieldName - The field to create the constraint on (as a string, so it can include the step), e.g. 'news.number'
Parameters:
  operator - The operator to use. This constant can be produces from a string using Queries.getOperator(String).
Parameters:
  value - The value to compare with, which must be of the right type. If field is number it might also be an alias. The new constraint, or null it by chance the specified arguments did not lead to a new actual constraint (e.g. if value is an empty set)



createConstraint
public static Constraint createConstraint(Query query, String fieldName, int operator, Object value, Object value2, boolean caseSensitive)(Code)
Defaulting version of Queries.createConstraint(Query,String,int,Object,Object,boolean,int) . DatePart set to -1 (so no date part comparison)
Parameters:
  query - The query to create the constraint for
Parameters:
  fieldName - The field to create the constraint on (as a string, so it can include the step), e.g. 'news.number'
Parameters:
  operator - The operator to use. This constant can be produces from a string using Queries.getOperator(String).
Parameters:
  value - The value to compare with, which must be of the right type. If field is number it might also be an alias.
Parameters:
  value2 - The other value (only relevant if operator is BETWEEN, the only terniary operator)
Parameters:
  caseSensitive - Whether it should happen case sensitively (not relevant for number fields) The new constraint, or null it by chance the specified arguments did not lead to a new actual constraint (e.g. if value is an empty set)



createConstraint
public static Constraint createConstraint(Query query, String fieldName, int operator, Object originalValue, Object value2, boolean caseSensitive, int datePart)(Code)
Creates a constraint smartly, depending on the type of the field, the value is cast to the right type, and the right type of constraint is created. This is used in taglib implementation, but could be useful more generally.
Parameters:
  query - The query to create the constraint for
Parameters:
  fieldName - The field to create the constraint on (as a string, so it can include the step), e.g. 'news.number'
Parameters:
  operator - The operator to use. This constant can be produces from a string using Queries.getOperator(String).
Parameters:
  value - The value to compare with, which must be of the right type. If field is number it might also be an alias.
Parameters:
  value2 - The other value (only relevant if operator is BETWEEN, the only terniary operator)
Parameters:
  caseSensitive - Whether it should happen case sensitively (not relevant for number fields)
Parameters:
  datePart - The part of a DATETIME value that is to be checked The new constraint, or null it by chance the specified arguments did not lead to a new actual constraint (e.g. if value is an empty set)



createNodeQuery
public static NodeQuery createNodeQuery(Node node)(Code)
Returns the NodeQuery returning the given Node. This query itself is not very useful, because you already have its result (the node), but it is convenient as a base query for many other goals. If the node is uncommited, it cannot be queried, and the node query returning all nodes from the currect type will be returned.
Parameters:
  node - Node to create the query from A new NodeQuery object



createQuery
public static Query createQuery(Cloud cloud, String startNodes, String nodePath, String fields, String constraints, String orderby, String directions, String searchDir, boolean distinct)(Code)
Creates a Query object using arguments for Cloud.getList(StringStringStringStringStringStringStringboolean) (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.
Parameters:
  cloud -
Parameters:
  startNodes -
Parameters:
  nodePath -
Parameters:
  fields -
Parameters:
  constraints -
Parameters:
  orderby -
Parameters:
  directions -
Parameters:
  searchDir -
Parameters:
  distinct - New query object



createRelatedNodesQuery
public static NodeQuery createRelatedNodesQuery(Node node, NodeManager otherNodeManager, String role, String direction)(Code)
Returns a query to find the nodes related to the given node.
Parameters:
  node - start node
Parameters:
  otherNodeManager - node manager on the other side of the relation
Parameters:
  role - role of the relation
Parameters:
  direction - direction of the relation A new NodeQuery object



createRelationNodesQuery
public static NodeQuery createRelationNodesQuery(Node node, NodeManager otherNodeManager, String role, String direction)(Code)
Returns a query to find the relations nodes of the given node.
Parameters:
  node - start node
Parameters:
  otherNodeManager - node manager on the other side of the relation
Parameters:
  role - role of the relation
Parameters:
  direction - direction of the relation A new NodeQuery object



createRelationNodesQuery
public static NodeQuery createRelationNodesQuery(Node node, Node otherNode, String role, String direction)(Code)
Returns a query to find the relations nodes between two given nodes. To test whether to nodes are related you can use e.g.: if (Queries.count(Queries.createRelationNodesQuery(node1, node2, "posrel", null)) > 0) { .. }
Parameters:
  node - start node
Parameters:
  otherNode - node on the other side of the relation
Parameters:
  role - role of the relation
Parameters:
  direction - direction of the relation A new NodeQuery object
since:
   MMBase-1.8



getCompareValue
protected static Object getCompareValue(int fieldType, int operator, Object value)(Code)
Used in implementation of createConstraint
Parameters:
  fieldType - Field Type constant (@link Field)
Parameters:
  operator - Compare operator
Parameters:
  value - value to convert new Compare value



getCompareValue
protected static Object getCompareValue(int fieldType, int operator, Object value, int datePart, Cloud cloud)(Code)
Used in implementation of createConstraint
Parameters:
  fieldType - Field Type constant (@link Field)
Parameters:
  operator - Compare operator
Parameters:
  value - value to convert
Parameters:
  cloud - The cloud may be used to pass locale sensitive properties which may be needed for comparisions (locales, timezones) new Compare value
since:
   MMBase-1.8.2



getDateTimePart
public static int getDateTimePart(String s)(Code)
Creates a part constant for use by createConstraint
Parameters:
  s - String representation of a datetime part FieldValueDateConstraint part constant
See Also:   Queries.createConstraint(Query,String,int,Object,Object,boolean,int)



getNumberValue
protected static Number getNumberValue(String stringValue) throws BridgeException(Code)
Used in implementation of createConstraint
Parameters:
  stringValue - string representation of a number Number object
throws:
  BridgeException - when failed to convert the string



getOperator
public static int getOperator(String s)(Code)
Creates a operator constant for use by createConstraint
Parameters:
  s - String representation of operator FieldCompareConstraint operator constant
See Also:   Queries.createConstraint(Query,String,int,Object)
See Also:   Queries.createConstraint(Query,String,int,Object,Object,boolean)



getRelatedNodes
public static NodeList getRelatedNodes(Node node, NodeManager otherNodeManager, String role, String direction, String relationFields, String sortOrders)(Code)
Queries a list of cluster nodes, using a org.mmbase.bridge.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 org.mmbase.bridge.Node.getNodeValue with the org.mmbase.bridge.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).
Parameters:
  node - start node
Parameters:
  otherNodeManager - node manager on the other side of the relation
Parameters:
  role - role of the relation
Parameters:
  direction - direction of the relation
Parameters:
  relationFields - Comma separated string of fields which must be queried from the relation step
Parameters:
  sortOrders - Comma separated string of fields of sortorders, or the empty string or nullSo, this methods is targeted at the use of 'posrel' and similar fields, because sorting on other fields isn't possible right now.
since:
   MMBase-1.8



getRelationStepDirection
public static int getRelationStepDirection(String search)(Code)
Translates a string to a search direction constant. If the string is null then 'BOTH' is returned.
Parameters:
  search - string representation of the searchdir constant Searchdir constant as in RelationStep
See Also:   ClusterBuilder.getSearchDir
See Also:    The same function, only with another return value if String is null



getSortOrder
public static int getSortOrder(String dir)(Code)
Converts a String to a SortOrder constant
Parameters:
  dir - string representation of direction of sortorder SortOrder constant
since:
   MMBase-1.7.1



getSortOrderFieldValue
public static Object getSortOrderFieldValue(Node node, SortOrder sortOrder)(Code)
Obtains a value for the field of a sortorder from a given node. Used to set constraints based on sortorder.
since:
   MMBase-1.8



main
public static void main(String[] argv)(Code)



max
public static Object max(Query query, StepField field)(Code)

since:
   MMBase-1.8



min
public static Object min(Query query, StepField field)(Code)

since:
   MMBase-1.8



removeDigits
public static String removeDigits(String complete)(Code)
Returns substring of given string without the leading digits (used in 'paths')
Parameters:
  complete - string with leading digits string with digits removed



searchStep
public static Step searchStep(List<Step> steps, String stepAlias)(Code)
Searches a list of Steps for a step with a certain name. (alias or tableName)
Parameters:
  steps - steps to search through
Parameters:
  stepAlias - alias to search for The Step if found, otherwise null
throws:
  ClassCastException - if list does not contain only Steps



sortUniquely
public static Query sortUniquely(Query q)(Code)
Add a sortorder (DESCENDING) on al the'number' fields of the query, on which there is not yet a sortorder. This ensures that the query result is ordered uniquely.
Parameters:
  q - query to change The changed Query



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.