public class HibernateBaseDAO
extends java.lang.Object
Constructor and Description |
---|
HibernateBaseDAO() |
Modifier and Type | Method and Description |
---|---|
protected <T> java.util.List<T> |
_all(java.lang.Class<T> type)
Get a list of all the objects of the specified class.
|
protected int |
_count(java.lang.Class<?> type)
Returns the number of instances of this class in the datastore.
|
protected int |
_count(java.lang.Class<?> searchClass,
ISearch search)
Same as
_count(ISearch) except that it uses the specified
search class instead of getting it from the search object. |
protected int |
_count(ISearch search)
Returns the total number of results that would be returned using the
given
ISearch if there were no paging or maxResult limits. |
protected void |
_deleteById(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.
|
protected boolean |
_deleteById(java.lang.Class<?> type,
java.io.Serializable id)
Remove the entity of the specified class with the specified id from the
datastore.
|
protected void |
_deleteEntities(java.lang.Object... entities)
Remove the specified entities from the datastore.
|
protected boolean |
_deleteEntity(java.lang.Object entity)
Remove the specified entity from the datastore.
|
protected boolean[] |
_exists(java.lang.Class<?> type,
java.io.Serializable... ids) |
protected boolean |
_exists(java.lang.Class<?> type,
java.io.Serializable id) |
protected boolean |
_exists(java.lang.Object entity) |
protected void |
_flush()
Flushes changes in the hibernate cache to the datastore.
|
protected <T> T[] |
_get(java.lang.Class<T> type,
java.io.Serializable... ids)
Return the all the persistent instances of the given entity class with
the given identifiers.
|
protected <T> T |
_get(java.lang.Class<T> type,
java.io.Serializable id)
Return the persistent instance of the given entity class with the given
identifier, or null if there is no such persistent instance.
|
protected Filter |
_getFilterFromExample(java.lang.Object example) |
protected Filter |
_getFilterFromExample(java.lang.Object example,
ExampleOptions options) |
protected <T> T[] |
_load(java.lang.Class<T> type,
java.io.Serializable... ids)
Return the persistent instance of the given entity class with the given
identifier, assuming that the instance exists.
|
protected <T> T |
_load(java.lang.Class<T> type,
java.io.Serializable id)
Return the persistent instance of the given entity class with the given
identifier, assuming that the instance exists.
|
protected void |
_load(java.lang.Object transientEntity,
java.io.Serializable id)
Read the persistent state associated with the given identifier into the
given transient instance.
|
protected <T> T |
_merge(T entity)
Copy the state of the given object onto the persistent object with the
same identifier.
|
protected void |
_persist(java.lang.Object... entities)
Make a transient instance persistent and add it to the datastore.
|
protected void |
_refresh(java.lang.Object... entities)
Refresh the content of the given entity from the current datastore state.
|
protected void |
_save(java.lang.Object... entities)
Persist the given transient instances and add them to the datastore,
first assigning a generated identifier.
|
protected java.io.Serializable |
_save(java.lang.Object entity)
Persist the given transient instance and add it to the datastore, first
assigning a generated identifier.
|
protected void |
_saveOrUpdate(java.lang.Object entity)
Calls Hibernate's
saveOrUpdate() , which behaves as follows: |
protected boolean[] |
_saveOrUpdateIsNew(java.lang.Object... entities)
Either
save() or update() each entity,
depending on whether or not an entity with the same id already exists in
the datastore. |
protected boolean |
_saveOrUpdateIsNew(java.lang.Object entity)
If an entity already exists in the datastore with the same id, call
_update and return false (not new).
|
protected java.util.List |
_search(java.lang.Class<?> searchClass,
ISearch search)
Same as
_search(ISearch) except that it uses the specified
search class instead of getting it from the search object. |
protected java.util.List |
_search(ISearch search)
Search for objects based on the search parameters in the specified
ISearch object. |
protected SearchResult |
_searchAndCount(java.lang.Class<?> searchClass,
ISearch search)
Same as
_searchAndCount(ISearch) except that it uses the specified
search class instead of getting it from the search object. |
protected SearchResult |
_searchAndCount(ISearch search)
Returns a
SearchResult object that includes the list of
results like search() and the total length like
searchLength . |
protected java.lang.Object |
_searchUnique(java.lang.Class<?> searchClass,
ISearch search)
Same as
_searchUnique(ISearch) except that it uses the specified
search class instead of getting it from the search object. |
protected java.lang.Object |
_searchUnique(ISearch search)
Search for a single result using the given parameters.
|
protected boolean |
_sessionContains(java.lang.Object o)
Returns true if the object is connected to the current hibernate session.
|
protected void |
_update(java.lang.Object... transientEntities)
Update the persistent instance with the identifier of the given detached
instance.
|
protected HibernateMetadataUtil |
getMetadataUtil()
Get the instance of HibernateMetadataUtil associated with the session
factory
|
protected HibernateSearchProcessor |
getSearchProcessor()
Get the instance of EJBSearchProcessor associated with the session
factory
|
protected org.hibernate.Session |
getSession()
Get the current Hibernate session
|
protected org.hibernate.SessionFactory |
getSessionFactory() |
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory) |
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
protected org.hibernate.SessionFactory getSessionFactory()
protected org.hibernate.Session getSession()
protected HibernateMetadataUtil getMetadataUtil()
protected HibernateSearchProcessor getSearchProcessor()
protected java.io.Serializable _save(java.lang.Object entity)
Persist the given transient instance and add it to the datastore, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to associated instances if the association is mapped with cascade="save-update".
This is different from persist()
in that it does guarantee
that the object will be assigned an identifier immediately. With
save()
a call is made to the datastore immediately if the id
is generated by the datastore so that the id can be determined. With
persist
this call may not occur until flush time.
protected void _save(java.lang.Object... entities)
protected void _saveOrUpdate(java.lang.Object entity)
Calls Hibernate's saveOrUpdate()
, which behaves as follows:
Either save()
or update()
based on the
following rules
protected boolean _saveOrUpdateIsNew(java.lang.Object entity)
If an entity already exists in the datastore with the same id, call _update and return false (not new). If no such entity exists in the datastore, call _save() and return true (new)
true
if _save(); false
if _update().protected boolean[] _saveOrUpdateIsNew(java.lang.Object... entities)
save()
or update()
each entity,
depending on whether or not an entity with the same id already exists in
the datastore.true
if the corresponding entity was
_save()
d or false
if it was
_update()
d.protected void _persist(java.lang.Object... entities)
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.
This is different from save()
in that it does not guarantee
that the object will be assigned an identifier immediately. With
save()
a call is made to the datastore immediately if the id
is generated by the datastore so that the id can be determined. With
persist
this call may not occur until flush time.
protected boolean _deleteById(java.lang.Class<?> type, java.io.Serializable id)
true
if the object is found in the datastore and
deleted, false
if the item is not found.protected void _deleteById(java.lang.Class<?> type, java.io.Serializable... ids)
protected boolean _deleteEntity(java.lang.Object entity)
true
if the object is found in the datastore and
removed, false
if the item is not found.protected void _deleteEntities(java.lang.Object... entities)
protected <T> T _get(java.lang.Class<T> type, java.io.Serializable id)
get()
always hits the database immediately.protected <T> T[] _get(java.lang.Class<T> type, java.io.Serializable... ids)
Return the all the persistent instances of the given entity class with the given identifiers. An array of entities is returned that matches the same order of the ids listed in the call. For each entity that is not found in the datastore, a null will be inserted in its place in the return array.
get()
always hits the database immediately.
protected <T> T _load(java.lang.Class<T> type, java.io.Serializable id)
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. Throw an unrecoverable exception if there is no matching database row.
If the class is mapped with a proxy, load()
just returns an
uninitialized proxy and does not actually hit the database until you
invoke a method of the proxy. This behaviour is very useful if you wish
to create an association to an object without actually loading it from
the database. It also allows multiple instances to be loaded as a batch
if batch-size is defined for the class mapping.
protected <T> T[] _load(java.lang.Class<T> type, java.io.Serializable... ids)
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. Throw an unrecoverable exception if there is no matching database row. An array of entities is returned that matches the same order of the ids listed in the call. For each entity that is not found in the datastore, a null will be inserted in its place in the return array.
_load(Class, Serializable)
protected void _load(java.lang.Object transientEntity, java.io.Serializable id)
protected <T> java.util.List<T> _all(java.lang.Class<T> type)
protected void _update(java.lang.Object... transientEntities)
Update the persistent instance with the identifier of the given detached instance. If there is a persistent instance with the same identifier, an exception is thrown. This operation cascades to associated instances if the association is mapped with cascade="save-update".
The difference between update()
and merge()
is
significant: update()
will make the given object persistent
and throw and error if another object with the same ID is already
persistent in the Session. merge()
doesn't care if another
object is already persistent, but it also doesn't make the given object
persistent; it just copies over the values to the datastore.
protected <T> T _merge(T entity)
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 of and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".
The difference between update()
and merge()
is
significant: update()
will make the given object persistent
and throw and error if another object with the same ID is already
persistent in the Session. merge()
doesn't care if another
object is already persistent, but it also doesn't make the given object
persistent; it just copies over the values to the datastore.
protected java.util.List _search(ISearch search)
ISearch
object.ISearch
protected java.util.List _search(java.lang.Class<?> searchClass, ISearch search)
_search(ISearch)
except that it uses the specified
search class instead of getting it from the search object. Also, if the search
object has a different search class than what is specified, an exception
is thrown.protected int _count(ISearch search)
ISearch
if there were no paging or maxResult limits.ISearch
protected int _count(java.lang.Class<?> searchClass, ISearch search)
_count(ISearch)
except that it uses the specified
search class instead of getting it from the search object. Also, if the search
object has a different search class than what is specified, an exception
is thrown.protected int _count(java.lang.Class<?> type)
protected SearchResult _searchAndCount(ISearch search)
SearchResult
object that includes the list of
results like search()
and the total length like
searchLength
.ISearch
protected SearchResult _searchAndCount(java.lang.Class<?> searchClass, ISearch search)
_searchAndCount(ISearch)
except that it uses the specified
search class instead of getting it from the search object. Also, if the search
object has a different search class than what is specified, an exception
is thrown.protected java.lang.Object _searchUnique(ISearch search) throws org.hibernate.NonUniqueResultException
org.hibernate.NonUniqueResultException
protected java.lang.Object _searchUnique(java.lang.Class<?> searchClass, ISearch search)
_searchUnique(ISearch)
except that it uses the specified
search class instead of getting it from the search object. Also, if the search
object has a different search class than what is specified, an exception
is thrown.protected boolean _sessionContains(java.lang.Object o)
protected void _flush()
protected void _refresh(java.lang.Object... entities)
protected boolean _exists(java.lang.Object entity)
protected boolean _exists(java.lang.Class<?> type, java.io.Serializable id)
protected boolean[] _exists(java.lang.Class<?> type, java.io.Serializable... ids)
protected Filter _getFilterFromExample(java.lang.Object example)
protected Filter _getFilterFromExample(java.lang.Object example, ExampleOptions options)