Package com.vladmihalcea.hibernate.type
Class ImmutableType<T>
- java.lang.Object
-
- com.vladmihalcea.hibernate.type.ImmutableType<T>
-
- All Implemented Interfaces:
java.io.Serializable
,org.hibernate.type.Type
,org.hibernate.usertype.UserType
- Direct Known Subclasses:
NullableCharacterType
,OracleIntervalDayToSecondType
,PostgreSQLCITextType
,PostgreSQLGuavaRangeType
,PostgreSQLHStoreType
,PostgreSQLInetType
,PostgreSQLIntervalType
,PostgreSQLPeriodType
,PostgreSQLRangeType
public abstract class ImmutableType<T> extends java.lang.Object implements org.hibernate.usertype.UserType, org.hibernate.type.Type
Very convenient base class for implementing immutable object types using HibernateUserType
.The
ImmutableType
implements theType
interface too, so you can pass all types extending theImmutableType
to theNativeQuery.addScalar(String, Type)
method to fix the No Dialect mapping for JDBC type issues.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<T>
clazz
private Configuration
configuration
-
Constructor Summary
Constructors Modifier Constructor Description protected
ImmutableType(java.lang.Class<T> clazz)
Initialization constructor taking theClass
and using the defaultConfiguration
object.protected
ImmutableType(java.lang.Class<T> clazz, Configuration configuration)
Initialization constructor taking theClass
andConfiguration
objects.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Object
assemble(java.io.Serializable cached, java.lang.Object owner)
java.lang.Object
assemble(java.io.Serializable cached, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
void
beforeAssemble(java.io.Serializable cached, org.hibernate.engine.spi.SharedSessionContractImplementor session)
int
compare(java.lang.Object x, java.lang.Object y)
java.lang.Object
deepCopy(java.lang.Object value)
java.lang.Object
deepCopy(java.lang.Object value, org.hibernate.engine.spi.SessionFactoryImplementor factory)
org.hibernate.engine.jdbc.Size[]
defaultSizes(org.hibernate.engine.spi.Mapping mapping)
org.hibernate.engine.jdbc.Size[]
dictatedSizes(org.hibernate.engine.spi.Mapping mapping)
java.io.Serializable
disassemble(java.lang.Object o)
java.io.Serializable
disassemble(java.lang.Object value, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
boolean
equals(java.lang.Object x, java.lang.Object y)
protected abstract T
get(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
Get the column value from the JDBCResultSet
.int
getColumnSpan(org.hibernate.engine.spi.Mapping mapping)
protected Configuration
getConfiguration()
Get the currentConfiguration
object.int
getHashCode(java.lang.Object x)
int
getHashCode(java.lang.Object x, org.hibernate.engine.spi.SessionFactoryImplementor factory)
java.lang.String
getName()
java.lang.Class
getReturnedClass()
org.hibernate.type.Type
getSemiResolvedType(org.hibernate.engine.spi.SessionFactoryImplementor factory)
int
hashCode(java.lang.Object x)
java.lang.Object
hydrate(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
boolean
isAnyType()
boolean
isAssociationType()
boolean
isCollectionType()
boolean
isComponentType()
protected boolean
isDirty(java.lang.Object old, java.lang.Object current)
boolean
isDirty(java.lang.Object old, java.lang.Object current, boolean[] checkable, org.hibernate.engine.spi.SharedSessionContractImplementor session)
boolean
isDirty(java.lang.Object old, java.lang.Object current, org.hibernate.engine.spi.SharedSessionContractImplementor session)
boolean
isEntityType()
boolean
isEqual(java.lang.Object x, java.lang.Object y)
boolean
isEqual(java.lang.Object x, java.lang.Object y, org.hibernate.engine.spi.SessionFactoryImplementor factory)
boolean
isModified(java.lang.Object dbState, java.lang.Object currentState, boolean[] checkable, org.hibernate.engine.spi.SharedSessionContractImplementor session)
boolean
isMutable()
boolean
isSame(java.lang.Object x, java.lang.Object y)
java.lang.Object
nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
java.lang.Object
nullSafeGet(java.sql.ResultSet rs, java.lang.String name, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
void
nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, org.hibernate.engine.spi.SharedSessionContractImplementor session)
void
nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session)
java.lang.Object
replace(java.lang.Object o, java.lang.Object target, java.lang.Object owner)
java.lang.Object
replace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner, java.util.Map copyCache)
java.lang.Object
replace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner, java.util.Map copyCache, org.hibernate.type.ForeignKeyDirection foreignKeyDirection)
java.lang.Object
resolve(java.lang.Object value, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
java.lang.Class<T>
returnedClass()
java.lang.Object
semiResolve(java.lang.Object value, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner)
protected abstract void
set(java.sql.PreparedStatement st, T value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session)
Set the column value on the provided JDBCPreparedStatement
.int[]
sqlTypes(org.hibernate.engine.spi.Mapping mapping)
boolean[]
toColumnNullness(java.lang.Object value, org.hibernate.engine.spi.Mapping mapping)
java.lang.String
toLoggableString(java.lang.Object value, org.hibernate.engine.spi.SessionFactoryImplementor factory)
-
-
-
Field Detail
-
configuration
private final Configuration configuration
-
clazz
private final java.lang.Class<T> clazz
-
-
Constructor Detail
-
ImmutableType
protected ImmutableType(java.lang.Class<T> clazz)
Initialization constructor taking theClass
and using the defaultConfiguration
object.- Parameters:
clazz
- the entity attributeClass
type to be handled
-
ImmutableType
protected ImmutableType(java.lang.Class<T> clazz, Configuration configuration)
Initialization constructor taking theClass
andConfiguration
objects.- Parameters:
clazz
- the entity attributeClass
type to be handledconfiguration
- customConfiguration
object.
-
-
Method Detail
-
getConfiguration
protected Configuration getConfiguration()
Get the currentConfiguration
object.- Returns:
- the current
Configuration
object.
-
get
protected abstract T get(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws java.sql.SQLException
Get the column value from the JDBCResultSet
.- Parameters:
rs
- JDBCResultSet
names
- database column namesession
- current HibernateSession
owner
- current HibernateSessionFactoryImplementor
- Returns:
- column value
- Throws:
java.sql.SQLException
- in case of failure
-
set
protected abstract void set(java.sql.PreparedStatement st, T value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws java.sql.SQLException
Set the column value on the provided JDBCPreparedStatement
.- Parameters:
st
- JDBCPreparedStatement
value
- database column valueindex
- database column indexsession
- current HibernateSession
- Throws:
java.sql.SQLException
- in case of failure
-
nullSafeGet
public java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws java.sql.SQLException
- Specified by:
nullSafeGet
in interfaceorg.hibernate.type.Type
- Specified by:
nullSafeGet
in interfaceorg.hibernate.usertype.UserType
- Throws:
java.sql.SQLException
-
nullSafeSet
public void nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws java.sql.SQLException
- Specified by:
nullSafeSet
in interfaceorg.hibernate.type.Type
- Specified by:
nullSafeSet
in interfaceorg.hibernate.usertype.UserType
- Throws:
java.sql.SQLException
-
returnedClass
public java.lang.Class<T> returnedClass()
- Specified by:
returnedClass
in interfaceorg.hibernate.usertype.UserType
-
equals
public boolean equals(java.lang.Object x, java.lang.Object y)
- Specified by:
equals
in interfaceorg.hibernate.usertype.UserType
-
hashCode
public int hashCode(java.lang.Object x)
- Specified by:
hashCode
in interfaceorg.hibernate.usertype.UserType
-
deepCopy
public java.lang.Object deepCopy(java.lang.Object value)
- Specified by:
deepCopy
in interfaceorg.hibernate.usertype.UserType
-
isMutable
public boolean isMutable()
- Specified by:
isMutable
in interfaceorg.hibernate.type.Type
- Specified by:
isMutable
in interfaceorg.hibernate.usertype.UserType
-
disassemble
public java.io.Serializable disassemble(java.lang.Object o)
- Specified by:
disassemble
in interfaceorg.hibernate.usertype.UserType
-
assemble
public java.lang.Object assemble(java.io.Serializable cached, java.lang.Object owner)
- Specified by:
assemble
in interfaceorg.hibernate.usertype.UserType
-
replace
public java.lang.Object replace(java.lang.Object o, java.lang.Object target, java.lang.Object owner)
- Specified by:
replace
in interfaceorg.hibernate.usertype.UserType
-
isAssociationType
public boolean isAssociationType()
- Specified by:
isAssociationType
in interfaceorg.hibernate.type.Type
-
isCollectionType
public boolean isCollectionType()
- Specified by:
isCollectionType
in interfaceorg.hibernate.type.Type
-
isEntityType
public boolean isEntityType()
- Specified by:
isEntityType
in interfaceorg.hibernate.type.Type
-
isAnyType
public boolean isAnyType()
- Specified by:
isAnyType
in interfaceorg.hibernate.type.Type
-
isComponentType
public boolean isComponentType()
- Specified by:
isComponentType
in interfaceorg.hibernate.type.Type
-
getColumnSpan
public int getColumnSpan(org.hibernate.engine.spi.Mapping mapping) throws org.hibernate.MappingException
- Specified by:
getColumnSpan
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.MappingException
-
sqlTypes
public int[] sqlTypes(org.hibernate.engine.spi.Mapping mapping) throws org.hibernate.MappingException
- Specified by:
sqlTypes
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.MappingException
-
dictatedSizes
public org.hibernate.engine.jdbc.Size[] dictatedSizes(org.hibernate.engine.spi.Mapping mapping) throws org.hibernate.MappingException
- Specified by:
dictatedSizes
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.MappingException
-
defaultSizes
public org.hibernate.engine.jdbc.Size[] defaultSizes(org.hibernate.engine.spi.Mapping mapping) throws org.hibernate.MappingException
- Specified by:
defaultSizes
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.MappingException
-
getReturnedClass
public java.lang.Class getReturnedClass()
- Specified by:
getReturnedClass
in interfaceorg.hibernate.type.Type
-
isSame
public boolean isSame(java.lang.Object x, java.lang.Object y) throws org.hibernate.HibernateException
- Specified by:
isSame
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
isEqual
public boolean isEqual(java.lang.Object x, java.lang.Object y) throws org.hibernate.HibernateException
- Specified by:
isEqual
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
isEqual
public boolean isEqual(java.lang.Object x, java.lang.Object y, org.hibernate.engine.spi.SessionFactoryImplementor factory) throws org.hibernate.HibernateException
- Specified by:
isEqual
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
getHashCode
public int getHashCode(java.lang.Object x) throws org.hibernate.HibernateException
- Specified by:
getHashCode
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
getHashCode
public int getHashCode(java.lang.Object x, org.hibernate.engine.spi.SessionFactoryImplementor factory) throws org.hibernate.HibernateException
- Specified by:
getHashCode
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
compare
public int compare(java.lang.Object x, java.lang.Object y)
- Specified by:
compare
in interfaceorg.hibernate.type.Type
-
isDirty
public final boolean isDirty(java.lang.Object old, java.lang.Object current, org.hibernate.engine.spi.SharedSessionContractImplementor session)
- Specified by:
isDirty
in interfaceorg.hibernate.type.Type
-
isDirty
public final boolean isDirty(java.lang.Object old, java.lang.Object current, boolean[] checkable, org.hibernate.engine.spi.SharedSessionContractImplementor session)
- Specified by:
isDirty
in interfaceorg.hibernate.type.Type
-
isDirty
protected final boolean isDirty(java.lang.Object old, java.lang.Object current)
-
isModified
public boolean isModified(java.lang.Object dbState, java.lang.Object currentState, boolean[] checkable, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws org.hibernate.HibernateException
- Specified by:
isModified
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
nullSafeGet
public java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String name, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException, java.sql.SQLException
- Specified by:
nullSafeGet
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
-
nullSafeSet
public void nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws org.hibernate.HibernateException, java.sql.SQLException
- Specified by:
nullSafeSet
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
-
toLoggableString
public java.lang.String toLoggableString(java.lang.Object value, org.hibernate.engine.spi.SessionFactoryImplementor factory) throws org.hibernate.HibernateException
- Specified by:
toLoggableString
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfaceorg.hibernate.type.Type
-
deepCopy
public java.lang.Object deepCopy(java.lang.Object value, org.hibernate.engine.spi.SessionFactoryImplementor factory) throws org.hibernate.HibernateException
- Specified by:
deepCopy
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
disassemble
public java.io.Serializable disassemble(java.lang.Object value, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException
- Specified by:
disassemble
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
assemble
public java.lang.Object assemble(java.io.Serializable cached, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException
- Specified by:
assemble
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
beforeAssemble
public void beforeAssemble(java.io.Serializable cached, org.hibernate.engine.spi.SharedSessionContractImplementor session)
- Specified by:
beforeAssemble
in interfaceorg.hibernate.type.Type
-
hydrate
public java.lang.Object hydrate(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException, java.sql.SQLException
- Specified by:
hydrate
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
-
resolve
public java.lang.Object resolve(java.lang.Object value, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException
- Specified by:
resolve
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
semiResolve
public java.lang.Object semiResolve(java.lang.Object value, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException
- Specified by:
semiResolve
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
getSemiResolvedType
public org.hibernate.type.Type getSemiResolvedType(org.hibernate.engine.spi.SessionFactoryImplementor factory)
- Specified by:
getSemiResolvedType
in interfaceorg.hibernate.type.Type
-
replace
public java.lang.Object replace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner, java.util.Map copyCache) throws org.hibernate.HibernateException
- Specified by:
replace
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
replace
public java.lang.Object replace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.spi.SharedSessionContractImplementor session, java.lang.Object owner, java.util.Map copyCache, org.hibernate.type.ForeignKeyDirection foreignKeyDirection) throws org.hibernate.HibernateException
- Specified by:
replace
in interfaceorg.hibernate.type.Type
- Throws:
org.hibernate.HibernateException
-
toColumnNullness
public boolean[] toColumnNullness(java.lang.Object value, org.hibernate.engine.spi.Mapping mapping)
- Specified by:
toColumnNullness
in interfaceorg.hibernate.type.Type
-
-