Class InstantType

All Implemented Interfaces:
DataType<Instant>

@Service(DataType.class) public final class InstantType extends AbstractDateTimeType<Instant>
Datatype for Instant.

Stored as 2 columns:

  1. the epochal seconds since 1970-01-01 00:00:00 GMT
  2. the nanoseconds
The [MAPNULL] option maps null values to 0s/0ns.
This type is sortable by the first column followed by the second.
  • Constructor Details

    • InstantType

      public InstantType()
      Creates the datatype for Instant.
  • Method Details

    • getJavaType

      public String getJavaType()
      Description copied from interface: DataType
      Gets the name of the Java type.
      Returns:
      the type
    • isMapNullSupported

      public boolean isMapNullSupported()
      Description copied from interface: DataType
      Returns whether this type supports mapping null values to some well-defined constant.
      Specified by:
      isMapNullSupported in interface DataType<Instant>
      Overrides:
      isMapNullSupported in class AbstractDataType<Instant>
      Returns:
      true if mapNull supported
    • getMappedNullValue

      public Object getMappedNullValue(Backend backend, int index)
      Description copied from interface: DataType
      Gets the mapped non-null value that represents the model's null value.
      The method throws a BackendException, if !DataType.isMapNullSupported().
      Specified by:
      getMappedNullValue in interface DataType<Instant>
      Overrides:
      getMappedNullValue in class AbstractDataType<Instant>
      Parameters:
      backend - the backend, null if not backend-specific
      index - the column index
      Returns:
      the non-null mapped value
    • getColumnCount

      public int getColumnCount(Backend backend)
      Description copied from interface: DataType
      Gets the number of database columns.
      A tentackle type may be mapped to more than one column for multi-column types such as BMoney.
      Specified by:
      getColumnCount in interface DataType<Instant>
      Overrides:
      getColumnCount in class AbstractDataType<Instant>
      Parameters:
      backend - the backend, ignored if !DataType.isColumnCountBackendSpecific()
      Returns:
      default is 1
    • getSortableColumns

      public int[] getSortableColumns()
      Description copied from interface: DataType
      Gets the indexes to the sortable columns.
      The number and order of the indexes is reflected in the generated order-by SQL clause.
      Specified by:
      getSortableColumns in interface DataType<Instant>
      Overrides:
      getSortableColumns in class AbstractDataType<Instant>
      Returns:
      the column indexes, null or empty if datatype is not sortable in a meaningful manner by the database
    • getCommentSuffix

      public Optional<String> getCommentSuffix(Backend backend, int index)
      Description copied from interface: DataType
      Gets the optional comment suffix.
      If present, it will be appended to the comment.

      Important: for datatypes with more than one column, none or exactly one should be without suffix. See WurbletArgument in tentackle-wurblets.

      Specified by:
      getCommentSuffix in interface DataType<Instant>
      Overrides:
      getCommentSuffix in class AbstractDataType<Instant>
      Parameters:
      backend - the backend, ignored if !DataType.isColumnCountBackendSpecific()
      index - the column index
      Returns:
      the optional suffix
    • getColumnGetter

      public String getColumnGetter(int index, String varName)
      Description copied from interface: DataType
      Returns the java code to get the value of a column.
      Specified by:
      getColumnGetter in interface DataType<Instant>
      Overrides:
      getColumnGetter in class AbstractDataType<Instant>
      Parameters:
      index - the column index
      varName - the java variable name
      Returns:
      the java code, empty string if this is a single column type
    • getColumnAlias

      public String getColumnAlias(int index)
      Description copied from interface: DataType
      Gets the alias name of a column.
      Specified by:
      getColumnAlias in interface DataType<Instant>
      Overrides:
      getColumnAlias in class AbstractDataType<Instant>
      Parameters:
      index - the column index
      Returns:
      the column's alias
    • getColumnValue

      public Object getColumnValue(Backend backend, int index, Instant value)
      Description copied from interface: DataType
      Gets the value of a column.
      Specified by:
      getColumnValue in interface DataType<Instant>
      Overrides:
      getColumnValue in class AbstractDataType<Instant>
      Parameters:
      backend - the backend, ignored if !DataType.isColumnCountBackendSpecific()
      index - the column index
      value - the datatype's value according to the model
      Returns:
      the column's value
    • getSize

      public int getSize(Backend backend, int index, Integer size)
      Description copied from interface: DataType
      Gets the column size.
      Sizes may be differently aligned according to the backend.
      Specified by:
      getSize in interface DataType<Instant>
      Overrides:
      getSize in class AbstractDataType<Instant>
      Parameters:
      backend - the backend
      index - the column index
      size - the size from the model
      Returns:
      the column size
    • getScale

      public int getScale(Backend backend, int index, Integer scale)
      Description copied from interface: DataType
      Gets the column scale.
      The scale may be differently aligned according to the backend.
      Specified by:
      getScale in interface DataType<Instant>
      Overrides:
      getScale in class AbstractDataType<Instant>
      Parameters:
      backend - the backend
      index - the column index
      scale - the scale from the model
      Returns:
      the column scale
    • getSqlType

      public SqlType getSqlType(Backend backend, int index)
      Description copied from interface: DataType
      Gets the SQL type.
      For predefined types, the type must be the same for all backends and the backend argument may be null.
      Application specific types, however, can use different sql types for different backends and for those types the backend argument is always valid.
      Parameters:
      backend - the backend, not used by predefined types
      index - the column index
      Returns:
      the SQL type
    • valueOf

      public Instant valueOf(String str)
      Description copied from interface: DataType
      Parses a string and converts to the value of this type.
      The method is used to parse a literal (for example the default value defined in the model).

      Notice: the method doesn't use any locale, so the results are always the same regardless of the JVM's locale.

      Parameters:
      str - the source string
      Returns:
      the value
    • toString

      public String toString(Instant object)
      Description copied from interface: DataType
      Takes an object and converts it to a string that can in turn be parsed with DataType.valueOf(String).
      The method is used to print a literal (for example the default value of a dumped attribute).

      Notice: the method doesn't use any locale, so the results are always the same regardless of the JVM's locale.

      Specified by:
      toString in interface DataType<Instant>
      Overrides:
      toString in class AbstractDataType<Instant>
      Parameters:
      object - the object of this DataType
      Returns:
      the printable string
    • valueOfLiteralToCode

      public String valueOfLiteralToCode(String str, Integer index)
      Description copied from interface: DataType
      Creates the java code to apply the valueOf method to a String.
      Specified by:
      valueOfLiteralToCode in interface DataType<Instant>
      Overrides:
      valueOfLiteralToCode in class AbstractDateTimeType<Instant>
      Parameters:
      str - the literal to be parsed
      index - the column index, null if applies to object of this type
      Returns:
      the java code
    • set

      public Object[] set(Backend backend, PreparedStatement statement, int pos, Instant object, boolean mapNull, Integer size) throws SQLException
      Description copied from interface: DataType
      Sets the object into a prepared statement.
      Must be implemented if DataType.isPredefined() returns false. Not invoked by framework otherwise.
      Parameters:
      backend - the database backend
      statement - the prepared statement
      pos - the position of the first SQL value
      object - the object, may be null
      mapNull - true if map null-values to non-null values
      size - the optional size specified in the model
      Returns:
      the values stored in the prepared statement
      Throws:
      SQLException - if failed
    • set

      public Object set(Backend backend, PreparedStatement statement, int pos, Instant object, int index, boolean mapNull, Integer size) throws SQLException
      Description copied from interface: DataType
      Sets a column of an object into a prepared statement.
      Must be implemented if DataType.isPredefined() returns false. Not invoked by framework otherwise.
      Specified by:
      set in interface DataType<Instant>
      Overrides:
      set in class AbstractDataType<Instant>
      Parameters:
      backend - the database backend
      statement - the prepared statement
      pos - the position of the first SQL value
      object - the object, may be null
      index - the column index
      mapNull - true if map null-values to non-null values
      size - the optional size specified in the model
      Returns:
      the object stored in the prepared statement
      Throws:
      SQLException - if failed
    • get

      public Instant get(Backend backend, ResultSet resultSet, int[] pos, boolean mapNull, Integer size) throws SQLException
      Description copied from interface: DataType
      Gets the object from a result set.
      Must be implemented if DataType.isPredefined() returns false. Not invoked by framework otherwise.
      Parameters:
      backend - the database backend
      resultSet - the result set
      pos - the column positions in the result set
      mapNull - true if unmap null-values from non-null values
      size - the optional size specified in the model
      Returns:
      the object or null if column(s) IS NULL
      Throws:
      SQLException - if failed
    • parse

      public Instant parse(String str) throws BackendException
      Converts a string to an instant.
      Parameters:
      str - the formatted string
      Returns:
      the instant
      Throws:
      BackendException - if parsing failed
    • format

      public String format(Instant instant)
      Converts an instant to a string.
      Parameters:
      instant - the instant
      Returns:
      the formatted instant