com.anasoft.os.daofusion
Interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>

Type Parameters:
T - Type of the persistent entity the DAO works with.
ID - Java type of persistent entity's primary key column.
All Known Subinterfaces:
PersistentEnumerationDao<T>
All Known Implementing Classes:
AbstractHibernateEntityDao, AbstractHibernateEnumerationDao

public interface PersistentEntityDao<T extends Persistable<ID>,ID extends java.io.Serializable>

Persistent entity DAO contract containing the standard set of operations supported by any persistence provider-specific DAO implementation.

The user is responsible for providing proper transaction support within the context of DAO method calls. The use of a specific transaction strategy based on a transaction model as well as proper transaction attributes always depend on specific business requirements of your project and should be therefore carefully considered in terms of concurrency, performance and data integrity.

Note that it is possible to query for subclasses of the implicit persistent entity class the DAO works with. This way, one can have a general persistent entity DAO working with a parent entity which is able to query for individual entity subclasses as well.

count / countAll methods rely on specific row count technique implementation - the user has to adapt the PersistentEntityCriteria accordingly prior to calling these methods (for example, it doesn't make sense to add paging constraints when performing a row count in general).

Author:
vojtech.szocs
See Also:
Persistable, PersistentEntityCriteria

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.lang.Class<T> getEntityClass()
          Returns the implicit persistent entity class the DAO works with.
 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).
 

Method Detail

getEntityClass

java.lang.Class<T> getEntityClass()
Returns the implicit persistent entity class the DAO works with.

Returns:
Persistent entity class.

get

<S extends T> S get(ID id,
                    java.lang.Class<S> targetEntityClass)
Retrieves a persistent instance.

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.

get

T get(ID id)
Retrieves a persistent instance, using the implicit persistent entity class.

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:
get(Serializable, Class), getEntityClass()

getAll

<S extends T> java.util.List<S> getAll(java.lang.Class<S> targetEntityClass)
Retrieves all persistent instances.

Parameters:
targetEntityClass - Target persistent entity class.
Returns:
Resulting list of persistent instances.

getAll

java.util.List<T> getAll()
Retrieves all persistent instances, using the implicit persistent entity class.

Returns:
Resulting list of persistent instances.
See Also:
getAll(Class), getEntityClass()

saveOrUpdate

<S extends T> S saveOrUpdate(S entity)
Persists a transient instance or updates a detached instance.

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

Parameters:
entity - Transient or detached instance to save or update.
Returns:
Resulting persistent instance.

delete

void delete(T entity)
Deletes a persistent instance.

Cascade types triggered by this operation: delete.

Parameters:
entity - Persistent instance to delete.

delete

<S extends T> void delete(ID id,
                          java.lang.Class<S> targetEntityClass)
Deletes a persistent instance.

Cascade types triggered by this operation: delete.

Parameters:
id - id of the persistent instance to delete.
targetEntityClass - Target persistent entity class.

delete

void delete(ID id)
Deletes a persistent instance, using the implicit persistent entity class.

Cascade types triggered by this operation: delete.

Parameters:
id - id of the persistent instance to delete.
See Also:
delete(Serializable, Class), getEntityClass()

deleteAll

<S extends T> int deleteAll(java.lang.Class<S> targetEntityClass)
Deletes all persistent instances.

Cascade types triggered by this operation: delete.

Parameters:
targetEntityClass - Target persistent entity class.
Returns:
Number of persistent instances deleted.

deleteAll

int deleteAll()
Deletes all persistent instances, using the implicit persistent entity class.

Cascade types triggered by this operation: delete.

Returns:
Number of persistent instances deleted.
See Also:
deleteAll(Class), getEntityClass()

refresh

void refresh(T entity)
Refreshes a persistent or a detached instance by synchronizing its state with the database.

Parameters:
entity - Persistent or detached instance to refresh.

query

<S extends T> java.util.List<S> query(PersistentEntityCriteria entityCriteria,
                                      java.lang.Class<S> targetEntityClass)
Retrieves a list of persistent instances.

Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
targetEntityClass - Target persistent entity class.
Returns:
Resulting list of persistent instances.

query

java.util.List<T> query(PersistentEntityCriteria entityCriteria)
Retrieves a list of persistent instances, using the implicit persistent entity class.

Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
Returns:
Resulting list of persistent instances.
See Also:
query(PersistentEntityCriteria, Class), getEntityClass()

uniqueResult

<S extends T> S uniqueResult(PersistentEntityCriteria entityCriteria,
                             boolean returnNullOnMultipleResults,
                             java.lang.Class<S> targetEntityClass)
Returns a single persistent instance (if available).

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.

uniqueResult

T uniqueResult(PersistentEntityCriteria entityCriteria,
               boolean returnNullOnMultipleResults)
Returns a single persistent instance (if available), using the implicit persistent entity class.

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:
uniqueResult(PersistentEntityCriteria, boolean, Class), getEntityClass()

count

<S extends T> int count(PersistentEntityCriteria entityCriteria,
                        java.lang.Class<S> targetEntityClass)
Returns the total number of instances persisted within the database.

Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
targetEntityClass - Target persistent entity class.
Returns:
Total instance count.

count

int count(PersistentEntityCriteria entityCriteria)
Returns the total number of instances persisted within the database, using the implicit persistent entity class.

Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
Returns:
Total instance count.
See Also:
count(PersistentEntityCriteria, Class), getEntityClass()

countAll

<S extends T> int countAll(java.lang.Class<S> targetEntityClass)
Returns the total number of all instances persisted within the database.

Parameters:
targetEntityClass - Target persistent entity class.
Returns:
Total instance count.

countAll

int countAll()
Returns the total number of all instances persisted within the database, using the implicit persistent entity class.

Returns:
Total instance count.
See Also:
countAll(Class), getEntityClass()


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