org.mmbase.storage.search.implementation
Class BasicSearchQuery

java.lang.Object
  extended byorg.mmbase.storage.search.implementation.BasicSearchQuery
All Implemented Interfaces:
java.lang.Cloneable, SearchQuery
Direct Known Subclasses:
NodeSearchQuery

public class BasicSearchQuery
extends java.lang.Object
implements SearchQuery, java.lang.Cloneable

Basic implementation.

Since:
MMBase-1.7
Version:
$Id: BasicSearchQuery.java,v 1.18 2004/04/01 20:57:48 robmaris Exp $
Author:
Rob van Maris

Field Summary
static int COPY_AGGREGATING
           
static int COPY_NORMAL
           
static int COPY_WITHOUTFIELDS
           
protected  java.util.List fields
          StepField list.
 
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, FieldDefs fielDefs, int aggregationType)
          Adds new aggregated field to this SearchQuery.
 BasicStepField addField(Step step, FieldDefs fieldDefs)
          Adds new field to this SearchQuery.
 void addFields(Step step)
           
 BasicRelationStep addRelationStep(InsRel builder, MMObjectBuilder nextBuilder)
          Adds new relationstep to this SearchQuery.
 BasicSortOrder addSortOrder(StepField field)
          Creates sortorder for this SearchQuery.
 BasicStep addStep(MMObjectBuilder builder)
          Adds new step to this SearchQuery.
 java.lang.Object clone()
           
protected  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  StepField createNewStepField(SearchQuery q, StepField f)
          Creates a new StepField like f for query q.
 boolean equals(java.lang.Object obj)
          Compares this query to the specified object.
 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.
 java.util.List 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(FieldDefs field, StepField stepField)
           
 void removeFields()
           
 void setConstraint(Constraint constraint)
          Sets constraint.
 BasicSearchQuery setDistinct(boolean distinct)
          Sets distinct.
 BasicSearchQuery setMaxNumber(int maxNumber)
          Sets maxNumber.
 BasicSearchQuery setOffset(int offset)
          Sets offset.
 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

fields

protected java.util.List fields
StepField list.


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 java.lang.Object clone()

copySteps

protected void copySteps(SearchQuery q)

copyFields

protected void copyFields(SearchQuery q)

copySortOrders

protected void copySortOrders(SearchQuery q)

createNewStepField

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


copyConstraint

protected 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:
java.lang.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:
java.lang.IllegalArgumentException - when an invalid argument is supplied.

addStep

public BasicStep addStep(MMObjectBuilder builder)
Adds new step to this SearchQuery.

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

addRelationStep

public BasicRelationStep addRelationStep(InsRel builder,
                                         MMObjectBuilder nextBuilder)
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:
java.lang.IllegalArgumentException - when an invalid argument is supplied.
java.lang.IllegalStateException - when there is no previous step.

addField

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

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

mapField

protected void mapField(FieldDefs field,
                        StepField stepField)

addFields

public void addFields(Step step)

removeFields

public void removeFields()

addAggregatedField

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

Parameters:
step - The associated step.
Returns:
The new field.
Throws:
java.lang.IllegalArgumentException - when an invalid argument is supplied.
java.lang.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:
java.lang.IllegalArgumentException - when an invalid argument is supplied.

setConstraint

public void setConstraint(Constraint constraint)
Sets constraint.

Parameters:
constraint - The constraint.
Throws:
java.lang.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 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

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

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

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.1.20041002