org.appfuse.dao
Interface GenericDao<T,PK extends Serializable>

Type Parameters:
T - a type variable
PK - the primary key for that type
All Known Subinterfaces:
RoleDao, UserDao
All Known Implementing Classes:
GenericDaoJpa, RoleDaoJpa, UserDaoJpa

public interface GenericDao<T,PK extends Serializable>

Generic DAO (Data Access Object) with common methods to CRUD POJOs.

Extend this interface if you want typesafe (no casting necessary) DAO's for your domain objects.

Author:
Bryan Noll, jgarcia (update: added full text search + reindexing)

Method Summary
 boolean exists(PK id)
          Checks for existence of an object of type T using the id arg.
 T get(PK id)
          Generic method to get an object based on class and identifier.
 List<T> getAll()
          Generic method used to get all objects of a particular type.
 List<T> getAllDistinct()
          Gets all records without duplicates.
 void reindex()
          Generic method to regenerate full text index of the persistent class T
 void reindexAll(boolean async)
          Generic method to regenerate full text index of all indexed classes
 void remove(PK id)
          Generic method to delete an object
 void remove(T object)
          Generic method to delete an object
 T save(T object)
          Generic method to save an object - handles both update and insert.
 List<T> search(String searchTerm)
          Gets all records that match a search term.
 

Method Detail

getAll

List<T> getAll()
Generic method used to get all objects of a particular type. This is the same as lookup up all rows in a table.

Returns:
List of populated objects

getAllDistinct

List<T> getAllDistinct()
Gets all records without duplicates.

Note that if you use this method, it is imperative that your model classes correctly implement the hashcode/equals methods

Returns:
List of populated objects

search

List<T> search(String searchTerm)
               throws SearchException
Gets all records that match a search term. "*" will get them all.

Parameters:
searchTerm - the term to search for
Returns:
the mathing records
Throws:
SearchException

get

T get(PK id)
Generic method to get an object based on class and identifier. An ObjectRetrievalFailureException Runtime Exception is thrown if nothing is found.

Parameters:
id - the identifier (primary key) of the object to get
Returns:
a populated object
See Also:
org.springframework.orm.ObjectRetrievalFailureException

exists

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

Parameters:
id - the id of the entity
Returns:
- true if it exists, false if it doesn't

save

T save(T object)
Generic method to save an object - handles both update and insert.

Parameters:
object - the object to save
Returns:
the persisted object

remove

void remove(T object)
Generic method to delete an object

Parameters:
object - the object to remove

remove

void remove(PK id)
Generic method to delete an object

Parameters:
id - the identifier (primary key) of the object to remove

reindex

void reindex()
Generic method to regenerate full text index of the persistent class T


reindexAll

void reindexAll(boolean async)
Generic method to regenerate full text index of all indexed classes

Parameters:
async - true to perform the reindexing asynchronously


Copyright © 2003-2012. All Rights Reserved.