Class PostgreSQLRangeType

java.lang.Object
io.hypersistence.utils.hibernate.type.ImmutableType<Range>
io.hypersistence.utils.hibernate.type.range.PostgreSQLRangeType
All Implemented Interfaces:
Serializable, org.hibernate.type.Type, org.hibernate.usertype.DynamicParameterizedType, org.hibernate.usertype.EnhancedUserType<Range>, org.hibernate.usertype.ParameterizedType, org.hibernate.usertype.UserType<Range>

public class PostgreSQLRangeType extends ImmutableType<Range> implements org.hibernate.usertype.DynamicParameterizedType
Maps a Range object type to a PostgreSQL range column type.

Supported range types:

  • int4range
  • int8range
  • numrange
  • tsrange
  • tstzrange
  • daterange

For more details about how to use it, check out this article on vladmihalcea.com.

Author:
Edgar Asatryan, Vlad Mihalcea
See Also:
  • Field Details

  • Constructor Details

    • PostgreSQLRangeType

      public PostgreSQLRangeType()
    • PostgreSQLRangeType

      public PostgreSQLRangeType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext)
  • Method Details

    • getSqlType

      public int getSqlType()
      Specified by:
      getSqlType in interface org.hibernate.usertype.UserType<Range>
    • get

      protected Range get(ResultSet rs, int position, org.hibernate.engine.spi.SharedSessionContractImplementor session, Object owner) throws SQLException
      Description copied from class: ImmutableType
      Get the column value from the JDBC ResultSet.
      Specified by:
      get in class ImmutableType<Range>
      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 void set(PreparedStatement st, Range range, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws SQLException
      Description copied from class: ImmutableType
      Set the column value on the provided JDBC PreparedStatement.
      Specified by:
      set in class ImmutableType<Range>
      Parameters:
      st - JDBC PreparedStatement
      range - database column value
      index - database column index
      session - current Hibernate Session
      Throws:
      SQLException - in case of failure
    • setParameterValues

      public void setParameterValues(Properties parameters)
      Specified by:
      setParameterValues in interface org.hibernate.usertype.ParameterizedType
    • getElementType

      public Class<?> getElementType()
    • fromStringValue

      public Range fromStringValue(CharSequence sequence) throws org.hibernate.HibernateException
      Specified by:
      fromStringValue in interface org.hibernate.usertype.EnhancedUserType<Range>
      Throws:
      org.hibernate.HibernateException