use of org.simpleflatmapper.map.fieldmapper.FieldMapperGetterWithConverter in project SimpleFlatMapper by arnaudroger.
the class SqlParameterSourceBuilder method build.
private <P> PlaceHolderValueGetter<T> build(JdbcColumnKey key, PropertyMapping<T, P, JdbcColumnKey> pm) {
if (pm != null) {
int parameterType = getParameterType(pm);
ContextualGetter<T, ? extends P> getter = ContextualGetterAdapter.of(pm.getPropertyMeta().getGetter());
// need conversion ?
final DefaultContextFactoryBuilder contextFactoryBuilder = new DefaultContextFactoryBuilder();
Type propertyType = pm.getPropertyMeta().getPropertyType();
Class<?> sqlType = JdbcTypeHelper.toJavaType(parameterType, propertyType);
boolean findConverter = false;
for (ConverterProperty cp : pm.getColumnDefinition().lookForAll(ConverterProperty.class)) {
if (TypeHelper.isAssignable(cp.inType, propertyType)) {
getter = new FieldMapperGetterWithConverter(cp.function, getter);
findConverter = true;
break;
}
}
if (!findConverter && !TypeHelper.isAssignable(sqlType, propertyType)) {
ContextualConverter<? super Object, ?> converter = ConverterService.getInstance().findConverter(propertyType, sqlType, contextFactoryBuilder);
if (converter != null) {
getter = new FieldMapperGetterWithConverter(converter, getter);
}
}
return new PlaceHolderValueGetter<T>(pm.getColumnKey().getOrginalName(), parameterType, null, getter, contextFactoryBuilder.build());
} else {
return new PlaceHolderValueGetter<T>(key.getOrginalName(), key.getSqlType(null), null, NullContextualGetter.<T, P>getter(), EmptyContextFactory.INSTANCE);
}
}
Aggregations