T
- The type of the domain object for which this instance is to be
used.ID
- The type of the id of the domain object for which this instance is
to be used.public class GenericDAOImpl<T,ID extends java.io.Serializable> extends HibernateBaseDAO implements GenericDAO<T,ID>
GenericDAO
using Hibernate.
The SessionFactory property is annotated for automatic resource injection.Modifier and Type | Field and Description |
---|---|
protected java.lang.Class<T> |
persistentClass |
Constructor and Description |
---|
GenericDAOImpl() |
Modifier and Type | Method and Description |
---|---|
int |
count(ISearch search)
Returns the total number of results that would be returned using the
given
ISearch if there were no paging or maxResults limits. |
T[] |
find(java.io.Serializable... ids)
Get all entities of the specified type from the datastore that have one
of these ids.
|
T |
find(java.io.Serializable id)
Get the entity with the specified type and id from the datastore.
|
java.util.List<T> |
findAll()
Get a list of all the objects of the specified type.
|
void |
flush()
Flushes changes in the Hibernate session to the datastore.
|
Filter |
getFilterFromExample(T example)
Generates a search filter from the given example using default options.
|
Filter |
getFilterFromExample(T example,
ExampleOptions options)
Generates a search filter from the given example using the specified options.
|
T |
getReference(java.io.Serializable id)
Get a reference to the entity with the specified type and id from the
datastore.
|
T[] |
getReferences(java.io.Serializable... ids)
Get a reference to the entities of the specified type with the given ids
from the datastore.
|
boolean |
isAttached(T entity)
Returns
true if the object is connected to the current
Hibernate session. |
void |
refresh(T... entities)
Refresh the content of the given entity from the current datastore state.
|
void |
remove(T... entities)
Remove all of the specified entities from the datastore.
|
boolean |
remove(T entity)
Remove the specified entity from the datastore.
|
boolean |
removeById(java.io.Serializable id)
Remove the entity with the specified type and id from the datastore.
|
void |
removeByIds(java.io.Serializable... ids)
Remove all the entities of the given type from the datastore that have
one of these ids.
|
boolean[] |
save(T... entities)
For each entity, if the id of the entity is null or zero, add it to the
datastore and assign it an id; otherwise, update the corresponding entity
in the datastore with the properties of this entity.
|
boolean |
save(T entity)
If the id of the entity is null or zero, add it to the datastore and
assign it an id; otherwise, update the corresponding entity in the
datastore with the properties of this entity.
|
<RT> java.util.List<RT> |
search(ISearch search)
Search for entities given the search parameters in the specified
ISearch object. |
<RT> SearchResult<RT> |
searchAndCount(ISearch search)
Returns a
SearchResult object that includes both the list of
results like search() and the total length like
count() . |
<RT> RT |
searchUnique(ISearch search)
Search for a single entity using the given parameters.
|
_all, _count, _count, _count, _deleteById, _deleteById, _deleteEntities, _deleteEntity, _exists, _exists, _exists, _flush, _get, _get, _getFilterFromExample, _getFilterFromExample, _load, _load, _load, _merge, _persist, _refresh, _save, _save, _saveOrUpdate, _saveOrUpdateIsNew, _saveOrUpdateIsNew, _search, _search, _searchAndCount, _searchAndCount, _searchUnique, _searchUnique, _sessionContains, _update, getMetadataUtil, getSearchProcessor, getSession, getSessionFactory, setSessionFactory
protected java.lang.Class<T> persistentClass
public int count(ISearch search)
GenericDAO
ISearch
if there were no paging or maxResults limits.count
in interface GenericDAO<T,ID extends java.io.Serializable>
public T find(java.io.Serializable id)
GenericDAO
Get the entity with the specified type and id from the datastore.
If none is found, return null.
find
in interface GenericDAO<T,ID extends java.io.Serializable>
public T[] find(java.io.Serializable... ids)
GenericDAO
find
in interface GenericDAO<T,ID extends java.io.Serializable>
public java.util.List<T> findAll()
GenericDAO
findAll
in interface GenericDAO<T,ID extends java.io.Serializable>
public void flush()
GenericDAO
flush
in interface GenericDAO<T,ID extends java.io.Serializable>
public T getReference(java.io.Serializable id)
GenericDAO
Get a reference to the entity with the specified type and id from the datastore.
This does not require a call to the datastore and does not populate any of the entity's values. Values may be fetched lazily at a later time. This increases performance if a another entity is being saved that should reference this entity but the values of this entity are not needed.
getReference
in interface GenericDAO<T,ID extends java.io.Serializable>
public T[] getReferences(java.io.Serializable... ids)
GenericDAO
Get a reference to the entities of the specified type with the given ids from the datastore.
This does not require a call to the datastore and does not populate any of the entities' values. Values may be fetched lazily at a later time. This increases performance if a another entity is being saved that should reference these entities but the values of these entities are not needed.
getReferences
in interface GenericDAO<T,ID extends java.io.Serializable>
public boolean isAttached(T entity)
GenericDAO
true
if the object is connected to the current
Hibernate session.isAttached
in interface GenericDAO<T,ID extends java.io.Serializable>
public void refresh(T... entities)
GenericDAO
refresh
in interface GenericDAO<T,ID extends java.io.Serializable>
public boolean remove(T entity)
GenericDAO
remove
in interface GenericDAO<T,ID extends java.io.Serializable>
true
if the entity is found in the datastore and
removed, false
if it is not found.public void remove(T... entities)
GenericDAO
remove
in interface GenericDAO<T,ID extends java.io.Serializable>
public boolean removeById(java.io.Serializable id)
GenericDAO
removeById
in interface GenericDAO<T,ID extends java.io.Serializable>
true
if the entity is found in the datastore and
removed, false
if it is not found.public void removeByIds(java.io.Serializable... ids)
GenericDAO
removeByIds
in interface GenericDAO<T,ID extends java.io.Serializable>
public boolean save(T entity)
GenericDAO
If the id of the entity is null or zero, add it to the datastore and assign it an id; otherwise, update the corresponding entity in the datastore with the properties of this entity. In either case the entity passed to this method will be attached to the session.
If an entity to update is already attached to the session, this method will have no effect. If an entity to update has the same id as another instance already attached to the session, an error will be thrown.
save
in interface GenericDAO<T,ID extends java.io.Serializable>
true
if create; false
if update.public boolean[] save(T... entities)
GenericDAO
For each entity, if the id of the entity is null or zero, add it to the datastore and assign it an id; otherwise, update the corresponding entity in the datastore with the properties of this entity. In either case the entity passed to this method will be attached to the session.
If an entity to update is already attached to the session, this method will have no effect. If an entity to update has the same id as another instance already attached to the session, an error will be thrown.
save
in interface GenericDAO<T,ID extends java.io.Serializable>
public <RT> java.util.List<RT> search(ISearch search)
GenericDAO
ISearch
object.search
in interface GenericDAO<T,ID extends java.io.Serializable>
public <RT> SearchResult<RT> searchAndCount(ISearch search)
GenericDAO
SearchResult
object that includes both the list of
results like search()
and the total length like
count()
.searchAndCount
in interface GenericDAO<T,ID extends java.io.Serializable>
public <RT> RT searchUnique(ISearch search)
GenericDAO
searchUnique
in interface GenericDAO<T,ID extends java.io.Serializable>
public Filter getFilterFromExample(T example)
GenericDAO
getFilterFromExample
in interface GenericDAO<T,ID extends java.io.Serializable>
public Filter getFilterFromExample(T example, ExampleOptions options)
GenericDAO
getFilterFromExample
in interface GenericDAO<T,ID extends java.io.Serializable>