org.mmbase.bridge.implementation
Class BasicQuery

java.lang.Object
  extended byorg.mmbase.bridge.implementation.BasicQuery
All Implemented Interfaces:
java.lang.Cloneable, Query, SearchQuery
Direct Known Subclasses:
BasicNodeQuery

public class BasicQuery
extends java.lang.Object
implements Query

'Basic' implementation of bridge Query. Wraps a 'BasicSearchQuery' from core.

Since:
MMBase-1.7
Version:
$Id: BasicQuery.java,v 1.36.2.6 2004/07/29 17:16:37 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
BasicSearchQuery

Field Summary
protected  boolean aggregating
           
protected  Cloud cloud
          reference to the cloud.
protected  java.util.List explicitFields
          The explicitely added 'extra' fields.
protected  java.util.List implicitFields
          The implicitely added 'extra' fields.
protected  Constraint insecureConstraint
          If a the contraint was made 'secure', in insecureConstraint the original Constraint is stored.
protected  BasicSearchQuery query
          The core query which is 'wrapped'
protected  Authorization.QueryCheck queryCheck
          The QueryCheck object associated with this Query, or null if no such object was determined yet.
protected  boolean used
          Wether this Query was used already.
 
Fields inherited from interface org.mmbase.storage.search.SearchQuery
DEFAULT_MAX_NUMBER, DEFAULT_OFFSET
 
Constructor Summary
BasicQuery(Cloud c, BasicSearchQuery q)
           
 
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 fieldIdentifier)
          Adds a field by string
protected  void addFieldImplicit(Step step, Field field)
          Fields which are added 'implicity' should be added by this function.
 void addNode(Step s, int nodeNumber)
           
 void addNode(Step s, Node node)
          Adds a node to a step.
protected  BasicRelationStep addRelationStep(InsRel insrel, NodeManager otherNodeManager, int direction)
           
 RelationStep addRelationStep(NodeManager otherNodeManager)
           
 RelationStep addRelationStep(NodeManager otherNodeManager, java.lang.String role, java.lang.String direction)
          Adds new Relation step to the query.
protected  RelationStep addRelationStep(NodeManager otherNodeManager, java.lang.String role, java.lang.String direction, boolean warnOnImpossibleStep)
           
 SortOrder addSortOrder(StepField f, int direction)
          Adds an order on a certain field.
 Step addStep(NodeManager nm)
          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
protected  java.lang.String createAlias(java.lang.String name)
          Creates a unique alias for this Query based on a given base String
 CompositeConstraint createConstraint(Constraint c1, int operator, 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).
protected  void createNewQuery()
           
 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 fieldIdentifier)
          Creates the step field for the given name.
 boolean equals(java.lang.Object obj)
          Compares this query to the specified object.
 Constraint getCleanConstraint()
          Gets the 'clean' constraint on this query.
 Cloud getCloud()
          Returns the Cloud for which this Query was defined.
 Constraint getConstraint()
          Gets the constraints on the search results.
 java.util.List getFields()
          Gets the stepfields in the search request.
 int getMaxNumber()
          Gets the maximum number of results to be returned, or -1 if the number of results to be returned is unlimited.
 int getOffset()
          Gets the (zerobased) offset in the list of results, of the first result to return.
 java.util.List getSortOrders()
          Gets the SortOrder objects in the order they are to be applied.
 Step getStep(java.lang.String stepAlias)
          Returns the step with given alias, or null if it is not present
 java.util.List getSteps()
          Gets the steps in the search request.
protected  java.lang.String glueAlias(java.lang.String aliasBase, java.lang.Integer seq)
          Glues a string and integer together to a new string.
 int hashCode()
           
 boolean isAggregating()
          Wheter this query is 'aggregating'.
 boolean isDistinct()
          Tests if the search request is to return distinct results.
 boolean isUsed()
          Whether this query was used or not.
 boolean markUsed()
          Mark this query 'used'.
 void removeFields()
          Removes all fields from the Query object.
protected  void removeSecurityConstraintFromClone(BasicSearchQuery clone)
           
 void setAlias(Step step, java.lang.String alias)
          Sets the alias to the given step.
 FieldConstraint setCaseSensitive(FieldConstraint c, boolean s)
          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.
 java.lang.String toString()
          Returns a string representation of this SearchQuery.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

used

protected boolean used
Wether this Query was used already. If it is used, it may not be changed any more.


aggregating

protected boolean aggregating

queryCheck

protected Authorization.QueryCheck queryCheck
The QueryCheck object associated with this Query, or null if no such object was determined yet.


insecureConstraint

protected Constraint insecureConstraint
If a the contraint was made 'secure', in insecureConstraint the original Constraint is stored. This object is null if either the queryCheck object is not yet determined, or the orignal query did not have constraints.


query

protected BasicSearchQuery query
The core query which is 'wrapped'


cloud

protected Cloud cloud
reference to the cloud.


implicitFields

protected java.util.List implicitFields
The implicitely added 'extra' fields. These are removed if the query becomes 'distinct'. So, you can e.g. not do element= on a distinct query result.


explicitFields

protected java.util.List explicitFields
The explicitely added 'extra' fields. Because you explicitely added those, they will not be removed if the query becomes 'distinct'.

Constructor Detail

BasicQuery

public BasicQuery(Cloud c,
                  BasicSearchQuery q)
Method Detail

createNewQuery

protected void createNewQuery()

getSteps

public java.util.List getSteps()
Description copied from interface: SearchQuery
Gets the steps in the search request.

This corresponds to the tables in SQL SELECT-syntax.

Specified by:
getSteps in interface SearchQuery

getFields

public java.util.List getFields()
Description copied from interface: SearchQuery
Gets the stepfields in the search request.

This corresponds to the fields in SQL SELECT-syntax.

Specified by:
getFields in interface SearchQuery

getConstraint

public Constraint getConstraint()
Description copied from interface: SearchQuery
Gets the constraints on the search results.

This corresponds to (part of) the constraints in the WHERE-clause in SQL SELECT-syntax.

Specified by:
getConstraint in interface SearchQuery

getCleanConstraint

public Constraint getCleanConstraint()
Description copied from interface: Query
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.

Specified by:
getCleanConstraint in interface Query

getMaxNumber

public int getMaxNumber()
Description copied from interface: SearchQuery
Gets the maximum number of results to be returned, or -1 if the number of results to be returned is unlimited.

Note: limiting the number of results may not be supported by the database layer.

Specified by:
getMaxNumber in interface SearchQuery

getOffset

public int getOffset()
Description copied from interface: SearchQuery
Gets the (zerobased) offset in the list of results, of the first result to return. Note that, since it is zerobased, it is equal to the number of results that are skipped.

Note: skipping results may not be supported by the database layer.

Specified by:
getOffset in interface SearchQuery

getSortOrders

public java.util.List getSortOrders()
Description copied from interface: SearchQuery
Gets the SortOrder objects in the order they are to be applied. This specifies the sorting order of the search results.

This corresponds to the ORDER BY clause in SQL SELECT syntax.

Specified by:
getSortOrders in interface SearchQuery

isDistinct

public boolean isDistinct()
Description copied from interface: SearchQuery
Tests if the search request is to return distinct results. In that case duplicate nodes will be removed from the result.

This corresponds to the use of "DISTINCT" in SQL SELECT-syntax .

Specified by:
isDistinct in interface SearchQuery

isAggregating

public boolean isAggregating()
Description copied from interface: Query
Wheter this query is 'aggregating'. You can only use 'addAggregatedField' on aggregating querys.

Specified by:
isAggregating in interface Query

removeSecurityConstraintFromClone

protected void removeSecurityConstraintFromClone(BasicSearchQuery clone)
Since:
MMBase-1.7.1

clone

public java.lang.Object clone()
Description copied from interface: Query
Create an (unused) clone

Specified by:
clone in interface Query

aggregatingClone

public Query aggregatingClone()
Description copied from interface: Query
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.

Specified by:
aggregatingClone in interface Query

cloneWithoutFields

public Query cloneWithoutFields()
Description copied from interface: Query
Clones this object, only without the fields

Specified by:
cloneWithoutFields in interface Query

createAlias

protected java.lang.String createAlias(java.lang.String name)
Creates a unique alias for this Query based on a given base String


glueAlias

protected java.lang.String glueAlias(java.lang.String aliasBase,
                                     java.lang.Integer seq)
Glues a string and integer together to a new string.


addStep

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

Specified by:
addStep in interface Query
Parameters:
nm - The nodeManager associated with the step.
Returns:
The 'step' wrapping the NodeManager.
See Also:
Query.addRelationStep(org.mmbase.bridge.NodeManager, java.lang.String, java.lang.String)

setAlias

public void setAlias(Step step,
                     java.lang.String alias)
Description copied from interface: Query
Sets the alias to the given step.

Specified by:
setAlias in interface Query
Parameters:
alias - The alias which must be given to the step. If it is "" an alias should be generated. 'null' removes the alias.

addRelationStep

protected BasicRelationStep addRelationStep(InsRel insrel,
                                            NodeManager otherNodeManager,
                                            int direction)

addRelationStep

public RelationStep addRelationStep(NodeManager otherNodeManager)
Specified by:
addRelationStep in interface Query

addRelationStep

public RelationStep addRelationStep(NodeManager otherNodeManager,
                                    java.lang.String role,
                                    java.lang.String direction)
Description copied from interface: Query
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.

Specified by:
addRelationStep in interface Query

addRelationStep

protected RelationStep addRelationStep(NodeManager otherNodeManager,
                                       java.lang.String role,
                                       java.lang.String direction,
                                       boolean warnOnImpossibleStep)

removeFields

public void removeFields()
Description copied from interface: Query
Removes all fields from the Query object.

Specified by:
removeFields in interface Query

addField

public StepField addField(Step step,
                          Field field)
Description copied from interface: Query
Adds a field to a step.

Specified by:
addField in interface Query

addField

public StepField addField(java.lang.String fieldIdentifier)
Description copied from interface: Query
Adds a field by string

Specified by:
addField in interface Query

addFieldImplicit

protected void addFieldImplicit(Step step,
                                Field field)
Fields which are added 'implicity' should be added by this function.


createStepField

public StepField createStepField(Step step,
                                 Field field)
Description copied from interface: Query
Creates a StepField object withouth adding it (needed for aggregated queries).

Specified by:
createStepField in interface Query

createStepField

public StepField createStepField(Step step,
                                 java.lang.String fieldName)
Specified by:
createStepField in interface Query

getStep

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

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

createStepField

public StepField createStepField(java.lang.String fieldIdentifier)
Description copied from interface: Query
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.

Specified by:
createStepField in interface Query

addAggregatedField

public AggregatedField addAggregatedField(Step step,
                                          Field field,
                                          int aggregationType)
Description copied from interface: Query
Add an aggregated field to a step

Specified by:
addAggregatedField in interface Query

setDistinct

public Query setDistinct(boolean distinct)
Description copied from interface: Query
Specifies wether the query result must contain only 'distinct' results.

Specified by:
setDistinct in interface Query
See Also:
BasicSearchQuery.setDistinct(boolean), SearchQuery.isDistinct()

setMaxNumber

public Query setMaxNumber(int maxNumber)
Description copied from interface: Query
Limits the query-result to maxNumber records.

Specified by:
setMaxNumber in interface Query
See Also:
BasicSearchQuery.setMaxNumber(int), SearchQuery.getMaxNumber()

setOffset

public Query setOffset(int offset)
Description copied from interface: Query
Offsets the query-result with offset records.

Specified by:
setOffset in interface Query
See Also:
BasicSearchQuery.setOffset(int), SearchQuery.getOffset()

createConstraint

public LegacyConstraint createConstraint(java.lang.String s)
Description copied from interface: Query
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.

Specified by:
createConstraint in interface Query
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)
Description copied from interface: Query
Create a contraint (for use with this Query object). The given field must be 'null'.

Specified by:
createConstraint in interface Query

createConstraint

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

Specified by:
createConstraint in interface Query

createConstraint

public FieldValueConstraint createConstraint(StepField f,
                                             int op,
                                             java.lang.Object v)
Description copied from interface: Query
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.

Specified by:
createConstraint in interface Query

createConstraint

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

Specified by:
createConstraint in interface Query

createConstraint

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

Specified by:
createConstraint in interface Query

createConstraint

public FieldValueInConstraint createConstraint(StepField f,
                                               java.util.SortedSet v)
Description copied from interface: Query
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).

Specified by:
createConstraint in interface Query
Returns:
the new Constraint.

setInverse

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

Specified by:
setInverse in interface Query

setCaseSensitive

public FieldConstraint setCaseSensitive(FieldConstraint c,
                                        boolean s)
Description copied from interface: Query
Changes the given constraint's 'case sensitivity' (if applicable). Default it is true.

Specified by:
setCaseSensitive in interface Query

createConstraint

public CompositeConstraint createConstraint(Constraint c1,
                                            int operator,
                                            Constraint c2)
Description copied from interface: Query
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.

Specified by:
createConstraint in interface Query
Returns:
a Composite constraint (might not be a new one)

setConstraint

public void setConstraint(Constraint c)
Description copied from interface: Query
The (composite) constraint can actually be set into the query with this method.

Specified by:
setConstraint in interface Query

addSortOrder

public SortOrder addSortOrder(StepField f,
                              int direction)
Description copied from interface: Query
Adds an order on a certain field.

Specified by:
addSortOrder in interface Query
See Also:
BasicSearchQuery.addSortOrder(org.mmbase.storage.search.StepField), SearchQuery.getSortOrders()

addNode

public void addNode(Step s,
                    int nodeNumber)
Since:
MMBase-1.7.1
To Do:
should this method be in the interface?

addNode

public void addNode(Step s,
                    Node node)
Description copied from interface: Query
Adds a node to a step.

Specified by:
addNode in interface Query

isUsed

public boolean isUsed()
Description copied from interface: Query
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)

Specified by:
isUsed in interface Query

markUsed

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

Specified by:
markUsed in interface Query

getCloud

public Cloud getCloud()
Description copied from interface: Query
Returns the Cloud for which this Query was defined.

Specified by:
getCloud in interface Query

equals

public boolean equals(java.lang.Object obj)
Description copied from interface: SearchQuery
Compares this query to the specified object. The result is true if and only if the argument is a non-null SearchQuery object representing the same query.

Specified by:
equals in interface SearchQuery

hashCode

public int hashCode()
Specified by:
hashCode in interface SearchQuery

toString

public java.lang.String toString()
Description copied from interface: SearchQuery
Returns a string representation of this SearchQuery. The string representation has the form "SearchQuery(distinct:<distinct>, steps:<steps>, fields:<fields>, constraint:<constraint>, sortorders:<sortorders>, max:<max>, offset:<offset>)" where

Specified by:
toString in interface SearchQuery


MMBase build 1.7.4.20050922