info.joseluismartin.dao.hibernate
Class HibernateDao<T,PK extends Serializable>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by info.joseluismartin.dao.hibernate.HibernateDao<T,PK>
All Implemented Interfaces:
Dao<T,PK>, PageableDataSource<T>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
HibernateReportDao

public class HibernateDao<T,PK extends Serializable>
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements Dao<T,PK>

Hibernate generic DAO implementation. Support pagination of results with filters using getPage(Page page) method.

Author:
Jose Luis Martin - (jlm@joseluismartin.info).
See Also:
Dao

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
HibernateDao()
           
HibernateDao(Class<T> persistentClass)
           
 
Method Summary
protected  void applyOrder(Page<T> page, Criteria criteria)
          Apply Order to Criteria
 int count()
          Count rows
protected  Order createOrder(Criteria criteria, String propertyPath, boolean ascending)
          Create Order from criteria and property path
 void delete(T entity)
          Delete a entity from db
 void deleteById(PK id)
          Delete an object by primary key
 boolean enableFilter(Filter f)
          Enable predefined filter in current session
 boolean exists(PK id)
          Checks for existence of an object of type T using the id arg.
 List<T> findByNamedQuery(String queryName, Map<String,Object> queryParams)
          Find a list of records by using a named query
 T get(PK id)
          Find object by id
<E> E
get(PK id, Class<E> clazz)
          
 List<T> getAll()
          Get all models
<E> List<E>
getAll(Class<E> clazz)
          
 List<T> getAllDistinct()
           
 Map<String,CriteriaBuilder> getCriteriaBuilderMap()
           
 Class<T> getEntityClass()
           
 List<Serializable> getKeys(Page<T> page)
          Gets a List with keys of page
 Page<T> getPage(Page<T> page)
          Get Page, apply filter if any.
 T initialize(T entity)
          Initalize entity at default depth
 T initialize(T entity, int depth)
          Initalize entity
 boolean isCachePageQueries()
           
 T save(T entity)
          Save or update an object
 void setCachePageQueries(boolean cachePageQueries)
           
 void setCriteriaBuilderMap(Map<String,CriteriaBuilder> criteriaBuilderMap)
           
 void setEntityClass(Class<T> entityClass)
           
 
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

HibernateDao

public HibernateDao()

HibernateDao

public HibernateDao(Class<T> persistentClass)
Parameters:
persistentClass -
Method Detail

getPage

public Page<T> getPage(Page<T> page)
Get Page, apply filter if any. If Filter is a entity model, use Example to create a criteria. else enable filter by name on session.

Specified by:
getPage in interface PageableDataSource<T>
Parameters:
page - with page definitions
Returns:
page of results

enableFilter

public boolean enableFilter(Filter f)
Enable predefined filter in current session

Parameters:
f - Filter with filter name and parameters
Returns:
true if hibernate filter exists

applyOrder

protected void applyOrder(Page<T> page,
                          Criteria criteria)
Apply Order to Criteria

Parameters:
page - the page
criteria - the criteria

createOrder

protected Order createOrder(Criteria criteria,
                            String propertyPath,
                            boolean ascending)
Create Order from criteria and property path

Parameters:
criteria - the hibernate criteria to apply order on
propertyPath - the property path
Returns:
Order

getEntityClass

public Class<T> getEntityClass()
Returns:
the entityClass

setEntityClass

public void setEntityClass(Class<T> entityClass)
Parameters:
entityClass - the entityClass to set

delete

public void delete(T entity)
Delete a entity from db

Specified by:
delete in interface Dao<T,PK extends Serializable>
Parameters:
entity -

save

public T save(T entity)
Description copied from interface: Dao
Save or update an object

Specified by:
save in interface Dao<T,PK extends Serializable>
Parameters:
entity - the object to save
Returns:
the persisted object

getKeys

public List<Serializable> getKeys(Page<T> page)
Description copied from interface: PageableDataSource
Gets a List with keys of page

Specified by:
getKeys in interface PageableDataSource<T>
Returns:
List with keys

deleteById

public void deleteById(PK id)
Description copied from interface: Dao
Delete an object by primary key

Specified by:
deleteById in interface Dao<T,PK extends Serializable>
Parameters:
id - the primary key

initialize

public T initialize(T entity)
Description copied from interface: Dao
Initalize entity at default depth

Specified by:
initialize in interface Dao<T,PK extends Serializable>
Parameters:
entity - to intialize
Returns:
intialized entity

initialize

public T initialize(T entity,
                    int depth)
Description copied from interface: Dao
Initalize entity

Specified by:
initialize in interface Dao<T,PK extends Serializable>
Parameters:
entity - to intialize
depth - to descend.
Returns:
intialized entity

getCriteriaBuilderMap

public Map<String,CriteriaBuilder> getCriteriaBuilderMap()
Returns:
the criteriaBuilderMap

setCriteriaBuilderMap

public void setCriteriaBuilderMap(Map<String,CriteriaBuilder> criteriaBuilderMap)
Parameters:
criteriaBuilderMap - the criteriaBuilderMap to set

getAll

public List<T> getAll()
Get all models

Specified by:
getAll in interface Dao<T,PK extends Serializable>
Returns:
List of entities

getAllDistinct

public List<T> getAllDistinct()

findByNamedQuery

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

Specified by:
findByNamedQuery in interface Dao<T,PK extends 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

get

public T get(PK id)
Find object by id

Specified by:
get in interface Dao<T,PK extends Serializable>
Parameters:
id - the identifier (primary key) of the object to get
Returns:
entity or null if none

exists

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

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

count

public int count()
Count rows

Returns:
number of rows

isCachePageQueries

public boolean isCachePageQueries()
Returns:
the cachePageQueries

setCachePageQueries

public void setCachePageQueries(boolean cachePageQueries)
Parameters:
cachePageQueries - the cachePageQueries to set

get

public <E> E get(PK id,
                 Class<E> clazz)

Specified by:
get in interface Dao<T,PK extends Serializable>

getAll

public <E> List<E> getAll(Class<E> clazz)

Specified by:
getAll in interface Dao<T,PK extends Serializable>


Copyright © 2012 JDAL. All Rights Reserved.