Class ImmutableType<T>

java.lang.Object
io.hypersistence.utils.hibernate.type.ImmutableType<T>
All Implemented Interfaces:
Serializable, org.hibernate.type.Type, org.hibernate.usertype.EnhancedUserType<T>, org.hibernate.usertype.UserType<T>
Direct Known Subclasses:
DescriptorImmutableType, ImmutableDynamicParameterizedType, NullableCharacterType, OracleIntervalDayToSecondType, PostgreSQLCITextType, PostgreSQLGuavaRangeType, PostgreSQLHStoreType, PostgreSQLInetType, PostgreSQLIntervalType, PostgreSQLLTreeType, PostgreSQLPeriodType, PostgreSQLRangeType, PostgreSQLSpringRangeType

public abstract class ImmutableType<T> extends Object implements org.hibernate.usertype.UserType<T>, org.hibernate.type.Type, org.hibernate.usertype.EnhancedUserType<T>
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 NativeQuery.addScalar(String, BasicDomainType) method to fix the No Dialect mapping for JDBC type issues.

Author:
Vlad Mihalcea
See Also:
  • Constructor Details

    • 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 Details

    • getConfiguration

      protected Configuration getConfiguration()
      Get the current Configuration object.
      Returns:
      the current Configuration object.
    • get

      protected abstract T get(ResultSet rs, int position, org.hibernate.engine.spi.SharedSessionContractImplementor session, Object owner) throws SQLException
      Get the column value from the JDBC ResultSet.
      Parameters:
      rs - JDBC ResultSet
      position - database column position
      session - current Hibernate Session
      owner - current Hibernate SessionFactoryImplementor
      Returns:
      column value
      Throws:
      SQLException - in case of failure
    • set

      protected abstract void set(PreparedStatement st, T value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor 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 T nullSafeGet(ResultSet rs, int position, org.hibernate.engine.spi.SharedSessionContractImplementor session, Object owner) throws SQLException
      Specified by:
      nullSafeGet in interface org.hibernate.usertype.UserType<T>
      Throws:
      SQLException
    • nullSafeSet

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

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

      public boolean equals(Object x, Object y)
      Specified by:
      equals in interface org.hibernate.usertype.UserType<T>
    • hashCode

      public int hashCode(Object x)
      Specified by:
      hashCode in interface org.hibernate.usertype.UserType<T>
    • deepCopy

      public T deepCopy(Object value)
      Specified by:
      deepCopy in interface org.hibernate.usertype.UserType<T>
    • isMutable

      public boolean isMutable()
      Specified by:
      isMutable in interface org.hibernate.type.Type
      Specified by:
      isMutable in interface org.hibernate.usertype.UserType<T>
    • disassemble

      public Serializable disassemble(Object o)
      Specified by:
      disassemble in interface org.hibernate.usertype.UserType<T>
    • assemble

      public T assemble(Serializable cached, Object owner)
      Specified by:
      assemble in interface org.hibernate.usertype.UserType<T>
    • replace

      public T replace(Object o, Object target, Object owner)
      Specified by:
      replace in interface org.hibernate.usertype.UserType<T>
    • 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
    • getReturnedClass

      public Class<T> 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.SharedSessionContractImplementor 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.SharedSessionContractImplementor 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.SharedSessionContractImplementor session) throws org.hibernate.HibernateException
      Specified by:
      isModified in interface org.hibernate.type.Type
      Throws:
      org.hibernate.HibernateException
    • nullSafeSet

      public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, org.hibernate.engine.spi.SharedSessionContractImplementor 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.SharedSessionContractImplementor 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.SharedSessionContractImplementor 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.SharedSessionContractImplementor session)
      Specified by:
      beforeAssemble in interface org.hibernate.type.Type
    • replace

      public Object replace(Object original, Object target, org.hibernate.engine.spi.SharedSessionContractImplementor 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.SharedSessionContractImplementor 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
    • getSqlTypeCodes

      public int[] getSqlTypeCodes(org.hibernate.engine.spi.Mapping mapping) throws org.hibernate.MappingException
      Specified by:
      getSqlTypeCodes in interface org.hibernate.type.Type
      Throws:
      org.hibernate.MappingException
    • toSqlLiteral

      public String toSqlLiteral(T o)
      Specified by:
      toSqlLiteral in interface org.hibernate.usertype.EnhancedUserType<T>
    • toString

      public String toString(T o) throws org.hibernate.HibernateException
      Specified by:
      toString in interface org.hibernate.usertype.EnhancedUserType<T>
      Throws:
      org.hibernate.HibernateException