Search in sources :

Example 1 with OneColumnMapper

use of org.apache.ignite.table.mapper.OneColumnMapper in project ignite-3 by apache.

the class Marshaller method simpleMarshaller.

/**
 * Creates a marshaller for class.
 *
 * @param cols   Columns.
 * @param mapper Mapper.
 * @return Marshaller.
 */
static <T> SimpleMarshaller simpleMarshaller(Column[] cols, @NotNull OneColumnMapper<T> mapper) {
    final Class<T> targetType = mapper.targetType();
    Column col = (mapper.mappedColumn() == null && cols.length == 1) ? cols[0] : Arrays.stream(cols).filter(c -> c.name().equals(mapper.mappedColumn())).findFirst().orElseThrow(() -> new SchemaMismatchException("Failed to map object to a single column:" + mapper.mappedColumn()));
    assert !targetType.isPrimitive() : "Non-nullable types are not allowed.";
    return new SimpleMarshaller(ColumnBinding.createIdentityBinding(col, targetType, mapper.converter()));
}
Also used : OneColumnMapper(org.apache.ignite.table.mapper.OneColumnMapper) Arrays(java.util.Arrays) MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException) Factory(org.apache.ignite.internal.util.Factory) Objects(java.util.Objects) PojoMapper(org.apache.ignite.table.mapper.PojoMapper) Nullable(org.jetbrains.annotations.Nullable) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) Row(org.apache.ignite.internal.schema.row.Row) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Mapper(org.apache.ignite.table.mapper.Mapper) NotNull(org.jetbrains.annotations.NotNull) SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException) Column(org.apache.ignite.internal.schema.Column)

Aggregations

Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Column (org.apache.ignite.internal.schema.Column)1 SchemaMismatchException (org.apache.ignite.internal.schema.SchemaMismatchException)1 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)1 Row (org.apache.ignite.internal.schema.row.Row)1 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)1 Factory (org.apache.ignite.internal.util.Factory)1 ObjectFactory (org.apache.ignite.internal.util.ObjectFactory)1 Mapper (org.apache.ignite.table.mapper.Mapper)1 OneColumnMapper (org.apache.ignite.table.mapper.OneColumnMapper)1 PojoMapper (org.apache.ignite.table.mapper.PojoMapper)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1