Class PostgreSQLRangeType

  • All Implemented Interfaces:
    java.io.Serializable, org.hibernate.type.Type, org.hibernate.usertype.DynamicParameterizedType, org.hibernate.usertype.ParameterizedType, org.hibernate.usertype.UserType

    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.

    See Also:
    Serialized Form
    • Field Detail

      • type

        private java.lang.reflect.Type type
    • Constructor Detail

      • PostgreSQLRangeType

        public PostgreSQLRangeType()
    • Method Detail

      • sqlTypes

        public int[] sqlTypes()
        Specified by:
        sqlTypes in interface org.hibernate.usertype.UserType
      • get

        protected Range get​(java.sql.ResultSet rs,
                            java.lang.String[] names,
                            org.hibernate.engine.spi.SharedSessionContractImplementor session,
                            java.lang.Object owner)
                     throws java.sql.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
        names - database column name
        session - current Hibernate Session
        owner - current Hibernate SessionFactoryImplementor
        Returns:
        column value
        Throws:
        java.sql.SQLException - in case of failure
      • set

        protected void set​(java.sql.PreparedStatement st,
                           Range range,
                           int index,
                           org.hibernate.engine.spi.SharedSessionContractImplementor session)
                    throws java.sql.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:
        java.sql.SQLException - in case of failure
      • determineRangeType

        private static java.lang.String determineRangeType​(Range<?> range)
      • setParameterValues

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

        public java.lang.Class<?> getElementType()