com.anasoft.os.daofusion
Class AbstractHibernateEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>

java.lang.Object
  extended by com.anasoft.os.daofusion.BaseHibernateDataAccessor
      extended by com.anasoft.os.daofusion.AbstractHibernateEntityDao<T,ID>
Type Parameters:
T - Type of the persistent entity the DAO works with.
ID - Java type of persistent entity's primary key column.
All Implemented Interfaces:
PersistentEntityDao<T,ID>
Direct Known Subclasses:
AbstractHibernateEnumerationDao

public abstract class AbstractHibernateEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
extends BaseHibernateDataAccessor
implements PersistentEntityDao<T,ID>

Generic persistent entity DAO implementation using JPA / Hibernate persistence APIs.

Note that the row count technique implementation relies on Hibernate rowCount projection. See the BaseHibernateDataAccessor.rowCount(Criteria) method for more information about the row count implementation and its implications regarding Criteria instances.

Author:
vojtech.szocs
See Also:
PersistentEntityDao, BaseHibernateDataAccessor

Constructor Summary
AbstractHibernateEntityDao()
           
 
Method Summary
 int count(PersistentEntityCriteria entityCriteria)
          Returns the total number of instances persisted within the database, using the implicit persistent entity class.
<S extends T>
int
count(PersistentEntityCriteria entityCriteria, java.lang.Class<S> targetEntityClass)
          Returns the total number of instances persisted within the database.
 int countAll()
          Returns the total number of all instances persisted within the database, using the implicit persistent entity class.
<S extends T>
int
countAll(java.lang.Class<S> targetEntityClass)
          Returns the total number of all instances persisted within the database.
 void delete(ID id)
          Deletes a persistent instance, using the implicit persistent entity class.
<S extends T>
void
delete(ID id, java.lang.Class<S> targetEntityClass)
          Deletes a persistent instance.
 void delete(T entity)
          Deletes a persistent instance.
 int deleteAll()
          Deletes all persistent instances, using the implicit persistent entity class.
<S extends T>
int
deleteAll(java.lang.Class<S> targetEntityClass)
          Deletes all persistent instances.
 T get(ID id)
          Retrieves a persistent instance, using the implicit persistent entity class.
<S extends T>
S
get(ID id, java.lang.Class<S> targetEntityClass)
          Retrieves a persistent instance.
 java.util.List<T> getAll()
          Retrieves all persistent instances, using the implicit persistent entity class.
<S extends T>
java.util.List<S>
getAll(java.lang.Class<S> targetEntityClass)
          Retrieves all persistent instances.
 java.util.List<T> query(PersistentEntityCriteria entityCriteria)
          Retrieves a list of persistent instances, using the implicit persistent entity class.
<S extends T>
java.util.List<S>
query(PersistentEntityCriteria entityCriteria, java.lang.Class<S> targetEntityClass)
          Retrieves a list of persistent instances.
 void refresh(T entity)
          Refreshes a persistent or a detached instance by synchronizing its state with the database.
<S extends T>
S
saveOrUpdate(S entity)
          Persists a transient instance or updates a detached instance.
 T uniqueResult(PersistentEntityCriteria entityCriteria, boolean returnNullOnMultipleResults)
          Returns a single persistent instance (if available), using the implicit persistent entity class.
<S extends T>
S
uniqueResult(PersistentEntityCriteria entityCriteria, boolean returnNullOnMultipleResults, java.lang.Class<S> targetEntityClass)
          Returns a single persistent instance (if available).
 
Methods inherited from class com.anasoft.os.daofusion.BaseHibernateDataAccessor
getCriteria, getHibernateCriteria, getHibernateEntityManager, getSession, rowCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.anasoft.os.daofusion.PersistentEntityDao
getEntityClass
 

Constructor Detail

AbstractHibernateEntityDao

public AbstractHibernateEntityDao()
Method Detail

get

public <S extends T> S get(ID id,
                           java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Retrieves a persistent instance.

Specified by:
get in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
id - id of the persistent instance to retrieve.
targetEntityClass - Target persistent entity class.
Returns:
Resulting persistent instance or null in case the requested instance was not found.
See Also:
PersistentEntityDao.get(java.io.Serializable, java.lang.Class)

get

public T get(ID id)
Description copied from interface: PersistentEntityDao
Retrieves a persistent instance, using the implicit persistent entity class.

Specified by:
get in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
id - id of the persistent instance to retrieve.
Returns:
Resulting persistent instance or null in case the requested instance was not found.
See Also:
PersistentEntityDao.get(java.io.Serializable)

getAll

public <S extends T> java.util.List<S> getAll(java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Retrieves all persistent instances.

Specified by:
getAll in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
targetEntityClass - Target persistent entity class.
Returns:
Resulting list of persistent instances.
See Also:
PersistentEntityDao.getAll(java.lang.Class)

getAll

public java.util.List<T> getAll()
Description copied from interface: PersistentEntityDao
Retrieves all persistent instances, using the implicit persistent entity class.

Specified by:
getAll in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Returns:
Resulting list of persistent instances.
See Also:
PersistentEntityDao.getAll()

saveOrUpdate

public <S extends T> S saveOrUpdate(S entity)
Description copied from interface: PersistentEntityDao
Persists a transient instance or updates a detached instance.

Cascade types triggered by this operation: save-update, merge.

Specified by:
saveOrUpdate in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entity - Transient or detached instance to save or update.
Returns:
Resulting persistent instance.
See Also:
PersistentEntityDao.saveOrUpdate(com.anasoft.os.daofusion.entity.Persistable)

delete

public void delete(T entity)
Description copied from interface: PersistentEntityDao
Deletes a persistent instance.

Cascade types triggered by this operation: delete.

Specified by:
delete in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entity - Persistent instance to delete.
See Also:
PersistentEntityDao.delete(com.anasoft.os.daofusion.entity.Persistable)

delete

public <S extends T> void delete(ID id,
                                 java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Deletes a persistent instance.

Cascade types triggered by this operation: delete.

Specified by:
delete in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
id - id of the persistent instance to delete.
targetEntityClass - Target persistent entity class.
See Also:
PersistentEntityDao.delete(java.io.Serializable, java.lang.Class)

delete

public void delete(ID id)
Description copied from interface: PersistentEntityDao
Deletes a persistent instance, using the implicit persistent entity class.

Cascade types triggered by this operation: delete.

Specified by:
delete in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
id - id of the persistent instance to delete.
See Also:
PersistentEntityDao.delete(java.io.Serializable)

deleteAll

public <S extends T> int deleteAll(java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Deletes all persistent instances.

Cascade types triggered by this operation: delete.

Specified by:
deleteAll in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
targetEntityClass - Target persistent entity class.
Returns:
Number of persistent instances deleted.
See Also:
PersistentEntityDao.deleteAll(java.lang.Class)

deleteAll

public int deleteAll()
Description copied from interface: PersistentEntityDao
Deletes all persistent instances, using the implicit persistent entity class.

Cascade types triggered by this operation: delete.

Specified by:
deleteAll in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Returns:
Number of persistent instances deleted.
See Also:
PersistentEntityDao.deleteAll()

refresh

public void refresh(T entity)
Description copied from interface: PersistentEntityDao
Refreshes a persistent or a detached instance by synchronizing its state with the database.

Specified by:
refresh in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entity - Persistent or detached instance to refresh.
See Also:
PersistentEntityDao.refresh(com.anasoft.os.daofusion.entity.Persistable)

query

public <S extends T> java.util.List<S> query(PersistentEntityCriteria entityCriteria,
                                             java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Retrieves a list of persistent instances.

Specified by:
query in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
targetEntityClass - Target persistent entity class.
Returns:
Resulting list of persistent instances.
See Also:
PersistentEntityDao.query(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria, java.lang.Class)

query

public java.util.List<T> query(PersistentEntityCriteria entityCriteria)
Description copied from interface: PersistentEntityDao
Retrieves a list of persistent instances, using the implicit persistent entity class.

Specified by:
query in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
Returns:
Resulting list of persistent instances.
See Also:
PersistentEntityDao.query(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria)

uniqueResult

public <S extends T> S uniqueResult(PersistentEntityCriteria entityCriteria,
                                    boolean returnNullOnMultipleResults,
                                    java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Returns a single persistent instance (if available).

Specified by:
uniqueResult in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
returnNullOnMultipleResults - true to return null in case the query results in more than one persistent instance.
targetEntityClass - Target persistent entity class.
Returns:
Resulting persistent instance or null in case the requested instance was not found.
See Also:
PersistentEntityDao.uniqueResult(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria, boolean, java.lang.Class)

uniqueResult

public T uniqueResult(PersistentEntityCriteria entityCriteria,
                      boolean returnNullOnMultipleResults)
Description copied from interface: PersistentEntityDao
Returns a single persistent instance (if available), using the implicit persistent entity class.

Specified by:
uniqueResult in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
returnNullOnMultipleResults - true to return null in case the query results in more than one persistent instance.
Returns:
Resulting persistent instance or null in case the requested instance was not found.
See Also:
PersistentEntityDao.uniqueResult(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria, boolean)

count

public <S extends T> int count(PersistentEntityCriteria entityCriteria,
                               java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Returns the total number of instances persisted within the database.

Specified by:
count in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
targetEntityClass - Target persistent entity class.
Returns:
Total instance count.
See Also:
PersistentEntityDao.count(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria, java.lang.Class)

count

public int count(PersistentEntityCriteria entityCriteria)
Description copied from interface: PersistentEntityDao
Returns the total number of instances persisted within the database, using the implicit persistent entity class.

Specified by:
count in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
Returns:
Total instance count.
See Also:
PersistentEntityDao.count(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria)

countAll

public <S extends T> int countAll(java.lang.Class<S> targetEntityClass)
Description copied from interface: PersistentEntityDao
Returns the total number of all instances persisted within the database.

Specified by:
countAll in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Parameters:
targetEntityClass - Target persistent entity class.
Returns:
Total instance count.
See Also:
PersistentEntityDao.countAll(java.lang.Class)

countAll

public int countAll()
Description copied from interface: PersistentEntityDao
Returns the total number of all instances persisted within the database, using the implicit persistent entity class.

Specified by:
countAll in interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>
Returns:
Total instance count.
See Also:
PersistentEntityDao.countAll()


Copyright © 2008-2009 ANASOFT and contributors. All Rights Reserved.