Package org.hibernate.engine.internal
Class AbstractEntityEntry
- java.lang.Object
-
- org.hibernate.engine.internal.AbstractEntityEntry
-
- All Implemented Interfaces:
Serializable,EntityEntry
- Direct Known Subclasses:
ImmutableEntityEntry,MutableEntityEntry
public abstract class AbstractEntityEntry extends Object implements Serializable, EntityEntry
A base implementation of EntityEntry- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractEntityEntry.BooleanStateRepresents a boolean flag stored within a number value, using one bit at a specified offset.protected static classAbstractEntityEntry.EnumState<E extends Enum<E>>Represents an enum value stored within a number value, using four bits starting at a specified offset.
-
Field Summary
Fields Modifier and Type Field Description protected EntityKeycachedEntityKeyprotected Objectidprotected Object[]loadedStateprotected EntityEntryExtraStatenextprotected PersistenceContextpersistenceContextprotected EntityPersisterpersisterprotected ObjectrowIdprotected Objectversion
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractEntityEntry(SessionFactoryImplementor factory, String entityName, Object id, Status status, Status previousStatus, Object[] loadedState, Object[] deletedState, Object version, LockMode lockMode, boolean existsInDatabase, boolean isBeingReplicated, PersistenceContext persistenceContext)This for is used during custom deserialization handlingAbstractEntityEntry(Status status, Object[] loadedState, Object rowId, Object id, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement, PersistenceContext persistenceContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExtraState(EntityEntryExtraState extraState)voidforceLocked(Object entity, Object nextVersion)protected booleangetCompressedValue(AbstractEntityEntry.BooleanState state)Gets the current value of the given boolean flag.protected <E extends Enum<E>>
EgetCompressedValue(AbstractEntityEntry.EnumState<E> state)Gets the current value of the given enum property.Object[]getDeletedState()EntityKeygetEntityKey()Get the EntityKey based on this EntityEntry.StringgetEntityName()<T extends EntityEntryExtraState>
TgetExtraState(Class<T> extraStateType)ObjectgetId()Object[]getLoadedState()ObjectgetLoadedValue(String propertyName)LockModegetLockMode()PersistenceContextgetPersistenceContext()EntityPersistergetPersister()ObjectgetRowId()StatusgetStatus()ObjectgetVersion()booleanisBeingReplicated()booleanisExistsInDatabase()booleanisModifiableEntity()Can the entity be modified? The entity is modifiable if all of the following are true: the entity class is mutable the entity is not read-only if the current status is Status.DELETED, then the entity was not read-only when it was deletedbooleanisNullifiable(boolean earlyInsert, SharedSessionContractImplementor session)booleanisReadOnly()voidoverwriteLoadedStateCollectionValue(String propertyName, PersistentCollection<?> collection)voidpostDelete()After actually deleting a row, record the fact that the instance no longer exists in the databasevoidpostInsert(Object[] insertedState)After actually inserting a row, record the fact that the instance exists on the database (needed for identity-column key generation)voidpostUpdate(Object entity, Object[] updatedState, Object nextVersion)Handle updating the internal state of the entry after actually performing the database update.booleanrequiresDirtyCheck(Object entity)Not sure this is the best method name, but the general idea here is to returntrueif the entity can possibly be dirty.voidserialize(ObjectOutputStream oos)Custom serialization routine used during serialization of a Session/PersistenceContext for increased performance.protected voidsetCompressedValue(AbstractEntityEntry.BooleanState state, boolean value)Saves the value for the given boolean flag.protected <E extends Enum<E>>
voidsetCompressedValue(AbstractEntityEntry.EnumState<E> state, E value)Saves the value for the given enum property.voidsetDeletedState(Object[] deletedState)voidsetLockMode(LockMode lockMode)voidsetReadOnly(boolean readOnly, Object entity)voidsetStatus(Status status)StringtoString()
-
-
-
Field Detail
-
id
protected final Object id
-
loadedState
protected Object[] loadedState
-
version
protected Object version
-
persister
protected final EntityPersister persister
-
cachedEntityKey
protected transient EntityKey cachedEntityKey
-
rowId
protected final transient Object rowId
-
persistenceContext
protected final transient PersistenceContext persistenceContext
-
next
protected EntityEntryExtraState next
-
-
Constructor Detail
-
AbstractEntityEntry
public AbstractEntityEntry(Status status, Object[] loadedState, Object rowId, Object id, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement, PersistenceContext persistenceContext)
-
AbstractEntityEntry
protected AbstractEntityEntry(SessionFactoryImplementor factory, String entityName, Object id, Status status, Status previousStatus, Object[] loadedState, Object[] deletedState, Object version, LockMode lockMode, boolean existsInDatabase, boolean isBeingReplicated, PersistenceContext persistenceContext)
This for is used during custom deserialization handling
-
-
Method Detail
-
getLockMode
public LockMode getLockMode()
- Specified by:
getLockModein interfaceEntityEntry
-
setLockMode
public void setLockMode(LockMode lockMode)
- Specified by:
setLockModein interfaceEntityEntry
-
getStatus
public Status getStatus()
- Specified by:
getStatusin interfaceEntityEntry
-
setStatus
public void setStatus(Status status)
- Specified by:
setStatusin interfaceEntityEntry
-
getId
public Object getId()
- Specified by:
getIdin interfaceEntityEntry
-
getLoadedState
public Object[] getLoadedState()
- Specified by:
getLoadedStatein interfaceEntityEntry
-
getDeletedState
public Object[] getDeletedState()
- Specified by:
getDeletedStatein interfaceEntityEntry
-
setDeletedState
public void setDeletedState(Object[] deletedState)
- Specified by:
setDeletedStatein interfaceEntityEntry
-
isExistsInDatabase
public boolean isExistsInDatabase()
- Specified by:
isExistsInDatabasein interfaceEntityEntry
-
getVersion
public Object getVersion()
- Specified by:
getVersionin interfaceEntityEntry
-
getPersister
public EntityPersister getPersister()
- Specified by:
getPersisterin interfaceEntityEntry
-
getEntityKey
public EntityKey getEntityKey()
Description copied from interface:EntityEntryGet the EntityKey based on this EntityEntry.- Specified by:
getEntityKeyin interfaceEntityEntry- Returns:
- the EntityKey
-
getEntityName
public String getEntityName()
- Specified by:
getEntityNamein interfaceEntityEntry
-
isBeingReplicated
public boolean isBeingReplicated()
- Specified by:
isBeingReplicatedin interfaceEntityEntry
-
getRowId
public Object getRowId()
- Specified by:
getRowIdin interfaceEntityEntry
-
postUpdate
public void postUpdate(Object entity, Object[] updatedState, Object nextVersion)
Description copied from interface:EntityEntryHandle updating the internal state of the entry after actually performing the database update. Specifically we update the snapshot information and escalate the lock mode- Specified by:
postUpdatein interfaceEntityEntry- Parameters:
entity- The entity instanceupdatedState- The state calculated after the update (becomes the newloaded state.nextVersion- The new version.
-
postDelete
public void postDelete()
Description copied from interface:EntityEntryAfter actually deleting a row, record the fact that the instance no longer exists in the database- Specified by:
postDeletein interfaceEntityEntry
-
postInsert
public void postInsert(Object[] insertedState)
Description copied from interface:EntityEntryAfter actually inserting a row, record the fact that the instance exists on the database (needed for identity-column key generation)- Specified by:
postInsertin interfaceEntityEntry
-
isNullifiable
public boolean isNullifiable(boolean earlyInsert, SharedSessionContractImplementor session)- Specified by:
isNullifiablein interfaceEntityEntry
-
getLoadedValue
public Object getLoadedValue(String propertyName)
- Specified by:
getLoadedValuein interfaceEntityEntry
-
overwriteLoadedStateCollectionValue
public void overwriteLoadedStateCollectionValue(String propertyName, PersistentCollection<?> collection)
- Specified by:
overwriteLoadedStateCollectionValuein interfaceEntityEntry
-
requiresDirtyCheck
public boolean requiresDirtyCheck(Object entity)
Description copied from interface:EntityEntryNot sure this is the best method name, but the general idea here is to returntrueif the entity can possibly be dirty. This can only be the case if it is in a modifiable state (not read-only/deleted) and it either has mutable properties or field-interception is not telling us it is dirty. Clear as mud? :/ A name like canPossiblyBeDirty might be better- Specified by:
requiresDirtyCheckin interfaceEntityEntry- Parameters:
entity- The entity to test- Returns:
trueindicates that the entity could possibly be dirty and that dirty check should happen;falseindicates there is no way the entity can be dirty
-
isModifiableEntity
public boolean isModifiableEntity()
Description copied from interface:EntityEntryCan the entity be modified? The entity is modifiable if all of the following are true:- the entity class is mutable
- the entity is not read-only
- if the current status is Status.DELETED, then the entity was not read-only when it was deleted
- Specified by:
isModifiableEntityin interfaceEntityEntry- Returns:
- true, if the entity is modifiable; false, otherwise,
-
forceLocked
public void forceLocked(Object entity, Object nextVersion)
- Specified by:
forceLockedin interfaceEntityEntry
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceEntityEntry
-
setReadOnly
public void setReadOnly(boolean readOnly, Object entity)- Specified by:
setReadOnlyin interfaceEntityEntry
-
toString
public String toString()
- Specified by:
toStringin interfaceEntityEntry- Overrides:
toStringin classObject
-
serialize
public void serialize(ObjectOutputStream oos) throws IOException
Description copied from interface:EntityEntryCustom serialization routine used during serialization of a Session/PersistenceContext for increased performance.- Specified by:
serializein interfaceEntityEntry- Parameters:
oos- The stream to which we should write the serial data.- Throws:
IOException- If a stream error occurs
-
addExtraState
public void addExtraState(EntityEntryExtraState extraState)
- Specified by:
addExtraStatein interfaceEntityEntry
-
getExtraState
public <T extends EntityEntryExtraState> T getExtraState(Class<T> extraStateType)
- Specified by:
getExtraStatein interfaceEntityEntry
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
-
setCompressedValue
protected <E extends Enum<E>> void setCompressedValue(AbstractEntityEntry.EnumState<E> state, E value)
Saves the value for the given enum property.- Parameters:
state- identifies the value to storevalue- the value to store; The caller must make sure that it matches the given identifier
-
getCompressedValue
protected <E extends Enum<E>> E getCompressedValue(AbstractEntityEntry.EnumState<E> state)
Gets the current value of the given enum property.- Parameters:
state- identifies the value to store- Returns:
- the current value of the specified property
-
setCompressedValue
protected void setCompressedValue(AbstractEntityEntry.BooleanState state, boolean value)
Saves the value for the given boolean flag.- Parameters:
state- identifies the value to storevalue- the value to store
-
getCompressedValue
protected boolean getCompressedValue(AbstractEntityEntry.BooleanState state)
Gets the current value of the given boolean flag.- Parameters:
state- identifies the value to store- Returns:
- the current value of the specified flag
-
-