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
 int count(java.lang.Class clazz, com.trg.search.IMutableSearch search)
          Returns the total number of results that would be returned using the given ISearch if there were no paging or maxResult limits.
 boolean exists(java.lang.Class clazz, java.io.Serializable id)
          Checks for existence of an object of type T using the id arg.
 java.util.List 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
 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.
 java.lang.Object merge(java.lang.Object o)
          
 java.lang.Object persist(java.lang.Object o)
          
 void remove(java.lang.Class clazz, java.io.Serializable id)
          Generic method to delete an object based on class and id
 void removeAll(java.lang.Class clazz, java.util.List ids)
          Generic method to delete all object based on class and ids list
 void removeAll(java.util.List objects)
          
 java.lang.Object save(java.lang.Object o)
          Generic method to save an object - handles both update and insert.
 java.lang.Object saveOnly(java.lang.Object o)
           
 java.util.List search(java.lang.Class clazz, com.trg.search.IMutableSearch search)
          Search for objects based on the search parameters in the specified ISearch object.
 com.trg.search.SearchResult searchAndCount(java.lang.Class clazz, com.trg.search.IMutableSearch search)
          Returns a SearchResult object that includes the list of results like search() and the total length like searchLength.
 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.
 java.lang.Object searchUnique(java.lang.Class clazz, com.trg.search.IMutableSearch search)
          Search for a single result using the given parameters.
 java.lang.Object updateOnly(java.lang.Object o)
           
 
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.

Specified by:
get in interface UniversalORMDAO
Parameters:
clazz - model class to lookup
id - the identifier (primary key) of the class
Returns:
a populated object or null if not found

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

removeAll

public void removeAll(java.lang.Class clazz,
                      java.util.List ids)
Generic method to delete all object based on class and ids list

Specified by:
removeAll in interface UniversalORMDAO
Parameters:
clazz - model class to lookup
ids - the identifiers (primary key) of object to delete

removeAll

public void removeAll(java.util.List objects)

Specified by:
removeAll in interface UniversalORMDAO

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.

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

search

public java.util.List search(java.lang.Class clazz,
                             com.trg.search.IMutableSearch search)
Search for objects based on the search parameters in the specified ISearch object.

Specified by:
search in interface UniversalORMDAO
See Also:
ISearch

count

public int count(java.lang.Class clazz,
                 com.trg.search.IMutableSearch search)
Returns the total number of results that would be returned using the given ISearch if there were no paging or maxResult limits.

Specified by:
count in interface UniversalORMDAO
See Also:
ISearch

searchAndCount

public com.trg.search.SearchResult searchAndCount(java.lang.Class clazz,
                                                  com.trg.search.IMutableSearch search)
Returns a SearchResult object that includes the list of results like search() and the total length like searchLength.

Specified by:
searchAndCount in interface UniversalORMDAO
See Also:
ISearch

searchUnique

public java.lang.Object searchUnique(java.lang.Class clazz,
                                     com.trg.search.IMutableSearch search)
                              throws org.hibernate.NonUniqueResultException
Search for a single result using the given parameters.

Specified by:
searchUnique in interface UniversalORMDAO
Throws:
org.hibernate.NonUniqueResultException

exists

public boolean exists(java.lang.Class clazz,
                      java.io.Serializable id)
Checks for existence of an object of type T using the id arg.

Specified by:
exists in interface UniversalORMDAO
id - the id of the entity
Returns:
- true if it exists, false if it doesn't

findByNamedQuery

public java.util.List 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 UniversalORMDAO
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

merge

public java.lang.Object merge(java.lang.Object o)

Specified by:
merge in interface UniversalORMDAO

persist

public java.lang.Object persist(java.lang.Object o)

Specified by:
persist in interface UniversalORMDAO

saveOnly

public java.lang.Object saveOnly(java.lang.Object o)
Specified by:
saveOnly in interface UniversalORMDAO

updateOnly

public java.lang.Object updateOnly(java.lang.Object o)
Specified by:
updateOnly in interface UniversalORMDAO


Copyright © 2008-2009 eBMWebsourcing. All Rights Reserved.