com.ebmwebsourcing.webcommons.persistence.dao
Interface GenericORMDAO<T,PK extends java.io.Serializable>

Type Parameters:
T - a type variable
PK - the primary key for that type
All Known Implementing Classes:
GenericHibernateDAOImpl

public interface GenericORMDAO<T,PK extends java.io.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:
ofabre - eBM WebSourcing

Method Summary
 int count(com.trg.search.IMutableSearch search)
          Returns the total number of results that would be returned using the given ISearch if there were no paging or maxResult limits.
 boolean exists(PK id)
          Checks for existence of an object of type T using the id arg.
 java.util.List<T> findByNamedQuery(java.lang.String queryName, java.util.Map<java.lang.String,java.lang.Object> queryParams)
          Find a list of records by using a named query
 T get(PK id)
          Return the persistent instance of an entity with the given identifier, or null if not found.
 java.util.List<T> getAll()
          Generic method used to get all objects of a particular type.
 java.util.List<T> getAll(java.util.List<PK> ids)
          Retrieve a List of entities matching given ids
 java.util.List<T> getAll(java.util.List<PK> ids, RequestOptions requestOptions)
          Retrieve a List of entities matching given ids, sorted and paginated according to the given request options
 java.util.List<T> getAll(RequestOptions requestOptionsTO)
          Generic method used to get all objects of a particular type, sorted and paginated according to the given request options.
 java.util.List<T> getAllDistinct()
          Gets all records without duplicates.
 org.hibernate.search.FullTextSession getFullTextSession()
          Return the FullTextSession associated to the current Session
 java.lang.Class<T> getManipulatedType()
          Return the type of entity manipulated by this DAO
 void remove(PK id)
          Generic method to delete an object based on class and id
 void remove(T object)
          Generic method to delete an object
 void removeAll(java.util.List<T> objects)
          Generic method to delete a list of objects
 T save(T object)
          Generic method to save an object - handles both update and insert.
 java.util.List<T> search(com.trg.search.IMutableSearch search)
          Search for objects based on the search parameters in the specified ISearch object.
 com.trg.search.SearchResult<T> searchAndCount(com.trg.search.IMutableSearch search)
          Returns a SearchResult object that includes the list of results like search() and the total length like searchLength.
 java.util.List<T> searchEquals(java.lang.String[] criteria, java.lang.String[] properties, RequestOptions requestOptionsTO)
          This method allows to search Objects on String properties, fitting search criteria.
 java.util.List<T> searchLike(java.lang.String[] criteria, java.lang.String[] properties, RequestOptions requestOptionsTO)
          This method allows to search Objects on String properties, fitting search criteria.
 java.util.List<T> searchLucene(java.lang.String[] criteria, java.lang.String[] searchedProperties)
          This method allows to search Objects on String properties, fitting search criteria.
 java.util.List<T> searchLucene(java.lang.String[] criteria, java.lang.String[] searchedProperties, RequestOptions requestOptions)
          This method allows to search Objects on String properties, fitting search criteria.
 T searchUnique(com.trg.search.IMutableSearch search)
          Search for a single result using the given parameters.
 

Method Detail

getAll

java.util.List<T> getAll(RequestOptions requestOptionsTO)
Generic method used to get all objects of a particular type, sorted and paginated according to the given request options. This is the same as lookup up all rows in a table. The sort option works only on single properties, cause colection properties need to be sorted. If you have to sort on collection properties, use search(IMutableSearch search) method with sort and fetching options

Parameters:
requestOptionsTO - include sort order and pagination information
Returns:
List of populated objects

getAll

java.util.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

get

T get(PK id)
Return the persistent instance of an entity with the given identifier, or null if not found.

Parameters:
id - the identifier of the persistent instance
Returns:
the persistent instance, or null if not found
Throws:
org.springframework.dao.DataAccessException - in case of Hibernate errors
See Also:
Session.get(Class, java.io.Serializable)

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

@Transactional
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(PK id)
Generic method to delete an object based on class and id

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

remove

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

Parameters:
object - the object to remove

removeAll

void removeAll(java.util.List<T> objects)
Generic method to delete a list of objects

Parameters:
objects - the object list to remove

getAllDistinct

java.util.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

findByNamedQuery

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

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

getManipulatedType

java.lang.Class<T> getManipulatedType()
Return the type of entity manipulated by this DAO

Returns:
the Class of the manipulated entity

getAll

java.util.List<T> getAll(java.util.List<PK> ids)
Retrieve a List of entities matching given ids

Parameters:
ids - a List of ids
Returns:
a List of entities matching ids, must be non null, could be empty

getAll

java.util.List<T> getAll(java.util.List<PK> ids,
                         RequestOptions requestOptions)
Retrieve a List of entities matching given ids, sorted and paginated according to the given request options

Parameters:
ids - a List of ids
requestOptions - include sort order and pagination information
Returns:
a sorted/paginated List of entities matching ids, must be non null, could be empty

search

java.util.List<T> search(com.trg.search.IMutableSearch search)
Search for objects based on the search parameters in the specified ISearch object.

See Also:
ISearch

count

int count(com.trg.search.IMutableSearch search)
Returns the total number of results that would be returned using the given ISearch if there were no paging or maxResult limits.

See Also:
ISearch

searchAndCount

com.trg.search.SearchResult<T> searchAndCount(com.trg.search.IMutableSearch search)
Returns a SearchResult object that includes the list of results like search() and the total length like searchLength.

See Also:
ISearch

searchUnique

T searchUnique(com.trg.search.IMutableSearch search)
               throws org.hibernate.NonUniqueResultException
Search for a single result using the given parameters.

Throws:
org.hibernate.NonUniqueResultException

searchLike

java.util.List<T> searchLike(java.lang.String[] criteria,
                             java.lang.String[] properties,
                             RequestOptions requestOptionsTO)
This method allows to search Objects on String properties, fitting search criteria. Properties can be direct object fields or fields of included objects (in this case, fields must be referenced by the doted notation like "foo.bar"). Use a like statement for each criteria on each property. Results are sorted and paginated in respect of the given request options.

Parameters:
criteria - the search criteria
properties - the searched properties
requestOptionsTO - include sort order and pagination information
Returns:
a list of object matching the different criteria sorted and paginated

searchEquals

java.util.List<T> searchEquals(java.lang.String[] criteria,
                               java.lang.String[] properties,
                               RequestOptions requestOptionsTO)
This method allows to search Objects on String properties, fitting search criteria. Properties can be direct object fields or fields of included objects (in this case, fields must be referenced by the doted notation like "foo.bar"). Use a equality statement for each criteria on each property. Results are sorted and paginated in respect of the given request options.

Parameters:
criteria - the search criteria
properties - the searched properties
requestOptionsTO - include sort order and pagination information
Returns:
a list of object matching the different criteria sorted and paginated

searchLucene

java.util.List<T> searchLucene(java.lang.String[] criteria,
                               java.lang.String[] searchedProperties)
                               throws DAOLayerException
This method allows to search Objects on String properties, fitting search criteria. Properties can be direct object fields or fields of included objects (in this case, fields must be referenced by the doted notation like "foo.bar"). Process a research on Full Text Search Engine (Hibernate Search) index and return a List of entity managed by the ORM engine (Hibernate). All ORM managed attributes of these entities are populated.

Parameters:
criteria - the search criteria
properties - the searched properties
Returns:
a List of entity managed by the ORM engine.
Throws:
DAOLayerException - if criteria or searchedProperties are empty

searchLucene

java.util.List<T> searchLucene(java.lang.String[] criteria,
                               java.lang.String[] searchedProperties,
                               RequestOptions requestOptions)
                               throws DAOLayerException
This method allows to search Objects on String properties, fitting search criteria. Properties can be direct object fields or fields of included objects (in this case, fields must be referenced by the doted notation like "foo.bar"). Process a research on Full Text Search Engine (Hibernate Search) index and return a List of entity managed by the ORM engine (Hibernate), sorted and paginated according to the given request options. All ORM managed attributes of these entities are populated.

Parameters:
criteria - the search criteria
properties - the searched properties
requestOptions - include sort order and pagination information, could be null
Returns:
a List of entity managed by the ORM engine.
Throws:
DAOLayerException - if criteria or searchedProperties are empty

getFullTextSession

org.hibernate.search.FullTextSession getFullTextSession()
Return the FullTextSession associated to the current Session

Returns:
the FullTextSession associated to the current Session


Copyright © 2010 eBM WebSourcing. All Rights Reserved.