use of org.simpleflatmapper.reflect.Setter 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");
}
use of org.simpleflatmapper.reflect.Setter in project SimpleFlatMapper by arnaudroger.
the class PreparedStatementSetterFactory method getSetter.
@SuppressWarnings("unchecked")
@Override
public <P> Setter<PreparedStatement, P> getSetter(PropertyMapping<?, ?, JdbcColumnKey, ? extends ColumnDefinition<JdbcColumnKey, ?>> pm) {
int columnIndex = pm.getColumnKey().getIndex();
Type type = pm.getPropertyMeta().getPropertyType();
Class<?> clazz = TypeHelper.toBoxedClass(type);
if (Boolean.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new BooleanPreparedStatementSetter(columnIndex);
} else if (Byte.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new BytePreparedStatementSetter(columnIndex);
} else if (Character.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new CharacterPreparedStatementSetter(columnIndex);
} else if (Short.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new ShortPreparedStatementSetter(columnIndex);
} else if (Integer.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new IntegerPreparedStatementSetter(columnIndex);
} else if (Long.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new LongPreparedStatementSetter(columnIndex);
} else if (Double.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new DoublePreparedStatementSetter(columnIndex);
} else if (Float.class.equals(clazz)) {
return (Setter<PreparedStatement, P>) new FloatPreparedStatementSetter(columnIndex);
}
IndexedSetter<PreparedStatement, P> setter = preparedStatementIndexedSetterFactory.getIndexedSetter(pm);
if (setter != null) {
return new PreparedStatementSetterImpl<P>(columnIndex, setter);
} else
return null;
}
Aggregations