fr.ifremer.allegro
Class CriteriaSearch

java.lang.Object
  extended by fr.ifremer.allegro.CriteriaSearch
Direct Known Subclasses:
PropertySearch

public class CriteriaSearch
extends java.lang.Object

Implements a generic search mechanism based on the Hibernate Criteria API. The CriteriaSearch allows adding parameters which function as where clause. The parameters are analysed whether they should be considered or not. This depends both on the actual value of the parameter and on the configuration.
The CriteriaSearch is expected to be a general solution for a basic search with parameters connected by logical and. This search does not provide grouping.

Author:
Stefan Reichert, Peter Friese, Chad Brandon
See Also:
org.hibernate.Criteria, org.hibernate.criterion.Expression

Constructor Summary
CriteriaSearch(org.hibernate.Session session, java.lang.Class resultType)
          Constructor for CriteriaSearch.
 
Method Summary
 void addParameter(CriteriaSearchParameter parameter)
          Adds a CriteriaSearchParameter to this search.
 void addParameter(java.lang.Object parameterValue, java.lang.String parameterPattern)
          Adds a CriteriaSearchParameter to this search.
 void addParameter(java.lang.String parameterValue, java.lang.String parameterPattern)
          Adds a CriteriaSearchParameter to this search.
 java.util.List executeAsList()
          Executes a HibernateQuery using the currently defined CriteriaSearchParameters, and returns a java.util.List containing the query results.
 java.util.Set executeAsSet()
          Executes a HibernateQuery using the currently defined CriteriaSearchParameters, and returns a java.util.Set containing the query results.
 CriteriaSearchConfiguration getConfiguration()
          Returns the configuration of this search.
protected  org.hibernate.Criteria getRootCriteria()
          Exposes the root criteria to subclasses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CriteriaSearch

public CriteriaSearch(org.hibernate.Session session,
                      java.lang.Class resultType)
Constructor for CriteriaSearch. Creates a CriteriaSearch with a default CriteriaSearchConfiguration.

Parameters:
session - The Hibernate session.
resultType - The Class of the result.
Method Detail

getRootCriteria

protected org.hibernate.Criteria getRootCriteria()
Exposes the root criteria to subclasses.


executeAsSet

public java.util.Set executeAsSet()
                           throws org.hibernate.HibernateException
Executes a HibernateQuery using the currently defined CriteriaSearchParameters, and returns a java.util.Set containing the query results.

Returns:
result The result of the query.
Throws:
org.hibernate.HibernateException

executeAsList

public java.util.List executeAsList()
                             throws org.hibernate.HibernateException
Executes a HibernateQuery using the currently defined CriteriaSearchParameters, and returns a java.util.List containing the query results.

Returns:
result The result of the query as a List
Throws:
org.hibernate.HibernateException

addParameter

public void addParameter(java.lang.Object parameterValue,
                         java.lang.String parameterPattern)
                  throws org.hibernate.HibernateException
Adds a CriteriaSearchParameter to this search. The parameter is connected to the search by logical and. It is not considered if the value is null. If the value is not null it is compared using the CriteriaSearchParameter.EQUALS_COMPARATOR.

Parameters:
parameterValue - The value of the parameter.
parameterPattern - The pattern of the parameter (dot-seperated path e.g. person.address.street).
Throws:
org.hibernate.HibernateException

addParameter

public void addParameter(java.lang.String parameterValue,
                         java.lang.String parameterPattern)
                  throws org.hibernate.HibernateException
Adds a CriteriaSearchParameter to this search. The parameter is connected to the search by logical and. It is not considered if the value is null or if the String empty. If the value is not null it is compared using the CriteriaSearchParameter.LIKE_COMPARATOR.

Parameters:
parameterValue - The value of the parameter.
parameterPattern - The pattern of the parameter (dot-seperated path e.g. person.address.street).
Throws:
org.hibernate.HibernateException

addParameter

public void addParameter(CriteriaSearchParameter parameter)
                  throws org.hibernate.HibernateException
Adds a CriteriaSearchParameter to this search. The parameter is connected to the search by logical and.

Parameters:
parameter - The CriteriaSearchParameter to add.
Throws:
org.hibernate.HibernateException

getConfiguration

public CriteriaSearchConfiguration getConfiguration()
Returns the configuration of this search.

Returns:
configuration


Copyright © 2008-2010 IFREMER. All Rights Reserved.