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

org.simpleflatmapper.jdbc.property.IndexedSetterFactoryProperty Maven / Gradle / Ivy

Go to download

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

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.jdbc.property;


import org.simpleflatmapper.map.property.SetterFactoryProperty;
import org.simpleflatmapper.map.mapper.PropertyMapping;
import org.simpleflatmapper.reflect.IndexedSetter;
import org.simpleflatmapper.reflect.IndexedSetterFactory;
import org.simpleflatmapper.reflect.Setter;
import org.simpleflatmapper.reflect.SetterFactory;
import org.simpleflatmapper.util.TypeHelper;

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

public class IndexedSetterFactoryProperty extends SetterFactoryProperty {
    private final IndexedSetterFactory setterFactory;

    public IndexedSetterFactoryProperty(final IndexedSetterFactory setterFactory) {
        this(setterFactory, getTargetType(setterFactory));
    }

    public IndexedSetterFactoryProperty(final IndexedSetterFactory setterFactory, Type targetType) {
        super(getSetterFactory(setterFactory), targetType);
        this.setterFactory = setterFactory;
    }

    private static  SetterFactory getSetterFactory(final IndexedSetterFactory setterFactory) {
        return new SetterFactory() {
            @Override
            public 

Setter getSetter(A arg) { final int index = ((PropertyMapping)arg).getColumnKey().getIndex(); final IndexedSetter setter = setterFactory.getIndexedSetter(arg); if (setter != null) { return new Setter() { @Override public void set(PreparedStatement target, P value) throws Exception { setter.set(target, value, index); } }; } return null; } }; } public IndexedSetterFactory getIndexedSetterFactory() { return setterFactory; } @Override public String toString() { return "IndexedSetterFactory{IndexedSetterFactory}"; } private static Type getTargetType(IndexedSetterFactory setterFactory) { Type[] types = TypeHelper.getGenericParameterForClass(setterFactory.getClass(), IndexedSetterFactory.class); return types != null ? types[0] : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy