FileDocCategorySizeDatePackage
EntityEntry.javaAPI DocHibernate 3.2.58776Mon Feb 13 20:24:18 GMT 2006org.hibernate.engine

EntityEntry

public final class EntityEntry extends Object implements Serializable
We need an entry to tell us all about the current state of an object with respect to its persistent state
author
Gavin King

Fields Summary
private org.hibernate.LockMode
lockMode
private Status
status
private final Serializable
id
private Object[]
loadedState
private Object[]
deletedState
private boolean
existsInDatabase
private Object
version
private transient org.hibernate.persister.entity.EntityPersister
persister
private final org.hibernate.EntityMode
entityMode
private final String
entityName
private boolean
isBeingReplicated
private boolean
loadedWithLazyPropertiesUnfetched
private final transient Object
rowId
Constructors Summary
EntityEntry(Status status, Object[] loadedState, Object rowId, Serializable id, Object version, org.hibernate.LockMode lockMode, boolean existsInDatabase, org.hibernate.persister.entity.EntityPersister persister, org.hibernate.EntityMode entityMode, boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)

		this.status=status;
		this.loadedState=loadedState;
		this.id=id;
		this.rowId=rowId;
		this.existsInDatabase=existsInDatabase;
		this.version=version;
		this.lockMode=lockMode;
		this.isBeingReplicated=disableVersionIncrement;
		this.loadedWithLazyPropertiesUnfetched = lazyPropertiesAreUnfetched;
		this.persister=persister;
		this.entityMode = entityMode;
		this.entityName = persister == null ?
				null : persister.getEntityName();
	
private EntityEntry(SessionFactoryImplementor factory, String entityName, Serializable id, org.hibernate.EntityMode entityMode, Status status, Object[] loadedState, Object[] deletedState, Object version, org.hibernate.LockMode lockMode, boolean existsInDatabase, boolean isBeingReplicated, boolean loadedWithLazyPropertiesUnfetched)
Used during custom deserialization

		this.entityName = entityName;
		this.persister = factory.getEntityPersister( entityName );
		this.id = id;
		this.entityMode = entityMode;
		this.status = status;
		this.loadedState = loadedState;
		this.deletedState = deletedState;
		this.version = version;
		this.lockMode = lockMode;
		this.existsInDatabase = existsInDatabase;
		this.isBeingReplicated = isBeingReplicated;
		this.loadedWithLazyPropertiesUnfetched = loadedWithLazyPropertiesUnfetched;
		this.rowId = null; // this is equivalent to the old behavior...
	
Methods Summary
voidafterDeserialize(SessionFactoryImplementor factory)

		persister = factory.getEntityPersister( entityName );
	
static org.hibernate.engine.EntityEntrydeserialize(java.io.ObjectInputStream ois, SessionImplementor session)
Custom deserialization routine used during deserialization of a Session/PersistenceContext for increased performance.

param
ois The stream from which to read the entry.
param
session The session being deserialized.
return
The deserialized EntityEntry
throws
IOException
throws
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()
		);
	
public voidforceLocked(java.lang.Object entity, java.lang.Object nextVersion)

		version = nextVersion;
		loadedState[ persister.getVersionProperty() ] = version;
		setLockMode( LockMode.FORCE );
		persister.setPropertyValue(
				entity,
		        getPersister().getVersionProperty(),
		        nextVersion,
		        entityMode
		);
	
public java.lang.Object[]getDeletedState()

		return deletedState;
	
public java.lang.StringgetEntityName()

		return entityName;
	
public java.io.SerializablegetId()

		return id;
	
public java.lang.Object[]getLoadedState()

		return loadedState;
	
public java.lang.ObjectgetLoadedValue(java.lang.String propertyName)

		int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex(propertyName);
		return loadedState[propertyIndex];
	
public org.hibernate.LockModegetLockMode()

		return lockMode;
	
public org.hibernate.persister.entity.EntityPersistergetPersister()

		return persister;
	
public java.lang.ObjectgetRowId()

		return rowId;
	
public StatusgetStatus()

		return status;
	
public java.lang.ObjectgetVersion()

		return version;
	
public booleanisBeingReplicated()

		return isBeingReplicated;
	
public booleanisExistsInDatabase()

		return existsInDatabase;
	
public booleanisLoadedWithLazyPropertiesUnfetched()

		return loadedWithLazyPropertiesUnfetched;
	
public booleanisNullifiable(boolean earlyInsert, SessionImplementor session)

		return getStatus() == Status.SAVING || (
				earlyInsert ?
						!isExistsInDatabase() :
						session.getPersistenceContext().getNullifiableEntityKeys()
							.contains( new EntityKey( getId(), getPersister(), entityMode ) )
				);
	
public voidpostDelete()
After actually deleting a row, record the fact that the instance no longer exists in the database

		status = Status.GONE;
		existsInDatabase = false;
	
public voidpostInsert()
After actually inserting a row, record the fact that the instance exists on the database (needed for identity-column key generation)

		existsInDatabase = true;
	
public voidpostUpdate(java.lang.Object entity, java.lang.Object[] updatedState, java.lang.Object nextVersion)
After actually updating the database, update the snapshot information, and escalate the lock mode

		this.loadedState = updatedState;
		
		setLockMode(LockMode.WRITE);
		
		if ( getPersister().isVersioned() ) {
			this.version = nextVersion;
			getPersister().setPropertyValue( 
					entity, 
					getPersister().getVersionProperty(), 
					nextVersion, 
					entityMode 
				);
		}
		
		FieldInterceptionHelper.clearDirty( entity );
	
public booleanrequiresDirtyCheck(java.lang.Object entity)

		
		boolean isMutableInstance = 
				status != Status.READ_ONLY && 
				persister.isMutable();
		
		return isMutableInstance && (
				getPersister().hasMutableProperties() ||
				!FieldInterceptionHelper.isInstrumented( entity ) ||
				FieldInterceptionHelper.extractFieldInterceptor( entity).isDirty()
			);
		
	
voidserialize(java.io.ObjectOutputStream oos)
Custom serialization routine used during serialization of a Session/PersistenceContext for increased performance.

param
oos The stream to which we should write the serial data.
throws
java.io.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 );
	
public voidsetDeletedState(java.lang.Object[] deletedState)

		this.deletedState = deletedState;
	
public voidsetLockMode(org.hibernate.LockMode lockMode)

		this.lockMode = lockMode;
	
public voidsetReadOnly(boolean readOnly, java.lang.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 voidsetStatus(Status status)

		if (status==Status.READ_ONLY) {
			loadedState = null; //memory optimization
		}
		this.status = status;
	
public java.lang.StringtoString()

		return "EntityEntry" + 
				MessageHelper.infoString(entityName, id) + 
				'(" + status + ')";