We need an entry to tell us all about the current state
of an object with respect to its persistent state
| Method from org.hibernate.engine.EntityEntry Detail: |
void afterDeserialize(SessionFactoryImplementor factory) {
persister = factory.getEntityPersister( entityName );
}
|
static EntityEntry deserialize(ObjectInputStream ois,
SessionImplementor session) throws IOException, ClassNotFoundException {
return new EntityEntry(
session.getFactory(),
( String ) ois.readObject(),
( Serializable ) ois.readObject(),
EntityMode.parse( ( String ) ois.readObject() ),
Status.parse( ( String ) ois.readObject() ),
( Object[] ) ois.readObject(),
( Object[] ) ois.readObject(),
( Object ) ois.readObject(),
LockMode.parse( ( String ) ois.readObject() ),
ois.readBoolean(),
ois.readBoolean(),
ois.readBoolean()
);
}
Custom deserialization routine used during deserialization of a
Session/PersistenceContext for increased performance. |
public void forceLocked(Object entity,
Object nextVersion) {
version = nextVersion;
loadedState[ persister.getVersionProperty() ] = version;
setLockMode( LockMode.FORCE );
persister.setPropertyValue(
entity,
getPersister().getVersionProperty(),
nextVersion,
entityMode
);
}
|
public Object[] getDeletedState() {
return deletedState;
}
|
public String getEntityName() {
return entityName;
}
|
public Serializable getId() {
return id;
}
|
public Object[] getLoadedState() {
return loadedState;
}
|
public Object getLoadedValue(String propertyName) {
int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex(propertyName);
return loadedState[propertyIndex];
}
|
public LockMode getLockMode() {
return lockMode;
}
|
public EntityPersister getPersister() {
return persister;
}
|
public Object getRowId() {
return rowId;
}
|
public Status getStatus() {
return status;
}
|
public Object getVersion() {
return version;
}
|
public boolean isBeingReplicated() {
return isBeingReplicated;
}
|
public boolean isExistsInDatabase() {
return existsInDatabase;
}
|
public boolean isLoadedWithLazyPropertiesUnfetched() {
return loadedWithLazyPropertiesUnfetched;
}
|
public boolean isNullifiable(boolean earlyInsert,
SessionImplementor session) {
return getStatus() == Status.SAVING || (
earlyInsert ?
!isExistsInDatabase() :
session.getPersistenceContext().getNullifiableEntityKeys()
.contains( new EntityKey( getId(), getPersister(), entityMode ) )
);
}
|
public void postDelete() {
status = Status.GONE;
existsInDatabase = false;
}
After actually deleting a row, record the fact that the instance no longer
exists in the database |
public void postInsert() {
existsInDatabase = true;
}
After actually inserting a row, record the fact that the instance exists on the
database (needed for identity-column key generation) |
public void postUpdate(Object entity,
Object[] updatedState,
Object nextVersion) {
this.loadedState = updatedState;
setLockMode(LockMode.WRITE);
if ( getPersister().isVersioned() ) {
this.version = nextVersion;
getPersister().setPropertyValue(
entity,
getPersister().getVersionProperty(),
nextVersion,
entityMode
);
}
FieldInterceptionHelper.clearDirty( entity );
}
After actually updating the database, update the snapshot information,
and escalate the lock mode |
public boolean requiresDirtyCheck(Object entity) {
boolean isMutableInstance =
status != Status.READ_ONLY &&
persister.isMutable();
return isMutableInstance && (
getPersister().hasMutableProperties() ||
!FieldInterceptionHelper.isInstrumented( entity ) ||
FieldInterceptionHelper.extractFieldInterceptor( entity).isDirty()
);
}
|
void serialize(ObjectOutputStream oos) throws IOException {
oos.writeObject( entityName );
oos.writeObject( id );
oos.writeObject( entityMode.toString() );
oos.writeObject( status.toString() );
// todo : potentially look at optimizing these two arrays
oos.writeObject( loadedState );
oos.writeObject( deletedState );
oos.writeObject( version );
oos.writeObject( lockMode.toString() );
oos.writeBoolean( existsInDatabase );
oos.writeBoolean( isBeingReplicated );
oos.writeBoolean( loadedWithLazyPropertiesUnfetched );
}
Custom serialization routine used during serialization of a
Session/PersistenceContext for increased performance. |
public void setDeletedState(Object[] deletedState) {
this.deletedState = deletedState;
}
|
public void setLockMode(LockMode lockMode) {
this.lockMode = lockMode;
}
|
public void setReadOnly(boolean readOnly,
Object entity) {
if (status!=Status.MANAGED && status!=Status.READ_ONLY) {
throw new HibernateException("instance was not in a valid state");
}
if (readOnly) {
setStatus(Status.READ_ONLY);
loadedState = null;
}
else {
setStatus(Status.MANAGED);
loadedState = getPersister().getPropertyValues(entity, entityMode);
}
}
|
public void setStatus(Status status) {
if (status==Status.READ_ONLY) {
loadedState = null; //memory optimization
}
this.status = status;
}
|
public String toString() {
return "EntityEntry" +
MessageHelper.infoString(entityName, id) +
'(' + status + ')';
}
|