Search in sources :

Example 6 with FieldMapperColumnDefinition

use of org.simpleflatmapper.map.property.FieldMapperColumnDefinition in project SimpleFlatMapper by arnaudroger.

the class PropertyMappingsBuilderTest method testSelfPropertyInvalidation.

@Test
public void testSelfPropertyInvalidation() {
    final ClassMeta<DbObject> classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
    MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
    PropertyMappingsBuilder<DbObject, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> builder = PropertyMappingsBuilder.of(classMeta, MapperConfig.<SampleFieldKey>fieldMapperConfig().mapperBuilderErrorHandler(errorHandler), ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
    builder.addProperty(new SampleFieldKey("self", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    verify(errorHandler, never()).customFieldError(any(FieldKey.class), any(String.class));
    verify(errorHandler, never()).accessorNotFound(any(String.class));
    verify(errorHandler, never()).propertyNotFound(any(Type.class), any(String.class));
    builder.addProperty(new SampleFieldKey("id", 1), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    verify(errorHandler).propertyNotFound(DbObject.class, "self");
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) Type(java.lang.reflect.Type) IgnoreMapperBuilderErrorHandler(org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler) MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) DbObject(org.simpleflatmapper.test.beans.DbObject) FieldKey(org.simpleflatmapper.map.FieldKey) Test(org.junit.Test)

Example 7 with FieldMapperColumnDefinition

use of org.simpleflatmapper.map.property.FieldMapperColumnDefinition in project SimpleFlatMapper by arnaudroger.

the class CsvWriterBuilder method newBuilder.

public static <T> CsvWriterBuilder<T> newBuilder(ClassMeta<T> classMeta, CellWriter cellWriter) {
    MapperConfig<CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> config = MapperConfig.<CsvColumnKey>fieldMapperConfig();
    FieldMapperToAppendableFactory appenderFactory = new FieldMapperToAppendableFactory(cellWriter);
    CsvWriterBuilder<T> builder = new CsvWriterBuilder<T>(classMeta, config, appenderFactory, cellWriter);
    return builder;
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) FieldMapperToAppendableFactory(org.simpleflatmapper.csv.mapper.FieldMapperToAppendableFactory)

Example 8 with FieldMapperColumnDefinition

use of org.simpleflatmapper.map.property.FieldMapperColumnDefinition in project SimpleFlatMapper by arnaudroger.

the class CsvWriter method from.

/**
 * Create a DSL on the specified type.
 * @param type the type of object to write
 * @param <T> the type
 * @return a DSL on the specified type
 */
public static <T> CsvWriterDSL<T> from(Type type) {
    ClassMeta<T> classMeta = ReflectionService.newInstance().getClassMeta(type);
    CellWriter cellWriter = CsvCellWriter.DEFAULT_WRITER;
    CsvWriterBuilder<T> builder = CsvWriterBuilder.newBuilder(classMeta, cellWriter);
    MapperConfig<CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> mapperConfig = MapperConfig.<CsvColumnKey>fieldMapperConfig();
    try {
        String[] headers = defaultHeaders(classMeta);
        for (String header : headers) {
            builder.addColumn(header);
        }
        ContextualMapper<T, Appendable> mapper = (ContextualMapper<T, Appendable>) builder.mapper();
        return new DefaultCsvWriterDSL<T>(CsvWriter.<T>toColumnDefinitions(headers), cellWriter, mapper, classMeta, mapperConfig, false);
    } catch (UnsupportedOperationException e) {
        return new NoColumnCsvWriterDSL<T>(cellWriter, classMeta, mapperConfig, false);
    }
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) ContextualMapper(org.simpleflatmapper.map.mapper.ContextualMapper) CsvCellWriter(org.simpleflatmapper.csv.impl.writer.CsvCellWriter)

Example 9 with FieldMapperColumnDefinition

use of org.simpleflatmapper.map.property.FieldMapperColumnDefinition in project SimpleFlatMapper by arnaudroger.

the class ResultSetFieldMapperFactoryTest method testPrimitiveField.

@Test
public void testPrimitiveField() {
    ClassMeta<DbObject> classMeta = ReflectionService.newInstance(false).getClassMeta(DbObject.class);
    PropertyMeta<DbObject, Long> id = classMeta.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()).<Long>findProperty(new DefaultPropertyNameMatcher("id", 0, false, false), new Object[0]);
    FieldMapperColumnDefinition<JdbcColumnKey> identity = FieldMapperColumnDefinition.identity();
    PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>> propertyMapping = new PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>>(id, new JdbcColumnKey("id", 1), identity);
    FieldMapper<ResultSet, DbObject> fieldMapper = factory.newFieldMapper(propertyMapping, null, RethrowMapperBuilderErrorHandler.INSTANCE);
    assertTrue(fieldMapper instanceof LongFieldMapper);
    PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>> propertyMapping1 = new PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>>(id, new JdbcColumnKey("id", 0), identity);
    fieldMapper = factory.newFieldMapper(propertyMapping1, null, RethrowMapperBuilderErrorHandler.INSTANCE);
    assertTrue(fieldMapper instanceof LongFieldMapper);
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) LongFieldMapper(org.simpleflatmapper.map.fieldmapper.LongFieldMapper) DbObject(org.simpleflatmapper.test.beans.DbObject) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) JdbcColumnKey(org.simpleflatmapper.jdbc.JdbcColumnKey) PropertyMapping(org.simpleflatmapper.map.mapper.PropertyMapping) ResultSet(java.sql.ResultSet) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) Test(org.junit.Test)

Example 10 with FieldMapperColumnDefinition

use of org.simpleflatmapper.map.property.FieldMapperColumnDefinition in project SimpleFlatMapper by arnaudroger.

the class DatastaxUDTGetter method newFieldMapperBuilder.

public static <P> ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey> newFieldMapperBuilder(DatastaxMapperFactory factory, Type target) {
    MapperConfig<DatastaxColumnKey, FieldMapperColumnDefinition<DatastaxColumnKey>> config = factory.mapperConfig();
    MapperSourceImpl<GettableByIndexData, DatastaxColumnKey> mapperSource = new MapperSourceImpl<GettableByIndexData, DatastaxColumnKey>(GettableByIndexData.class, new RowGetterFactory(factory));
    ClassMeta<P> classMeta = factory.getClassMeta(target);
    return new ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey>(mapperSource, classMeta, config, new DatastaxMappingContextFactoryBuilder(), DatastaxMapperBuilder.KEY_FACTORY);
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) GettableByIndexData(com.datastax.driver.core.GettableByIndexData) DatastaxMappingContextFactoryBuilder(org.simpleflatmapper.datastax.impl.DatastaxMappingContextFactoryBuilder) MapperSourceImpl(org.simpleflatmapper.map.mapper.MapperSourceImpl) RowGetterFactory(org.simpleflatmapper.datastax.impl.RowGetterFactory) DatastaxColumnKey(org.simpleflatmapper.datastax.DatastaxColumnKey) ConstantSourceMapperBuilder(org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder)

Aggregations

FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)20 Test (org.junit.Test)8 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)6 PropertyMapping (org.simpleflatmapper.map.mapper.PropertyMapping)5 PropertyMeta (org.simpleflatmapper.reflect.meta.PropertyMeta)5 FieldMapper (org.simpleflatmapper.map.FieldMapper)4 DbObject (org.simpleflatmapper.test.beans.DbObject)4 Type (java.lang.reflect.Type)3 ArrayList (java.util.ArrayList)3 MappingContext (org.simpleflatmapper.map.MappingContext)3 MappingContextFactoryBuilder (org.simpleflatmapper.map.context.MappingContextFactoryBuilder)3 MapperFieldMapper (org.simpleflatmapper.map.fieldmapper.MapperFieldMapper)3 AbstractMapperFactory (org.simpleflatmapper.map.mapper.AbstractMapperFactory)3 Getter (org.simpleflatmapper.reflect.Getter)3 CsvColumnKey (org.simpleflatmapper.csv.CsvColumnKey)2 DatastaxColumnKey (org.simpleflatmapper.datastax.DatastaxColumnKey)2 FieldKey (org.simpleflatmapper.map.FieldKey)2 IgnoreMapperBuilderErrorHandler (org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler)2 MapperBuilderErrorHandler (org.simpleflatmapper.map.MapperBuilderErrorHandler)2 MapperBuildingException (org.simpleflatmapper.map.MapperBuildingException)2