org.ow2.dragon.persistence.dao
Class UniversalHibernateDAOImpl

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.UniversalHibernateDAOImpl
All Implemented Interfaces:
UniversalORMDAO, org.springframework.beans.factory.InitializingBean

public class UniversalHibernateDAOImpl
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements UniversalORMDAO

This class serves as the a class that can CRUD any object witout any Spring configuration. The only downside is it does require casting from Object to the object class.

Author:
Bryan Noll, Olivier FABRE

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
UniversalHibernateDAOImpl()
           
 
Method Summary
 java.lang.Object get(java.lang.Class clazz, java.io.Serializable id)
          Generic method to get an object based on class and identifier.
 java.util.List getAll(java.lang.Class clazz)
          Generic method used to get all objects of a particular type.
 java.util.List getAll(java.lang.Class clazz, java.util.List ids)
          Retrieve a List of entities matching given ids
 java.util.List getAll(java.lang.Class clazz, java.util.List ids, RequestOptions requestOptions)
          Retrieve a List of entities matching given ids, sorted and paginated according to the given request options
 java.util.List getAll(java.lang.Class clazz, RequestOptions requestOptions)
          Generic method used to get all objects of a particular type, sorted and paginated according to the given request options.
 void remove(java.lang.Class clazz, java.io.Serializable id)
          Generic method to delete an object based on class and id
 java.lang.Object save(java.lang.Object o)
          Generic method to save an object - handles both update and insert.
 java.util.List searchEquals(java.lang.Class clazz, 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 searchLike(java.lang.Class clazz, java.lang.String[] criteria, java.lang.String[] properties, RequestOptions requestOptions)
          This method allows to search Objects on String properties, fitting search criteria.
 
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
 

Constructor Detail

UniversalHibernateDAOImpl

public UniversalHibernateDAOImpl()
Method Detail

save

public java.lang.Object save(java.lang.Object o)
Generic method to save an object - handles both update and insert.

Specified by:
save in interface UniversalORMDAO
Parameters:
o - the object to save
Returns:
a populated object

get

public java.lang.Object get(java.lang.Class clazz,
                            java.io.Serializable 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 UniversalORMDAO
Parameters:
clazz - model class to lookup
id - the identifier (primary key) of the class
Returns:
a populated object
See Also:
ObjectRetrievalFailureException

getAll

public java.util.List getAll(java.lang.Class clazz)
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 UniversalORMDAO
Parameters:
clazz - the type of objects (a.k.a. while table) to get data from
Returns:
List of populated objects

remove

public void remove(java.lang.Class clazz,
                   java.io.Serializable id)
Generic method to delete an object based on class and id

Specified by:
remove in interface UniversalORMDAO
Parameters:
clazz - model class to lookup
id - the identifier (primary key) of the class

getAll

public java.util.List getAll(java.lang.Class clazz,
                             java.util.List ids)
Retrieve a List of entities matching given ids

Specified by:
getAll in interface UniversalORMDAO
Parameters:
clazz - model class to lookup
ids - a List of ids
Returns:
a List of entities matching ids, must be non null, could be empty

getAll

public java.util.List getAll(java.lang.Class clazz,
                             java.util.List 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 UniversalORMDAO
Parameters:
clazz - model class to lookup
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

getAll

public java.util.List getAll(java.lang.Class clazz,
                             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 UniversalORMDAO
Parameters:
clazz - model class to lookup
requestOptions - include sort order and pagination information
Returns:
List of populated objects

searchEquals

public java.util.List searchEquals(java.lang.Class clazz,
                                   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 UniversalORMDAO
Parameters:
clazz - model class to lookup
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 searchLike(java.lang.Class clazz,
                                 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 UniversalORMDAO
Parameters:
clazz - model class to lookup
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


Copyright © 2008 eBMWebsourcing. All Rights Reserved.