public class HibernateBaseDAO extends Object
| Constructor and Description |
|---|
HibernateBaseDAO() |
| Modifier and Type | Method and Description |
|---|---|
protected <T> List<T> |
_all(Class<T> type)
Get a list of all the objects of the specified class.
|
protected int |
_count(Class<?> type)
Returns the number of instances of this class in the datastore.
|
protected int |
_count(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(Class<?> type,
Serializable... ids)
Remove all the entities of the given type from the datastore that have
one of these ids.
|
protected boolean |
_deleteById(Class<?> type,
Serializable id)
Remove the entity of the specified class with the specified id from the
datastore.
|
protected void |
_deleteEntities(Object... entities)
Remove the specified entities from the datastore.
|
protected boolean |
_deleteEntity(Object entity)
Remove the specified entity from the datastore.
|
protected boolean[] |
_exists(Class<?> type,
Serializable... ids) |
protected boolean |
_exists(Class<?> type,
Serializable id) |
protected boolean |
_exists(Object entity) |
protected void |
_flush()
Flushes changes in the hibernate cache to the datastore.
|
protected <T> T[] |
_get(Class<T> type,
Serializable... ids)
Return the all the persistent instances of the given entity class with
the given identifiers.
|
protected <T> T |
_get(Class<T> type,
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(Object example) |
protected Filter |
_getFilterFromExample(Object example,
ExampleOptions options) |
protected <T> T[] |
_load(Class<T> type,
Serializable... ids)
Return the persistent instance of the given entity class with the given
identifier, assuming that the instance exists.
|
protected <T> T |
_load(Class<T> type,
Serializable id)
Return the persistent instance of the given entity class with the given
identifier, assuming that the instance exists.
|
protected void |
_load(Object transientEntity,
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(Object... entities)
Make a transient instance persistent and add it to the datastore.
|
protected void |
_refresh(Object... entities)
Refresh the content of the given entity from the current datastore state.
|
protected void |
_save(Object... entities)
Persist the given transient instances and add them to the datastore,
first assigning a generated identifier.
|
protected Serializable |
_save(Object entity)
Persist the given transient instance and add it to the datastore, first
assigning a generated identifier.
|
protected void |
_saveOrUpdate(Object entity)
Calls Hibernate's
saveOrUpdate(), which behaves as follows: |
protected boolean[] |
_saveOrUpdateIsNew(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(Object entity)
If an entity already exists in the datastore with the same id, call
_update and return false (not new).
|
protected List |
_search(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 List |
_search(ISearch search)
Search for objects based on the search parameters in the specified
ISearch object. |
protected SearchResult |
_searchAndCount(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 Object |
_searchUnique(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 Object |
_searchUnique(ISearch search)
Search for a single result using the given parameters.
|
protected boolean |
_sessionContains(Object o)
Returns true if the object is connected to the current hibernate session.
|
protected void |
_update(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 Serializable _save(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(Object... entities)
protected void _saveOrUpdate(Object entity)
Calls Hibernate's saveOrUpdate(), which behaves as follows:
Either save() or update() based on the
following rules
protected boolean _saveOrUpdateIsNew(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(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(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(Class<?> type, Serializable id)
true if the object is found in the datastore and
deleted, false if the item is not found.protected void _deleteById(Class<?> type, Serializable... ids)
protected boolean _deleteEntity(Object entity)
true if the object is found in the datastore and
removed, false if the item is not found.protected void _deleteEntities(Object... entities)
protected <T> T _get(Class<T> type, Serializable id)
get() always hits the database immediately.protected <T> T[] _get(Class<T> type, 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(Class<T> type, 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(Class<T> type, 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(Object transientEntity, Serializable id)
protected <T> List<T> _all(Class<T> type)
protected void _update(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 List _search(ISearch search)
ISearch object.ISearchprotected List _search(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.ISearchprotected int _count(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(Class<?> type)
protected SearchResult _searchAndCount(ISearch search)
SearchResult object that includes the list of
results like search() and the total length like
searchLength.ISearchprotected SearchResult _searchAndCount(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 Object _searchUnique(ISearch search) throws org.hibernate.NonUniqueResultException
org.hibernate.NonUniqueResultExceptionprotected Object _searchUnique(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(Object o)
protected void _flush()
protected void _refresh(Object... entities)
protected boolean _exists(Object entity)
protected boolean _exists(Class<?> type, Serializable id)
protected boolean[] _exists(Class<?> type, Serializable... ids)
protected Filter _getFilterFromExample(Object example, ExampleOptions options)
Copyright © 2008-2013. All Rights Reserved.