Interface MutabilityPlan<T>
-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
ArrayMutabilityPlan
,AttributeConverterMutabilityPlanImpl
,BlobJavaType.BlobMutabilityPlan
,CalendarJavaType.CalendarMutabilityPlan
,ClobJavaType.ClobMutabilityPlan
,CompositeUserTypeJavaTypeWrapper.MutabilityPlanWrapper
,DateJavaType.DateMutabilityPlan
,DiscriminatedAssociationAttributeMapping.MutabilityPlanImpl
,FormatMapperBasedJavaType
,Immutability
,ImmutableMutabilityPlan
,JdbcDateJavaType.DateMutabilityPlan
,JdbcTimeJavaType.TimeMutabilityPlan
,JdbcTimestampJavaType.TimestampMutabilityPlan
,JsonJavaType
,MutableMutabilityPlan
,NClobJavaType.NClobMutabilityPlan
,SerializableJavaType.SerializableMutabilityPlan
,UserTypeJavaTypeWrapper.MutabilityPlanWrapper
,UserTypeMutabilityPlanAdapter
,XmlJavaType
public interface MutabilityPlan<T> extends Serializable
Describes the mutability aspects of a given Java type.Mutable values require special handling that is not necessary for immutable values:
- a mutable value must be cloned when taking a "snapshot" of the state of an entity for dirty-checking, and
- a mutable value requires more careful handling when the entity is disassembled for storage in destructured form in the second-level cache.
Neither is a requirement for correctness when dealing with an immutable object. But there might be other reasons why an immutable object requires custom implementations of
disassemble(T, org.hibernate.SharedSessionContract)
andassemble(java.io.Serializable, org.hibernate.SharedSessionContract)
.For example:
- if the object is not serializable, we might convert it to a serializable format,
- if the object hold a reference to an entity, we must replace that reference with an identifier, or
- if the object hold a reference to some heavyweight resource, we must release it.
For an immutable type, it's not usually necessary to do anything special in
deepCopy(T)
. The method can simply return its argument.- See Also:
Mutability
- API Note:
- The term "mutability" refers to the fact that, in general, the aspects of the Java type described by this contract are determined by whether the Java type has mutable internal state.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description @Nullable T
assemble(@Nullable Serializable cached, SharedSessionContract session)
Assemble a previously disassembled value.@Nullable T
deepCopy(@Nullable T value)
Return a deep copy of the value.@Nullable Serializable
disassemble(@Nullable T value, SharedSessionContract session)
Return a disassembled representation of the value.boolean
isMutable()
Can the internal state of instances ofT
be changed?
-
-
-
Method Detail
-
isMutable
boolean isMutable()
Can the internal state of instances ofT
be changed?- Returns:
- True if the internal state can be changed; false otherwise.
-
deepCopy
@Nullable T deepCopy(@Nullable T value)
Return a deep copy of the value.- Parameters:
value
- The value to deep copy- Returns:
- The deep copy.
-
disassemble
@Nullable Serializable disassemble(@Nullable T value, SharedSessionContract session)
Return a disassembled representation of the value.Called before storing a value in the second-level cache.
Complementary to
assemble(java.io.Serializable, org.hibernate.SharedSessionContract)
.
-
assemble
@Nullable T assemble(@Nullable Serializable cached, SharedSessionContract session)
Assemble a previously disassembled value.Called after reading a value from the second level cache.
Complementary to
disassemble(T, org.hibernate.SharedSessionContract)
.
-
-