org.ow2.dragon.persistence.dao
Class GenericHibernateDAOImpl<T,PK extends java.io.Serializable>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by org.ow2.dragon.persistence.dao.GenericHibernateDAOImpl<T,PK>
Type Parameters:
T - a type variable
PK - the primary key for that type
All Implemented Interfaces:
GenericORMDAO<T,PK>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
AgreementDAOImpl, BindingDAOImpl, BindingOperationDAOImpl, BusinessValueDAOImpl, CompensationAssessmentDAOImpl, CompensationDAOImpl, EndpointDAOImpl, GuaranteeDAOImpl, ItemDAOImpl, ManagedAgreementDAOImpl, MessageSpecificationDAOImpl, MetricDAOImpl, OrganizationUnitDAOImpl, PartyDAOImpl, PersonDAOImpl, PostDAOImpl, ProposedOperationDAOImpl, ProtocolDAOImpl, RoleOfPartyDAOImpl, ServiceDAOImpl, ServiceDefinitionLanguageFileDAOImpl, ServiceDescriptionTermDAOImpl, ServiceInterfaceDAOImpl, ServiceLevelObjectiveDAOImpl, ServicePropertiesDAOImpl, ServiceReferenceDAOImpl, ServiceSelectorDAOImpl, ServiceSelectorItemDAOImpl, ServiceSpecificationDAOImpl, SimpleFileDAOImpl, SpecifiedOperationDAOImpl, TechnicalServiceDAOImpl

public class GenericHibernateDAOImpl<T,PK extends java.io.Serializable>
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements GenericORMDAO<T,PK>

This class serves as the Base class for all other DAOs - namely to hold common CRUD methods that they might all use. You should only need to extend this class when your require custom CRUD logic.

To register this class in your Spring context file, use the following XML.

      <bean id="fooDao" class="org.appfuse.dao.hibernate.GenericDaoHibernate">
          <property name="type" value="org.appfuse.model.Foo"/>
          <property name="sessionFactory" ref="sessionFactory"/>
      </bean>
 

Author:
Bryan Noll, ofabre - eBM WebSourcing

Field Summary
 java.lang.Class<T> type
           
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
GenericHibernateDAOImpl()
           
 
Method Summary
 boolean exists(PK id)
          Checks for existence of an object of type T using the id arg.
 java.util.List<T> findByNamedQuery(java.lang.String queryName, java.util.Map<java.lang.String,java.lang.Object> queryParams)
          Find a list of records by using a named query
 T get(PK id)
          Generic method to get an object based on class and identifier.
 java.util.List<T> getAll()
          Generic method used to get all objects of a particular type.
 java.util.List<T> getAll(java.util.List<PK> ids)
          Retrieve a List of entities matching given ids
 java.util.List<T> getAll(java.util.List<PK> ids, RequestOptions requestOptions)
          Retrieve a List of entities matching given ids, sorted and paginated according to the given request options
 java.util.List<T> getAll(RequestOptions requestOptions)
          Generic method used to get all objects of a particular type, sorted and paginated according to the given request options.
 java.util.List<T> getAllDistinct()
          Gets all records without duplicates.
 java.lang.Class<T> getManipulatedType()
          Return the type of entity manipulated by this DAO
 void remove(PK id)
          Generic method to delete an object based on class and id
 T save(T object)
          Generic method to save an object - handles both update and insert.
 java.util.List<T> searchEquals(java.lang.String[] criteria, java.lang.String[] properties, RequestOptions requestOptions)
          This method allows to search Objects on String properties, fitting search criteria.
 java.util.List<T> searchLike(java.lang.String[] criteria, java.lang.String[] properties, RequestOptions requestOptions)
          This method allows to search Objects on String properties, fitting search criteria.
 void setType(java.lang.Class<T> type)
           
 
Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

public java.lang.Class<T> type
Constructor Detail

GenericHibernateDAOImpl

public GenericHibernateDAOImpl()
Method Detail

setType

public void setType(java.lang.Class<T> type)

getAll

public java.util.List<T> getAll(RequestOptions requestOptions)
Generic method used to get all objects of a particular type, sorted and paginated according to the given request options. This is the same as lookup up all rows in a table.

Specified by:
getAll in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
requestOptions - include sort order and pagination information
Returns:
List of populated objects

searchEquals

public java.util.List<T> searchEquals(java.lang.String[] criteria,
                                      java.lang.String[] properties,
                                      RequestOptions requestOptions)
This method allows to search Objects on String properties, fitting search criteria. Properties can be direct object fields or fields of included objects (in this case, fields must be referenced by the doted notation like "foo.bar"). Use a equality statement for each criteria on each property. Results are sorted and paginated in respect of the given request options.

Specified by:
searchEquals in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
criteria - the search criteria
properties - the searched properties
requestOptions - include sort order and pagination information
Returns:
a list of object matching the different criteria sorted and paginated

searchLike

public java.util.List<T> searchLike(java.lang.String[] criteria,
                                    java.lang.String[] properties,
                                    RequestOptions requestOptions)
This method allows to search Objects on String properties, fitting search criteria. Properties can be direct object fields or fields of included objects (in this case, fields must be referenced by the doted notation like "foo.bar"). Use a like statement for each criteria on each property. Results are sorted and paginated in respect of the given request options.
Limitations: this method can have some troubles if two or more doted properties contains the same field like "aaa.bbb" and "ccc.ddd. bbb"

Specified by:
searchLike in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
criteria - the search criteria
properties - the searched properties
requestOptions - include sort order and pagination information
Returns:
a list of object matching the different criteria sorted and paginated

getAll

public java.util.List<T> getAll()
Generic method used to get all objects of a particular type. This is the same as lookup up all rows in a table.

Specified by:
getAll in interface GenericORMDAO<T,PK extends java.io.Serializable>
Returns:
List of populated objects

getAll

public java.util.List<T> getAll(java.util.List<PK> ids)
Description copied from interface: GenericORMDAO
Retrieve a List of entities matching given ids

Specified by:
getAll in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
ids - a List of ids
Returns:
a List of entities matching ids, must be non null, could be empty

getAll

public java.util.List<T> getAll(java.util.List<PK> ids,
                                RequestOptions requestOptions)
Retrieve a List of entities matching given ids, sorted and paginated according to the given request options

Specified by:
getAll in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
ids - a List of ids
requestOptions - include sort order and pagination information
Returns:
a sorted/paginated List of entities matching ids, must be non null, could be empty

getAllDistinct

public java.util.List<T> getAllDistinct()
Gets all records without duplicates.

Note that if you use this method, it is imperative that your model classes correctly implement the hashcode/equals methods

Specified by:
getAllDistinct in interface GenericORMDAO<T,PK extends java.io.Serializable>
Returns:
List of populated objects

get

public T get(PK id)
Generic method to get an object based on class and identifier. An ObjectRetrievalFailureException Runtime Exception is thrown if nothing is found.

Specified by:
get in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
id - the identifier (primary key) of the object to get
Returns:
a populated object
See Also:
ObjectRetrievalFailureException

exists

public boolean exists(PK id)
Checks for existence of an object of type T using the id arg.

Specified by:
exists in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
id - the id of the entity
Returns:
- true if it exists, false if it doesn't

save

public T save(T object)
Generic method to save an object - handles both update and insert.

Specified by:
save in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
object - the object to save
Returns:
the persisted object

remove

public void remove(PK id)
Generic method to delete an object based on class and id

Specified by:
remove in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
id - the identifier (primary key) of the object to remove

findByNamedQuery

public java.util.List<T> findByNamedQuery(java.lang.String queryName,
                                          java.util.Map<java.lang.String,java.lang.Object> queryParams)
Find a list of records by using a named query

Specified by:
findByNamedQuery in interface GenericORMDAO<T,PK extends java.io.Serializable>
Parameters:
queryName - query name of the named query
queryParams - a map of the query names and the values
Returns:
a list of the records found

getManipulatedType

public java.lang.Class<T> getManipulatedType()
Return the type of entity manipulated by this DAO

Specified by:
getManipulatedType in interface GenericORMDAO<T,PK extends java.io.Serializable>
Returns:
the Class of the manipulated entity


Copyright © 2008 eBMWebsourcing. All Rights Reserved.