Class MappingProjection<T>

Type Parameters:
T - expression type
All Implemented Interfaces:
Expression<T>, FactoryExpression<T>, Serializable

@Immutable public abstract class MappingProjection<T> extends FactoryExpressionBase<T>
Projection template that allows implementing arbitrary mapping of rows to result objects.

Example


 MappingProjection<Pair<String, String>> mapping = new MappingProjection<Pair<String, String>>(Pair.class, str1, str2) {
     @Override
     protected Pair<String, String> map(Tuple row) {
          return Pair.of(row.get(str1), row.get(str2));
     }
 };
 
See Also:
  • Constructor Details

    • MappingProjection

      public MappingProjection(Class<? super T> type, Expression<?>... args)
      Create a new MappingProjection instance
      Parameters:
      type -
      args -
    • MappingProjection

      public MappingProjection(Class<? super T> type, Expression<?>[]... args)
      Create a new MappingProjection instance
      Parameters:
      type -
      args -
  • Method Details

    • newInstance

      public T newInstance(Object... values)
      Description copied from interface: FactoryExpression
      Create a projection with the given arguments
      Parameters:
      values - row arguments
      Returns:
      constructed value
    • map

      protected abstract T map(Tuple row)
      Creates a result object from the given row.
      Parameters:
      row - The row to map
      Returns:
      The result object
    • getArgs

      public List<Expression<?>> getArgs()
      Description copied from interface: FactoryExpression
      Get the invocation arguments
      Returns:
      argument expressions
    • accept

      public <R, C> R accept(Visitor<R,C> v, @Nullable C context)
      Description copied from interface: Expression
      Accept the visitor with the given context
      Type Parameters:
      R - return type
      C - context type
      Parameters:
      v - visitor
      context - context of visit
      Returns:
      result of visit