public class DAODispatcher extends BaseDAODispatcher implements GeneralDAO
This is an implementation of GeneralDAO that delegates to other DAOs depending on what entity class is being processed.
Set the specificDAOs Map in order to configure which DAO will be used for which entity class. If the map contains no entry for a given class, the generalDAO is used.
For example to dispatch operation on com.myproject.model.Customer to a DAO called customerDAO, set the map like this. (Of course tools like Spring can be used to do this configuration more elequently.)
MapspecificDAOs = new HashMap (); specificDAOs.put("com.myproject.model.Customer", customerDAO); DAODispatcher dispatcher = new DAODispatcher(); dispatcher.setSpecificDAOs(specificDAOs);
| Modifier and Type | Field and Description |
|---|---|
protected GeneralDAO |
generalDAO |
specificDAOs| Constructor and Description |
|---|
DAODispatcher() |
| 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> T[] |
find(Class<T> type,
Serializable... ids)
Get all entities of the specified type from the datastore that have one
of these ids.
|
<T> T |
find(Class<T> type,
Serializable id)
Get the entity with the specified type and id from the datastore.
|
<T> List<T> |
findAll(Class<T> type)
Get a list of all the objects of the specified type.
|
void |
flush()
Deprecated.
use flush(Class>)
|
void |
flush(Class<?> klass) |
Filter |
getFilterFromExample(Object example)
Generates a search filter from the given example using default options.
|
Filter |
getFilterFromExample(Object example,
ExampleOptions options)
Generates a search filter from the given example using the specified options.
|
<T> T |
getReference(Class<T> type,
Serializable id)
Get a reference to the entity with the specified type and id from the
datastore.
|
<T> T[] |
getReferences(Class<T> type,
Serializable... ids)
Get a reference to the entities of the specified type with the given ids
from the datastore.
|
boolean |
isAttached(Object entity)
Returns
true if the object is connected to the current
Hibernate session. |
void |
refresh(Object... entities)
Refresh the content of the given entity from the current datastore state.
|
void |
remove(Object... entities)
Remove all of the specified entities from the datastore.
|
boolean |
remove(Object entity)
Remove the specified entity from the datastore.
|
boolean |
removeById(Class<?> type,
Serializable id)
Remove the entity with the specified type and id from the datastore.
|
void |
removeByIds(Class<?> type,
Serializable... ids)
Remove all the entities of the given type from the datastore that have
one of these ids.
|
boolean[] |
save(Object... 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(Object 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.
|
List |
search(ISearch search)
Search for objects given the search parameters in the specified
ISearch object. |
SearchResult |
searchAndCount(ISearch search)
Returns a
SearchResult object that includes both the list of
results like search() and the total length like
count(). |
Object |
searchUnique(ISearch search)
Search for a single result using the given parameters.
|
void |
setGeneralDAO(GeneralDAO generalDAO)
GeneralDAO has default implementations for the standard DAO methods.
|
callMethod, callMethod, getSpecificDAO, getTypeFromArray, getUniformArrayType, setSpecificDAOsprotected GeneralDAO generalDAO
public void setGeneralDAO(GeneralDAO generalDAO)
public int count(ISearch search)
GeneralDAOISearch if there were no paging or maxResults limits.count in interface GeneralDAOpublic <T> T find(Class<T> type, Serializable id)
GeneralDAOGet the entity with the specified type and id from the datastore.
If none is found, return null.
find in interface GeneralDAOpublic <T> T[] find(Class<T> type, Serializable... ids)
GeneralDAOfind in interface GeneralDAOpublic <T> List<T> findAll(Class<T> type)
GeneralDAOfindAll in interface GeneralDAOpublic void flush()
GeneralDAOflush in interface GeneralDAOpublic void flush(Class<?> klass)
public <T> T getReference(Class<T> type, Serializable id)
GeneralDAOGet 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 GeneralDAOpublic <T> T[] getReferences(Class<T> type, Serializable... ids)
GeneralDAOGet a reference to the entities of the specified type with the given ids from the datastore. An array of entities is returned that matches the same order of the ids listed in the call.
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 GeneralDAOpublic boolean isAttached(Object entity)
GeneralDAOtrue if the object is connected to the current
Hibernate session.isAttached in interface GeneralDAOpublic void refresh(Object... entities)
GeneralDAOrefresh in interface GeneralDAOpublic boolean remove(Object entity)
GeneralDAOremove in interface GeneralDAOtrue if the entity is found in the datastore and
removed, false if it is not found.public void remove(Object... entities)
GeneralDAOremove in interface GeneralDAOpublic boolean removeById(Class<?> type, Serializable id)
GeneralDAOremoveById in interface GeneralDAOtrue if the entity is found in the datastore and
removed, false if it is not found.public void removeByIds(Class<?> type, Serializable... ids)
GeneralDAOremoveByIds in interface GeneralDAOpublic boolean save(Object entity)
GeneralDAOIf 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 GeneralDAOtrue if create; false if update.public boolean[] save(Object... entities)
GeneralDAOFor 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 GeneralDAOpublic List search(ISearch search)
GeneralDAOISearch object.search in interface GeneralDAOpublic SearchResult searchAndCount(ISearch search)
GeneralDAOSearchResult object that includes both the list of
results like search() and the total length like
count().searchAndCount in interface GeneralDAOpublic Object searchUnique(ISearch search)
GeneralDAOsearchUnique in interface GeneralDAOpublic Filter getFilterFromExample(Object example)
GeneralDAOgetFilterFromExample in interface GeneralDAOpublic Filter getFilterFromExample(Object example, ExampleOptions options)
GeneralDAOgetFilterFromExample in interface GeneralDAOCopyright © 2008-2013. All Rights Reserved.