public abstract class

AbstractLazyInitializer

extends Object
implements LazyInitializer
java.lang.Object
   ↳ org.hibernate.proxy.AbstractLazyInitializer
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

Protected Constructors
AbstractLazyInitializer()
For serialization from the non-pojo initializers (HHH-3309)
AbstractLazyInitializer(String entityName, Serializable id, SessionImplementor session)
Main constructor.
Public Methods
final String getEntityName()
The entity-name of the entity our owning proxy represents.
final Serializable getIdentifier()
Retrieve the identifier value for the enity our owning proxy represents.
final Object getImplementation()
Return the underlying persistent object, initializing if necessary
final Object getImplementation(SessionImplementor s)
Return the underlying persistent object in the given Session, or null, do not initialize the proxy
final SessionImplementor getSession()
Get the session to which this proxy is associated, or null if it is not attached.
final void initialize()
Initialize the proxy, fetching the target entity if necessary.
final boolean isReadOnly()
Is the proxy read-only?.
final boolean isReadOnlySettingAvailable()
Is the proxy's read-only/modifiable setting available?
final boolean isUninitialized()
Is the proxy uninitialzed?
boolean isUnwrap()
final void setIdentifier(Serializable id)
Set the identifier value for the enity our owning proxy represents.
final void setImplementation(Object target)
Initialize the proxy manually by injecting its target.
final void setReadOnly(boolean readOnly)
Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode.
final void setSession(SessionImplementor s)
Associate the proxy with the given session.
void setUnwrap(boolean unwrap)
final void unsetSession()
Unset this initializer's reference to session.
Protected Methods
final Object getTarget()
Getter for property 'target'.
final boolean isConnectedToSession()
Getter for property 'connectedToSession'.
final Boolean isReadOnlyBeforeAttachedToSession()
Get the read-only/modifiable setting that should be put in affect when it is attached to a session.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.proxy.LazyInitializer

Protected Constructors

protected AbstractLazyInitializer ()

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

protected AbstractLazyInitializer (String entityName, Serializable id, SessionImplementor session)

Main constructor.

Parameters
entityName The name of the entity being proxied.
id The identifier of the entity being proxied.
session The session owning the proxy.

Public Methods

public final String getEntityName ()

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

Returns
  • The entity-name.

public final Serializable getIdentifier ()

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

Returns
  • The identifier value.

public final Object getImplementation ()

Return the underlying persistent object, initializing if necessary

Returns
  • The underlying target entity.

public final Object getImplementation (SessionImplementor s)

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

Parameters
s The session to check
Returns
  • The target, or null.

public final SessionImplementor getSession ()

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

Returns
  • The associated session.

public final void initialize ()

Initialize the proxy, fetching the target entity if necessary.

public final boolean 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
  • true, if this proxy is read-only; false, otherwise

public final boolean isReadOnlySettingAvailable ()

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

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

public final boolean isUninitialized ()

Is the proxy uninitialzed?

Returns
  • True if uninitialized; false otherwise.

public boolean isUnwrap ()

public final void setIdentifier (Serializable id)

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

Parameters
id The identifier value.

public final void setImplementation (Object target)

Initialize the proxy manually by injecting its target.

Parameters
target The proxy target (the actual entity being proxied).

public final void setReadOnly (boolean readOnly)

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.

public final void setSession (SessionImplementor s)

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 The session

public void setUnwrap (boolean unwrap)

public final void 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 evict(Object) and clear() processing; most other use-cases should call setSession(SessionImplementor) instead.

Protected Methods

protected final Object getTarget ()

Getter for property 'target'.

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

Returns
  • Value for property 'target'.

protected final boolean isConnectedToSession ()

Getter for property 'connectedToSession'.

Returns
  • Value for property 'connectedToSession'.

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)

Throws
IllegalStateException if isReadOnlySettingAvailable() == true