org.apache.ojb.broker.query
Class QueryByCriteria

java.lang.Object
  extended by org.apache.ojb.broker.query.AbstractQueryImpl
      extended by org.apache.ojb.broker.query.QueryByCriteria
All Implemented Interfaces:
java.io.Serializable, Query
Direct Known Subclasses:
QueryByMtoNCriteria, ReportQueryByCriteria

public class QueryByCriteria
extends AbstractQueryImpl

represents a search by criteria. "find all articles where article.price > 100" could be represented as: Criteria crit = new Criteria(); crit.addGreaterThan("price", new Double(100)); Query qry = new QueryByCriteria(Article.class, crit); The PersistenceBroker can retrieve Objects by Queries as follows: PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(); Collection col = broker.getCollectionByQuery(qry); Creation date: (24.01.2001 21:45:46)

Version:
$Id: QueryByCriteria.java 365232 2005-12-21 22:36:07Z tomdz $
Author:
Thomas Mahler
See Also:
Serialized Form

Field Summary
static Criteria CRITERIA_SELECT_ALL
          handy criteria that can be used to select all instances of a class.
 
Fields inherited from interface org.apache.ojb.broker.query.Query
NO_END_AT_INDEX, NO_START_AT_INDEX, NOT_SCROLLABLE, SCROLLABLE
 
Constructor Summary
QueryByCriteria(java.lang.Class aClassToSearchFrom)
          Build a Query based on a Class Object.
QueryByCriteria(java.lang.Class targetClass, Criteria criteria)
          Build a Query for class targetClass with criteria.
QueryByCriteria(java.lang.Class targetClass, Criteria criteria, boolean distinct)
          Build a Query for class targetClass with criteria.
QueryByCriteria(java.lang.Class targetClass, Criteria whereCriteria, Criteria havingCriteria)
          Build a Query for class targetClass with criteria.
QueryByCriteria(java.lang.Class targetClass, Criteria whereCriteria, Criteria havingCriteria, boolean distinct)
          Build a Query for class targetClass with criteria.
QueryByCriteria(java.lang.Object anObject)
          Build a Query based on anObject
all non null values are used as EqualToCriteria
QueryByCriteria(java.lang.Object anObject, boolean distinct)
          Build a Query based on anObject
all non null values are used as EqualToCriteria
 
Method Summary
 void addGroupBy(FieldHelper aField)
          Adds a field for groupby
 void addGroupBy(java.lang.String fieldName)
          Adds a groupby fieldName for ReportQueries.
 void addGroupBy(java.lang.String[] fieldNames)
          Adds an array of groupby fieldNames for ReportQueries.
 void addOrderBy(FieldHelper aField)
          Adds a field for orderBy
 void addOrderBy(java.lang.String fieldName)
          Deprecated. use #addOrderByAscending(String fieldName)
 void addOrderBy(java.lang.String fieldName, boolean sortAscending)
          Adds a field for orderBy
 void addOrderByAscending(java.lang.String fieldName)
          Adds a field for orderBy ASCENDING
 void addOrderByDescending(java.lang.String fieldName)
          Adds a field for orderBy DESCENDING
 void addPathClass(java.lang.String aPath, java.lang.Class aClass)
          Add a hint Class for a path.
 void addPrefetchedRelationship(java.lang.String aName)
          add the name of aRelationship for prefetched read
 java.util.List getClassesForPath(java.lang.String aPath)
          Get the a List of Class objects used as hints for a path
 Criteria getCriteria()
          return the criteria of the query if present or null.
 java.util.List getGroupBy()
          Gets the groupby for ReportQueries of all Criteria and Sub Criteria the elements are of class FieldHelper
 Criteria getHavingCriteria()
          return the criteria of the query if present or null.
 java.lang.String getObjectProjectionAttribute()
           
 java.util.List getOrderBy()
          Answer the orderBy of all Criteria and Sub Criteria the elements are of class FieldHelper
 java.util.Collection getOuterJoinPaths()
          Get a Collection containing all Paths having an Outer-Joins-Setting
 java.util.Map getPathClasses()
          Gets the pathClasses.
 java.util.List getPrefetchedRelationships()
          Returns the names of Relationships to be prefetched
 boolean isDistinct()
          Gets the distinct.
 boolean isPathOuterJoin(java.lang.String aPath)
          Answer true if outer join for path should be used.
 void setCriteria(Criteria criteria)
          Sets the criteria.
 void setDistinct(boolean distinct)
          Sets the distinct.
 void setHavingCriteria(Criteria havingCriteria)
          Sets the havingCriteria.
 void setObjectProjectionAttribute(java.lang.String objectProjectionAttribute)
          Use this method to query some related class by object references, for example query.setObjectProjectionAttribute("ref1.ref2.ref3");
 void setObjectProjectionAttribute(java.lang.String objectProjectionAttribute, java.lang.Class objectProjectionClass)
           
 void setPathClass(java.lang.String aPath, java.lang.Class aClass)
          Set the Class for a path.
 void setPathOuterJoin(java.lang.String aPath)
          Force outer join for the last segment of the path.
 java.lang.String toString()
          Insert the method's description here.
 
Methods inherited from class org.apache.ojb.broker.query.AbstractQueryImpl
fullSize, fullSize, getBaseClass, getEndAtIndex, getExampleObject, getFetchSize, getSearchClass, getStartAtIndex, getWithExtents, setEndAtIndex, setFetchSize, setStartAtIndex, setWithExtents, usePaging
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CRITERIA_SELECT_ALL

public static final Criteria CRITERIA_SELECT_ALL
handy criteria that can be used to select all instances of a class.

Constructor Detail

QueryByCriteria

public QueryByCriteria(java.lang.Class targetClass,
                       Criteria whereCriteria,
                       Criteria havingCriteria,
                       boolean distinct)
Build a Query for class targetClass with criteria. Criteriy may be null (will result in a query returning ALL objects from a table)


QueryByCriteria

public QueryByCriteria(java.lang.Class targetClass,
                       Criteria whereCriteria,
                       Criteria havingCriteria)
Build a Query for class targetClass with criteria. Criteriy may be null (will result in a query returning ALL objects from a table)


QueryByCriteria

public QueryByCriteria(java.lang.Class targetClass,
                       Criteria criteria)
Build a Query for class targetClass with criteria. Criteriy may be null (will result in a query returning ALL objects from a table)


QueryByCriteria

public QueryByCriteria(java.lang.Class targetClass,
                       Criteria criteria,
                       boolean distinct)
Build a Query for class targetClass with criteria. Criteriy may be null (will result in a query returning ALL objects from a table)


QueryByCriteria

public QueryByCriteria(java.lang.Object anObject,
                       boolean distinct)
Build a Query based on anObject
all non null values are used as EqualToCriteria


QueryByCriteria

public QueryByCriteria(java.lang.Object anObject)
Build a Query based on anObject
all non null values are used as EqualToCriteria


QueryByCriteria

public QueryByCriteria(java.lang.Class aClassToSearchFrom)
Build a Query based on a Class Object. This Query will return all instances of the given class.

Parameters:
aClassToSearchFrom - the class to search from
Method Detail

addPathClass

public void addPathClass(java.lang.String aPath,
                         java.lang.Class aClass)
Add a hint Class for a path. Used for relationships to extents.
SqlStatment will use these hint classes when resolving the path. Without these hints SqlStatment will use the base class the relationship points to ie: Article instead of CdArticle.

Parameters:
aPath - the path segment ie: allArticlesInGroup
aClass - the Class ie: CdArticle
See Also:
org.apache.ojb.broker.QueryTest#testInversePathExpression()

setPathClass

public void setPathClass(java.lang.String aPath,
                         java.lang.Class aClass)
Set the Class for a path. Used for relationships to extents.
SqlStatment will use this class when resolving the path. Without this hint SqlStatment will use the base class the relationship points to ie: Article instead of CdArticle. Using this method is the same as adding just one hint

Parameters:
aPath - the path segment ie: allArticlesInGroup
aClass - the Class ie: CdArticle
See Also:
org.apache.ojb.broker.QueryTest#testInversePathExpression(), addPathClass(java.lang.String, java.lang.Class)

getClassesForPath

public java.util.List getClassesForPath(java.lang.String aPath)
Get the a List of Class objects used as hints for a path

Parameters:
aPath - the path segment ie: allArticlesInGroup
Returns:
a List o Class objects to be used in SqlStatment
See Also:
addPathClass(java.lang.String, java.lang.Class), org.apache.ojb.broker.QueryTest#testInversePathExpression()

isPathOuterJoin

public boolean isPathOuterJoin(java.lang.String aPath)
Answer true if outer join for path should be used.

Parameters:
aPath - the path to query the outer join setting for
Returns:
true for outer join

setPathOuterJoin

public void setPathOuterJoin(java.lang.String aPath)
Force outer join for the last segment of the path. ie. path = 'a.b.c' the outer join will be applied only to the relationship from B to C. if multiple segments need an outer join, setPathOuterJoin needs to be called for each segement.

Parameters:
aPath - force outer join to the last segment of this path

getCriteria

public Criteria getCriteria()
Description copied from interface: Query
return the criteria of the query if present or null.

Specified by:
getCriteria in interface Query
Overrides:
getCriteria in class AbstractQueryImpl

getHavingCriteria

public Criteria getHavingCriteria()
Description copied from interface: Query
return the criteria of the query if present or null.

Specified by:
getHavingCriteria in interface Query
Overrides:
getHavingCriteria in class AbstractQueryImpl

toString

public java.lang.String toString()
Insert the method's description here. Creation date: (07.02.2001 22:01:55)

Overrides:
toString in class java.lang.Object
Returns:
java.lang.String

isDistinct

public boolean isDistinct()
Gets the distinct.

Specified by:
isDistinct in interface Query
Overrides:
isDistinct in class AbstractQueryImpl
Returns:
Returns a boolean

setDistinct

public void setDistinct(boolean distinct)
Sets the distinct.

Parameters:
distinct - The distinct to set

getPathClasses

public java.util.Map getPathClasses()
Gets the pathClasses. A Map containing hints about what Class to be used for what path segment

Returns:
Returns a Map

setCriteria

public void setCriteria(Criteria criteria)
Sets the criteria.

Parameters:
criteria - The criteria to set

setHavingCriteria

public void setHavingCriteria(Criteria havingCriteria)
Sets the havingCriteria.

Parameters:
havingCriteria - The havingCriteria to set

addGroupBy

public void addGroupBy(java.lang.String fieldName)
Adds a groupby fieldName for ReportQueries.

Parameters:
fieldName - The groupby to set

addGroupBy

public void addGroupBy(FieldHelper aField)
Adds a field for groupby

Parameters:
aField -

addGroupBy

public void addGroupBy(java.lang.String[] fieldNames)
Adds an array of groupby fieldNames for ReportQueries.

Parameters:
fieldNames - The groupby to set

getGroupBy

public java.util.List getGroupBy()
Description copied from interface: Query
Gets the groupby for ReportQueries of all Criteria and Sub Criteria the elements are of class FieldHelper

Specified by:
getGroupBy in interface Query
Overrides:
getGroupBy in class AbstractQueryImpl
Returns:
List of FieldHelper
See Also:
Query.getGroupBy()

addOrderBy

public void addOrderBy(java.lang.String fieldName,
                       boolean sortAscending)
Adds a field for orderBy

Parameters:
fieldName - The field name to be used
sortAscending - true for ASCENDING, false for DESCENDING

addOrderBy

public void addOrderBy(java.lang.String fieldName)
Deprecated. use #addOrderByAscending(String fieldName)

Adds a field for orderBy, order is ASCENDING

Parameters:
fieldName - The field name to be used

addOrderBy

public void addOrderBy(FieldHelper aField)
Adds a field for orderBy

Parameters:
aField -

addOrderByAscending

public void addOrderByAscending(java.lang.String fieldName)
Adds a field for orderBy ASCENDING

Parameters:
fieldName - The field name to be used

addOrderByDescending

public void addOrderByDescending(java.lang.String fieldName)
Adds a field for orderBy DESCENDING

Parameters:
fieldName - The field name to be used

getOrderBy

public java.util.List getOrderBy()
Description copied from interface: Query
Answer the orderBy of all Criteria and Sub Criteria the elements are of class FieldHelper

Specified by:
getOrderBy in interface Query
Overrides:
getOrderBy in class AbstractQueryImpl
Returns:
List of FieldHelper
See Also:
Query.getOrderBy()

addPrefetchedRelationship

public void addPrefetchedRelationship(java.lang.String aName)
add the name of aRelationship for prefetched read


getPrefetchedRelationships

public java.util.List getPrefetchedRelationships()
Description copied from interface: Query
Returns the names of Relationships to be prefetched

Specified by:
getPrefetchedRelationships in interface Query
Overrides:
getPrefetchedRelationships in class AbstractQueryImpl
Returns:
List of Strings

getOuterJoinPaths

public java.util.Collection getOuterJoinPaths()
Get a Collection containing all Paths having an Outer-Joins-Setting

Returns:
a Collection containing the Paths (Strings)

getObjectProjectionAttribute

public java.lang.String getObjectProjectionAttribute()

setObjectProjectionAttribute

public void setObjectProjectionAttribute(java.lang.String objectProjectionAttribute)
Use this method to query some related class by object references, for example query.setObjectProjectionAttribute("ref1.ref2.ref3");


setObjectProjectionAttribute

public void setObjectProjectionAttribute(java.lang.String objectProjectionAttribute,
                                         java.lang.Class objectProjectionClass)


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30