Search in sources :

Example 1 with PreparedStatementSetterImpl

use of org.simpleflatmapper.jdbc.impl.setter.PreparedStatementSetterImpl 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;
}
Also used : BooleanPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.BooleanPreparedStatementSetter) FloatPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.FloatPreparedStatementSetter) Type(java.lang.reflect.Type) DoublePreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.DoublePreparedStatementSetter) BytePreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.BytePreparedStatementSetter) ShortPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.ShortPreparedStatementSetter) PreparedStatementSetterImpl(org.simpleflatmapper.jdbc.impl.setter.PreparedStatementSetterImpl) ShortPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.ShortPreparedStatementSetter) DoublePreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.DoublePreparedStatementSetter) IndexedSetter(org.simpleflatmapper.reflect.IndexedSetter) BooleanPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.BooleanPreparedStatementSetter) Setter(org.simpleflatmapper.reflect.Setter) CharacterPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.CharacterPreparedStatementSetter) BytePreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.BytePreparedStatementSetter) IntegerPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.IntegerPreparedStatementSetter) FloatPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.FloatPreparedStatementSetter) LongPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.LongPreparedStatementSetter) IntegerPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.IntegerPreparedStatementSetter) LongPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.LongPreparedStatementSetter) CharacterPreparedStatementSetter(org.simpleflatmapper.jdbc.impl.setter.CharacterPreparedStatementSetter)

Aggregations

Type (java.lang.reflect.Type)1 BooleanPreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.BooleanPreparedStatementSetter)1 BytePreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.BytePreparedStatementSetter)1 CharacterPreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.CharacterPreparedStatementSetter)1 DoublePreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.DoublePreparedStatementSetter)1 FloatPreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.FloatPreparedStatementSetter)1 IntegerPreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.IntegerPreparedStatementSetter)1 LongPreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.LongPreparedStatementSetter)1 PreparedStatementSetterImpl (org.simpleflatmapper.jdbc.impl.setter.PreparedStatementSetterImpl)1 ShortPreparedStatementSetter (org.simpleflatmapper.jdbc.impl.setter.ShortPreparedStatementSetter)1 IndexedSetter (org.simpleflatmapper.reflect.IndexedSetter)1 Setter (org.simpleflatmapper.reflect.Setter)1