ch.elca.el4j.services.search
Class QueryObject

java.lang.Object
  extended by ch.elca.el4j.services.search.QueryObject
All Implemented Interfaces:
Serializable

public class QueryObject
extends Object
implements Serializable

Object to holds criterias to execute queries. A query object can be specified for exactly one class. A query object is an AND-joined set of Criteria objects. Features:

Example on how to use this (with paging, ordering and criteria):

       // code fragments taken from HibernateKeywordDaoTest

       query = new QueryObject();

       // criteria is deliberately a bit noisy
       query.addCriteria(
           or(and(not(new ComparisonCriteria("name","Ghost","!=","String")),
                  (or(not(like("name", "%host%")),
                      like("name", "%host%"))))));

      query.addOrder(Order.desc("name"));
      query.setMaxResults(2);
      query.setFirstResult(4);

      // dao is typically a generic dao implementation
      list = dao.findByQuery(query);
    
Sample uses in EL4J: GenericDao, CriteriaTransformer

Author:
Martin Zeltner (MZE), Philipp Oser (POS)
See Also:
Serialized Form
File-location:
QueryObject
Last check-in date:
2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) by swismer for revision 3883

Field Summary
protected  int m_firstResult
           
protected  int m_maxResults
          Default value is s_defaultMaxResults
static int NO_CONSTRAINT
          Constant (=-1) to use for property firstResult.
 
Constructor Summary
QueryObject()
          Specifies a general query object.
QueryObject(Class<?> beanClass)
          Specifies the query object for a specific class.
 
Method Summary
 void addCriteria(Criteria... criteria)
          Adds the given criteria.
 void addCriterias(Criteria... criterias)
          Deprecated. please use the more versatile addCriteria method
 void addOrder(Order order)
          Add an ordering constraint (particularly useful when doing paging)

Example usage:
query.addOrder(Order.desc("name"));
 AndCriteria getAndCriterias()
           
 Class<?> getBeanClass()
           
 List<Criteria> getCriteriaList()
           
 Criteria[] getCriterias()
           
static int getDefaultMaxResults()
           
 int getFirstResult()
           
 int getMaxResults()
           
 List<Order> getOrderConstraints()
          Get the list of all defined ordering constraints.
static void setDefaultMaxResults(int defaultMaxResults)
          How many results shall we return by default?
 void setFirstResult(int firstResult)
          What is the id of the first result we want to get back?
 void setMaxResults(int maxResults)
          How many results do we want to get back at most?
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_CONSTRAINT

public static final int NO_CONSTRAINT
Constant (=-1) to use for property firstResult. NO_CONSTRAINT means we do not constrain anything

See Also:
Constant Field Values

m_firstResult

protected int m_firstResult

m_maxResults

protected int m_maxResults
Default value is s_defaultMaxResults

Constructor Detail

QueryObject

public QueryObject()
Specifies a general query object.


QueryObject

public QueryObject(Class<?> beanClass)
Specifies the query object for a specific class.

Parameters:
beanClass - Is the bean class this query object is made for.
Method Detail

getBeanClass

public Class<?> getBeanClass()
Returns:
Returns the bean class this query object is made for.

addCriteria

public void addCriteria(Criteria... criteria)
Adds the given criteria. The criterias are combined via "AND" (it's a logical conjunction of Criterias). This method can be used with one or n Criteria(s).

Parameters:
criteria - Is the criteria to add.

addCriterias

public void addCriterias(Criteria... criterias)
Deprecated. please use the more versatile addCriteria method

Adds the given criterias.

Parameters:
criterias - Are the criterias to add. The criterias are combined via "AND" (it's a logical conjunction of Criterias).

getCriteriaList

public List<Criteria> getCriteriaList()
Returns:
Returns a list of criterias (all criterias must be valid for this query object (they are combined with AND)).

getCriterias

public Criteria[] getCriterias()
Returns:
Returns an array of criterias. (all criterias must be true for this query (they are combined with AND)).

toString

public String toString()

Overrides:
toString in class Object

getAndCriterias

public AndCriteria getAndCriterias()

setFirstResult

public void setFirstResult(int firstResult)
What is the id of the first result we want to get back? By default there is no constraint on the first result. The counting starts at 0 (i.e. the first result is 0)!

Parameters:
firstResult -

setMaxResults

public void setMaxResults(int maxResults)
How many results do we want to get back at most? (The default can be set via the setDefaultMaxResults method). It defaults to 100. -1 means there is no constraint.

Parameters:
maxResults -

getFirstResult

public int getFirstResult()
Returns:
See Also:
setFirstResult

getMaxResults

public int getMaxResults()
Returns:
See Also:
setMaxResults

getDefaultMaxResults

public static int getDefaultMaxResults()
Returns:
See Also:
setDefaultMaxResults

setDefaultMaxResults

public static void setDefaultMaxResults(int defaultMaxResults)
How many results shall we return by default? Defaults to 100. -1 stands for no constraint.

Parameters:
defaultMaxResults -

addOrder

public void addOrder(Order order)
Add an ordering constraint (particularly useful when doing paging)

Example usage:
query.addOrder(Order.desc("name"));

Parameters:
order -

getOrderConstraints

public List<Order> getOrderConstraints()
Get the list of all defined ordering constraints.

Returns:


Copyright © 2005-2011 ELCA. All Rights Reserved.