org.simpleflatmapper.jdbc.impl.MapperQueryPreparer Maven / Gradle / Ivy
package org.simpleflatmapper.jdbc.impl;
import org.simpleflatmapper.jdbc.QueryBinder;
import org.simpleflatmapper.jdbc.QueryPreparer;
import org.simpleflatmapper.jdbc.named.NamedSqlQuery;
import org.simpleflatmapper.map.FieldMapper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class MapperQueryPreparer implements QueryPreparer {
private final NamedSqlQuery query;
private final FieldMapper mapper;
private final String[] generatedKeys;
public MapperQueryPreparer(NamedSqlQuery query, FieldMapper 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 FieldMapper mapper() {
return mapper;
}
@Override
public String toRewrittenSqlQuery(final T value) {
return query.toSqlQuery();
}
}