All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.jdbc.impl.PreparedStatementSetterFactory Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

The newest version!
package org.simpleflatmapper.jdbc.impl;

import org.simpleflatmapper.converter.ContextFactoryBuilder;
import org.simpleflatmapper.jdbc.JdbcColumnKey;

import org.simpleflatmapper.map.mapper.PropertyMapping;
import org.simpleflatmapper.map.setter.ContextualIndexedSetter;
import org.simpleflatmapper.map.setter.ContextualIndexedSetterFactory;
import org.simpleflatmapper.map.setter.ContextualSetter;
import org.simpleflatmapper.map.setter.ContextualSetterFactory;
import org.simpleflatmapper.util.TypeHelper;
import org.simpleflatmapper.jdbc.impl.setter.BooleanPreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.BytePreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.CharacterPreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.DoublePreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.FloatPreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.IntegerPreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.LongPreparedStatementSetter;
import org.simpleflatmapper.jdbc.impl.setter.PreparedStatementSetterImpl;
import org.simpleflatmapper.jdbc.impl.setter.ShortPreparedStatementSetter;

import java.lang.reflect.Type;
import java.sql.*;

public class PreparedStatementSetterFactory implements
        ContextualSetterFactory> {

    public static final PreparedStatementSetterFactory INSTANCE = new PreparedStatementSetterFactory(PreparedStatementIndexedSetterFactory.INSTANCE);

    private final ContextualIndexedSetterFactory> preparedStatementIndexedSetterFactory;

    private PreparedStatementSetterFactory(ContextualIndexedSetterFactory> preparedStatementIndexedSetterFactory) {
        this.preparedStatementIndexedSetterFactory = preparedStatementIndexedSetterFactory;
    }


    @SuppressWarnings("unchecked")
    @Override
    public 

ContextualSetter getSetter(PropertyMapping pm, ContextFactoryBuilder contextFactoryBuilder) { int columnIndex = pm.getColumnKey().getIndex(); Type type = pm.getPropertyMeta().getPropertyType(); Class clazz = TypeHelper.toBoxedClass(type); if (Boolean.class.equals(clazz)) { return (ContextualSetter) new BooleanPreparedStatementSetter(columnIndex); } else if (Byte.class.equals(clazz)) { return (ContextualSetter) new BytePreparedStatementSetter(columnIndex); } else if (Character.class.equals(clazz)) { return (ContextualSetter) new CharacterPreparedStatementSetter(columnIndex); } else if (Short.class.equals(clazz)) { return (ContextualSetter) new ShortPreparedStatementSetter(columnIndex); } else if (Integer.class.equals(clazz)) { return (ContextualSetter) new IntegerPreparedStatementSetter(columnIndex); } else if (Long.class.equals(clazz)) { return (ContextualSetter) new LongPreparedStatementSetter(columnIndex); } else if (Double.class.equals(clazz)) { return (ContextualSetter) new DoublePreparedStatementSetter(columnIndex); } else if (Float.class.equals(clazz)) { return (ContextualSetter) new FloatPreparedStatementSetter(columnIndex); } ContextualIndexedSetter setter = preparedStatementIndexedSetterFactory.getIndexedSetter(pm, contextFactoryBuilder); if (setter != null) { return new PreparedStatementSetterImpl

(columnIndex, setter); } else return null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy