Class CustomType<J>
- All Implemented Interfaces:
BasicType<J>,Type<J>,Serializable,BasicValuedMapping,Bindable,JdbcMapping,JdbcMappingContainer,MappingModelExpressible,MappingType,SqlExpressible,ValueMapping,BasicDomainType<J>,DomainType<J>,ReturnableType<J>,SimpleDomainType<J>,SqmBindableType<J>,SqmExpressible<J>,SqmDomainType<J>,BasicType<J>,BindableType<J>,ConvertedBasicType<J>,JavaTypedExpressible,OutputableType<J>,ProcedureParameterExtractionAware<J>,ProcedureParameterNamedBinder<J>,Type
UserType to the genericType interface, in order to isolate user code from changes in the internal Type contracts.- See Also:
- API Note:
- Many of the interfaces implemented here are implemented just to handle the case of the wrapped type implementing them so we can pass them along.
Nested Class Summary
Nested classes/interfaces inherited from interface org.hibernate.metamodel.mapping.Bindable
Bindable.JdbcValuesBiConsumer<X,Y>,Bindable.JdbcValuesConsumer Nested classes/interfaces inherited from interface jakarta.persistence.metamodel.Type
Type.PersistenceTypeConstructor Summary
ConstructorsConstructorDescriptionCustomType(UserType<J> userType,String[] registrationKeys,TypeConfiguration typeConfiguration) CustomType(UserType<J> userType,TypeConfiguration typeConfiguration) Method Summary
Modifier and TypeMethodDescriptionvoidaddToCacheKey(MutableCacheKeyBuilder cacheKey,Object value,SharedSessionContractImplementor session) Add to the MutableCacheKey the values obtained disassembling the value and the hasCode generated from the disassembled value.assemble(Serializable cached,SharedSessionContractImplementor session,Object owner) Reconstruct the object from its disassembled state.booleanCan the given instance of this type actually perform the parameter value extractions?booleanCan the given instance of this type actually set the parameter value by namedeepCopy(Object value,SessionFactoryImplementor factory) Return a deep copy of the persistent state, stopping at entities and at collections.disassemble(Object value,SessionFactoryImplementor sessionFactory) Return a disassembled representation of the object.disassemble(Object value,SharedSessionContractImplementor session) Breaks down a value ofJinto its simple pieces.disassemble(Object value,SharedSessionContractImplementor session,Object owner) Return a disassembled representation of the object.booleanextract(CallableStatement statement, int startIndex,SharedSessionContractImplementor session) Perform the extractionextract(CallableStatement statement,String paramName,SharedSessionContractImplementor session) Perform the extractionintgetColumnSpan(MappingContext session) How many columns are used to persist this type?TheJavaTyperepresenting this domain type.intGet a hash code, consistent with persistence "equality".The Java class which represents by this domain type.The descriptor for the Java type represented by this expressible typeJavaType<?>The strategy for formatting values of this expressible type to a SQL literal.Descriptor for the SQL type mapped by this type.The strategy for binding values of this expressible type to JDBCPreparedStatements andCallableStatements.The strategy for extracting values of this expressible type from JDBC ResultSets, CallableStatements, etcThedescriptor descriptor for the mapped Java typegetName()Returns the abbreviated name of the type.String[]Get the names under which this type should be registered in the type registry.The class handled by this type.int[]getSqlTypeCodes(MappingContext mappingContext) Returns the converter that this basic type uses for transforming from the domain type, to the relational type, ornullif there is no conversion.inthashCode()booleanisDirty(Object old,Object current, boolean[] checkable,SharedSessionContractImplementor session) Should the parent be considered dirty, given both the old and current value?booleanCompare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state.booleanAre objects of this type mutable with respect to the referencing object? Entities and collections are considered immutable because they manage their own internal state.voidnullSafeSet(CallableStatement statement,J value,String name,SharedSessionContractImplementor session) Bind a value to the JDBC prepared statement, ignoring some columns as dictated by the 'settable' parameter.voidnullSafeSet(PreparedStatement st,Object value, int index, boolean[] settable,SharedSessionContractImplementor session) Bind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter.voidnullSafeSet(PreparedStatement st,Object value, int index,SharedSessionContractImplementor session) Bind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter.replace(Object original,Object target,SharedSessionContractImplementor session,Object owner,Map<Object, Object> 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.boolean[]toColumnNullness(Object value,MappingContext mapping) Given an instance of the type, return an array ofbooleanvalues indicating which mapped columns would be null.toLoggableString(Object value,SessionFactoryImplementor factory) Generate a representation of the given value for logging purposes.Methods inherited from class org.hibernate.type.AbstractType
beforeAssemble,compare,getHashCode,isAnyType,isAssociationType,isCollectionType,isComponentType,isDirty,isEntityType,isEqual,isModified,isSame,replaceMethods inherited from class java.lang.Object
clone,finalize,getClass,notify,notifyAll,toString,wait,wait,waitMethods inherited from interface org.hibernate.metamodel.model.domain.BasicDomainType
getPersistenceTypeMethods inherited from interface org.hibernate.type.BasicType
compare,forEachDisassembledJdbcValue,forEachJdbcType,forEachJdbcType,getCheckCondition,getJdbcMapping,getJdbcMapping,getJdbcTypeCount,getMappedType,getSingleJdbcMapping,getSqmTypeMethods inherited from interface org.hibernate.metamodel.mapping.Bindable
forEachDisassembledJdbcValue,forEachDisassembledJdbcValue,forEachDisassembledJdbcValue,forEachJdbcValue,forEachJdbcValue,forEachJdbcValue,forEachJdbcValueMethods inherited from interface org.hibernate.metamodel.mapping.JdbcMapping
convertToDomainValue,convertToRelationalValue,getCastTypeMethods inherited from interface org.hibernate.query.sqm.SqmBindableType
resolveExpressibleMethods inherited from interface org.hibernate.query.sqm.tree.domain.SqmDomainType
getTupleLength,getTypeNameMethods inherited from interface org.hibernate.query.sqm.SqmExpressible
getRelationalJavaTypeMethods inherited from interface org.hibernate.type.Type
beforeAssemble,compare,getHashCode,getReturnedClassName,getTypeForEqualsHashCode,isAnyType,isAssociationType,isCollectionType,isComponentType,isDirty,isEntityType,isEqual,isModified,isSame,replaceMethods inherited from interface org.hibernate.metamodel.mapping.ValueMapping
treatAs
Constructor Details
CustomType
- Throws:
MappingException
CustomType
public CustomType(UserType<J> userType,String[] registrationKeys,TypeConfiguration typeConfiguration)
Method Details
getUserType
getJdbcValueExtractor
Description copied from interface:JdbcMappingThe strategy for extracting values of this expressible type from JDBC ResultSets, CallableStatements, etc- Specified by:
getJdbcValueExtractorin interfaceBasicType<J>- Specified by:
getJdbcValueExtractorin interfaceJdbcMapping
getJdbcValueBinder
Description copied from interface:JdbcMappingThe strategy for binding values of this expressible type to JDBCPreparedStatements andCallableStatements.- Specified by:
getJdbcValueBinderin interfaceBasicType<J>- Specified by:
getJdbcValueBinderin interfaceJdbcMapping
getJdbcLiteralFormatter
Description copied from interface:JdbcMappingThe strategy for formatting values of this expressible type to a SQL literal.- Specified by:
getJdbcLiteralFormatterin interfaceBasicType<J>- Specified by:
getJdbcLiteralFormatterin interfaceJdbcMapping
getJdbcType
Description copied from interface:OutputableTypeDescriptor for the SQL type mapped by this type.- Specified by:
getJdbcTypein interfaceJdbcMapping- Specified by:
getJdbcTypein interfaceOutputableType<J>
getSqlTypeCodes
Description copied from interface:TypeReturn the JDBC types codes as defined byTypesorSqlTypesfor the columns mapped by this type.The number of elements in this array must match the return from
Type.getColumnSpan(org.hibernate.type.MappingContext).- Specified by:
getSqlTypeCodesin interfaceType- Parameters:
mappingContext- The mapping contextMappingContext:/- Returns:
- The JDBC type codes.
getRegistrationKeys
Description copied from interface:BasicTypeGet the names under which this type should be registered in the type registry.- Specified by:
getRegistrationKeysin interfaceBasicType<J>- Returns:
- The keys under which to register this type.
getColumnSpan
Description copied from interface:TypeHow many columns are used to persist this type?Always the same as
getSqlTypCodes(mappingContext).length.- Specified by:
getColumnSpanin interfaceType- Parameters:
session- The mapping Context objectMappingContext- Returns:
- The number of columns
getReturnedClass
Description copied from interface:TypeThe class handled by this type.- Specified by:
getReturnedClassin interfaceType- Returns:
- The Java class handled by this type.
isEqual
Description copied from interface:TypeCompare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state. For most types this could simply delegate toequals().This should always equate to some form of comparison of the value's internal state. As an example, for Java's
Dateclass, the comparison should be of its internal state, but based only on the specific part which is persistent (the timestamp, date, or time).- Specified by:
isEqualin interfaceType- Overrides:
isEqualin classAbstractType- Parameters:
x- The first valuey- The second value- Returns:
- True if there are considered equal (see discussion above).
- Throws:
HibernateException- A problem occurred performing the comparison
getHashCode
Description copied from interface:TypeGet a hash code, consistent with persistence "equality". For most types this could simply delegate to the given value'shashCode.- Specified by:
getHashCodein interfaceType- Overrides:
getHashCodein classAbstractType- Parameters:
x- The value for which to retrieve a hash code- Returns:
- The hash code
assemble
Description copied from interface:TypeReconstruct the object from its disassembled state. This function is the inverse ofType.disassemble(Object, SharedSessionContractImplementor, Object).- Specified by:
assemblein interfaceType- Overrides:
assemblein classAbstractType- Parameters:
cached- the disassembled state from the cachesession- the originating sessionowner- the parent entity object- Returns:
- the (re)assembled object
disassemble
Description copied from interface:TypeReturn a disassembled representation of the object. This is the representation that is stored in the second-level cache.A reference to an associated entity should be disassembled to its primary key value.
- Specified by:
disassemblein interfaceType- Overrides:
disassemblein classAbstractType- Parameters:
value- the value to cachesession- the originating sessionowner- optional parent entity object (needed for collections)- Returns:
- the disassembled, deep cloned state
disassemble
Description copied from interface:TypeReturn a disassembled representation of the object. This is the representation that is stored in the second-level cache.A reference to an associated entity should be disassembled to its primary key value.
A high-quality implementation of this method should ensure that:
Objects.equals(disassemble(x,s), disassemble(y,s))== isEqual(x,y,sf)and that:
Objects.equals(x, assemble(disassemble(x,s),s,o))That is, the implementation must be consistent with
Type.isEqual(Object, Object, SessionFactoryImplementor)and withType.assemble(Serializable, SharedSessionContractImplementor, Object).- Specified by:
disassemblein interfaceType- Overrides:
disassemblein classAbstractType- Parameters:
value- the value to cachesessionFactory- the session factory- Returns:
- the disassembled, deep cloned state
disassemble
Description copied from interface:BindableBreaks down a value ofJinto its simple pieces. E.g., an embedded value gets broken down into an array of its attribute state; a basic value converts to itself; etc.Generally speaking, this is the form in which entity state is kept relative to a Session via
EntityEntry.@Entity class Person { @Id Integer id; @Embedded Name name; int age; } @Embeddable class Name { String familiarName; String familyName; }At the top level, we would want to disassemble a
Personvalue, so we'd ask theBindablefor thePersonentity to disassemble. Given aPersonvalue:Person( id=1, name=Name( 'Steve', 'Ebersole' ), 28 )
this disassemble would result in a multidimensional array:
[ ["Steve", "Ebersole"], 28 ]
Note that the identifier is not part of this disassembled state. Note also how the embedded value results in a sub-array.
- Specified by:
disassemblein interfaceBasicType<J>- Specified by:
disassemblein interfaceBasicValuedMapping- Specified by:
disassemblein interfaceBindable- See Also:
addToCacheKey
public void addToCacheKey(MutableCacheKeyBuilder cacheKey,Object value,SharedSessionContractImplementor session) Description copied from interface:BindableAdd to the MutableCacheKey the values obtained disassembling the value and the hasCode generated from the disassembled value.- Specified by:
addToCacheKeyin interfaceBasicValuedMapping- Specified by:
addToCacheKeyin interfaceBindable- Specified by:
addToCacheKeyin interfaceJavaTypedExpressible<J>- Parameters:
cacheKey- the MutableCacheKey used to add the disassembled value and the hashCodevalue- the value to disassemblesession- the SharedSessionContractImplementor
replace
public Object replace(Object original,Object target,SharedSessionContractImplementor session,Object owner,Map<Object, Object> copyCache) Description copied from interface:TypeDuring 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.nullSafeSet
public void nullSafeSet(PreparedStatement st,Object value, int index, boolean[] settable,SharedSessionContractImplementor session) throwsSQLException Description copied from interface:TypeBind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter. Implementors should handle the possibility of null values. A multi-column type should bind parameters starting fromindex.- Specified by:
nullSafeSetin interfaceType- Parameters:
st- The JDBC prepared statement to which to bindvalue- the object to writeindex- starting parameter bind indexsettable- an array indicating which columns to bind/ignoresession- The originating session- Throws:
SQLException- An error from the JDBC driver
nullSafeSet
public void nullSafeSet(PreparedStatement st,Object value, int index,SharedSessionContractImplementor session) throwsSQLException Description copied from interface:TypeBind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter. Implementors should handle the possibility of null values. A multi-column type should bind parameters starting fromindex.- Specified by:
nullSafeSetin interfaceType- Parameters:
st- The JDBC prepared statement to which to bindvalue- the object to writeindex- starting parameter bind indexsession- The originating session- Throws:
SQLException- An error from the JDBC driver
getName
Description copied from interface:TypeReturns the abbreviated name of the type.deepCopy
Description copied from interface:TypeReturn a deep copy of the persistent state, stopping at entities and at collections.- Specified by:
deepCopyin interfaceType- Parameters:
value- The value to be copiedfactory- The session factory- Returns:
- The deep copy
- Throws:
HibernateException- An error from Hibernate
isMutable
public boolean isMutable()Description copied from interface:TypeAre objects of this type mutable with respect to the referencing object? Entities and collections are considered immutable because they manage their own internal state.toLoggableString
Description copied from interface:TypeGenerate a representation of the given value for logging purposes.- Specified by:
toLoggableStringin interfaceType- Parameters:
value- The value to be loggedfactory- The session factory- Returns:
- The loggable representation
toColumnNullness
Description copied from interface:TypeGiven an instance of the type, return an array ofbooleanvalues indicating which mapped columns would be null.- Specified by:
toColumnNullnessin interfaceType- Parameters:
value- an instance of the typemapping- The mapping contextMappingContext- Returns:
- array indicating column nullness for a value instance
isDirty
public boolean isDirty(Object old,Object current, boolean[] checkable,SharedSessionContractImplementor session) throwsHibernateException Description copied from interface:TypeShould the parent be considered dirty, given both the old and current value?- Specified by:
isDirtyin interfaceType- Parameters:
old- the old valuecurrent- the current valuecheckable- An array of booleans indicating which columns making up the value are actually checkablesession- The session from which the request originated.- Returns:
- true if the field is dirty
- Throws:
HibernateException- A problem occurred performing the checking
canDoSetting
public boolean canDoSetting()Description copied from interface:ProcedureParameterNamedBinderCan the given instance of this type actually set the parameter value by name- Specified by:
canDoSettingin interfaceProcedureParameterNamedBinder<J>- Returns:
trueindicates that @{link #nullSafeSet} calls will not fail
nullSafeSet
public void nullSafeSet(CallableStatement statement,J value,String name,SharedSessionContractImplementor session) throwsSQLException Description copied from interface:ProcedureParameterNamedBinderBind 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- Specified by:
nullSafeSetin interfaceProcedureParameterNamedBinder<J>- Parameters:
statement- The CallableStatement to which to bindvalue- the object to writename- parameter bind namesession- The originating session- Throws:
SQLException- An error from the JDBC driver
canDoExtraction
public boolean canDoExtraction()Description copied from interface:OutputableTypeCan the given instance of this type actually perform the parameter value extractions?- Specified by:
canDoExtractionin interfaceOutputableType<J>- Returns:
trueindicates thatOutputableType.extract(java.sql.CallableStatement, int, org.hibernate.engine.spi.SharedSessionContractImplementor)calls will not fail due toIllegalStateException.
extract
public J extract(CallableStatement statement, int startIndex,SharedSessionContractImplementor session) throwsSQLException Description copied from interface:OutputableTypePerform the extraction- Specified by:
extractin interfaceOutputableType<J>- Parameters:
statement- The CallableStatement from which to extract the parameter value(s).startIndex- The parameter index from which to extractsession- The originating session- Returns:
- The extracted value.
- Throws:
SQLException- Indicates an issue calling into the CallableStatement
extract
public J extract(CallableStatement statement,String paramName,SharedSessionContractImplementor session) throwsSQLException Description copied from interface:OutputableTypePerform the extraction- Specified by:
extractin interfaceOutputableType<J>- Parameters:
statement- The CallableStatement from which to extract the parameter value(s).paramName- The parameter names.session- The originating session- Returns:
- The extracted value.
- Throws:
SQLException- Indicates an issue calling into the CallableStatement
hashCode
public int hashCode()equals
getJavaType
Description copied from interface:DomainTypeThe Java class which represents by this domain type.- Specified by:
getJavaTypein interfaceBasicDomainType<J>- Specified by:
getJavaTypein interfaceBasicType<J>- Specified by:
getJavaTypein interfaceDomainType<J>- Specified by:
getJavaTypein interfaceSimpleDomainType<J>- Specified by:
getJavaTypein interfaceType<J>- See Also:
getMappedJavaType
Description copied from interface:MappingTypeThedescriptor descriptor for the mapped Java type- Specified by:
getMappedJavaTypein interfaceBasicType<J>- Specified by:
getMappedJavaTypein interfaceJdbcMapping- Specified by:
getMappedJavaTypein interfaceMappingType
getExpressibleJavaType
Description copied from interface:DomainTypeTheJavaTyperepresenting this domain type.- Specified by:
getExpressibleJavaTypein interfaceBasicType<J>- Specified by:
getExpressibleJavaTypein interfaceDomainType<J>- Specified by:
getExpressibleJavaTypein interfaceJavaTypedExpressible<J>- Specified by:
getExpressibleJavaTypein interfaceSqmExpressible<J>- Specified by:
getExpressibleJavaTypein interfaceValueMapping
getJavaTypeDescriptor
Description copied from interface:JdbcMappingThe descriptor for the Java type represented by this expressible type- Specified by:
getJavaTypeDescriptorin interfaceBasicType<J>- Specified by:
getJavaTypeDescriptorin interfaceJdbcMapping
getJdbcJavaType
- Specified by:
getJdbcJavaTypein interfaceJdbcMapping
getValueConverter
Description copied from interface:JdbcMappingReturns the converter that this basic type uses for transforming from the domain type, to the relational type, ornullif there is no conversion.- Specified by:
getValueConverterin interfaceBasicType<J>- Specified by:
getValueConverterin interfaceConvertedBasicType<J>- Specified by:
getValueConverterin interfaceJdbcMapping