com.gisgraphy.domain.repository
Class GenericDao<T,PK extends Serializable>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by com.gisgraphy.domain.repository.GenericDao<T,PK>
All Implemented Interfaces:
IDao<T,PK>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
AlternateNameDao, GenericGisDao, LanguageDao, OpenStreetMapDao, StatsUsageDao, ZipCodeDao

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

A generic dao That implements basic functions with java 5.0 generics

Author:
David Masclet

Field Summary
protected  Class<T> persistentClass
           
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
GenericDao(Class<T> persistentClass)
          constructor
 
Method Summary
 long count()
           
 int deleteAll()
          Delete all the object from the datastore
 void deleteAll(List<T> list)
          Delete all the specified object from the datastore
 boolean exists(PK id)
          Checks for existence of an object of type T using the id arg.
 void flushAndClear()
          Flush all Memory Objects to the database, and clear the L1 cache, of the current thread-bound Hibernate Session.
 T get(PK id)
          Retrieve the Object whith the specified primary key
 List<T> getAll()
          Generic method used to get all objects of a particular type.
 List<T> getAllPaginate(int from, int maxResults)
          Returns all object of a particular type (i.e getAllPaginate(2,5) will return the [2,3,4,5,6] object
 Class<T> getPersistenceClass()
           
 void remove(T o)
          remove the object from the datastore
 T save(T o)
          Saves the passed object, and returns an attached entity.
 void setFlushMode(org.hibernate.FlushMode flushMode)
          Sets the flush mode (i.e. when objects are flushed to the database) of the current thread-bound session.
 
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

persistentClass

protected Class<T> persistentClass
Constructor Detail

GenericDao

public GenericDao(Class<T> persistentClass)
constructor

Parameters:
persistentClass - The specified Class for the GenericDao
Method Detail

getPersistenceClass

public Class<T> getPersistenceClass()
Specified by:
getPersistenceClass in interface IDao<T,PK extends Serializable>
Returns:
The class, this DAO 'process'

flushAndClear

public void flushAndClear()
Description copied from interface: IDao
Flush all Memory Objects to the database, and clear the L1 cache, of the current thread-bound Hibernate Session.

Specified by:
flushAndClear in interface IDao<T,PK extends Serializable>

remove

public void remove(T o)
Description copied from interface: IDao
remove the object from the datastore

Specified by:
remove in interface IDao<T,PK extends Serializable>
Parameters:
o - The object to remove

save

public T save(T o)
Description copied from interface: IDao
Saves the passed object, and returns an attached entity. It is very very very important to use the returned entity, because of the way the underlying mechanism possibly works. For instance, when using Db4o, this is completly useless, but when using JPA and the merge method of the EntityManager, things are going to be buggy (Duplicate Key exceptions) if you don't use the returned object. Please consult EJB3 (or the concrete persistence framework doc) Spec for more information about the way the merge method works.

Specified by:
save in interface IDao<T,PK extends Serializable>
Parameters:
o - The object to save
Returns:
The saved instance

setFlushMode

public void setFlushMode(org.hibernate.FlushMode flushMode)
Description copied from interface: IDao
Sets the flush mode (i.e. when objects are flushed to the database) of the current thread-bound session. By default, it is equivalent (in the case of JPA persistence) to FlushModeType.AUTO, which lets the persistence framework handle that issue. However, for performance reasons, it might be necessary to set it to FlushModeType.COMMIT. Warning : this sets the default flush mode of the session (either hibernate Session, JPA EntityManager, or similar) that is currently bound to the current thread. This means that it has absolutely no effect if no transaction is currently opened.

Specified by:
setFlushMode in interface IDao<T,PK extends Serializable>
Parameters:
flushMode - The flush mode To set for this dao

get

public T get(PK id)
Description copied from interface: IDao
Retrieve the Object whith the specified primary key

Specified by:
get in interface IDao<T,PK extends Serializable>
Parameters:
id - the primarey key
Returns:
The object

exists

public boolean exists(PK id)
Description copied from interface: IDao
Checks for existence of an object of type T using the id arg.

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

getAll

public List<T> getAll()
Description copied from interface: IDao
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 IDao<T,PK extends Serializable>
Returns:
List of populated objects (never return null, but an empty list)

deleteAll

public void deleteAll(List<T> list)
Description copied from interface: IDao
Delete all the specified object from the datastore

Specified by:
deleteAll in interface IDao<T,PK extends Serializable>
Parameters:
list - the list of element to delete

count

public long count()
Specified by:
count in interface IDao<T,PK extends Serializable>
Returns:
the number of element in the Datastore

getAllPaginate

public List<T> getAllPaginate(int from,
                              int maxResults)
Description copied from interface: IDao
Returns all object of a particular type (i.e getAllPaginate(2,5) will return the [2,3,4,5,6] object

Specified by:
getAllPaginate in interface IDao<T,PK extends Serializable>
Parameters:
from - The first result to return numbered from 1
maxResults - The maximum list size to return
Returns:
List of populated objects, (never return null, but an empty list)

deleteAll

public int deleteAll()
Description copied from interface: IDao
Delete all the object from the datastore

Specified by:
deleteAll in interface IDao<T,PK extends Serializable>
Returns:
the number of deleted objects


Copyright © 2012. All Rights Reserved.