Package org.hibernate.proxy
Class AbstractLazyInitializer
java.lang.Object
org.hibernate.proxy.AbstractLazyInitializer
- All Implemented Interfaces:
LazyInitializer
- Direct Known Subclasses:
BasicLazyInitializer,Dom4jLazyInitializer,MapLazyInitializer
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.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFor serialization from the non-pojo initializers (HHH-3309)protectedAbstractLazyInitializer(String entityName, Serializable id, SessionImplementor session) Main constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringThe entity-name of the entity our owning proxy represents.final SerializableRetrieve the identifier value for the enity our owning proxy represents.final ObjectReturn the underlying persistent object, initializing if necessaryfinal ObjectReturn the underlying persistent object in the given Session, or null, do not initialize the proxyfinal SessionImplementorGet the session to which this proxy is associated, or null if it is not attached.protected final ObjectGetter for property 'target'.final voidInitialize the proxy, fetching the target entity if necessary.protected final booleanGetter for property 'connectedToSession'.final booleanIs the proxy read-only?.protected final BooleanGet the read-only/modifiable setting that should be put in affect when it is attached to a session.final booleanIs the proxy's read-only/modifiable setting available?final booleanIs the proxy uninitialzed?booleanisUnwrap()final voidSet the identifier value for the enity our owning proxy represents.final voidsetImplementation(Object target) Initialize the proxy manually by injecting its target.final voidsetReadOnly(boolean readOnly) Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode.final voidAssociate the proxy with the given session.voidsetUnwrap(boolean unwrap) final voidUnset this initializer's reference to session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.proxy.LazyInitializer
getPersistentClass
-
Constructor Details
-
AbstractLazyInitializer
protected AbstractLazyInitializer()For serialization from the non-pojo initializers (HHH-3309) -
AbstractLazyInitializer
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.
-
-
Method Details
-
getEntityName
The entity-name of the entity our owning proxy represents.- Specified by:
getEntityNamein interfaceLazyInitializer- Returns:
- The entity-name.
-
getIdentifier
Retrieve the identifier value for the enity our owning proxy represents.- Specified by:
getIdentifierin interfaceLazyInitializer- Returns:
- The identifier value.
-
setIdentifier
Set the identifier value for the enity our owning proxy represents.- Specified by:
setIdentifierin interfaceLazyInitializer- Parameters:
id- The identifier value.
-
isUninitialized
public final boolean isUninitialized()Is the proxy uninitialzed?- Specified by:
isUninitializedin interfaceLazyInitializer- Returns:
- True if uninitialized; false otherwise.
-
getSession
Get the session to which this proxy is associated, or null if it is not attached.- Specified by:
getSessionin interfaceLazyInitializer- Returns:
- The associated session.
-
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.- Specified by:
setSessionin interfaceLazyInitializer- Parameters:
s- The session- Throws:
HibernateException- Indicates that the proxy was still contained in the persistence context of the "previous session".
-
unsetSession
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 duringSession.evict(java.lang.Object)andSession.clear()processing; most other use-cases should callLazyInitializer.setSession(org.hibernate.engine.SessionImplementor)instead.- Specified by:
unsetSessionin interfaceLazyInitializer
-
initialize
Initialize the proxy, fetching the target entity if necessary.- Specified by:
initializein interfaceLazyInitializer- Throws:
HibernateException- Indicates a problem initializing the proxy.
-
isConnectedToSession
protected final boolean isConnectedToSession()Getter for property 'connectedToSession'.- Returns:
- Value for property 'connectedToSession'.
-
getImplementation
Return the underlying persistent object, initializing if necessary- Specified by:
getImplementationin interfaceLazyInitializer- Returns:
- The underlying target entity.
-
setImplementation
Initialize the proxy manually by injecting its target.- Specified by:
setImplementationin interfaceLazyInitializer- Parameters:
target- The proxy target (the actual entity being proxied).
-
getImplementation
Return the underlying persistent object in the given Session, or null, do not initialize the proxy- Specified by:
getImplementationin interfaceLazyInitializer- Parameters:
s- The session to check- Returns:
- The target, or null.
- Throws:
HibernateException- Indicates problem locating the target.
-
getTarget
Getter for property 'target'. Same asgetImplementation()except that this method will not force initialization.- Returns:
- Value for property 'target'.
-
isReadOnlySettingAvailable
public final boolean isReadOnlySettingAvailable()Is the proxy's read-only/modifiable setting available?- Specified by:
isReadOnlySettingAvailablein interfaceLazyInitializer- Returns:
- true, if the setting is available false, if the proxy is detached or its associated session is closed
-
isReadOnly
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:- Specified by:
isReadOnlyin interfaceLazyInitializer- Returns:
- true, if this proxy is read-only; false, otherwise
- See Also:
-
setReadOnly
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.- Specified by:
setReadOnlyin interfaceLazyInitializer- Parameters:
readOnly- , if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.- See Also:
-
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
-
isUnwrap
public boolean isUnwrap()- Specified by:
isUnwrapin interfaceLazyInitializer
-
setUnwrap
public void setUnwrap(boolean unwrap) - Specified by:
setUnwrapin interfaceLazyInitializer
-