public abstract class AbstractLazyInitializer extends Object implements LazyInitializer
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.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLazyInitializer()
For serialization from the non-pojo initializers (HHH-3309)
|
protected |
AbstractLazyInitializer(String entityName,
Serializable id,
SharedSessionContractImplementor session)
Main constructor.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getEntityName()
The entity-name of the entity our owning proxy represents.
|
Serializable |
getIdentifier()
Retrieve the identifier value for the entity our owning proxy represents.
|
Object |
getImplementation()
Return the underlying persistent object, initializing if necessary
|
Object |
getImplementation(SharedSessionContractImplementor s)
Return the underlying persistent object in the given session, or null if not contained in this session’s
persistence context.
|
SharedSessionContractImplementor |
getSession()
Get the session to which this proxy is associated, or null if it is not attached.
|
protected Object |
getTarget()
Getter for property 'target'.
|
void |
initialize()
Initialize the proxy, fetching the target entity if necessary.
|
protected boolean |
isConnectedToSession()
Getter for property 'connectedToSession'.
|
boolean |
isReadOnly()
Is the proxy read-only?.
|
protected Boolean |
isReadOnlyBeforeAttachedToSession()
Get the read-only/modifiable setting that should be put in affect when it is
attached to a session.
|
boolean |
isReadOnlySettingAvailable()
Is the proxy’s read-only/modifiable setting available?
|
boolean |
isUninitialized()
Is the proxy uninitialzed?
|
boolean |
isUnwrap() |
protected void |
permissiveInitialization() |
protected void |
prepareForPossibleLoadingOutsideTransaction() |
void |
setIdentifier(Serializable id)
Set the identifier value for the entity our owning proxy represents.
|
void |
setImplementation(Object target)
Initialize the proxy manually by injecting its target.
|
void |
setReadOnly(boolean readOnly)
Set an associated modifiable proxy to read-only mode, or a read-only
proxy to modifiable mode.
|
void |
setSession(SharedSessionContractImplementor s)
Associate the proxy with the given session.
|
void |
setUnwrap(boolean unwrap) |
void |
unsetSession()
Unset this initializer’s reference to session.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPersistentClassprotected AbstractLazyInitializer()
For serialization from the non-pojo initializers (HHH-3309)
protected AbstractLazyInitializer(String entityName, Serializable id, SharedSessionContractImplementor session)
Main constructor.
entityName - The name of the entity being proxied.id - The identifier of the entity being proxied.session - The session owning the proxy.public final String getEntityName()
LazyInitializerThe entity-name of the entity our owning proxy represents.
getEntityName in interface LazyInitializerpublic final Serializable getIdentifier()
LazyInitializerRetrieve the identifier value for the entity our owning proxy represents.
getIdentifier in interface LazyInitializerpublic final void setIdentifier(Serializable id)
LazyInitializerSet the identifier value for the entity our owning proxy represents.
setIdentifier in interface LazyInitializerid - The identifier value.public final boolean isUninitialized()
LazyInitializerIs the proxy uninitialzed?
isUninitialized in interface LazyInitializerpublic final SharedSessionContractImplementor getSession()
LazyInitializerGet the session to which this proxy is associated, or null if it is not attached.
getSession in interface LazyInitializerpublic final void setSession(SharedSessionContractImplementor s) throws HibernateException
LazyInitializerAssociate the proxy with the given session. <p/> 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.
setSession in interface LazyInitializers - The sessionHibernateException - Indicates that the proxy was still contained in the persistence context of the
"previous session".public final void unsetSession()
LazyInitializerUnset 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.
<p/>
Generally speaking this is intended to be called only during Session.evict(java.lang.Object) and
Session.clear() processing; most other use-cases should call LazyInitializer.setSession(org.hibernate.engine.spi.SharedSessionContractImplementor) instead.
unsetSession in interface LazyInitializerpublic final void initialize()
throws HibernateException
LazyInitializerInitialize the proxy, fetching the target entity if necessary.
initialize in interface LazyInitializerHibernateException - Indicates a problem initializing the proxy.protected void permissiveInitialization()
protected void prepareForPossibleLoadingOutsideTransaction()
protected final boolean isConnectedToSession()
Getter for property 'connectedToSession'.
public final Object getImplementation()
LazyInitializerReturn the underlying persistent object, initializing if necessary
getImplementation in interface LazyInitializerpublic final void setImplementation(Object target)
LazyInitializerInitialize the proxy manually by injecting its target.
setImplementation in interface LazyInitializertarget - The proxy target (the actual entity being proxied).public final Object getImplementation(SharedSessionContractImplementor s) throws HibernateException
LazyInitializerReturn the underlying persistent object in the given session, or null if not contained in this session’s persistence context.
getImplementation in interface LazyInitializers - The session to checkHibernateException - Indicates problem locating the target.protected final Object getTarget()
Getter for property 'target'.
<p/>
Same as getImplementation() except that this method will not force initialization.
public final boolean isReadOnlySettingAvailable()
LazyInitializerIs the proxy’s read-only/modifiable setting available?
isReadOnlySettingAvailable in interface LazyInitializerpublic final boolean isReadOnly()
LazyInitializerIs 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:
isReadOnly in interface LazyInitializerLazyInitializer.isReadOnlySettingAvailable(),
Session.isReadOnly(Object entityOrProxy)public final void setReadOnly(boolean readOnly)
LazyInitializerSet 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.
setReadOnly in interface LazyInitializerreadOnly - if true, the associated proxy is made read-only;
if false, the associated proxy is made modifiable.Session.setReadOnly(Object entityOrProxy, boolean readOnly)protected final Boolean isReadOnlyBeforeAttachedToSession()
Get the read-only/modifiable setting that should be put in affect when it is attached to a session. <p/> This method should only be called during serialization when read-only/modifiable setting is not available (i.e., isReadOnlySettingAvailable() == false)
IllegalStateException - if isReadOnlySettingAvailable() == truepublic boolean isUnwrap()
isUnwrap in interface LazyInitializerpublic void setUnwrap(boolean unwrap)
setUnwrap in interface LazyInitializerCopyright © 2001-2018 Red Hat, Inc. All Rights Reserved.