|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.riotfamily.common.beans.config.ConfigurableBean
org.riotfamily.riot.hibernate.domain.ActiveRecord
public abstract class ActiveRecord
Use as base class for persistent entity beans if you prefer the active record pattern.
| Nested Class Summary | |
|---|---|
protected static interface |
ActiveRecord.ForEachCallback<T>
|
| Constructor Summary | |
|---|---|
ActiveRecord()
|
|
| Method Summary | ||
|---|---|---|
protected static org.hibernate.Query |
createQuery(String hql,
Object... params)
Creates a HQL Query, binding a number of values to "?" |
|
void |
delete()
Removes this persistent instance from the data store. |
|
protected static
|
find(String hql,
Object... params)
Executes a HQL query, binding a number of values to "?" |
|
protected static
|
forEach(ActiveRecord.ForEachCallback<T> callback,
String hql,
Object... params)
Convenience method to perform some code for every single result obtained by the given query. |
|
protected static org.hibernate.Session |
getSession()
Returns the Hibernate Session to use for persistence operations. |
|
protected static org.hibernate.SessionFactory |
getSessionFactory()
|
|
protected static
|
load(Class<T> clazz,
Serializable id)
Returns the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
|
protected static
|
load(String hql,
Object... params)
Convenience method to return a single instance that matches the query, or null if the query returns no results. |
|
void |
lock(org.hibernate.LockMode lockMode)
Obtains the specified lock level upon this persistent instance. |
|
|
merge()
Copies the state of this object onto the persistent object with the same identifier. |
|
void |
save()
Persists this transient instance, first assigning a generated identifier. |
|
void |
update()
Updates the persistent instance with the same identifier as this detached instance. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ActiveRecord()
| Method Detail |
|---|
protected static final org.hibernate.SessionFactory getSessionFactory()
public final void save()
Why is this method final? Changing the implementation of
this method could seriously defect the whole persistence mechanism.
Session.save(Object)public final <T> T merge()
Why is this method final? Changing the implementation of
this method could seriously defect the whole persistence mechanism.
Session.merge(Object)public final void update()
Session.update(Object)public final void delete()
Why is this method final? Changing the implementation of
this method could seriously defect the whole persistence mechanism.
Session.delete(Object)
protected static <T> T load(Class<T> clazz,
Serializable id)
Under the hood Session.get(Class, java.io.Serializable) is used,
not Session.load(Class, java.io.Serializable) as one might
expect because of this method's name. See Hibernate documentation for
a detailed discussion of the difference.
clazz - a persistent classid - an identifier
Session.get(Class, java.io.Serializable),
Session.load(Class, java.io.Serializable)public final void lock(org.hibernate.LockMode lockMode)
Why is this method final? Changing the implementation of
this method could seriously defect the whole persistence mechanism.
lockMode - a LockModeSession.lock(Object, LockMode)protected static final org.hibernate.Session getSession()
Session to use for persistence operations.
Session
protected static org.hibernate.Query createQuery(String hql,
Object... params)
Query, binding a number of values to "?"
parameters in the query string.
hql - a query expressed in Hibernate's query language that may
contain one or more '?' parameter placeholdersparams - the values of the parameters
Query
protected static <T> List<T> find(String hql,
Object... params)
hql - a query expressed in Hibernate's query language that may
contain one or more '?' parameter placeholdersparams - the values of the parameters
List containing the results of the query execution
protected static <T> T load(String hql,
Object... params)
throws org.hibernate.NonUniqueResultException
hql - a query expressed in Hibernate's query language that may
contain one or more '?' parameter placeholdersparams - the values of the parameters
null
org.hibernate.NonUniqueResultException - if there is more than one matching
result
protected static <T> void forEach(ActiveRecord.ForEachCallback<T> callback,
String hql,
Object... params)
This is achieved by two design decisions: Query.scroll()
is used to obtain a scrollable result set and after processing a single
result, Session.evict(Object) is called for the entity just
processed. So, implementors of ActiveRecord.ForEachCallback must be aware
that only the currently processed entity is attached to the
Hibernate Session.
T - a mapped type or Object[] if the query returns more
than 1 column per rowcallback - a ActiveRecord.ForEachCallback to call for every entity
returned by the given queryhql - a query expressed in Hibernate's query language that may
contain one or more '?' parameter placeholdersparams - the values of the parametersQuery.scroll(),
Session.evict(Object),
ActiveRecord.ForEachCallback
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||