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 TypeMethodDescriptiondefault 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.Maps source rows to target rows.default boolean
Returns true if the map method can filter out rows, which is true by default.default QueryPlan
plan
(QueryPlan.Mapper plan) Override this method to customize the mapper's query plan.default String
Returns a comma-separated list of source columns which are needed by thisMapper
.
-
Method Details
-
map
Maps source rows to target rows.- Parameters:
source
- never nulltarget
- never null; all columns are initially unset- Returns:
- null if filtered out
- Throws:
IOException
-
performsFiltering
default boolean performsFiltering()Returns true if the map method can filter out rows, which is true by default. If the map method never performs filtering, then false should be returned to allow sort operations to be pushed to the source table whenever possible. -
checkStore
Checks if the given source row can be stored into the source table. By default, aViewConstraintException
is always thrown.- Parameters:
row
- all required columns are guaranteed to be set- Throws:
ViewConstraintException
-
checkUpdate
Checks if the given source row can be updated into the source table. By default, aViewConstraintException
is always thrown.- Parameters:
row
- only the primary key columns are guaranteed to be set- Throws:
ViewConstraintException
-
checkDelete
Checks if the given source row can be deleted from the source table. By default, aViewConstraintException
is always thrown.- Parameters:
row
- only the primary key columns are guaranteed to be set- Throws:
ViewConstraintException
-
sourceProjection
Returns a comma-separated list of source columns which are needed by thisMapper
. Null is returned by default, which indicates that all columns are needed. The implementation of this method must return a static constant. -
plan
Override this method to customize the mapper's query plan.- Parameters:
plan
- original plan- Returns:
- original or replacement plan
-