Abstract extension of the GormInstanceApi class that provides common logic shared by Hibernate 3 and Hibernate 4
<
- D >Modifiers | Name | Description |
---|---|---|
protected static java.lang.Object[] |
EMPTY_ARRAY |
|
protected java.lang.ClassLoader |
classLoader |
|
protected IHibernateTemplate |
hibernateTemplate |
|
protected ProxyHandler |
proxyHandler |
|
protected org.hibernate.SessionFactory |
sessionFactory |
Fields inherited from class | Fields |
---|---|
class AbstractGormApi |
persistentClass, persistentEntity |
class AbstractDatastoreApi |
datastore |
Type | Name and description |
---|---|
boolean |
autoFlush |
static java.lang.ThreadLocal<java.lang.Boolean> |
insertActiveThreadLocal When a domain instance is saved without validation, we put it into this thread local variable. |
Constructor and description |
---|
protected AbstractHibernateGormInstanceApi
(java.lang.Class<D> persistentClass, AbstractHibernateDatastore datastore, java.lang.ClassLoader classLoader, IHibernateTemplate hibernateTemplate) |
Type | Name and description |
---|---|
D |
attach(D instance) |
void |
delete(D instance, java.util.Map params = Collections.emptyMap() |
void |
discard(D instance) |
protected void |
flushSession(org.hibernate.Session session) |
static java.lang.Boolean |
getAssumedUnsaved() Prevents hitting the database for an extra check if the row exists in the database. |
org.hibernate.SessionFactory |
getSessionFactory() |
protected java.lang.Object |
handleValidationError(PersistentEntity entity, java.lang.Object target, org.springframework.validation.Errors errors) Sets the flush mode to manual. which ensures that the database changes are not persisted to the database if a validation error occurs. |
protected void |
incrementVersion(java.lang.Object target) Increments the entities version number in order to force an update |
D |
insert(D instance, java.util.Map params) |
boolean |
instanceOf(D instance, java.lang.Class cls) |
boolean |
isAttached(D instance) |
D |
lock(D instance) |
static void |
markInsertActive() Called by org.grails.orm.hibernate.metaclass.SavePersistentMethod's performInsert to set a ThreadLocal variable that determines the value for getAssumedUnsaved(). |
D |
merge(D instance, java.util.Map params) |
protected D |
performInsert(D target, boolean shouldFlush) |
protected D |
performMerge(D target, boolean flush) |
protected D |
performSave(D target, boolean flush) |
D |
refresh(D instance) |
static void |
resetInsertActive() Clears the ThreadLocal variable set by markInsertActive(). |
D |
save(D target, java.util.Map arguments) |
protected void |
setErrorsOnInstance(java.lang.Object target, org.springframework.validation.Errors errors) Associates the Errors object on the instance |
void |
setObjectToReadOnly(java.lang.Object target) Sets the target object to read-only using the given SessionFactory instance. |
void |
setObjectToReadWrite(java.lang.Object target) Sets the target object to read-write, allowing Hibernate to dirty check it and auto-flush changes. |
protected boolean |
shouldFail(java.util.Map map) |
protected boolean |
shouldFlush(java.util.Map map) |
Methods inherited from class | Name |
---|---|
class GormInstanceApi |
attach, delete, delete, discard, doSave, getDirtyPropertyNames, getPersistentValue, ident, insert, insert, instanceOf, isAttached, isDirty, isDirty, lock, merge, merge, mutex, propertyMissing, refresh, save, save, save |
class AbstractGormApi |
getExtendedMethods, getMethods, initializeMethods |
class AbstractDatastoreApi |
execute, execute, getDatastore |
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
When a domain instance is saved without validation, we put it into this thread local variable. Any code that needs to know whether the domain instance should be validated can just check the value. Note that this only works because the session is flushed when a domain instance is saved without validation.
Prevents hitting the database for an extra check if the row exists in the database. ThreadLocal is used to pass the "insert:true" information to Hibernate.
Sets the flush mode to manual. which ensures that the database changes are not persisted to the database if a validation error occurs. If save() is called again and validation passes the code will check if there is a manual flush mode and flush manually if necessary
domainClass
- The domain classtarget
- The target object that failed validationerrors
- The Errors instanceIncrements the entities version number in order to force an update
target
- The target entityCalled by org.grails.orm.hibernate.metaclass.SavePersistentMethod's performInsert to set a ThreadLocal variable that determines the value for getAssumedUnsaved().
Clears the ThreadLocal variable set by markInsertActive().
Associates the Errors object on the instance
target
- The target instanceerrors
- The Errors objectSets the target object to read-only using the given SessionFactory instance. This avoids Hibernate performing any dirty checking on the object
target
- The target objectsessionFactory
- The SessionFactory instanceSets the target object to read-write, allowing Hibernate to dirty check it and auto-flush changes.
target
- The target objectsessionFactory
- The SessionFactory instanceGroovy Documentation