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.)
Map<String, Object> specificDAOs = new HashMap<String, Object>(); 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(java.lang.Class<T> type,
java.io.Serializable... ids)
Get all entities of the specified type from the datastore that have one
of these ids.
|
<T> T |
find(java.lang.Class<T> type,
java.io.Serializable id)
Get the entity with the specified type and id from the datastore.
|
<T> java.util.List<T> |
findAll(java.lang.Class<T> type)
Get a list of all the objects of the specified type.
|
void |
flush()
Deprecated.
use flush(Class>)
|
void |
flush(java.lang.Class<?> klass) |
Filter |
getFilterFromExample(java.lang.Object example)
Generates a search filter from the given example using default options.
|
Filter |
getFilterFromExample(java.lang.Object example,
ExampleOptions options)
Generates a search filter from the given example using the specified
options.
|
<T> T |
getReference(java.lang.Class<T> type,
java.io.Serializable id)
Get a reference to the entity with the specified type and id from the
datastore.
|
<T> T[] |
getReferences(java.lang.Class<T> type,
java.io.Serializable... ids)
Get a reference to the entities of the specified type with the given ids
from the datastore.
|
boolean |
isAttached(java.lang.Object entity)
Returns
true if the object is connected to the current
Hibernate session. |
java.lang.Object[] |
merge(java.lang.Object... entities)
Copy the state of the given objects onto the persistent objects with the
same identifier.
|
<T> T |
merge(T entity)
Copy the state of the given object onto the persistent object with the
same identifier.
|
void |
persist(java.lang.Object... entities)
Make a transient instance persistent and add it to the datastore.
|
void |
refresh(java.lang.Object... entities)
Refresh the content of the given entity from the current datastore state.
|
void |
remove(java.lang.Object... entities)
Remove all of the specified entities from the datastore.
|
boolean |
remove(java.lang.Object entity)
Remove the specified entity from the datastore.
|
boolean |
removeById(java.lang.Class<?> type,
java.io.Serializable id)
Remove the entity with the specified type and id from the datastore.
|
void |
removeByIds(java.lang.Class<?> type,
java.io.Serializable... ids)
Remove all the entities of the given type from the datastore that have
one of these ids.
|
java.lang.Object[] |
save(java.lang.Object... entities)
For each entity: If an entity with the same ID already exists in the
database, merge the changes into that entity.
|
<T> T |
save(T entity)
If an entity with the same ID already exists in the database, merge the
changes into that entity.
|
java.util.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() . |
java.lang.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, setSpecificDAOs
protected GeneralDAO generalDAO
public void setGeneralDAO(GeneralDAO generalDAO)
public int count(ISearch search)
GeneralDAO
ISearch
if there were no paging or maxResults limits.count
in interface GeneralDAO
public <T> T find(java.lang.Class<T> type, java.io.Serializable id)
GeneralDAO
Get the entity with the specified type and id from the datastore.
If none is found, return null.
find
in interface GeneralDAO
public <T> T[] find(java.lang.Class<T> type, java.io.Serializable... ids)
GeneralDAO
find
in interface GeneralDAO
public <T> java.util.List<T> findAll(java.lang.Class<T> type)
GeneralDAO
findAll
in interface GeneralDAO
public void flush()
GeneralDAO
flush
in interface GeneralDAO
public void flush(java.lang.Class<?> klass)
public <T> T getReference(java.lang.Class<T> type, java.io.Serializable id)
GeneralDAO
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 GeneralDAO
public <T> T[] getReferences(java.lang.Class<T> type, java.io.Serializable... ids)
GeneralDAO
Get 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 GeneralDAO
public boolean isAttached(java.lang.Object entity)
GeneralDAO
true
if the object is connected to the current
Hibernate session.isAttached
in interface GeneralDAO
public void refresh(java.lang.Object... entities)
GeneralDAO
refresh
in interface GeneralDAO
public boolean remove(java.lang.Object entity)
GeneralDAO
remove
in interface GeneralDAO
true
if the entity is found in the datastore and
removed, false
if it is not found.public void remove(java.lang.Object... entities)
GeneralDAO
remove
in interface GeneralDAO
public boolean removeById(java.lang.Class<?> type, java.io.Serializable id)
GeneralDAO
removeById
in interface GeneralDAO
true
if the entity is found in the datastore and
removed, false
if it is not found.public void removeByIds(java.lang.Class<?> type, java.io.Serializable... ids)
GeneralDAO
removeByIds
in interface GeneralDAO
public <T> T save(T entity)
GeneralDAO
save
in interface GeneralDAO
public java.lang.Object[] save(java.lang.Object... entities)
GeneralDAO
For each entity: If an entity with the same ID already exists in the database, merge the changes into that entity. If not persist the given entity. In either case, a managed entity with the changed values is returned. It may or may not be the same object as was passed in.
save
in interface GeneralDAO
public java.util.List search(ISearch search)
GeneralDAO
ISearch
object.search
in interface GeneralDAO
public SearchResult searchAndCount(ISearch search)
GeneralDAO
SearchResult
object that includes both the list of
results like search()
and the total length like
count()
.searchAndCount
in interface GeneralDAO
public java.lang.Object searchUnique(ISearch search)
GeneralDAO
searchUnique
in interface GeneralDAO
public Filter getFilterFromExample(java.lang.Object example)
GeneralDAO
getFilterFromExample
in interface GeneralDAO
public Filter getFilterFromExample(java.lang.Object example, ExampleOptions options)
GeneralDAO
getFilterFromExample
in interface GeneralDAO
public <T> T merge(T entity)
GeneralDAO
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance.
The instance that is passed in does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".
merge
in interface GeneralDAO
public java.lang.Object[] merge(java.lang.Object... entities)
GeneralDAO
Copy the state of the given objects onto the persistent objects with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instances. If a given instance is unsaved, save a copy and return it as a newly persistent instance.
The instances that are passed in do not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".
merge
in interface GeneralDAO
public void persist(java.lang.Object... entities)
GeneralDAO
Make a transient instance persistent and add it to the datastore. This operation cascades to associated instances if the association is mapped with cascade="persist". Throws an error if the entity already exists.
Does not guarantee that the object will be assigned an identifier
immediately. With persist
a datastore-generated id may not
be pulled until flush time.
persist
in interface GeneralDAO