com.jpattern.orm.session.PlainSqlPerformer Maven / Gradle / Ivy
package com.jpattern.orm.session;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jpattern.orm.exception.OrmException;
import com.jpattern.orm.exception.OrmNotUniqueResultException;
import com.jpattern.orm.session.reader.ArrayResultSetReader;
import com.jpattern.orm.session.reader.BigDecimalResultSetReader;
import com.jpattern.orm.session.reader.BooleanResultSetReader;
import com.jpattern.orm.session.reader.DoubleResultSetReader;
import com.jpattern.orm.session.reader.FloatResultSetReader;
import com.jpattern.orm.session.reader.IntegerResultSetReader;
import com.jpattern.orm.session.reader.ListResultSetReader;
import com.jpattern.orm.session.reader.LongResultSetReader;
import com.jpattern.orm.session.reader.StringResultSetReader;
/**
*
* @author Francesco Cina
*
* 02/lug/2011
*/
public class PlainSqlPerformer implements SqlPerformer {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final SqlPerformerStrategy sqlPerformerTemplate;
private int queryTimeout = 0;
private int maxRows = 0;
public PlainSqlPerformer(final SqlPerformerStrategy sqlPerformerTemplate) {
this.sqlPerformerTemplate = sqlPerformerTemplate;
}
@Override
public final void setMaxRows(final int maxRows) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("max rows sets to " + maxRows);
}
this.maxRows = maxRows;
}
@Override
public final int getMaxRows() {
return this.maxRows;
}
@Override
public final void setQueryTimeout(final int queryTimeout) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("queryTimeout sets to " + queryTimeout);
}
this.queryTimeout = queryTimeout;
}
@Override
public final int getQueryTimeout() {
return this.queryTimeout;
}
@Override
public final Integer queryForInt(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new IntegerResultSetReader(), values);
}
@Override
public final Integer queryForInt(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new IntegerResultSetReader(), values);
}
@Override
public final Long queryForLong(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new LongResultSetReader(), values);
}
@Override
public final Long queryForLong(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new LongResultSetReader(), values);
}
@Override
public final Double queryForDouble(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new DoubleResultSetReader(), values);
}
@Override
public final Double queryForDouble(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new DoubleResultSetReader(), values);
}
@Override
public final Float queryForFloat(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new FloatResultSetReader(), values);
}
@Override
public final Float queryForFloat(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new FloatResultSetReader(), values);
}
@Override
public final String queryForString(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new StringResultSetReader(), values);
}
@Override
public final String queryForString(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new StringResultSetReader(), values);
}
@Override
public final Boolean queryForBoolean(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new BooleanResultSetReader(), values);
}
@Override
public final Boolean queryForBoolean(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new BooleanResultSetReader(), values);
}
@Override
public final BigDecimal queryForBigDecimal(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new BigDecimalResultSetReader(), values);
}
@Override
public final BigDecimal queryForBigDecimal(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new BigDecimalResultSetReader(), values);
}
@Override
public final Object[] queryForArray(final String sql, final Object... values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new ArrayResultSetReader(), values);
}
@Override
public final Object[] queryForArray(final String sql, final Collection> values) throws OrmException, OrmNotUniqueResultException {
return this.query(sql, new ArrayResultSetReader(), values);
}
@Override
public final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy