Interface DbColumn

All Superinterfaces:
OptionalValue<Object>, Value<Object>
All Known Implementing Classes:
DbColumnBase, MongoDbColumn

public interface DbColumn extends OptionalValue<Object>
Column data and metadata.

Column may represent a null value. Get methods on this class would throw an exception if the value is null, use Value.asOptional(), or one of the mapping methods that support optional values, such as OptionalValue.ifPresent(java.util.function.Consumer) to consume such columns.

  • Method Details

    • get

      <T> T get(Class<T> type) throws MapperException
      Typed value of this column. This method can return a correct result only if the type is the same as javaType() or there is a Mapper registered that can map it.
      Specified by:
      get in interface Value<Object>
      Type Parameters:
      T - type of the returned value
      Parameters:
      type - class of the type that should be returned (must be supported by the underlying data type)
      Returns:
      value of this column correctly typed
      Throws:
      MapperException - in case the type is not the underlying javaType() and there is no mapper registered for it
    • get

      <T> T get(GenericType<T> type) throws MapperException
      Value of this column as a generic type. This method can return a correct result only if the type represents a class, or if there is a Mapper registered that can map underlying javaType() to the type requested.
      Specified by:
      get in interface Value<Object>
      Type Parameters:
      T - type of the returned value
      Parameters:
      type - requested type
      Returns:
      value mapped to the expected type if possible
      Throws:
      MapperException - in case the mapping cannot be done
    • get

      default Object get()
      Untyped value of this column, returns java type as provided by the underlying database driver.

      WARNING: for backward compatibility, this method MAY return null if the underlying column value is null. As this is not aligned with Helidon APIs, which forbid returns of null, this will change in future versions. If you need support for nullable columns, use the optional-like methods on this type, such as OptionalValue.isEmpty(), OptionalValue.isPresent(), OptionalValue.ifPresent(java.util.function.Consumer) etc. to handle {code null} values.

      Specified by:
      get in interface OptionalValue<Object>
      Specified by:
      get in interface Value<Object>
      Returns:
      value of this column
    • javaType

      Class<?> javaType()
      Type of the column as would be returned by the underlying database driver.
      Returns:
      class of the type
      See Also:
    • dbType

      String dbType()
      Type of the column in the language of the database.

      Example for SQL - if a column is declared as VARCHAR(256) in the database, this method would return VARCHAR and method javaType() would return String.

      Returns:
      column type as the database understands it
    • name

      String name()
      Column name.
      Specified by:
      name in interface Value<Object>
      Returns:
      name of this column
    • precision

      default Optional<Integer> precision()
      Precision of this column.

      Precision depends on data type:

      • Numeric: The maximal number of digits of the number
      • String/Character: The maximal length
      • Binary: The maximal number of bytes
      • Other: Implementation specific
      Returns:
      precision of this column or empty if precision is not available
    • scale

      default Optional<Integer> scale()
      Scale of this column.

      Scale is the number of digits in a decimal number to the right of the decimal separator.

      Returns:
      scale of this column or empty if scale is not available