Class PostgreSQLGuavaRangeType
java.lang.Object
io.hypersistence.utils.hibernate.type.ImmutableType<com.google.common.collect.Range>
io.hypersistence.utils.hibernate.type.range.guava.PostgreSQLGuavaRangeType
- All Implemented Interfaces:
Serializable,org.hibernate.type.Type,org.hibernate.usertype.DynamicParameterizedType,org.hibernate.usertype.EnhancedUserType<com.google.common.collect.Range>,org.hibernate.usertype.ParameterizedType,org.hibernate.usertype.UserType<com.google.common.collect.Range>
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.hibernate.usertype.DynamicParameterizedType
org.hibernate.usertype.DynamicParameterizedType.ParameterType -
Field Summary
FieldsFields inherited from interface org.hibernate.usertype.DynamicParameterizedType
ACCESS_TYPE, ENTITY, IS_DYNAMIC, IS_PRIMARY_KEY, PARAMETER_TYPE, PROPERTY, RETURNED_CLASS, XPROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasString(com.google.common.collect.Range range) static com.google.common.collect.Range<BigDecimal>bigDecimalRange(String range) Creates theBigDecimalrange from provided string:com.google.common.collect.RangefromStringValue(CharSequence sequence) protected com.google.common.collect.Rangeget(ResultSet rs, int position, org.hibernate.engine.spi.SharedSessionContractImplementor session, Object owner) Get the column value from the JDBCResultSet.Class<?>intstatic com.google.common.collect.Range<Integer>integerRange(String range) Creates theIntegerrange from provided string:static com.google.common.collect.Range<LocalDate>localDateRange(String range) Creates theLocalDaterange from provided string:static com.google.common.collect.Range<LocalDateTime>localDateTimeRange(String range) Creates theLocalDateTimerange from provided string:static com.google.common.collect.Range<Long>Creates theLongrange from provided string:static com.google.common.collect.Range<OffsetDateTime>offsetDateTimeRange(String rangeStr) Creates theOffsetDateTimerange from provided string:static <T extends Comparable<?>>
com.google.common.collect.Range<T>protected voidset(PreparedStatement st, com.google.common.collect.Range range, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session) Set the column value on the provided JDBCPreparedStatement.voidsetParameterValues(Properties parameters) static com.google.common.collect.Range<ZonedDateTime>zonedDateTimeRange(String rangeStr) Creates theZonedDateTimerange from provided string:Methods inherited from class io.hypersistence.utils.hibernate.type.ImmutableType
assemble, assemble, beforeAssemble, compare, compare, deepCopy, deepCopy, disassemble, disassemble, equals, getColumnSpan, getConfiguration, getHashCode, getHashCode, getName, getReturnedClass, getSqlTypeCodes, hashCode, isAnyType, isAssociationType, isCollectionType, isComponentType, isDirty, isDirty, isDirty, isEntityType, isEqual, isEqual, isModified, isMutable, isSame, nullSafeGet, nullSafeSet, nullSafeSet, replace, replace, replace, returnedClass, toColumnNullness, toLoggableString, toSqlLiteral, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.type.Type
disassemble, getReturnedClassNameMethods inherited from interface org.hibernate.usertype.UserType
getDefaultSqlLength, getDefaultSqlPrecision, getDefaultSqlScale, getJdbcType, getValueConverter
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
PostgreSQLGuavaRangeType
public PostgreSQLGuavaRangeType() -
PostgreSQLGuavaRangeType
-
-
Method Details
-
getSqlType
public int getSqlType()- Specified by:
getSqlTypein interfaceorg.hibernate.usertype.UserType<com.google.common.collect.Range>
-
ofString
public static <T extends Comparable<?>> com.google.common.collect.Range<T> ofString(String str, Function<String, T> converter, Class<T> clazz) -
bigDecimalRange
Creates theBigDecimalrange 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
BigDecimals. - Throws:
NumberFormatException- when one of the bounds are invalid.
-
integerRange
Creates theIntegerrange 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
Integers. - Throws:
NumberFormatException- when one of the bounds are invalid.
-
longRange
Creates theLongrange 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
Longs. - Throws:
NumberFormatException- when one of the bounds are invalid.
-
localDateTimeRange
Creates theLocalDateTimerange from provided string:Range<LocalDateTime> closed = Range.localDateTimeRange("[2014-04-28 16:00:49,2015-04-28 16:00:49]"); Range<LocalDateTime> quoted = Range.localDateTimeRange("[\"2014-04-28 16:00:49\",\"2015-04-28 16:00:49\"]"); Range<LocalDateTime> iso = Range.localDateTimeRange("[\"2014-04-28T16:00:49.2358\",\"2015-04-28T16:00:49\"]");The valid formats for bounds are:
- yyyy-MM-dd HH:mm:ss[.SSSSSS]
- yyyy-MM-dd'T'HH:mm:ss[.SSSSSS]
- Parameters:
range- The range string, for example "[2014-04-28 16:00:49,2015-04-28 16:00:49]".- Returns:
- The range of
LocalDateTimes. - Throws:
DateTimeParseException- when one of the bounds are invalid.
-
localDateRange
Creates theLocalDaterange from provided string:Range<LocalDate> closed = Range.localDateRange("[2014-04-28,2015-04-289]"); Range<LocalDate> quoted = Range.localDateRange("[\"2014-04-28\",\"2015-04-28\"]"); Range<LocalDate> iso = Range.localDateRange("[\"2014-04-28\",\"2015-04-28\"]");The valid formats for bounds are:
- yyyy-MM-dd
- yyyy-MM-dd
- Parameters:
range- The range string, for example "[2014-04-28,2015-04-28]".- Returns:
- The range of
LocalDates. - Throws:
DateTimeParseException- when one of the bounds are invalid.
-
zonedDateTimeRange
Creates theZonedDateTimerange from provided string:Range<ZonedDateTime> closed = Range.zonedDateTimeRange("[2007-12-03T10:15:30+01:00\",\"2008-12-03T10:15:30+01:00]"); Range<ZonedDateTime> quoted = Range.zonedDateTimeRange("[\"2007-12-03T10:15:30+01:00\",\"2008-12-03T10:15:30+01:00\"]"); Range<ZonedDateTime> iso = Range.zonedDateTimeRange("[2011-12-03T10:15:30+01:00[Europe/Paris], 2012-12-03T10:15:30+01:00[Europe/Paris]]");The valid formats for bounds are:
- yyyy-MM-dd HH:mm:ss[.SSSSSS]X
- yyyy-MM-dd'T'HH:mm:ss[.SSSSSS]X
- Parameters:
rangeStr- The range string, for example "[2011-12-03T10:15:30+01:00,2012-12-03T10:15:30+01:00]".- Returns:
- The range of
ZonedDateTimes. - Throws:
DateTimeParseException- when one of the bounds are invalid.IllegalArgumentException- when bounds time zones are different.
-
offsetDateTimeRange
Creates theOffsetDateTimerange from provided string:Range<OffsetDateTime> closed = Range.offsetDateTimeRange("[2007-12-03T10:15:30+01:00\",\"2008-12-03T10:15:30+01:00]"); Range<OffsetDateTime> quoted = Range.offsetDateTimeRange("[\"2007-12-03T10:15:30+01:00\",\"2008-12-03T10:15:30+01:00\"]"); Range<OffsetDateTime> iso = Range.offsetDateTimeRange("[2011-12-03T10:15:30+01:00[Europe/Paris], 2012-12-03T10:15:30+01:00[Europe/Paris]]");The valid formats for bounds are:
- yyyy-MM-dd HH:mm:ss[.SSSSSS]X
- yyyy-MM-dd'T'HH:mm:ss[.SSSSSS]X
- Parameters:
rangeStr- The range string, for example "[2011-12-03T10:15:30+01:00,2012-12-03T10:15:30+01:00]".- Returns:
- The range of
OffsetDateTimes. - Throws:
DateTimeParseException- when one of the bounds are invalid.IllegalArgumentException- when bounds time zones are different.
-
asString
-
setParameterValues
- Specified by:
setParameterValuesin interfaceorg.hibernate.usertype.ParameterizedType
-
getElementType
-
fromStringValue
public com.google.common.collect.Range fromStringValue(CharSequence sequence) throws org.hibernate.HibernateException - Specified by:
fromStringValuein interfaceorg.hibernate.usertype.EnhancedUserType<com.google.common.collect.Range>- Throws:
org.hibernate.HibernateException
-