org.mmbase.storage.search.implementation
Class BasicSearchQuery

java.lang.Object
  extended by org.mmbase.storage.search.implementation.BasicSearchQuery
All Implemented Interfaces:
Serializable, Cloneable, Cacheable, SearchQuery, PublicCloneable<BasicSearchQuery>, SizeMeasurable
Direct Known Subclasses:
NodeSearchQuery

public class BasicSearchQuery
extends Object
implements SearchQuery, PublicCloneable<BasicSearchQuery>, SizeMeasurable, Serializable

Basic implementation.

Since:
MMBase-1.7
Version:
$Id: BasicSearchQuery.java 42925 2010-07-15 18:23:52Z michiel $
Author:
Rob van Maris
See Also:
Serialized Form

Field Summary
static int COPY_AGGREGATING
           
static int COPY_NORMAL
           
static int COPY_WITHOUTFIELDS
           
protected  List<StepField> fields
           
 
Fields inherited from interface org.mmbase.storage.search.SearchQuery
DEFAULT_MAX_NUMBER, DEFAULT_OFFSET
 
Constructor Summary
BasicSearchQuery()
          Constructor, constructs non-aggragating query.
BasicSearchQuery(boolean aggregating)
          Constructor.
BasicSearchQuery(SearchQuery q)
          A deep copy.
BasicSearchQuery(SearchQuery q, int copyMethod)
          A deep copy, but sets also aggregating, and clear fields if aggregating is true then.
 
Method Summary
 BasicAggregatedField addAggregatedField(Step step, Field field, int aggregationType)
          Adds new aggregated field to this SearchQuery.
 BasicStepField addField(Step step, Field fieldDefs)
          Adds new field to this SearchQuery.
 void addFields(Step step, QueryContext qc)
           
protected  void addFields(Step step, String builder, QueryContext qc)
          Add all fields of given step
 BasicStepField addFieldUnlessPresent(Step step, Field fieldDefs)
           
 BasicRelationStep addRelationStep(Object builder, Object nextBuilder)
          Deprecated. Use {@link #addRelationStep(String, String).
 BasicRelationStep addRelationStep(String builder, String nextBuilder)
           
 BasicSortOrder addSortOrder(StepField field)
          Creates sortorder for this SearchQuery.
 BasicStep addStep(Object builder)
          Deprecated. Use {@link #addStep(String).
 BasicStep addStep(String name)
           
protected  int calculateHashCode()
           
 BasicSearchQuery clone()
           
protected static Constraint copyConstraint(SearchQuery q, Constraint c)
          Used by copy-constructor.
protected  void copyFields(SearchQuery q)
           
protected  void copySortOrders(SearchQuery q)
           
protected  void copySteps(SearchQuery q)
           
protected static StepField createNewStepField(SearchQuery q, StepField f)
          Creates a new StepField like f for query q.
 boolean equals(Object obj)
          Compares this query to the specified object.
 int getByteSize()
          Determines the byte-size of this object
 int getByteSize(SizeOf sizeof)
          Determines the byte-size of this object using the given SizeOf instance.
 CachePolicy getCachePolicy()
          Returns the CachePolicy of the object.
 Constraint getConstraint()
          Gets the constraints on the search results.
 List<StepField> 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.
 List<SortOrder> getSortOrders()
          Gets the SortOrder objects in the order they are to be applied.
 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.
protected  void mapField(Field field, BasicStepField stepField)
           
 boolean markUsed()
           
 void removeFields()
           
 void setCachePolicy(CachePolicy policy)
          Sets the CachePolicy of the query.
 void setConstraint(Constraint constraint)
          Sets constraint.
 BasicSearchQuery setDistinct(boolean distinct)
          Sets distinct.
 BasicSearchQuery setMaxNumber(int maxNumber)
          Sets maxNumber.
 void setModifiable(boolean b)
           
 BasicSearchQuery setOffset(int offset)
          Sets offset.
 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

fields

protected List<StepField> fields

COPY_NORMAL

public static final int COPY_NORMAL
See Also:
Constant Field Values

COPY_AGGREGATING

public static final int COPY_AGGREGATING
See Also:
Constant Field Values

COPY_WITHOUTFIELDS

public static final int COPY_WITHOUTFIELDS
See Also:
Constant Field Values
Constructor Detail

BasicSearchQuery

public BasicSearchQuery(boolean aggregating)
Constructor.

Parameters:
aggregating - True for an aggregating query, false otherwise.

BasicSearchQuery

public BasicSearchQuery()
Constructor, constructs non-aggragating query.


BasicSearchQuery

public BasicSearchQuery(SearchQuery q,
                        int copyMethod)
A deep copy, but sets also aggregating, and clear fields if aggregating is true then.


BasicSearchQuery

public BasicSearchQuery(SearchQuery q)
A deep copy. Needed if you want to do multiple queries (and change the query between them). Used by bridge.Query#clone (so it will be decided that that is not needed, ths can be removed too)

See Also:
Query.clone()
Method Detail

clone

public BasicSearchQuery clone()
Specified by:
clone in interface PublicCloneable<BasicSearchQuery>
Overrides:
clone in class Object

copySteps

protected void copySteps(SearchQuery q)

copyFields

protected void copyFields(SearchQuery q)

copySortOrders

protected void copySortOrders(SearchQuery q)

createNewStepField

protected static StepField createNewStepField(SearchQuery q,
                                              StepField f)
Creates a new StepField like f for query q.


copyConstraint

protected static Constraint copyConstraint(SearchQuery q,
                                           Constraint c)
Used by copy-constructor. Constraints have to be done recursively.


setDistinct

public BasicSearchQuery setDistinct(boolean distinct)
Sets distinct.

Parameters:
distinct - The distinct value.
Returns:
This BasicSearchQuery instance.

setMaxNumber

public BasicSearchQuery setMaxNumber(int maxNumber)
Sets maxNumber.

Parameters:
maxNumber - The maxNumber value.
Returns:
This BasicSearchQuery instance.
Throws:
IllegalArgumentException - when an invalid argument is supplied.

setOffset

public BasicSearchQuery setOffset(int offset)
Sets offset.

Parameters:
offset - The offset value.
Returns:
This BasicSearchQuery instance.
Throws:
IllegalArgumentException - when an invalid argument is supplied.

addStep

public BasicStep addStep(Object builder)
Deprecated. Use {@link #addStep(String).

Adds new step to this SearchQuery. This method used to have an MMObjectBuilder argument. This Object version is supplied for backwards compatibility (using reflection)

Parameters:
builder - The builder associated with the step.
Returns:
The new step.
Throws:
IllegalArgumentException - when an invalid argument is supplied.

addStep

public BasicStep addStep(String name)

addRelationStep

public BasicRelationStep addRelationStep(Object builder,
                                         Object nextBuilder)
Deprecated. Use {@link #addRelationStep(String, String).

Adds new relationstep to this SearchQuery. This adds the next step as well, it can be retrieved by calling getNext() on the relationstep, and cast to BasicStep.

Parameters:
builder - The builder associated with the relation step.
nextBuilder - The builder associated with the next step.
Returns:
The new relationstep.
Throws:
IllegalArgumentException - when an invalid argument is supplied.
IllegalStateException - when there is no previous step.

addRelationStep

public BasicRelationStep addRelationStep(String builder,
                                         String nextBuilder)
Since:
MMBase-1.9.2

addField

public BasicStepField addField(Step step,
                               Field fieldDefs)
Adds new field to this SearchQuery.

Parameters:
step - The associated step.
fieldDefs - The associated fieldDefs.
Returns:
The new field.
Throws:
IllegalArgumentException - when an invalid argument is supplied.
UnsupportedOperationException - when called on an aggregating query.

addFieldUnlessPresent

public BasicStepField addFieldUnlessPresent(Step step,
                                            Field fieldDefs)
Since:
MMBase-1.8.2

mapField

protected void mapField(Field field,
                        BasicStepField stepField)

addFields

public void addFields(Step step,
                      QueryContext qc)

addFields

protected void addFields(Step step,
                         String builder,
                         QueryContext qc)
Add all fields of given step


removeFields

public void removeFields()

addAggregatedField

public BasicAggregatedField addAggregatedField(Step step,
                                               Field field,
                                               int aggregationType)
Adds new aggregated field to this SearchQuery.

Parameters:
step - The associated step.
field - The associated Field.
aggregationType - The aggregation type.
Returns:
The new field.
Throws:
IllegalArgumentException - when an invalid argument is supplied.
UnsupportedOperationException - when called on an non-aggregating query.

addSortOrder

public BasicSortOrder addSortOrder(StepField field)
Creates sortorder for this SearchQuery.

Parameters:
field - The associated stepfield.
Returns:
The new sortOrder
Throws:
IllegalArgumentException - when an invalid argument is supplied.

setConstraint

public void setConstraint(Constraint constraint)
Sets constraint.

Parameters:
constraint - The constraint.
Throws:
IllegalArgumentException - when an invalid argument is supplied.

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

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

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

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.

setModifiable

public void setModifiable(boolean b)
Since:
MMBase-1.9.1

markUsed

public boolean markUsed()
Specified by:
markUsed in interface SearchQuery
Since:
MMBase-1.9.2

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.

calculateHashCode

protected int calculateHashCode()

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.

getByteSize

public int getByteSize()
Description copied from interface: SizeMeasurable
Determines the byte-size of this object

Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
Description copied from interface: SizeMeasurable
Determines the byte-size of this object using the given SizeOf instance. A SizeOf instance stores a Set already counted objects. So this method is typically called by SizeOf itself (recursion).

Specified by:
getByteSize in interface SizeMeasurable


MMBase 2.0-SNAPSHOT - null