Class DurationJavaType

java.lang.Object
org.hibernate.type.descriptor.java.AbstractClassJavaType<Duration>
org.hibernate.type.descriptor.java.DurationJavaType
All Implemented Interfaces:
Serializable, BasicJavaType<Duration>, JavaType<Duration>

public class DurationJavaType extends AbstractClassJavaType<Duration>
Descriptor for Duration, which is represented internally as (long seconds, int nanoseconds), approximately 28 decimal digits of precision. This quantity must be stored in the database as a single integer with units of nanoseconds, unless the ANSI SQL interval type is supported.

In practice, the 19 decimal digits of a SQL bigint are capable of representing six centuries in nanoseconds and are sufficient for many applications. However, by default, we map Java Duration to SQL numeric(21) here, which can comfortably represent 60 millennia of nanos.

See Also:
  • Field Details

  • Constructor Details

    • DurationJavaType

      public DurationJavaType()
  • Method Details

    • isInstance

      public boolean isInstance(Object value)
      Description copied from interface: JavaType
      Is the given value an instance of the described type?

      Usually just getJavaTypeClass().isInstance(value), but some descriptors need specialized semantics, for example, the descriptors for java.sql.Date, java.sql.Time, and java.sql.Timestamp.

      For EntityJavaType, this method handles proxies in a semantically correct way, by checking the entity instance underlying the proxy object.

    • cast

      public Duration cast(Object value)
      Description copied from interface: JavaType
      Apply a simple type cast to the given value, without attempting any sort of coercion or wrapping. This method is provided as a convenient way to avoid an unchecked cast to a type variable. Use javaType.cast(value) instead of (T) value wherever possible.

      Usually just getJavaTypeClass().cast(value), but overridden in some cases as an "optimization". This optimization is almost certainly unnecessary, and might even indeed be harmful, since Class.cast() is an intrinsic.

    • getRecommendedJdbcType

      public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context)
      Description copied from interface: BasicJavaType
      Obtain the "recommended" SQL type descriptor for this Java type. Often, but not always, the source of this recommendation is the JDBC specification.
      Parameters:
      context - Contextual information
      Returns:
      The recommended SQL type descriptor
    • useObjectEqualsHashCode

      public boolean useObjectEqualsHashCode()
      Description copied from interface: JavaType
      Whether to use Object.equals(Object) and Object.hashCode() or JavaType.areEqual(Object, Object) and JavaType.extractHashCode(Object) for objects of this java type. This is useful to avoid mega-morphic callsites.
    • toString

      public String toString(Duration value)
    • fromString

      public Duration fromString(CharSequence string)
    • unwrap

      public <X> X unwrap(Duration duration, Class<X> type, WrapperOptions options)
      Description copied from interface: JavaType
      Unwrap an instance of our handled Java type into the requested type.

      As an example, if this is a JavaType<Integer> and we are asked to unwrap the Integer value as a Long, we would return something like Long.valueOf( value.longValue() ).

      Intended use is during PreparedStatement binding.

      Type Parameters:
      X - The conversion type.
      Parameters:
      duration - The value to unwrap
      type - The type as which to unwrap
      options - The options
      Returns:
      The unwrapped value.
    • wrap

      public <X> Duration wrap(X value, WrapperOptions options)
      Description copied from interface: JavaType
      Wrap a value as our handled Java type.

      Intended use is during ResultSet extraction.

      Type Parameters:
      X - The conversion type.
      Parameters:
      value - The value to wrap.
      options - The options
      Returns:
      The wrapped value.
    • getDefaultSqlPrecision

      public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType)
      Description copied from interface: JavaType
      The default column precision when this Java type is mapped to a SQL data type which is parametrized by precision, for example Types.DECIMAL.
      Returns:
      Size.DEFAULT_PRECISION unless overridden
    • getDefaultSqlScale

      public int getDefaultSqlScale(Dialect dialect, JdbcType jdbcType)
      Description copied from interface: JavaType
      The default column scale when this Java type is mapped to a SQL data type which is parametrized by scale, for example Types.DECIMAL.
      Returns:
      Size.DEFAULT_SCALE unless overridden