use of org.simpleflatmapper.converter.Context in project SimpleFlatMapper by arnaudroger.
the class AbstractBatchInsertQueryExecutor method bindTo.
private void bindTo(PreparedStatement preparedStatement, Collection<T> values) throws Exception {
int i = 0;
Context context = contextFactory.newContext();
for (T value : values) {
for (MultiIndexFieldMapper<T> multiIndexFieldMapper : multiIndexFieldMappers) {
multiIndexFieldMapper.map(preparedStatement, value, i, context);
i++;
}
}
}
use of org.simpleflatmapper.converter.Context in project SimpleFlatMapper by arnaudroger.
the class ConvertDelegateSetterTest method testSet.
@Test
public void testSet() throws Exception {
ConvertDelegateSetter<DbObject, UUID, String> setter = new ConvertDelegateSetter<DbObject, UUID, String>(new Setter<DbObject, String>() {
@Override
public void set(DbObject target, String value) throws Exception {
target.setName(value);
}
}, new ContextualConverter<UUID, String>() {
@Override
public String convert(UUID in, Context context) throws Exception {
return in.toString();
}
});
DbObject o = new DbObject();
UUID uuid = UUID.randomUUID();
setter.set(o, uuid);
assertEquals(uuid.toString(), o.getName());
}
use of org.simpleflatmapper.converter.Context in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testErrorHandlers.
@Test
public void testErrorHandlers() {
MapperFactory mapperFactory = new MapperFactory();
FieldMapperErrorHandler<SampleFieldKey> fieldMapperErrorHandler = new FieldMapperErrorHandler<SampleFieldKey>() {
@Override
public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error, Context mappingContext) throws MappingException {
}
};
MapperBuilderErrorHandler mapperBuilderErrorHandler = new MapperBuilderErrorHandler() {
@Override
public void accessorNotFound(String msg) {
}
@Override
public void propertyNotFound(Type target, String property) {
}
@Override
public void customFieldError(FieldKey<?> key, String message) {
}
};
ConsumerErrorHandler consumerErrorHandler = new ConsumerErrorHandler() {
@Override
public void handlerError(Throwable error, Object target) {
}
};
mapperFactory.fieldMapperErrorHandler(fieldMapperErrorHandler);
mapperFactory.mapperBuilderErrorHandler(mapperBuilderErrorHandler);
mapperFactory.consumerErrorHandler(consumerErrorHandler);
MapperConfig<SampleFieldKey, Object[]> mapperConfig = mapperFactory.mapperConfig();
assertEquals(fieldMapperErrorHandler, mapperConfig.fieldMapperErrorHandler());
assertEquals(mapperBuilderErrorHandler, mapperConfig.mapperBuilderErrorHandler());
assertEquals(consumerErrorHandler, mapperConfig.consumerErrorHandler());
Assert.assertEquals(consumerErrorHandler, mapperFactory.consumerErrorHandler());
}
use of org.simpleflatmapper.converter.Context in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testFieldMapperErrorHandler.
@Test
public void testFieldMapperErrorHandler() throws Exception {
ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = ConstantSourceMapperBuilder.<Object, MyObjectWithInner, SampleFieldKey>newConstantSourceMapperBuilder(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()).fieldMapperErrorHandler(new FieldMapperErrorHandler<SampleFieldKey>() {
@Override
public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error, Context mappingContext) throws MappingException {
}
}), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null, true), SampleFieldKey.KEY_FACTORY);
constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 16), FieldMapperColumnDefinition.<SampleFieldKey>identity());
SourceMapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
MyObjectWithInner o = mapper.map(null, null);
System.out.println("mapper = " + mapper);
assertNull(o.prop.date);
}
use of org.simpleflatmapper.converter.Context in project SimpleFlatMapper by arnaudroger.
the class KeyTupleQueryPreparer method bindTo.
public void bindTo(Collection<T> values, PreparedStatement ps, int offset) {
int index = offset;
Context context = contextFactory.newContext();
for (T value : values) {
for (MultiIndexFieldMapper<T> mapper : multiIndexFieldMappers) {
try {
mapper.map(ps, value, index, context);
} catch (Exception e) {
ErrorHelper.rethrow(e);
}
index++;
}
}
}
Aggregations