org.mmbase.bridge
Interface Query

All Superinterfaces:
java.lang.Cloneable, SearchQuery
All Known Subinterfaces:
NodeQuery
All Known Implementing Classes:
BasicNodeQuery, BasicQuery

public interface Query
extends SearchQuery, java.lang.Cloneable

Representation of a (database) query. It is modifiable for use by bridge-users.

Since:
MMBase-1.7
Version:
$Id: Query.java,v 1.23.2.1 2004/07/29 17:13:12 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
Queries

Field Summary
 
Fields inherited from interface org.mmbase.storage.search.SearchQuery
DEFAULT_MAX_NUMBER, DEFAULT_OFFSET
 
Method Summary
 AggregatedField addAggregatedField(Step step, Field field, int aggregationType)
          Add an aggregated field to a step
 StepField addField(Step step, Field field)
          Adds a field to a step.
 StepField addField(java.lang.String field)
          Adds a field by string
 void addNode(Step s, Node node)
          Adds a node to a step.
 RelationStep addRelationStep(NodeManager otherManager)
           
 RelationStep addRelationStep(NodeManager nodeManager, java.lang.String role, java.lang.String searchDir)
          Adds new Relation step to the query.
 SortOrder addSortOrder(StepField f, int direction)
          Adds an order on a certain field.
 Step addStep(NodeManager nodeManager)
          Adds a NodeManager to this Query.
 Query aggregatingClone()
          Creates an unused aggregate clone of this query.
 java.lang.Object clone()
          Create an (unused) clone
 Query cloneWithoutFields()
          Clones this object, only without the fields
 CompositeConstraint createConstraint(Constraint c1, int op, Constraint c2)
          Combines two Constraints to one new one, using a boolean operator (AND or OR).
 FieldNullConstraint createConstraint(StepField f)
          Create a contraint (for use with this Query object).
 FieldValueConstraint createConstraint(StepField f, int op, java.lang.Object v)
          Create a contraint (for use with this Query object).
 CompareFieldsConstraint createConstraint(StepField f, int op, StepField v)
          Create a contraint (for use with this Query object).
 FieldValueConstraint createConstraint(StepField f, java.lang.Object v)
          Create a contraint (for use with this Query object).
 FieldValueBetweenConstraint createConstraint(StepField f, java.lang.Object o1, java.lang.Object o2)
          Create a contraint (for use with this Query object).
 FieldValueInConstraint createConstraint(StepField f, java.util.SortedSet v)
          Create a contraint (for use with this Query object).
 LegacyConstraint createConstraint(java.lang.String s)
          Create a contraint (for use with this Query object).
 StepField createStepField(Step step, Field field)
          Creates a StepField object withouth adding it (needed for aggregated queries).
 StepField createStepField(Step step, java.lang.String fieldName)
           
 StepField createStepField(java.lang.String fieldIdentifer)
          Creates the step field for the given name.
 Constraint getCleanConstraint()
          Gets the 'clean' constraint on this query.
 Cloud getCloud()
          Returns the Cloud for which this Query was defined.
 Step getStep(java.lang.String stepAlias)
          Returns the step with given alias, or null if it is not present
 boolean isAggregating()
          Wheter this query is 'aggregating'.
 boolean isUsed()
          Whether this query was used or not.
 boolean markUsed()
          Mark this query 'used'.
 void removeFields()
          Removes all fields from the Query object.
 void setAlias(Step step, java.lang.String alias)
          Sets the alias to the given step.
 FieldConstraint setCaseSensitive(FieldConstraint constraint, boolean sensitive)
          Changes the given constraint's 'case sensitivity' (if applicable).
 void setConstraint(Constraint c)
          The (composite) constraint can actually be set into the query with this method.
 Query setDistinct(boolean distinct)
          Specifies wether the query result must contain only 'distinct' results.
 Constraint setInverse(Constraint c, boolean i)
          Changes the given constraint's 'inverse' (if applicable).
 Query setMaxNumber(int maxNumber)
          Limits the query-result to maxNumber records.
 Query setOffset(int offset)
          Offsets the query-result with offset records.
 
Methods inherited from interface org.mmbase.storage.search.SearchQuery
equals, getConstraint, getFields, getMaxNumber, getOffset, getSortOrders, getSteps, hashCode, isDistinct, toString
 

Method Detail

getCloud

public Cloud getCloud()
Returns the Cloud for which this Query was defined.


isAggregating

public boolean isAggregating()
Wheter this query is 'aggregating'. You can only use 'addAggregatedField' on aggregating querys.

Specified by:
isAggregating in interface SearchQuery
To Do:
Should this not appear in SearchQuery itself? Or should there be an AggregatingQuery interface? It is now used in BasicCloud.getList.

addStep

public Step addStep(NodeManager nodeManager)
Adds a NodeManager to this Query. This can normally be done only once. After that you need to use (one of the) 'addRelationStep'.

Parameters:
nodeManager - The nodeManager associated with the step.
Returns:
The 'step' wrapping the NodeManager.
Throws:
java.lang.IllegalArgumentException - when an invalid argument is supplied.
See Also:
addRelationStep(org.mmbase.bridge.NodeManager, java.lang.String, java.lang.String)

setAlias

public void setAlias(Step step,
                     java.lang.String alias)
Sets the alias to the given step.

Parameters:
alias - The alias which must be given to the step. If it is "" an alias should be generated. 'null' removes the alias.

getStep

public Step getStep(java.lang.String stepAlias)
Returns the step with given alias, or null if it is not present

Parameters:
stepAlias - Alias for the step (may also be tableName, in which case the first step for this table is returned)

addRelationStep

public RelationStep addRelationStep(NodeManager nodeManager,
                                    java.lang.String role,
                                    java.lang.String searchDir)
Adds new Relation step to the query. Adds the next step as well, it can be retrieved by calling getNext() on the relationstep, and cast to Step.

Throws:
java.lang.IllegalArgumentException - when an invalid argument is supplied.
java.lang.IllegalStateException - when there is no previous step.

addRelationStep

public RelationStep addRelationStep(NodeManager otherManager)

addField

public StepField addField(Step step,
                          Field field)
Adds a field to a step.


addField

public StepField addField(java.lang.String field)
Adds a field by string


removeFields

public void removeFields()
Removes all fields from the Query object.


createStepField

public StepField createStepField(Step step,
                                 Field field)
Creates a StepField object withouth adding it (needed for aggregated queries).


createStepField

public StepField createStepField(Step step,
                                 java.lang.String fieldName)

createStepField

public StepField createStepField(java.lang.String fieldIdentifer)
Creates the step field for the given name. For a NodeQuery the arguments is simply the name of the field. For a 'normal' query, it should be prefixed by the (automatic) alias of the Step.


addAggregatedField

public AggregatedField addAggregatedField(Step step,
                                          Field field,
                                          int aggregationType)
Add an aggregated field to a step


setDistinct

public Query setDistinct(boolean distinct)
Specifies wether the query result must contain only 'distinct' results.

See Also:
BasicSearchQuery.setDistinct(boolean), SearchQuery.isDistinct()

setMaxNumber

public Query setMaxNumber(int maxNumber)
Limits the query-result to maxNumber records.

See Also:
BasicSearchQuery.setMaxNumber(int), SearchQuery.getMaxNumber()

setOffset

public Query setOffset(int offset)
Offsets the query-result with offset records.

See Also:
BasicSearchQuery.setOffset(int), SearchQuery.getOffset()

getCleanConstraint

public Constraint getCleanConstraint()
Gets the 'clean' constraint on this query. I.e. the constraint which were automaticly added because of security are stripped away, and it is garanteed that you get back what you put in. It is adviced that you use this in stead of SearchQuery#getConstraint, because that function is used by the Query handlers, which do need the security constraints. But otherwise you don't want to see those.

Since:
MMBase-1.7.1

createConstraint

public LegacyConstraint createConstraint(java.lang.String s)
Create a contraint (for use with this Query object). The argument is a string, as also can be used as an argument of the 'non-query' getList. This should be considered legacy.

See Also:
Cloud.getList(String startNodes, String nodePath, String fields, String constraints, String orderby, String directions, String searchDir, boolean distinct), NodeManager.getList(String constraints, String orderby, String directions)

createConstraint

public FieldNullConstraint createConstraint(StepField f)
Create a contraint (for use with this Query object). The given field must be 'null'.


createConstraint

public FieldValueConstraint createConstraint(StepField f,
                                             java.lang.Object v)
Create a contraint (for use with this Query object). The given field must equal the given value 'v'.


createConstraint

public FieldValueConstraint createConstraint(StepField f,
                                             int op,
                                             java.lang.Object v)
Create a contraint (for use with this Query object). The given field and the given value 'v', combined with given operator must evaluate to true.


createConstraint

public CompareFieldsConstraint createConstraint(StepField f,
                                                int op,
                                                StepField v)
Create a contraint (for use with this Query object). The two given fields , combined with given operator must evaluate to true.


createConstraint

public FieldValueBetweenConstraint createConstraint(StepField f,
                                                    java.lang.Object o1,
                                                    java.lang.Object o2)
Create a contraint (for use with this Query object). The given field must lie between the two given values.


createConstraint

public FieldValueInConstraint createConstraint(StepField f,
                                               java.util.SortedSet v)
Create a contraint (for use with this Query object). The given field value must be contained by the given set of values. If the given set is empty, a FieldValueInConstraint will be constructed for the number field in stead ('number IN (-1)'), which ensures that also in that case the logical thing will happen. (' IN ()' fails in most databases).

Returns:
the new Constraint.

setCaseSensitive

public FieldConstraint setCaseSensitive(FieldConstraint constraint,
                                        boolean sensitive)
Changes the given constraint's 'case sensitivity' (if applicable). Default it is true.


setInverse

public Constraint setInverse(Constraint c,
                             boolean i)
Changes the given constraint's 'inverse' (if applicable). Default it is (of course) false.


createConstraint

public CompositeConstraint createConstraint(Constraint c1,
                                            int op,
                                            Constraint c2)
Combines two Constraints to one new one, using a boolean operator (AND or OR). Every new constraint must be combined with the ones you already have with such a new CompositeConstraint. If the first constraint is a composite constraint (with the same logical operator), then the second one will simply be added.

Returns:
a Composite constraint (might not be a new one)

setConstraint

public void setConstraint(Constraint c)
The (composite) constraint can actually be set into the query with this method.


addSortOrder

public SortOrder addSortOrder(StepField f,
                              int direction)
Adds an order on a certain field.

See Also:
BasicSearchQuery.addSortOrder(org.mmbase.storage.search.StepField), SearchQuery.getSortOrders()

addNode

public void addNode(Step s,
                    Node node)
Adds a node to a step.


isUsed

public boolean isUsed()
Whether this query was used or not. If is was used, then you cannot modify it anymore (would kill caches, and references to 'original query' would get invalid)


markUsed

public boolean markUsed()
Mark this query 'used'. It has to be copied first, if you want to add things to it.


clone

public java.lang.Object clone()
Create an (unused) clone


cloneWithoutFields

public Query cloneWithoutFields()
Clones this object, only without the fields


aggregatingClone

public Query aggregatingClone()
Creates an unused aggregate clone of this query. If this query is not itself aggregated, all fields are removed (but the contraints on them remain), and you can add aggregated fields then.



MMBase build 1.7.1.20041002