Interface Mapper<R,T>


public interface Mapper<R,T>
Interface for mapping source rows to target rows. Inverse mapping is optional, but it's necessary for supporting modifiable views, and it's also used by the query optimizer. Mapper implementations must be thread-safe.

For supporting inverse mapping, define a public static method for each target column which can be mapped to a source column. The naming pattern must be <target_name>_to_<source_name>, and the method must be a pure function. The parameter type must exactly match the target column type, and the return type must exactly match the source column type. If the function doesn't transform the column value, then it should be annotated with @Untransformed, since it helps with query optimization.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    checkDelete(Table<R> table, R row)
    Checks if the given source row can be deleted from the source table.
    default void
    checkStore(Table<R> table, R row)
    Checks if the given source row can be stored into the source table.
    default void
    checkUpdate(Table<R> table, R row)
    Checks if the given source row can be updated into the source table.
    map(R source, T target)
    Maps source rows to target rows.
    default QueryPlan
    Override this method to customize the mapper's query plan.
    default String
    Returns a comma-separated list of source columns which are needed by this Mapper.
  • Method Details

    • map

      T map(R source, T target) throws IOException
      Maps source rows to target rows.
      Parameters:
      source - never null
      target - never null; all columns are initially unset
      Returns:
      null if filtered out
      Throws:
      IOException
    • checkStore

      default void checkStore(Table<R> table, R row) throws ViewConstraintException
      Checks if the given source row can be stored into the source table. By default, a ViewConstraintException is always thrown.
      Parameters:
      row - all required columns are guaranteed to be set
      Throws:
      ViewConstraintException
    • checkUpdate

      default void checkUpdate(Table<R> table, R row) throws ViewConstraintException
      Checks if the given source row can be updated into the source table. By default, a ViewConstraintException is always thrown.
      Parameters:
      row - only the primary key columns are guaranteed to be set
      Throws:
      ViewConstraintException
    • checkDelete

      default void checkDelete(Table<R> table, R row) throws ViewConstraintException
      Checks if the given source row can be deleted from the source table. By default, a ViewConstraintException is always thrown.
      Parameters:
      row - only the primary key columns are guaranteed to be set
      Throws:
      ViewConstraintException
    • sourceProjection

      default String sourceProjection()
      Returns a comma-separated list of source columns which are needed by this Mapper. Null is returned by default, which indicates that all columns are needed. The implementation of this method must return a static constant.
    • plan

      default QueryPlan plan(QueryPlan.Mapper plan)
      Override this method to customize the mapper's query plan.
      Parameters:
      plan - original plan
      Returns:
      original or replacement plan