Top Description Fields Constructors Methods
org.hibernate.proxy

public abstract Class AbstractLazyInitializer

extends Object
implements LazyInitializer
Class Inheritance
All Implemented Interfaces
org.hibernate.proxy.LazyInitializer
Known Direct Subclasses
org.hibernate.proxy.dom4j.Dom4jLazyInitializer, org.hibernate.proxy.map.MapLazyInitializer, org.hibernate.proxy.pojo.BasicLazyInitializer
Imports
java.io.Serializable, org.hibernate.AssertionFailure, .HibernateException, .LazyInitializationException, .TransientObjectException, .SessionException, org.hibernate.engine.EntityKey, .SessionImplementor, org.hibernate.persister.entity.EntityPersister

Convenience base class for lazy initialization handlers. Centralizes the basic plumbing of doing lazy initialization freeing subclasses to acts as essentially adapters to their intended entity mode and/or proxy generation strategy.
Author
Gavin King

Field Summary

Modifier and TypeField and Description
private String
private Serializable
private boolean
private boolean
private Boolean
private transient SessionImplementor
private Object
private boolean

Constructor Summary

AccessConstructor and Description
protected
AbstractLazyInitializer()

For serialization from the non-pojo initializers (HHH-3309)

protected
AbstractLazyInitializer(String
The name of the entity being proxied.
entityName
,
Serializable
The identifier of the entity being proxied.
id
,
SessionImplementor
The session owning the proxy.
session
)

Main constructor.

Method Summary

Modifier and TypeMethod and Description
private void
private void
private static EntityKey
public final String
getEntityName()

Implements org.hibernate.proxy.LazyInitializer.getEntityName.

The entity-name of the entity our owning proxy represents.
public final Serializable
getIdentifier()

Implements org.hibernate.proxy.LazyInitializer.getIdentifier.

Retrieve the identifier value for the enity our owning proxy represents.
public final Object
getImplementation()

Implements org.hibernate.proxy.LazyInitializer.getImplementation.

Return the underlying persistent object, initializing if necessary
public final Object
getImplementation(SessionImplementor
The session to check
s
)

Implements org.hibernate.proxy.LazyInitializer.getImplementation.

Return the underlying persistent object in the given Session, or null, do not initialize the proxy
private Object
public final SessionImplementor
getSession()

Implements org.hibernate.proxy.LazyInitializer.getSession.

Get the session to which this proxy is associated, or null if it is not attached.
protected final Object

Returns:

Value for property 'target'.
getTarget
()

Getter for property 'target'.

public final void
initialize()

Implements org.hibernate.proxy.LazyInitializer.initialize.

Initialize the proxy, fetching the target entity if necessary.
protected final boolean

Returns:

Value for property 'connectedToSession'.
isConnectedToSession
()

Getter for property 'connectedToSession'.

public final boolean
isReadOnly()

Implements org.hibernate.proxy.LazyInitializer.isReadOnly.

Is the proxy read-only?.
protected final Boolean

Returns:

null, if the default setting should be used; true, for read-only; false, for modifiable
isReadOnlyBeforeAttachedToSession
()

Get the read-only/modifiable setting that should be put in affect when it is attached to a session.

public final boolean
isReadOnlySettingAvailable()

Implements org.hibernate.proxy.LazyInitializer.isReadOnlySettingAvailable.

Is the proxy's read-only/modifiable setting available?
public final boolean
public boolean
public final void
setIdentifier(Serializable
The identifier value.
id
)

Implements org.hibernate.proxy.LazyInitializer.setIdentifier.

Set the identifier value for the enity our owning proxy represents.
public final void
setImplementation(Object
The proxy target (the actual entity being proxied).
target
)

Implements org.hibernate.proxy.LazyInitializer.setImplementation.

Initialize the proxy manually by injecting its target.
public final void
setReadOnly(boolean
if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.
readOnly
)

Implements org.hibernate.proxy.LazyInitializer.setReadOnly.

Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode.
pack-priv final void
setReadOnlyBeforeAttachedToSession(Boolean
the read-only/modifiable setting to use when associated with a session; null indicates that the default should be used.
readOnlyBeforeAttachedToSession
)

Set the read-only/modifiable setting that should be put in affect when it is attached to a session.

public final void
setSession(SessionImplementor
The session
s
)

Implements org.hibernate.proxy.LazyInitializer.setSession.

Associate the proxy with the given session.
public void
public final void
unsetSession()

Implements org.hibernate.proxy.LazyInitializer.unsetSession.

Unset this initializer's reference to session.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entityNameback to summary
private String entityName
idback to summary
private Serializable id
initializedback to summary
private boolean initialized
readOnlyback to summary
private boolean readOnly
readOnlyBeforeAttachedToSessionback to summary
private Boolean readOnlyBeforeAttachedToSession
sessionback to summary
private transient SessionImplementor session
targetback to summary
private Object target
unwrapback to summary
private boolean unwrap

Constructor Detail

AbstractLazyInitializerback to summary
protected AbstractLazyInitializer()

For serialization from the non-pojo initializers (HHH-3309)

AbstractLazyInitializerback to summary
protected AbstractLazyInitializer(String entityName, Serializable id, SessionImplementor session)

Main constructor.

Parameters
entityName:String

The name of the entity being proxied.

id:Serializable

The identifier of the entity being proxied.

session:SessionImplementor

The session owning the proxy.

Method Detail

checkTargetStateback to summary
private void checkTargetState()
errorIfReadOnlySettingNotAvailableback to summary
private void errorIfReadOnlySettingNotAvailable()
generateEntityKeyOrNullback to summary
private static EntityKey generateEntityKeyOrNull(Serializable id, SessionImplementor s, String entityName)
getEntityNameback to summary
public final String getEntityName()

Implements org.hibernate.proxy.LazyInitializer.getEntityName.

Doc from org.hibernate.proxy.LazyInitializer.getEntityName.

The entity-name of the entity our owning proxy represents.

Returns:String

The entity-name.

getIdentifierback to summary
public final Serializable getIdentifier()

Implements org.hibernate.proxy.LazyInitializer.getIdentifier.

Doc from org.hibernate.proxy.LazyInitializer.getIdentifier.

Retrieve the identifier value for the enity our owning proxy represents.

Returns:Serializable

The identifier value.

getImplementationback to summary
public final Object getImplementation()

Implements org.hibernate.proxy.LazyInitializer.getImplementation.

Return the underlying persistent object, initializing if necessary

Returns:Object

Doc from org.hibernate.proxy.LazyInitializer.getImplementation.

The underlying target entity.

getImplementationback to summary
public final Object getImplementation(SessionImplementor s) throws HibernateException

Implements org.hibernate.proxy.LazyInitializer.getImplementation.

Return the underlying persistent object in the given Session, or null, do not initialize the proxy

Parameters
s:SessionImplementor

Doc from org.hibernate.proxy.LazyInitializer.getImplementation.

The session to check

Returns:Object

Doc from org.hibernate.proxy.LazyInitializer.getImplementation.

The target, or null.

Exceptions
HibernateException:

Doc from org.hibernate.proxy.LazyInitializer.getImplementation.

Indicates problem locating the target.

getProxyOrNullback to summary
private Object getProxyOrNull()
getSessionback to summary
public final SessionImplementor getSession()

Implements org.hibernate.proxy.LazyInitializer.getSession.

Doc from org.hibernate.proxy.LazyInitializer.getSession.

Get the session to which this proxy is associated, or null if it is not attached.

Returns:SessionImplementor

The associated session.

getTargetback to summary
protected final Object getTarget()

Getter for property 'target'.

Same as getImplementation() except that this method will not force initialization.

Returns:Object

Value for property 'target'.

initializeback to summary
public final void initialize() throws HibernateException

Implements org.hibernate.proxy.LazyInitializer.initialize.

Doc from org.hibernate.proxy.LazyInitializer.initialize.

Initialize the proxy, fetching the target entity if necessary.

Exceptions
HibernateException:
Indicates a problem initializing the proxy.
isConnectedToSessionback to summary
protected final boolean isConnectedToSession()

Getter for property 'connectedToSession'.

Returns:boolean

Value for property 'connectedToSession'.

isReadOnlyback to summary
public final boolean isReadOnly()

Implements org.hibernate.proxy.LazyInitializer.isReadOnly.

Doc from org.hibernate.proxy.LazyInitializer.isReadOnly.

Is the proxy read-only?. The read-only/modifiable setting is not available when the proxy is detached or its associated session is closed. To check if the read-only/modifiable setting is available:

Returns:boolean

true, if this proxy is read-only; false, otherwise

isReadOnlyBeforeAttachedToSessionback to summary
protected final Boolean isReadOnlyBeforeAttachedToSession()

Get the read-only/modifiable setting that should be put in affect when it is attached to a session. This method should only be called during serialization when read-only/modifiable setting is not available (i.e., isReadOnlySettingAvailable() == false)

Returns:Boolean

null, if the default setting should be used; true, for read-only; false, for modifiable

Exceptions
IllegalStateException:
if isReadOnlySettingAvailable() == true
isReadOnlySettingAvailableback to summary
public final boolean isReadOnlySettingAvailable()

Implements org.hibernate.proxy.LazyInitializer.isReadOnlySettingAvailable.

Doc from org.hibernate.proxy.LazyInitializer.isReadOnlySettingAvailable.

Is the proxy's read-only/modifiable setting available?

Returns:boolean

true, if the setting is available false, if the proxy is detached or its associated session is closed

isUninitializedback to summary
public final boolean isUninitialized()

Implements org.hibernate.proxy.LazyInitializer.isUninitialized.

Doc from org.hibernate.proxy.LazyInitializer.isUninitialized.

Is the proxy uninitialzed?

Returns:boolean

True if uninitialized; false otherwise.

isUnwrapback to summary
public boolean isUnwrap()

Implements org.hibernate.proxy.LazyInitializer.isUnwrap.

setIdentifierback to summary
public final void setIdentifier(Serializable id)

Implements org.hibernate.proxy.LazyInitializer.setIdentifier.

Doc from org.hibernate.proxy.LazyInitializer.setIdentifier.

Set the identifier value for the enity our owning proxy represents.

Parameters
id:Serializable

The identifier value.

setImplementationback to summary
public final void setImplementation(Object target)

Implements org.hibernate.proxy.LazyInitializer.setImplementation.

Doc from org.hibernate.proxy.LazyInitializer.setImplementation.

Initialize the proxy manually by injecting its target.

Parameters
target:Object

The proxy target (the actual entity being proxied).

setReadOnlyback to summary
public final void setReadOnly(boolean readOnly)

Implements org.hibernate.proxy.LazyInitializer.setReadOnly.

Doc from org.hibernate.proxy.LazyInitializer.setReadOnly.

Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode. If the proxy is currently initialized, its implementation will be set to the same mode; otherwise, when the proxy is initialized, its implementation will have the same read-only/ modifiable setting as the proxy. In read-only mode, no snapshot is maintained and the instance is never dirty checked. If the associated proxy already has the specified read-only/modifiable setting, then this method does nothing.

Parameters
readOnly:boolean

if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.

setReadOnlyBeforeAttachedToSessionback to summary
pack-priv final void setReadOnlyBeforeAttachedToSession(Boolean readOnlyBeforeAttachedToSession)

Set the read-only/modifiable setting that should be put in affect when it is attached to a session. This method should only be called during deserialization, before associating the proxy with a session.

Parameters
readOnlyBeforeAttachedToSession:Boolean

the read-only/modifiable setting to use when associated with a session; null indicates that the default should be used.

Exceptions
IllegalStateException:
if isReadOnlySettingAvailable() == true
setSessionback to summary
public final void setSession(SessionImplementor s) throws HibernateException

Implements org.hibernate.proxy.LazyInitializer.setSession.

Doc from org.hibernate.proxy.LazyInitializer.setSession.

Associate the proxy with the given session.

Care should be given to make certain that the proxy is added to the session's persistence context as well to maintain the symetry of the association. That must be done seperately as this method simply sets an internal reference. We do also check that if there is already an associated session that the proxy reference was removed from that previous session's persistence contet.

Parameters
s:SessionImplementor

The session

Exceptions
HibernateException:
Indicates that the proxy was still contained in the persistence context of the "previous session".
setUnwrapback to summary
public void setUnwrap(boolean unwrap)

Implements org.hibernate.proxy.LazyInitializer.setUnwrap.

unsetSessionback to summary
public final void unsetSession()

Implements org.hibernate.proxy.LazyInitializer.unsetSession.

Doc from org.hibernate.proxy.LazyInitializer.unsetSession.

Unset this initializer's reference to session. It is assumed that the caller is also taking care or cleaning up the owning proxy's reference in the persistence context.

Generally speaking this is intended to be called only during org.hibernate.Session#evict and org.hibernate.Session#clear processing; most other use-cases should call setSession instead.