com.vladmihalcea.hibernate.type
Class ImmutableType<T>

java.lang.Object
  extended by com.vladmihalcea.hibernate.type.ImmutableType<T>
All Implemented Interfaces:
Serializable, org.hibernate.type.Type, org.hibernate.usertype.UserType
Direct Known Subclasses:
NullableCharacterType, PostgreSQLCITextType, PostgreSQLGuavaRangeType, PostgreSQLHStoreType, PostgreSQLInetType, PostgreSQLRangeType, PostgreSQLTSVectorType

public abstract class ImmutableType<T>
extends Object
implements org.hibernate.usertype.UserType, org.hibernate.type.Type

Very convenient base class for implementing immutable object types using Hibernate UserType.

The ImmutableType implements the Type interface too, so you can pass all types extending the ImmutableType to the SQLQuery.addScalar(String, Type) method to fix the No Dialect mapping for JDBC type issues.

Author:
Vlad Mihalcea
See Also:
Serialized Form

Constructor Summary
protected ImmutableType(Class<T> clazz)
          Initialization constructor taking the Class and using the default Configuration object.
protected ImmutableType(Class<T> clazz, Configuration configuration)
          Initialization constructor taking the Class and Configuration objects.
 
Method Summary
 Object assemble(Serializable cached, Object owner)
           
 Object assemble(Serializable cached, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
 void beforeAssemble(Serializable cached, org.hibernate.engine.spi.SessionImplementor session)
           
 int compare(Object x, Object y)
           
 Object deepCopy(Object value)
           
 Object deepCopy(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)
           
 Serializable disassemble(Object o)
           
 Serializable disassemble(Object value, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
 boolean equals(Object x, Object y)
           
protected abstract  T get(ResultSet rs, String[] names, org.hibernate.engine.spi.SessionImplementor session, Object owner)
          Get the column value from the JDBC ResultSet.
 int getColumnSpan(org.hibernate.engine.spi.Mapping mapping)
           
protected  Configuration getConfiguration()
          Get the current Configuration object.
 int getHashCode(Object x)
           
 int getHashCode(Object x, org.hibernate.engine.spi.SessionFactoryImplementor factory)
           
 String getName()
           
 Class getReturnedClass()
           
 org.hibernate.type.Type getSemiResolvedType(org.hibernate.engine.spi.SessionFactoryImplementor factory)
           
 int hashCode(Object x)
           
 Object hydrate(ResultSet rs, String[] names, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
 boolean isAnyType()
           
 boolean isAssociationType()
           
 boolean isCollectionType()
           
 boolean isComponentType()
           
protected  boolean isDirty(Object old, Object current)
           
 boolean isDirty(Object old, Object current, boolean[] checkable, org.hibernate.engine.spi.SessionImplementor session)
           
 boolean isDirty(Object old, Object current, org.hibernate.engine.spi.SessionImplementor session)
           
 boolean isEntityType()
           
 boolean isEqual(Object x, Object y)
           
 boolean isEqual(Object x, Object y, org.hibernate.engine.spi.SessionFactoryImplementor factory)
           
 boolean isModified(Object dbState, Object currentState, boolean[] checkable, org.hibernate.engine.spi.SessionImplementor session)
           
 boolean isMutable()
           
 boolean isSame(Object x, Object y)
           
 Object nullSafeGet(ResultSet rs, String[] names, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
 Object nullSafeGet(ResultSet rs, String name, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
 void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, org.hibernate.engine.spi.SessionImplementor session)
           
 void nullSafeSet(PreparedStatement st, Object value, int index, org.hibernate.engine.spi.SessionImplementor session)
           
 Object replace(Object o, Object target, Object owner)
           
 Object replace(Object original, Object target, org.hibernate.engine.spi.SessionImplementor session, Object owner, Map copyCache)
           
 Object replace(Object original, Object target, org.hibernate.engine.spi.SessionImplementor session, Object owner, Map copyCache, org.hibernate.type.ForeignKeyDirection foreignKeyDirection)
           
 Object resolve(Object value, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
 Class<T> returnedClass()
           
 Object semiResolve(Object value, org.hibernate.engine.spi.SessionImplementor session, Object owner)
           
protected abstract  void set(PreparedStatement st, T value, int index, org.hibernate.engine.spi.SessionImplementor session)
          Set the column value on the provided JDBC PreparedStatement.
 int[] sqlTypes(org.hibernate.engine.spi.Mapping mapping)
           
 boolean[] toColumnNullness(Object value, org.hibernate.engine.spi.Mapping mapping)
           
 String toLoggableString(Object value, org.hibernate.engine.spi.SessionFactoryImplementor factory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hibernate.usertype.UserType
sqlTypes
 

Constructor Detail

ImmutableType

protected ImmutableType(Class<T> clazz)
Initialization constructor taking the Class and using the default Configuration object.

Parameters:
clazz - the entity attribute Class type to be handled

ImmutableType

protected ImmutableType(Class<T> clazz,
                        Configuration configuration)
Initialization constructor taking the Class and Configuration objects.

Parameters:
clazz - the entity attribute Class type to be handled
configuration - custom Configuration object.
Method Detail

getConfiguration

protected Configuration getConfiguration()
Get the current Configuration object.

Returns:
the current Configuration object.

get

protected abstract T get(ResultSet rs,
                         String[] names,
                         org.hibernate.engine.spi.SessionImplementor session,
                         Object owner)
                  throws SQLException
Get the column value from the JDBC ResultSet.

Parameters:
rs - JDBC ResultSet
names - database column name
session - current Hibernate Session
owner - current Hibernate SessionFactory
Returns:
column value
Throws:
SQLException - in case of failure

set

protected abstract void set(PreparedStatement st,
                            T value,
                            int index,
                            org.hibernate.engine.spi.SessionImplementor session)
                     throws SQLException
Set the column value on the provided JDBC PreparedStatement.

Parameters:
st - JDBC PreparedStatement
value - database column value
index - database column index
session - current Hibernate Session
Throws:
SQLException - in case of failure

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String[] names,
                          org.hibernate.engine.spi.SessionImplementor session,
                          Object owner)
                   throws SQLException
Specified by:
nullSafeGet in interface org.hibernate.type.Type
Specified by:
nullSafeGet in interface org.hibernate.usertype.UserType
Throws:
SQLException

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index,
                        org.hibernate.engine.spi.SessionImplementor session)
                 throws SQLException
Specified by:
nullSafeSet in interface org.hibernate.type.Type
Specified by:
nullSafeSet in interface org.hibernate.usertype.UserType
Throws:
SQLException

returnedClass

public Class<T> returnedClass()
Specified by:
returnedClass in interface org.hibernate.usertype.UserType

equals

public boolean equals(Object x,
                      Object y)
Specified by:
equals in interface org.hibernate.usertype.UserType

hashCode

public int hashCode(Object x)
Specified by:
hashCode in interface org.hibernate.usertype.UserType

deepCopy

public Object deepCopy(Object value)
Specified by:
deepCopy in interface org.hibernate.usertype.UserType

isMutable

public boolean isMutable()
Specified by:
isMutable in interface org.hibernate.type.Type
Specified by:
isMutable in interface org.hibernate.usertype.UserType

disassemble

public Serializable disassemble(Object o)
Specified by:
disassemble in interface org.hibernate.usertype.UserType

assemble

public Object assemble(Serializable cached,
                       Object owner)
Specified by:
assemble in interface org.hibernate.usertype.UserType

replace

public Object replace(Object o,
                      Object target,
                      Object owner)
Specified by:
replace in interface org.hibernate.usertype.UserType

isAssociationType

public boolean isAssociationType()
Specified by:
isAssociationType in interface org.hibernate.type.Type

isCollectionType

public boolean isCollectionType()
Specified by:
isCollectionType in interface org.hibernate.type.Type

isEntityType

public boolean isEntityType()
Specified by:
isEntityType in interface org.hibernate.type.Type

isAnyType

public boolean isAnyType()
Specified by:
isAnyType in interface org.hibernate.type.Type

isComponentType

public boolean isComponentType()
Specified by:
isComponentType in interface org.hibernate.type.Type

getColumnSpan

public int getColumnSpan(org.hibernate.engine.spi.Mapping mapping)
                  throws org.hibernate.MappingException
Specified by:
getColumnSpan in interface org.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 interface org.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 interface org.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 interface org.hibernate.type.Type
Throws:
org.hibernate.MappingException

getReturnedClass

public Class getReturnedClass()
Specified by:
getReturnedClass in interface org.hibernate.type.Type

isSame

public boolean isSame(Object x,
                      Object y)
               throws org.hibernate.HibernateException
Specified by:
isSame in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

isEqual

public boolean isEqual(Object x,
                       Object y)
                throws org.hibernate.HibernateException
Specified by:
isEqual in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

isEqual

public boolean isEqual(Object x,
                       Object y,
                       org.hibernate.engine.spi.SessionFactoryImplementor factory)
                throws org.hibernate.HibernateException
Specified by:
isEqual in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

getHashCode

public int getHashCode(Object x)
                throws org.hibernate.HibernateException
Specified by:
getHashCode in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

getHashCode

public int getHashCode(Object x,
                       org.hibernate.engine.spi.SessionFactoryImplementor factory)
                throws org.hibernate.HibernateException
Specified by:
getHashCode in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

compare

public int compare(Object x,
                   Object y)
Specified by:
compare in interface org.hibernate.type.Type

isDirty

public final boolean isDirty(Object old,
                             Object current,
                             org.hibernate.engine.spi.SessionImplementor session)
Specified by:
isDirty in interface org.hibernate.type.Type

isDirty

public final boolean isDirty(Object old,
                             Object current,
                             boolean[] checkable,
                             org.hibernate.engine.spi.SessionImplementor session)
Specified by:
isDirty in interface org.hibernate.type.Type

isDirty

protected final boolean isDirty(Object old,
                                Object current)

isModified

public boolean isModified(Object dbState,
                          Object currentState,
                          boolean[] checkable,
                          org.hibernate.engine.spi.SessionImplementor session)
                   throws org.hibernate.HibernateException
Specified by:
isModified in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String name,
                          org.hibernate.engine.spi.SessionImplementor session,
                          Object owner)
                   throws org.hibernate.HibernateException,
                          SQLException
Specified by:
nullSafeGet in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException
SQLException

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index,
                        boolean[] settable,
                        org.hibernate.engine.spi.SessionImplementor session)
                 throws org.hibernate.HibernateException,
                        SQLException
Specified by:
nullSafeSet in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException
SQLException

toLoggableString

public String toLoggableString(Object value,
                               org.hibernate.engine.spi.SessionFactoryImplementor factory)
                        throws org.hibernate.HibernateException
Specified by:
toLoggableString in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

getName

public String getName()
Specified by:
getName in interface org.hibernate.type.Type

deepCopy

public Object deepCopy(Object value,
                       org.hibernate.engine.spi.SessionFactoryImplementor factory)
                throws org.hibernate.HibernateException
Specified by:
deepCopy in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

disassemble

public Serializable disassemble(Object value,
                                org.hibernate.engine.spi.SessionImplementor session,
                                Object owner)
                         throws org.hibernate.HibernateException
Specified by:
disassemble in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

assemble

public Object assemble(Serializable cached,
                       org.hibernate.engine.spi.SessionImplementor session,
                       Object owner)
                throws org.hibernate.HibernateException
Specified by:
assemble in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

beforeAssemble

public void beforeAssemble(Serializable cached,
                           org.hibernate.engine.spi.SessionImplementor session)
Specified by:
beforeAssemble in interface org.hibernate.type.Type

hydrate

public Object hydrate(ResultSet rs,
                      String[] names,
                      org.hibernate.engine.spi.SessionImplementor session,
                      Object owner)
               throws org.hibernate.HibernateException,
                      SQLException
Specified by:
hydrate in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException
SQLException

resolve

public Object resolve(Object value,
                      org.hibernate.engine.spi.SessionImplementor session,
                      Object owner)
               throws org.hibernate.HibernateException
Specified by:
resolve in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

semiResolve

public Object semiResolve(Object value,
                          org.hibernate.engine.spi.SessionImplementor session,
                          Object owner)
                   throws org.hibernate.HibernateException
Specified by:
semiResolve in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

getSemiResolvedType

public org.hibernate.type.Type getSemiResolvedType(org.hibernate.engine.spi.SessionFactoryImplementor factory)
Specified by:
getSemiResolvedType in interface org.hibernate.type.Type

replace

public Object replace(Object original,
                      Object target,
                      org.hibernate.engine.spi.SessionImplementor session,
                      Object owner,
                      Map copyCache)
               throws org.hibernate.HibernateException
Specified by:
replace in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

replace

public Object replace(Object original,
                      Object target,
                      org.hibernate.engine.spi.SessionImplementor session,
                      Object owner,
                      Map copyCache,
                      org.hibernate.type.ForeignKeyDirection foreignKeyDirection)
               throws org.hibernate.HibernateException
Specified by:
replace in interface org.hibernate.type.Type
Throws:
org.hibernate.HibernateException

toColumnNullness

public boolean[] toColumnNullness(Object value,
                                  org.hibernate.engine.spi.Mapping mapping)
Specified by:
toColumnNullness in interface org.hibernate.type.Type


Copyright © 2021. All rights reserved.