use of org.simpleflatmapper.reflect.SetterFactory in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactory method setterFromFactory.
@SuppressWarnings("unchecked")
private <S, P> Setter<Appendable, ? super P> setterFromFactory(PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> pm) {
Setter<Appendable, ? super P> setter = null;
final SetterFactoryProperty setterFactoryProperty = pm.getColumnDefinition().lookFor(SetterFactoryProperty.class);
if (setterFactoryProperty != null) {
final SetterFactory<Appendable, PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>>> setterFactory = (SetterFactory<Appendable, PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>>>) setterFactoryProperty.getSetterFactory();
setter = setterFactory.getSetter(pm);
}
if (setter == null) {
if (!pm.getPropertyMeta().isSelf()) {
final ClassMeta<P> classMeta = pm.getPropertyMeta().getPropertyClassMeta();
if (classMeta instanceof ObjectClassMeta) {
ObjectClassMeta<P> ocm = (ObjectClassMeta<P>) classMeta;
if (ocm.getNumberOfProperties() == 1) {
PropertyMeta<P, ?> subProp = ocm.getFirstProperty();
Setter<Appendable, Object> subSetter = (Setter<Appendable, Object>) setterFromFactory(pm.propertyMeta(subProp));
if (subSetter != null) {
setter = new SetterOnGetter<Appendable, Object, P>(subSetter, (Getter<P, Object>) subProp.getGetter());
} else {
return new ObjectToStringSetter<P>(subProp.getGetter());
}
}
}
}
}
return setter;
}
use of org.simpleflatmapper.reflect.SetterFactory in project SimpleFlatMapper by arnaudroger.
the class PreparedStatementFieldMapperFactoryTest method testCustomSetterFactory.
@Test
public void testCustomSetterFactory() throws Exception {
Object o = new Object();
newFieldMapperAndMapToPS(new ConstantGetter<Object, Object>(o), Object.class, new SetterFactoryProperty(new SetterFactory<PreparedStatement, PropertyMapping<?, ?, ?, ?>>() {
@Override
public <P> Setter<PreparedStatement, P> getSetter(PropertyMapping<?, ?, ?, ?> arg) {
return new Setter<PreparedStatement, P>() {
@Override
public void set(PreparedStatement target, P value) throws Exception {
ps.setString(36, "bb");
}
};
}
}));
verify(ps).setString(36, "bb");
}
Aggregations