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

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

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.Setter;
import org.simpleflatmapper.reflect.SetterFactory;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class IndexedSetterProperty extends SetterFactoryProperty {

    private final IndexedSetter setter;

    public 

IndexedSetterProperty(final IndexedSetter setter) { super(new SetterFactory() { @SuppressWarnings("unchecked") @Override public Setter getSetter(Object arg) { final int index = ((PropertyMapping)arg).getColumnKey().getIndex(); return new Setter() { @Override public void set(PreparedStatement target, PP value) throws Exception { setter.set(target, (P) value, index); } }; } }, PreparedStatement.class); this.setter = setter; } public static IndexedSetterProperty of(final PreparedStatementSetter setter) { return new IndexedSetterProperty(new IndexedSetter() { @Override public void set(PreparedStatement target, T value, int index) throws Exception { setter.set(target, index, value); } }); } public IndexedSetter getIndexedSetter() { return setter; } @Override public String toString() { return "IndexedSetter{IndexedSetter}"; } public interface PreparedStatementSetter { void set(PreparedStatement ps, int i, T val) throws SQLException; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy