use of org.simpleflatmapper.converter.Converter in project SimpleFlatMapper by arnaudroger.
the class DiscriminatorJdbcBuilder method mapper.
/**
* @return a new jdbcMapper based on the current state
*/
public JdbcMapper<T> mapper() {
List<DiscriminatorMapper.PredicatedMapper<ResultSet, ResultSet, T, SQLException>> mappers = new ArrayList<DiscriminatorMapper.PredicatedMapper<ResultSet, ResultSet, T, SQLException>>();
for (DiscriminatorJdbcSubBuilder subBuilder : builders) {
JdbcMapper<T> mapper = subBuilder.createMapper();
Predicate<ResultSet> predicate = new ResultSetDiscriminatorPredicate(column, subBuilder.predicate);
mappers.add(new DiscriminatorMapper.PredicatedMapper<ResultSet, ResultSet, T, SQLException>(predicate, mapper, mapper));
}
DiscriminatorJdbcMapper<T> discriminatorMapper = new DiscriminatorJdbcMapper<T>(mappers, new UnaryFactory<ResultSet, Enumarable<ResultSet>>() {
@Override
public Enumarable<ResultSet> newInstance(ResultSet resultSet) {
return new ResultSetEnumarable(resultSet);
}
}, UncheckedConverterHelper.<ResultSet, String>toUnchecked(new Converter<ResultSet, String>() {
@Override
public String convert(ResultSet in) throws SQLException {
return column + ":" + in.getObject(column);
}
}), jdbcMapperFactory.consumerErrorHandler());
return discriminatorMapper;
}
use of org.simpleflatmapper.converter.Converter in project SimpleFlatMapper by arnaudroger.
the class AbstractMultiFormatConverterFactory method newConverter.
@SuppressWarnings("unchecked")
@Override
public Converter<? super I, ? extends O> newConverter(ConvertingTypes targetedTypes, Object... params) {
DateTimeFormatter[] dateTimeFormatters = JodaTimeHelper.getDateTimeFormatters(params);
DateTimeZone zoneId = JodaTimeHelper.getDateTimeZoneOrDefault(params);
Converter<I, O>[] converters = new Converter[dateTimeFormatters.length];
for (int i = 0; i < dateTimeFormatters.length; i++) {
DateTimeFormatter dateTimeFormatter = dateTimeFormatters[i];
if (dateTimeFormatter.getZone() == null) {
dateTimeFormatter.withZone(zoneId);
}
converters[i] = newConverter(dateTimeFormatter);
}
if (converters.length == 1) {
return converters[0];
} else {
return new MultiDateTimeFormatterConverter<I, O>(converters);
}
}
use of org.simpleflatmapper.converter.Converter in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceFieldMapperFactoryImpl method getGettetInstantiator.
private <T, P> Getter<? super S, ? extends P> getGettetInstantiator(ClassMeta<P> classMeta, InstantiatorDefinition id, K key, FieldMapperColumnDefinition<K> columnDefinition, Collection<Type> types) {
Instantiator<? super T, ? extends P> instantiator = classMeta.getReflectionService().getInstantiatorFactory().getOneArgIdentityInstantiator(id, classMeta.getReflectionService().builderIgnoresNullValues());
final Type paramType = id.getParameters()[0].getGenericType();
Getter<? super S, ? extends T> subGetter = getterFactory.newGetter(paramType, key, columnDefinition);
if (subGetter == null) {
if (types.contains(paramType)) {
// loop circuit cutter
return null;
}
types.add(paramType);
// converter?
Type sourceType = key.getType(paramType);
Converter converter = converterService.findConverter(sourceType, paramType, columnDefinition.properties());
if (converter != null) {
Getter sourceTypeGetter = getterFactory.newGetter(sourceType, key, columnDefinition);
subGetter = new GetterWithConverter(converter, sourceTypeGetter);
} else {
subGetter = lookForInstantiatorGetter(classMeta.getReflectionService().<T>getClassMeta(paramType), key, columnDefinition, types);
}
}
if (subGetter != null) {
return new InstantiatorGetter<T, S, P>(instantiator, subGetter);
} else
return null;
}
Aggregations