public abstract class AbstractStandardBasicType<T> extends Object implements BasicType, StringRepresentableType<T>, ProcedureParameterExtractionAware<T>, ProcedureParameterNamedBinder
Convenience base class for BasicType
implementations
Constructor and Description |
---|
AbstractStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor,
JavaTypeDescriptor<T> javaTypeDescriptor) |
Modifier and Type | Method and Description |
---|---|
Object |
assemble(Serializable cached,
SharedSessionContractImplementor session,
Object owner)
Reconstruct the object from its disassembled state.
|
void |
beforeAssemble(Serializable cached,
SharedSessionContractImplementor session)
Called before assembling a query result set from the query cache, to allow batch fetching
of entities missing from the second-level cache.
|
boolean |
canDoExtraction()
Can the given instance of this type actually perform the parameter value extractions?
|
boolean |
canDoSetting()
Can the given instance of this type actually set the parameter value by name
|
int |
compare(Object x,
Object y)
Perform a
Comparator style comparison between values |
Object |
deepCopy(Object value,
SessionFactoryImplementor factory)
Return a deep copy of the persistent state, stopping at entities and at collections.
|
protected T |
deepCopy(T value) |
Size[] |
defaultSizes(Mapping mapping)
Defines the column sizes to use according to this type if the user did not explicitly say (and if no
Type.dictatedSizes(org.hibernate.engine.spi.Mapping) were given). |
Size[] |
dictatedSizes(Mapping mapping)
Return the column sizes dictated by this type.
|
Serializable |
disassemble(Object value,
SharedSessionContractImplementor session,
Object owner)
Return a disassembled representation of the object.
|
T |
extract(CallableStatement statement,
int startIndex,
SharedSessionContractImplementor session)
Perform the extraction
|
T |
extract(CallableStatement statement,
String[] paramNames,
SharedSessionContractImplementor session)
Perform the extraction
|
T |
fromString(String string) |
T |
fromStringValue(String xml)
Consume the given string representation back into this types java form.
|
Object |
get(ResultSet rs,
String name,
SharedSessionContractImplementor session) |
int |
getColumnSpan(Mapping mapping)
How many columns are used to persist this type.
|
protected static Size |
getDefaultSize() |
protected Size |
getDictatedSize() |
int |
getHashCode(Object x)
Get a hash code, consistent with persistence "equality".
|
int |
getHashCode(Object x,
SessionFactoryImplementor factory)
Get a hash code, consistent with persistence "equality".
|
JavaTypeDescriptor<T> |
getJavaTypeDescriptor() |
protected MutabilityPlan<T> |
getMutabilityPlan() |
String[] |
getRegistrationKeys()
Get the names under which this type should be registered in the type registry.
|
protected T |
getReplacement(T original,
T target,
SharedSessionContractImplementor session) |
Class |
getReturnedClass()
|
Type |
getSemiResolvedType(SessionFactoryImplementor factory)
As part of 2-phase loading, when we perform resolving what is the resolved type for this type? Generally
speaking the type and its semi-resolved type will be the same.
|
SqlTypeDescriptor |
getSqlTypeDescriptor() |
Object |
hydrate(ResultSet rs,
String[] names,
SharedSessionContractImplementor session,
Object owner)
Extract a value from the JDBC result set.
|
boolean |
isAnyType()
Return true if the implementation is castable to
AnyType . |
boolean |
isAssociationType()
Return true if the implementation is castable to
AssociationType . |
boolean |
isCollectionType()
Return true if the implementation is castable to
CollectionType . |
boolean |
isComponentType()
Return true if the implementation is castable to
CompositeType . |
protected boolean |
isDirty(Object old,
Object current) |
boolean |
isDirty(Object old,
Object current,
boolean[] checkable,
SharedSessionContractImplementor session)
Should the parent be considered dirty, given both the old and current value?
|
boolean |
isDirty(Object old,
Object current,
SharedSessionContractImplementor session)
Should the parent be considered dirty, given both the old and current value?
|
boolean |
isEntityType()
Return true if the implementation is castable to
EntityType . |
boolean |
isEqual(Object one,
Object another)
Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
state).
|
boolean |
isEqual(Object x,
Object y,
SessionFactoryImplementor factory)
Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
state).
|
boolean |
isModified(Object oldHydratedState,
Object currentState,
boolean[] checkable,
SharedSessionContractImplementor session)
Has the value been modified compared to the current database state? The difference between this
and the
Type.isDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor) methods is that here we need to account for "partially" built values. |
boolean |
isMutable()
Are objects of this type mutable.
|
boolean |
isSame(Object x,
Object y)
Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
state) taking a shortcut for entity references.
|
boolean |
isXMLElement() |
Object |
nullSafeGet(ResultSet rs,
String[] names,
SharedSessionContractImplementor session,
Object owner)
Extract a value of the
mapped class from the JDBC result set. |
T |
nullSafeGet(ResultSet rs,
String name,
SharedSessionContractImplementor session) |
Object |
nullSafeGet(ResultSet rs,
String name,
SharedSessionContractImplementor session,
Object owner)
Extract a value of the
mapped class from the JDBC result set. |
protected T |
nullSafeGet(ResultSet rs,
String name,
WrapperOptions options) |
void |
nullSafeSet(CallableStatement st,
Object value,
String name,
SharedSessionContractImplementor session)
Bind a value to the JDBC prepared statement, ignoring some columns as dictated by the 'settable' parameter.
|
protected void |
nullSafeSet(CallableStatement st,
Object value,
String name,
WrapperOptions options) |
void |
nullSafeSet(PreparedStatement st,
Object value,
int index,
SharedSessionContractImplementor session)
Bind a value represented by an instance of the
mapped class to the JDBC prepared
statement. |
protected void |
nullSafeSet(PreparedStatement st,
Object value,
int index,
WrapperOptions options) |
protected boolean |
registerUnderJavaType() |
protected SqlTypeDescriptor |
remapSqlTypeDescriptor(WrapperOptions options) |
Object |
replace(Object original,
Object target,
SharedSessionContractImplementor session,
Object owner,
Map copyCache)
During merge, replace the existing (target) value in the entity we are merging to
with a new (original) value from the detached entity we are merging.
|
Object |
replace(Object original,
Object target,
SharedSessionContractImplementor session,
Object owner,
Map copyCache,
ForeignKeyDirection foreignKeyDirection)
During merge, replace the existing (target) value in the entity we are merging to
with a new (original) value from the detached entity we are merging.
|
Object |
resolve(Object value,
SharedSessionContractImplementor session,
Object owner) |
Object |
semiResolve(Object value,
SharedSessionContractImplementor session,
Object owner)
Given a hydrated, but unresolved value, return a value that may be used to reconstruct property-ref
associations.
|
void |
set(PreparedStatement st,
T value,
int index,
SharedSessionContractImplementor session) |
void |
setJavaTypeDescriptor(JavaTypeDescriptor<T> javaTypeDescriptor) |
void |
setSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) |
int[] |
sqlTypes(Mapping mapping)
Return the JDBC types codes (per
Types ) for the columns mapped by this type. |
boolean[] |
toColumnNullness(Object value,
Mapping mapping)
Given an instance of the type, return an array of boolean, indicating
which mapped columns would be null.
|
String |
toLoggableString(Object value,
SessionFactoryImplementor factory)
Generate a representation of the value for logging purposes.
|
String |
toString(T value)
Render the value to the string representation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName, nullSafeSet, resolve
public AbstractStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor)
public String toString(T value)
StringRepresentableType
Render the value to the string representation.
toString
in interface StringRepresentableType<T>
value
- The value to render to string.public T fromStringValue(String xml) throws HibernateException
StringRepresentableType
Consume the given string representation back into this types java form.
fromStringValue
in interface StringRepresentableType<T>
xml
- The string representation to be consumed.HibernateException
- Problem consumingprotected MutabilityPlan<T> getMutabilityPlan()
protected T getReplacement(T original, T target, SharedSessionContractImplementor session)
public boolean[] toColumnNullness(Object value, Mapping mapping)
Type
Given an instance of the type, return an array of boolean, indicating which mapped columns would be null.
toColumnNullness
in interface Type
value
- an instance of the typemapping
- The mapping abstractionpublic String[] getRegistrationKeys()
BasicType
Get the names under which this type should be registered in the type registry.
getRegistrationKeys
in interface BasicType
protected boolean registerUnderJavaType()
protected static Size getDefaultSize()
protected Size getDictatedSize()
public final JavaTypeDescriptor<T> getJavaTypeDescriptor()
public final void setJavaTypeDescriptor(JavaTypeDescriptor<T> javaTypeDescriptor)
public final SqlTypeDescriptor getSqlTypeDescriptor()
public final void setSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor)
public final Class getReturnedClass()
Type
The class returned by Type.nullSafeGet(java.sql.ResultSet, java.lang.String[], org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)
methods. This is used to establish the class of an array of
this type.
getReturnedClass
in interface Type
public final int getColumnSpan(Mapping mapping) throws MappingException
Type
How many columns are used to persist this type. Always the same as sqlTypes(mapping).length
getColumnSpan
in interface Type
mapping
- The mapping object :/MappingException
- Generally indicates an issue accessing the passed mapping object.public final int[] sqlTypes(Mapping mapping) throws MappingException
Type
Return the JDBC types codes (per Types
) for the columns mapped by this type.
<p/>
NOTE: The number of elements in this array matches the return from Type.getColumnSpan(org.hibernate.engine.spi.Mapping)
.
sqlTypes
in interface Type
mapping
- The mapping object :/MappingException
- Generally indicates an issue accessing the passed mapping object.public Size[] dictatedSizes(Mapping mapping) throws MappingException
Type
Return the column sizes dictated by this type. For example, the mapping for a char
/Character
would
have a dictated length limit of 1; for a string-based UUID
would have a size limit of 36; etc.
<p/>
NOTE: The number of elements in this array matches the return from Type.getColumnSpan(org.hibernate.engine.spi.Mapping)
.
dictatedSizes
in interface Type
mapping
- The mapping object :/MappingException
- Generally indicates an issue accessing the passed mapping object.public Size[] defaultSizes(Mapping mapping) throws MappingException
Type
Defines the column sizes to use according to this type if the user did not explicitly say (and if no
Type.dictatedSizes(org.hibernate.engine.spi.Mapping)
were given).
<p/>
NOTE: The number of elements in this array matches the return from Type.getColumnSpan(org.hibernate.engine.spi.Mapping)
.
defaultSizes
in interface Type
mapping
- The mapping object :/MappingException
- Generally indicates an issue accessing the passed mapping object.public final boolean isAssociationType()
Type
Return true if the implementation is castable to AssociationType
. This does not necessarily imply that
the type actually represents an association. Essentially a polymorphic version of
(type instanceof AssociationType.class)
isAssociationType
in interface Type
AssociationType
implementor; false otherwise.public final boolean isCollectionType()
Type
Return true if the implementation is castable to CollectionType
. Essentially a polymorphic version of
(type instanceof CollectionType.class)
<p/>
A CollectionType
is additionally an AssociationType
; so if this method returns true,
Type.isAssociationType()
should also return true.
isCollectionType
in interface Type
CollectionType
implementor; false otherwise.public final boolean isComponentType()
Type
Return true if the implementation is castable to CompositeType
. Essentially a polymorphic
version of (type instanceof CompositeType.class)
. A component type may own collections or
associations and hence must provide certain extra functionality.
isComponentType
in interface Type
CompositeType
implementor; false otherwise.public final boolean isEntityType()
Type
Return true if the implementation is castable to EntityType
. Essentially a polymorphic
version of (type instanceof EntityType.class)
.
<p/>
An EntityType
is additionally an AssociationType
; so if this method returns true,
Type.isAssociationType()
should also return true.
isEntityType
in interface Type
EntityType
implementor; false otherwise.public final boolean isAnyType()
Type
Return true if the implementation is castable to AnyType
. Essentially a polymorphic
version of (type instanceof AnyType.class)
.
<p/>
An AnyType
is additionally an AssociationType
; so if this method returns true,
Type.isAssociationType()
should also return true.
public final boolean isXMLElement()
public final boolean isSame(Object x, Object y)
Type
Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
state) taking a shortcut for entity references.
<p/>
For most types this should equate to an equals
check on the values. For associations
the implication is a bit different. For most types it is conceivable to simply delegate to Type.isEqual(java.lang.Object, java.lang.Object)
public final boolean isEqual(Object x, Object y, SessionFactoryImplementor factory)
Type
Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent state). <p/> This should always equate to some form of comparison of the value’s internal state. As an example, for something like a date the comparison should be based on its internal "time" state based on the specific portion it is meant to represent (timestamp, date, time).
public final boolean isEqual(Object one, Object another)
Type
Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent state). <p/> This should always equate to some form of comparison of the value’s internal state. As an example, for something like a date the comparison should be based on its internal "time" state based on the specific portion it is meant to represent (timestamp, date, time).
public final int getHashCode(Object x)
Type
Get a hash code, consistent with persistence "equality". Again for most types the normal usage is to
delegate to the value’s hashCode
.
getHashCode
in interface Type
x
- The value for which to retrieve a hash codepublic final int getHashCode(Object x, SessionFactoryImplementor factory)
Type
Get a hash code, consistent with persistence "equality". Again for most types the normal usage is to
delegate to the value’s hashCode
.
getHashCode
in interface Type
x
- The value for which to retrieve a hash codefactory
- The session factorypublic final int compare(Object x, Object y)
Type
Perform a Comparator
style comparison between values
compare
in interface Type
x
- The first valuey
- The second valueComparator.compare(T, T)
for a discussion.public final boolean isDirty(Object old, Object current, SharedSessionContractImplementor session)
Type
Should the parent be considered dirty, given both the old and current value?
public final boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session)
Type
Should the parent be considered dirty, given both the old and current value?
public final boolean isModified(Object oldHydratedState, Object currentState, boolean[] checkable, SharedSessionContractImplementor session)
Type
Has the value been modified compared to the current database state? The difference between this
and the Type.isDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor)
methods is that here we need to account for "partially" built values. This is really
only an issue with association types. For most type implementations it is enough to simply delegate to
Type.isDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor)
here/
isModified
in interface Type
oldHydratedState
- the database state, in a "hydrated" form, with identifiers unresolvedcurrentState
- the current state of the objectcheckable
- which columns are actually updatablesession
- The session from which the request originated.public final Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws SQLException
Type
Extract a value of the mapped class
from the JDBC result set. Implementors
should handle possibility of null values.
nullSafeGet
in interface Type
rs
- The result set from which to extract value.names
- the column names making up this type value (use to read from result set)session
- The originating sessionowner
- the parent entitySQLException
- An error from the JDBC driveralternative, 2-phase property initialization
public final Object nullSafeGet(ResultSet rs, String name, SharedSessionContractImplementor session, Object owner) throws SQLException
Type
Extract a value of the mapped class
from the JDBC result set. Implementors
should handle possibility of null values. This form might be called if the type is known to be a
single-column type.
nullSafeGet
in interface Type
rs
- The result set from which to extract value.name
- the column name making up this type value (use to read from result set)session
- The originating sessionowner
- the parent entitySQLException
- An error from the JDBC driverpublic final T nullSafeGet(ResultSet rs, String name, SharedSessionContractImplementor session) throws SQLException
SQLException
protected final T nullSafeGet(ResultSet rs, String name, WrapperOptions options) throws SQLException
SQLException
public Object get(ResultSet rs, String name, SharedSessionContractImplementor session) throws HibernateException, SQLException
HibernateException
SQLException
public final void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws SQLException
Type
Bind a value represented by an instance of the mapped class
to the JDBC prepared
statement. Implementors should handle possibility of null values. A multi-column type should bind parameters
starting from <tt>index</tt>.
nullSafeSet
in interface Type
st
- The JDBC prepared statement to which to bindvalue
- the object to writeindex
- starting parameter bind indexsession
- The originating sessionSQLException
- An error from the JDBC driverprotected final void nullSafeSet(PreparedStatement st, Object value, int index, WrapperOptions options) throws SQLException
SQLException
protected SqlTypeDescriptor remapSqlTypeDescriptor(WrapperOptions options)
public void set(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException
HibernateException
SQLException
public final String toLoggableString(Object value, SessionFactoryImplementor factory)
Type
Generate a representation of the value for logging purposes.
toLoggableString
in interface Type
value
- The value to be loggedfactory
- The session factorypublic final boolean isMutable()
Type
Are objects of this type mutable. (With respect to the referencing object … entities and collections are considered immutable because they manage their own internal state.)
public final Object deepCopy(Object value, SessionFactoryImplementor factory)
Type
Return a deep copy of the persistent state, stopping at entities and at collections.
public final Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException
Type
Return a disassembled representation of the object. This is the value Hibernate will use in second level caching, so care should be taken to break values down to their simplest forms; for entities especially, this means breaking them down into their constituent parts.
disassemble
in interface Type
value
- the value to cachesession
- the originating sessionowner
- optional parent entity object (needed for collections)HibernateException
- An error from Hibernatepublic final Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException
Type
Reconstruct the object from its disassembled state. This method is the reciprocal of Type.disassemble(java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)
assemble
in interface Type
cached
- the disassembled state from the cachesession
- the originating sessionowner
- the parent entity objectHibernateException
- An error from Hibernatepublic final void beforeAssemble(Serializable cached, SharedSessionContractImplementor session)
Type
Called before assembling a query result set from the query cache, to allow batch fetching of entities missing from the second-level cache.
beforeAssemble
in interface Type
cached
- The keysession
- The originating sessionpublic final Object hydrate(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException
Type
Extract a value from the JDBC result set. This is useful for 2-phase property initialization - the second
phase is a call to Type.resolve(java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)
This hydrated value will be either:<ul>
<li>in the case of an entity or collection type, the key</li>
<li>otherwise, the value itself</li>
</ul>
hydrate
in interface Type
rs
- The JDBC result setnames
- the column names making up this type value (use to read from result set)session
- The originating sessionowner
- the parent entityHibernateException
- An error from HibernateSQLException
- An error from the JDBC driverType.resolve(java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)
public final Object resolve(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException
resolve
in interface Type
HibernateException
Type.resolve(Object, SharedSessionContractImplementor, Object, Boolean)
public final Object semiResolve(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException
Type
Given a hydrated, but unresolved value, return a value that may be used to reconstruct property-ref associations.
semiResolve
in interface Type
value
- The unresolved, hydrated valuesession
- THe originating sessionowner
- The value ownerHibernateException
- An error from Hibernatepublic final Type getSemiResolvedType(SessionFactoryImplementor factory)
Type
As part of 2-phase loading, when we perform resolving what is the resolved type for this type? Generally speaking the type and its semi-resolved type will be the same. The main deviation from this is in the case of an entity where the type would be the entity type and semi-resolved type would be its identifier type
getSemiResolvedType
in interface Type
factory
- The session factorypublic final Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map copyCache)
Type
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.
replace
in interface Type
original
- the value from the detached entity being mergedtarget
- the value in the managed entitysession
- The originating sessionowner
- The owner of the valuecopyCache
- The cache of already copied/replaced valuespublic Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map copyCache, ForeignKeyDirection foreignKeyDirection)
Type
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.
replace
in interface Type
original
- the value from the detached entity being mergedtarget
- the value in the managed entitysession
- The originating sessionowner
- The owner of the valuecopyCache
- The cache of already copied/replaced valuesforeignKeyDirection
- For associations, which direction does the foreign key point?public boolean canDoExtraction()
ProcedureParameterExtractionAware
Can the given instance of this type actually perform the parameter value extractions?
canDoExtraction
in interface ProcedureParameterExtractionAware<T>
true
indicates that @{link #extract} calls will not fail due to IllegalStateException
.public T extract(CallableStatement statement, int startIndex, SharedSessionContractImplementor session) throws SQLException
ProcedureParameterExtractionAware
Perform the extraction
extract
in interface ProcedureParameterExtractionAware<T>
statement
- The CallableStatement from which to extract the parameter value(s).startIndex
- The parameter index from which to start extracting; assumes the values (if multiple) are contiguoussession
- The originating sessionSQLException
- Indicates an issue calling into the CallableStatementpublic T extract(CallableStatement statement, String[] paramNames, SharedSessionContractImplementor session) throws SQLException
ProcedureParameterExtractionAware
Perform the extraction
extract
in interface ProcedureParameterExtractionAware<T>
statement
- The CallableStatement from which to extract the parameter value(s).paramNames
- The parameter names.session
- The originating sessionSQLException
- Indicates an issue calling into the CallableStatementpublic void nullSafeSet(CallableStatement st, Object value, String name, SharedSessionContractImplementor session) throws SQLException
ProcedureParameterNamedBinder
Bind a value to the JDBC prepared statement, ignoring some columns as dictated by the 'settable' parameter. Implementors should handle the possibility of null values. Does not support multi-column type
nullSafeSet
in interface ProcedureParameterNamedBinder
st
- The CallableStatement to which to bindvalue
- the object to writename
- parameter bind namesession
- The originating sessionSQLException
- An error from the JDBC driverprotected final void nullSafeSet(CallableStatement st, Object value, String name, WrapperOptions options) throws SQLException
SQLException
public boolean canDoSetting()
ProcedureParameterNamedBinder
Can the given instance of this type actually set the parameter value by name
canDoSetting
in interface ProcedureParameterNamedBinder
true
indicates that @{link #nullSafeSet} calls will not failCopyright © 2001-2018 Red Hat, Inc. All Rights Reserved.