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:
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,v 1.1 2007-08-24 22:17:36 ewestfal Exp $
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.
private  Criteria m_criteria
           
private  boolean m_distinct
           
private  List m_groupby
           
private  Criteria m_havingCriteria
           
private  String m_objectProjectionAttribute
           
private  List m_orderby
           
private  Map m_pathClasses
           
private  Collection m_pathOuterJoins
           
private  List m_prefetchedRelationships
           
 
Fields inherited from class org.apache.ojb.broker.query.AbstractQueryImpl
m_baseClass, m_searchClass, serialVersionUID
 
Fields inherited from interface org.apache.ojb.broker.query.Query
NO_END_AT_INDEX, NO_START_AT_INDEX, NOT_SCROLLABLE, SCROLLABLE
 
Constructor Summary
QueryByCriteria(Class aClassToSearchFrom)
          Build a Query based on a Class Object.
QueryByCriteria(Class targetClass, Criteria criteria)
          Build a Query for class targetClass with criteria.
QueryByCriteria(Class targetClass, Criteria criteria, boolean distinct)
          Build a Query for class targetClass with criteria.
QueryByCriteria(Class targetClass, Criteria whereCriteria, Criteria havingCriteria)
          Build a Query for class targetClass with criteria.
QueryByCriteria(Class targetClass, Criteria whereCriteria, Criteria havingCriteria, boolean distinct)
          Build a Query for class targetClass with criteria.
QueryByCriteria(Object anObject)
          Build a Query based on anObject
all non null values are used as EqualToCriteria
QueryByCriteria(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(String fieldName)
          Adds a groupby fieldName for ReportQueries.
 void addGroupBy(String[] fieldNames)
          Adds an array of groupby fieldNames for ReportQueries.
 void addOrderBy(FieldHelper aField)
          Adds a field for orderBy
 void addOrderBy(String fieldName)
          Deprecated. use #addOrderByAscending(String fieldName)
 void addOrderBy(String fieldName, boolean sortAscending)
          Adds a field for orderBy
 void addOrderByAscending(String fieldName)
          Adds a field for orderBy ASCENDING
 void addOrderByDescending(String fieldName)
          Adds a field for orderBy DESCENDING
 void addPathClass(String aPath, Class aClass)
          Add a hint Class for a path.
 void addPrefetchedRelationship(String aName)
          add the name of aRelationship for prefetched read
private static Criteria buildCriteria(Object anExample)
          Build Criteria based on example object
all non null values are used as EqualToCriteria
 List getClassesForPath(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.
 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.
 String getObjectProjectionAttribute()
           
 List getOrderBy()
          Answer the orderBy of all Criteria and Sub Criteria the elements are of class FieldHelper
 Collection getOuterJoinPaths()
          Get a Collection containing all Paths having an Outer-Joins-Setting
 Map getPathClasses()
          Gets the pathClasses.
 List getPrefetchedRelationships()
          Returns the names of Relationships to be prefetched
 boolean isDistinct()
          Gets the distinct.
 boolean isPathOuterJoin(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(String objectProjectionAttribute)
          Use this method to query some related class by object references, for example query.setObjectProjectionAttribute("ref1.ref2.ref3");
 void setObjectProjectionAttribute(String objectProjectionAttribute, Class objectProjectionClass)
           
 void setPathClass(String aPath, Class aClass)
          Set the Class for a path.
 void setPathOuterJoin(String aPath)
          Force outer join for the last segment of the path.
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_criteria

private Criteria m_criteria

m_distinct

private boolean m_distinct

m_pathClasses

private Map m_pathClasses

m_havingCriteria

private Criteria m_havingCriteria

m_objectProjectionAttribute

private String m_objectProjectionAttribute

m_orderby

private List m_orderby

m_groupby

private List m_groupby

m_prefetchedRelationships

private List m_prefetchedRelationships

m_pathOuterJoins

private Collection m_pathOuterJoins

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(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(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(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(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(Object anObject,
                       boolean distinct)
Build a Query based on anObject
all non null values are used as EqualToCriteria


QueryByCriteria

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


QueryByCriteria

public QueryByCriteria(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

buildCriteria

private static Criteria buildCriteria(Object anExample)
Build Criteria based on example object
all non null values are used as EqualToCriteria


addPathClass

public void addPathClass(String aPath,
                         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(String aPath,
                         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 List getClassesForPath(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(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(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 String toString()
Insert the method's description here. Creation date: (07.02.2001 22:01:55)

Overrides:
toString in class 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 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(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(String[] fieldNames)
Adds an array of groupby fieldNames for ReportQueries.

Parameters:
fieldNames - The groupby to set

getGroupBy

public 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(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(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(String fieldName)
Adds a field for orderBy ASCENDING

Parameters:
fieldName - The field name to be used

addOrderByDescending

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

Parameters:
fieldName - The field name to be used

getOrderBy

public 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(String aName)
add the name of aRelationship for prefetched read


getPrefetchedRelationships

public 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 Collection getOuterJoinPaths()
Get a Collection containing all Paths having an Outer-Joins-Setting

Returns:
a Collection containing the Paths (Strings)

getObjectProjectionAttribute

public String getObjectProjectionAttribute()

setObjectProjectionAttribute

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


setObjectProjectionAttribute

public void setObjectProjectionAttribute(String objectProjectionAttribute,
                                         Class objectProjectionClass)


Copyright © 2007-2012 The Kuali Foundation. All Rights Reserved.