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");
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations