Class MapperBuilder<T>

java.lang.Object
org.apache.ignite.table.mapper.MapperBuilder<T>
Type Parameters:
T - Type of objects the mapper handles.

public final class MapperBuilder<T> extends Object
Mapper builder provides methods for mapping object fields to columns.

By default, the user must explicitly map the required fields to columns in tge one-to-one way using map(java.lang.String, java.lang.String, java.lang.String...) and/or map(String, String, TypeConverter) methods. All missed columns and/or fields become unmapped, and will be ignored during further table operations.

Calling automap() method maps all matching fields to columns by name. Any fields that don't match a column by name are ignored.

Note: Teh builder cannot be reused after the build() method is called.

  • Method Details

    • map

      public MapperBuilder<T> map(String fieldName, String columnName, String... fieldColumnPairs)
      Maps a field to a column.
      Parameters:
      fieldName - Field name.
      columnName - Column name in SQL-parser style notation, e.g., "myColumn" - column named "MYCOLUMN", "\"MyColumn\"" - "MyColumn", etc.
      fieldColumnPairs - Vararg that accepts (fieldName, columnName) pairs; column names must use SQL-parser style notation like columnName parameter.
      Returns:
      this for chaining.
      Throws:
      IllegalArgumentException - If a field name has no matching column name in fieldColumnPairs, or if a column was already mapped to another field.
      IllegalStateException - if an attempt is made to reuse the builder after a mapping has been built.
    • map

      public <ObjectT, ColumnT> MapperBuilder<T> map(String fieldName, String columnName, TypeConverter<ObjectT,ColumnT> converter)
      Maps a field to a column using a type converter. The value is converted before "write to" and after "read from" column using the provided converter.
      Type Parameters:
      ObjectT - Value type. Must match the object field type if the individual field is mapped to a given column.
      ColumnT - Column type.
      Parameters:
      fieldName - Field name.
      columnName - Column name in SQL-parser style notation, e.g., "myColumn" - column named "MYCOLUMN", "\"MyColumn\"" - "MyColumn", etc.
      converter - Converter for objects of MapperBuilder and MapperBuilder.
    • convert

      public <ObjectT, ColumnT> MapperBuilder<T> convert(String columnName, TypeConverter<ObjectT,ColumnT> converter)
      Sets a converter for a column whose value must be converted before "write to" and after "read from".
      Type Parameters:
      ObjectT - Value type. Must match either the object field type if the field is mapped to a given column, or the object type MapperBuilder
      ColumnT - Column type.
      Parameters:
      columnName - Column name in SQL-parser style notation, e.g., "myColumn" - column named "MYCOLUMN", "\"MyColumn\"" - "MyColumn", etc.
      converter - Converter for objects of MapperBuilder and MapperBuilder.
    • automap

      public MapperBuilder<T> automap()
      Maps all matching fields to columns by name. Fields that don't match a column by name are ignored.
      Returns:
      this for chaining.
    • build

      public Mapper<T> build()
      Builds a mapper.
      Returns:
      Mapper.
      Throws:
      IllegalStateException - if nothing was mapped or if more than one column was mapped to the same field.