Class DbColumnBase

java.lang.Object
io.helidon.dbclient.DbColumnBase
All Implemented Interfaces:
Value<Object>, DbColumn
Direct Known Subclasses:
MongoDbColumn

public abstract class DbColumnBase extends Object implements DbColumn
Base DbColumn implementation.
  • Constructor Details

    • DbColumnBase

      protected DbColumnBase(Object value, MapperManager mapperManager, String... mappingQualifiers)
      Create a new instance.
      Parameters:
      value - value
      mapperManager - mapper manager
      mappingQualifiers - mapping qualifiers
  • Method Details

    • rawValue

      protected Object rawValue()
      Get raw value of the database column.
      Returns:
      raw value of the column
    • get

      public <T> T get(Class<T> type) throws MapperException
      Description copied from interface: DbColumn
      Typed value of this column. This method can return a correct result only if the type is the same as DbColumn.javaType() or there is a Mapper registered that can map it.
      Specified by:
      get in interface DbColumn
      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 DbColumn.javaType() and there is no mapper registered for it
    • get

      public <T> T get(GenericType<T> type) throws MapperException
      Description copied from interface: DbColumn
      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 DbColumn.javaType() to the type requested.
      Specified by:
      get in interface DbColumn
      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
    • as

      public <N> Value<N> as(Class<N> type) throws MapperException
      Description copied from interface: Value
      Convert this value to a different type using a mapper.
      Specified by:
      as in interface Value<Object>
      Type Parameters:
      N - type we expect
      Parameters:
      type - type to convert to
      Returns:
      converted value
      Throws:
      MapperException - in case the value cannot be converted
    • as

      public <N> Value<N> as(GenericType<N> type) throws MapperException
      Description copied from interface: Value
      Convert this value to a different type using a mapper.
      Specified by:
      as in interface Value<Object>
      Type Parameters:
      N - type we expect
      Parameters:
      type - type to convert to
      Returns:
      converted value
      Throws:
      MapperException
    • as

      public <N> Value<N> as(Function<? super Object,? extends N> mapper)
      Description copied from interface: Value
      Convert this Value to a different type using a mapper function.
      Specified by:
      as in interface Value<Object>
      Type Parameters:
      N - type of the returned Value
      Parameters:
      mapper - mapper to map the type of this Value to a type of the returned Value
      Returns:
      a new value with the new type
    • asOptional

      public Optional<Object> asOptional() throws MapperException
      Description copied from interface: Value
      Typed value as Optional. Returns a empty if this value does not have a backing value present. As this class implements all methods of Optional, this is only a utility method if an actual Optional instance is needed (Optional itself is {code final}).
      Specified by:
      asOptional in interface Value<Object>
      Returns:
      value as Optional, empty in case the value does not have a direct value
      Throws:
      MapperException - in case the value cannot be converted to the expected type
      See Also:
    • asBoolean

      public Value<Boolean> asBoolean()
      Description copied from interface: Value
      Boolean typed value.
      Specified by:
      asBoolean in interface Value<Object>
      Returns:
      typed value
    • asString

      public Value<String> asString()
      Description copied from interface: Value
      String typed value.
      Specified by:
      asString in interface Value<Object>
      Returns:
      typed value
    • asInt

      public Value<Integer> asInt()
      Description copied from interface: Value
      Integer typed value.
      Specified by:
      asInt in interface Value<Object>
      Returns:
      typed value
    • asLong

      public Value<Long> asLong()
      Description copied from interface: Value
      Long typed value.
      Specified by:
      asLong in interface Value<Object>
      Returns:
      typed value
    • asDouble

      public Value<Double> asDouble()
      Description copied from interface: Value
      Double typed value.
      Specified by:
      asDouble in interface Value<Object>
      Returns:
      typed value
    • map

      protected <SRC, T> T map(SRC value, GenericType<T> type)
      Map value to target type using Mapper.
      Type Parameters:
      SRC - type of the source value
      T - type of the target value
      Parameters:
      value - source value
      type - target type
      Returns:
      result of the mapping
      Throws:
      MapperException - in case the mapper was not found or failed
    • map

      protected <SRC, T> T map(SRC value, Class<T> type)
      Map value to target type using Mapper. String.valueOf(Object) is used as fallback option when Mapper fails.
      Type Parameters:
      SRC - type of the source value
      T - type of the target value
      Parameters:
      value - source value
      type - target type
      Returns:
      result of the mapping