org.simpleflatmapper.jdbc.impl.MapperQueryPreparer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-jdbc Show documentation
Show all versions of sfm-jdbc Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.jdbc.impl;
import org.simpleflatmapper.jdbc.QueryBinder;
import org.simpleflatmapper.jdbc.QueryPreparer;
import org.simpleflatmapper.jdbc.SizeSupplier;
import org.simpleflatmapper.jdbc.named.NamedSqlQuery;
import org.simpleflatmapper.map.Mapper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class MapperQueryPreparer implements QueryPreparer {
private final NamedSqlQuery query;
private final Mapper mapper;
private final String[] generatedKeys;
public MapperQueryPreparer(NamedSqlQuery query, Mapper mapper, String[] generatedKeys) {
this.query = query;
this.mapper = mapper;
this.generatedKeys = generatedKeys;
}
@Override
public QueryBinder prepare(Connection connection) throws SQLException {
return new MapperQueryBinder(this, connection);
}
@Override
public PreparedStatement prepareStatement(Connection connection) throws SQLException {
return generatedKeys != null ? connection.prepareStatement(query.toSqlQuery(), generatedKeys) : connection.prepareStatement(query.toSqlQuery());
}
@Override
public Mapper mapper() {
return mapper;
}
@Override
public String toRewrittenSqlQuery(final T value) {
return query.toSqlQuery();
}
}