com.vladmihalcea.hibernate.type.range.guava
Class PostgreSQLGuavaRangeType
java.lang.Object
com.vladmihalcea.hibernate.type.ImmutableType<com.google.common.collect.Range>
com.vladmihalcea.hibernate.type.range.guava.PostgreSQLGuavaRangeType
- All Implemented Interfaces:
- Serializable, org.hibernate.type.Type, org.hibernate.usertype.DynamicParameterizedType, org.hibernate.usertype.ParameterizedType, org.hibernate.usertype.UserType
public class PostgreSQLGuavaRangeType
- extends ImmutableType<com.google.common.collect.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
- Author:
- Edgar Asatryan, Vlad Mihalcea, Jan-Willem Gmelig Meyling
- See Also:
- Serialized Form
Nested classes/interfaces inherited from interface org.hibernate.usertype.DynamicParameterizedType |
org.hibernate.usertype.DynamicParameterizedType.ParameterType |
Fields inherited from interface org.hibernate.usertype.DynamicParameterizedType |
ACCESS_TYPE, ENTITY, IS_DYNAMIC, IS_PRIMARY_KEY, PARAMETER_TYPE, PROPERTY, RETURNED_CLASS, XPROPERTY |
Methods inherited from class com.vladmihalcea.hibernate.type.ImmutableType |
assemble, assemble, beforeAssemble, compare, deepCopy, deepCopy, defaultSizes, dictatedSizes, disassemble, disassemble, equals, getColumnSpan, getConfiguration, getHashCode, getHashCode, getName, getReturnedClass, getSemiResolvedType, hashCode, hydrate, isAnyType, isAssociationType, isCollectionType, isComponentType, isDirty, isDirty, isDirty, isEntityType, isEqual, isEqual, isModified, isMutable, isSame, nullSafeGet, nullSafeGet, nullSafeSet, nullSafeSet, replace, replace, replace, resolve, returnedClass, semiResolve, sqlTypes, toColumnNullness, toLoggableString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
INSTANCE
public static final PostgreSQLGuavaRangeType INSTANCE
PostgreSQLGuavaRangeType
public PostgreSQLGuavaRangeType()
sqlTypes
public int[] sqlTypes()
- Specified by:
sqlTypes
in interface org.hibernate.usertype.UserType
get
protected com.google.common.collect.Range get(ResultSet rs,
String[] names,
org.hibernate.engine.spi.SessionImplementor session,
Object owner)
throws SQLException
- Description copied from class:
ImmutableType
- Get the column value from the JDBC
ResultSet
.
- Specified by:
get
in class ImmutableType<com.google.common.collect.Range>
- Parameters:
rs
- JDBC ResultSet
names
- database column namesession
- current Hibernate Session
owner
- current Hibernate SessionFactory
- Returns:
- column value
- Throws:
SQLException
- in case of failure
set
protected void set(PreparedStatement st,
com.google.common.collect.Range range,
int index,
org.hibernate.engine.spi.SessionImplementor session)
throws SQLException
- Description copied from class:
ImmutableType
- Set the column value on the provided JDBC
PreparedStatement
.
- Specified by:
set
in class ImmutableType<com.google.common.collect.Range>
- Parameters:
st
- JDBC PreparedStatement
range
- database column valueindex
- database column indexsession
- current Hibernate Session
- Throws:
SQLException
- in case of failure
ofString
public static <T extends Comparable> com.google.common.collect.Range<T> ofString(String str,
PostgreSQLGuavaRangeType.Function<String,T> converter,
Class<T> cls)
bigDecimalRange
public static com.google.common.collect.Range<BigDecimal> bigDecimalRange(String range)
- Creates the
BigDecimal
range from provided string:
Range<BigDecimal> closed = Range.bigDecimalRange("[0.1,1.1]");
Range<BigDecimal> halfOpen = Range.bigDecimalRange("(0.1,1.1]");
Range<BigDecimal> open = Range.bigDecimalRange("(0.1,1.1)");
Range<BigDecimal> leftUnbounded = Range.bigDecimalRange("(,1.1)");
- Parameters:
range
- The range string, for example "[5.5,7.8]".
- Returns:
- The range of
BigDecimal
s.
- Throws:
NumberFormatException
- when one of the bounds are invalid.
integerRange
public static com.google.common.collect.Range<Integer> integerRange(String range)
- Creates the
Integer
range from provided string:
Range<Integer> closed = Range.integerRange("[1,5]");
Range<Integer> halfOpen = Range.integerRange("(-1,1]");
Range<Integer> open = Range.integerRange("(1,2)");
Range<Integer> leftUnbounded = Range.integerRange("(,10)");
Range<Integer> unbounded = Range.integerRange("(,)");
- Parameters:
range
- The range string, for example "[5,7]".
- Returns:
- The range of
Integer
s.
- Throws:
NumberFormatException
- when one of the bounds are invalid.
longRange
public static com.google.common.collect.Range<Long> longRange(String range)
- Creates the
Long
range from provided string:
Range<Long> closed = Range.longRange("[1,5]");
Range<Long> halfOpen = Range.longRange("(-1,1]");
Range<Long> open = Range.longRange("(1,2)");
Range<Long> leftUnbounded = Range.longRange("(,10)");
Range<Long> unbounded = Range.longRange("(,)");
- Parameters:
range
- The range string, for example "[5,7]".
- Returns:
- The range of
Long
s.
- Throws:
NumberFormatException
- when one of the bounds are invalid.
asString
public String asString(com.google.common.collect.Range range)
setParameterValues
public void setParameterValues(Properties parameters)
- Specified by:
setParameterValues
in interface org.hibernate.usertype.ParameterizedType
getElementType
public Class<?> getElementType()
Copyright © 2021. All rights reserved.