org.mmbase.bridge.util
Class AbstractQueryWrapper<Q extends Query>

java.lang.Object
  extended by org.mmbase.bridge.util.AbstractQueryWrapper<Q>
All Implemented Interfaces:
Cloneable, Query, Cacheable, SearchQuery, SearchQueryWrapper, PublicCloneable<Query>
Direct Known Subclasses:
NodeQueryWrapper, QueryWrapper

public abstract class AbstractQueryWrapper<Q extends Query>
extends Object
implements Query

Abstract base class for both QueryWrapper and NodeQueryWrapper.

Since:
MMBase-1.9.2
Version:
$Id: AbstractQueryWrapper.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Michiel Meeuwissen

Field Summary
protected  Q query
           
 
Fields inherited from interface org.mmbase.storage.search.SearchQuery
DEFAULT_MAX_NUMBER, DEFAULT_OFFSET
 
Constructor Summary
protected AbstractQueryWrapper(Q 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(String field)
          Adds a field by string
 void addNode(Step s, int number)
           
 void addNode(Step s, Node node)
          Adds a node to a step.
 RelationStep addRelationStep(NodeManager otherManager)
          If you need to add a 'related' NodeManager without specifying a role/searchDir simply use these addRelationStep.
 RelationStep addRelationStep(NodeManager nodeManager, String role, String searchDir)
          Adds new Relation step to the query.
 SortOrder addSortOrder(StepField f, int direction)
          Defaulting version of Query.addSortOrder(StepField, int, boolean, int) (sorting case insensitively, and no date parts).
 SortOrder addSortOrder(StepField f, int direction, boolean caseSensitive)
          Defaulting version of Query.addSortOrder(StepField, int, boolean, int) (no date parts)
 SortOrder addSortOrder(StepField f, int direction, boolean caseSensitive, int part)
          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.
 Query clone()
          Create an (unused) clone
 void cloneQuery()
           
 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 constraint (for use with this Query object).
 FieldValueConstraint createConstraint(StepField f, int op, Object v)
          Create a constraint (for use with this Query object).
 FieldValueConstraint createConstraint(StepField f, int op, Object v, int part)
          Create a constraint (for use with this Query object).
 CompareFieldsConstraint createConstraint(StepField f, int op, StepField v)
          Create a constraint (for use with this Query object).
 FieldValueConstraint createConstraint(StepField f, Object v)
          Create a constraint (for use with this Query object).
 FieldValueBetweenConstraint createConstraint(StepField f, Object o1, Object o2)
          Create a constraint (for use with this Query object).
 FieldValueInQueryConstraint createConstraint(StepField f, Query q)
           
 FieldValueInConstraint createConstraint(StepField f, SortedSet<? extends Object> v)
          Create a constraint (for use with this Query object).
 LegacyConstraint createConstraint(String s)
          Create a constraint (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, String fieldName)
          Creates a StepField object withouth adding it (needed for aggregated queries).
 StepField createStepField(String fieldIdentifier)
          Creates the step field for the given name.
 boolean equals(Object obj)
          Compares this query to the specified object.
 CachePolicy getCachePolicy()
          Returns the CachePolicy of the 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.
 List<StepField> getFields()
          Gets the stepfields in the search request.
 NodeList getList()
          Executes the query and returns the resulting node list.
 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.
 Q getQuery()
           
 List<SortOrder> getSortOrders()
          Gets the SortOrder objects in the order they are to be applied.
 String getSql()
           
 Step getStep(String stepAlias)
          Returns the step with given alias, or null if it is not present
 List<Step> getSteps()
          Gets the steps in the search request.
 int hashCode()
           
 boolean isAggregating()
          Tests if this is an aggregating query, i.e.
 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.
 void removeImplicitFields()
           
 void setAlias(Step step, String alias)
          Sets the alias to the given step.
 void setCachePolicy(CachePolicy policy)
          Sets the CachePolicy of the query.
 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.
 String toSql()
          Shows the query in a human-readable SQL form.
 String toString()
          Returns a string representation of this SearchQuery.
 SearchQuery unwrap()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

query

protected Q extends Query query
Constructor Detail

AbstractQueryWrapper

protected AbstractQueryWrapper(Q q)
Method Detail

cloneQuery

public void cloneQuery()

getSql

public String getSql()

getQuery

public Q getQuery()

unwrap

public SearchQuery unwrap()
Specified by:
unwrap in interface SearchQueryWrapper

getCloud

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

Specified by:
getCloud in interface Query
Returns:
Cloud

addStep

public Step addStep(NodeManager nodeManager)
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:
nodeManager - The nodeManager associated with the step.
Returns:
The 'step' wrapping the NodeManager.
See Also:
Query.addRelationStep(NodeManager)

setAlias

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

Specified by:
setAlias in interface Query
Parameters:
step - step to add the alias for
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(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)
Returns:
step with given alias

addRelationStep

public RelationStep addRelationStep(NodeManager nodeManager,
                                    String role,
                                    String searchDir)
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
Parameters:
nodeManager - node manager on the other side of the relation
role - role of a relation
searchDir - the direction of the relation
Returns:
new Relation step

addRelationStep

public RelationStep addRelationStep(NodeManager otherManager)
Description copied from interface: Query
If you need to add a 'related' NodeManager without specifying a role/searchDir simply use these addRelationStep.

Specified by:
addRelationStep in interface Query
Parameters:
otherManager - node manager on the other side of the relation
Returns:
new Relation step

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
Parameters:
step - step to add field to
field - field to add
Returns:
new StepField

addField

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

Specified by:
addField in interface Query
Parameters:
field - field to add
Returns:
new StepField

removeFields

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

Specified by:
removeFields in interface Query

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
Parameters:
step - step to create StepField from
field - field to create StepField from
Returns:
new StepField

createStepField

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

Specified by:
createStepField in interface Query
Parameters:
step - step to create StepField from
fieldName - name of field to create StepField from
Returns:
new StepField

createStepField

public StepField createStepField(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
Parameters:
fieldIdentifier - field identifier to create StepField from
Returns:
new StepField

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
Parameters:
step - step to add field to
field - field to add
aggregationType - Type of aggregation
Returns:
new AggregatedField

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
Parameters:
distinct - 'distinct' results
Returns:
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
Parameters:
maxNumber - max number of results
Returns:
Query
See Also:
BasicSearchQuery.setMaxNumber(int)

setOffset

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

Specified by:
setOffset in interface Query
Parameters:
offset - offset in results
Returns:
Query
See Also:
BasicSearchQuery.setOffset(int)

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
Returns:
Constraint

createConstraint

public LegacyConstraint createConstraint(String s)
Description copied from interface: Query
Create a constraint (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
Parameters:
s - String with LegacyConstraint
Returns:
LegacyConstraint
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 constraint (for use with this Query object). The given field must be 'null'.

Specified by:
createConstraint in interface Query
Parameters:
f - Stepfield
Returns:
FieldNullConstraint

createConstraint

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

Specified by:
createConstraint in interface Query
Parameters:
f - field
v - value
Returns:
FieldValueConstraint

createConstraint

public FieldValueConstraint createConstraint(StepField f,
                                             int op,
                                             Object v)
Description copied from interface: Query
Create a constraint (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
Parameters:
f - field
op - operator
v - value
Returns:
FieldValueConstraint

createConstraint

public FieldValueConstraint createConstraint(StepField f,
                                             int op,
                                             Object v,
                                             int part)
Description copied from interface: Query
Create a constraint (for use with this Query object). The given date field and the given value 'v', combined with given operator must evaluate to true for the specified date part.

Specified by:
createConstraint in interface Query
Parameters:
f - field
op - operator
v - value
part - part of the date value
Returns:
FieldValueConstraint

createConstraint

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

Specified by:
createConstraint in interface Query
Parameters:
f - field
op - operator
v - value
Returns:
CompareFieldsConstraint

createConstraint

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

Specified by:
createConstraint in interface Query
Parameters:
f - field
o1 - value one
o2 - value two
Returns:
FieldValueBetweenConstraint

createConstraint

public FieldValueInConstraint createConstraint(StepField f,
                                               SortedSet<? extends Object> v)
Description copied from interface: Query
Create a constraint (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
Parameters:
f - field
v - value
Returns:
the new Constraint.

createConstraint

public FieldValueInQueryConstraint createConstraint(StepField f,
                                                    Query q)
Specified by:
createConstraint in interface Query

setCaseSensitive

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

Specified by:
setCaseSensitive in interface Query
Parameters:
constraint - constraint to change
sensitive - case sensitivity
Returns:
modified FieldConstraint

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
Parameters:
c - constraint
i - inverse
Returns:
Inversed constraint

createConstraint

public CompositeConstraint createConstraint(Constraint c1,
                                            int op,
                                            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
Parameters:
c1 - constraint one
op - operator (CompositeConstraint.LOGICAL_AND, CompositeConstraint.LOGICAL_OR)
c2 - constraint two
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
Parameters:
c - constraint

addSortOrder

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

Specified by:
addSortOrder in interface Query
Parameters:
f - field
direction - SortOrder.ORDER_ASCENDING or SortOrder.ORDER_DESCENDING
caseSensitive - case sensitivity
part - part to sort on for a date value
Returns:
new SortOrder
See Also:
BasicSearchQuery.addSortOrder(org.mmbase.storage.search.StepField)

addSortOrder

public SortOrder addSortOrder(StepField f,
                              int direction,
                              boolean caseSensitive)
Description copied from interface: Query
Defaulting version of Query.addSortOrder(StepField, int, boolean, int) (no date parts)

Specified by:
addSortOrder in interface Query
Parameters:
f - field
direction - SortOrder.ORDER_ASCENDING or SortOrder.ORDER_DESCENDING
caseSensitive - case sensitivity
Returns:
new SortOrder

addSortOrder

public SortOrder addSortOrder(StepField f,
                              int direction)
Description copied from interface: Query
Defaulting version of Query.addSortOrder(StepField, int, boolean, int) (sorting case insensitively, and no date parts).

Specified by:
addSortOrder in interface Query
Parameters:
f - field
direction - SortOrder.ORDER_ASCENDING or SortOrder.ORDER_DESCENDING
Returns:
new SortOrder

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
Parameters:
s - step
node - node to add

addNode

public void addNode(Step s,
                    int number)
Specified by:
addNode in interface Query
Parameters:
s - query step
number - node number

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
Returns:
query already used or not

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
Specified by:
markUsed in interface SearchQuery
Returns:
if this query is was used before this method call

clone

public Query clone()
Description copied from interface: Query
Create an (unused) clone

Specified by:
clone in interface Query
Specified by:
clone in interface PublicCloneable<Query>
Overrides:
clone in class Object
Returns:
Cloned Query

cloneWithoutFields

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

Specified by:
cloneWithoutFields in interface Query
Returns:
Cloned 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 constraints on them remain), and you can add aggregated fields then.

Specified by:
aggregatingClone in interface Query
Returns:
Cloned Query

getList

public NodeList getList()
Description copied from interface: Query
Executes the query and returns the resulting node list.

Specified by:
getList in interface Query
Returns:
resulting node list

toSql

public String toSql()
Description copied from interface: Query
Shows the query in a human-readable SQL form. This is probably not the query which will actually be sent to the database. This method is provided because 'toString' on a Query object is pretty complete, but pretty undigestable for mere mortals too. Implementions can also implement getSql(), which would make this available in e.g. EL too.

Specified by:
toSql in interface Query
Returns:
human-readable SQL

removeImplicitFields

public void removeImplicitFields()
Specified by:
removeImplicitFields in interface Query

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: SearchQuery
Tests if this is an aggregating query, i.e. containing aggregated fields.

Specified by:
isAggregating in interface SearchQuery

getSteps

public List<Step> 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 List<StepField> 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

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 List<SortOrder> 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

equals

public boolean equals(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
Overrides:
equals in class Object
Parameters:
obj - The object to compare with.
Returns:
true if the objects are equal, false otherwise.

hashCode

public int hashCode()
Specified by:
hashCode in interface SearchQuery
Overrides:
hashCode in class Object

toString

public 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
Overrides:
toString in class Object
Returns:
A string representation of this SearchQuery.

getCachePolicy

public CachePolicy getCachePolicy()
Description copied from interface: Cacheable
Returns the CachePolicy of the object.

Specified by:
getCachePolicy in interface Cacheable
Returns:
the CachePolicy object.

setCachePolicy

public void setCachePolicy(CachePolicy policy)
Description copied from interface: Cacheable
Sets the CachePolicy of the query.

Specified by:
setCachePolicy in interface Cacheable
Parameters:
policy - the CachePolicy object.


MMBase 2.0-SNAPSHOT - null