2014-04-22 14:40:18 -04:00
|
|
|
package com.moparisthebest.jdbc;
|
|
|
|
|
2017-06-30 23:37:36 -04:00
|
|
|
import com.moparisthebest.jdbc.codegen.JdbcMapper;
|
2017-07-03 03:05:53 -04:00
|
|
|
import com.moparisthebest.jdbc.codegen.JdbcMapperFactory;
|
2019-02-07 01:09:15 -05:00
|
|
|
import com.moparisthebest.jdbc.util.PreparedStatementUtil;
|
2017-06-08 23:02:12 -04:00
|
|
|
import com.moparisthebest.jdbc.util.ResultSetIterable;
|
2018-09-21 00:35:20 -04:00
|
|
|
import com.moparisthebest.jdbc.util.ResultSetUtil;
|
2019-02-07 01:09:15 -05:00
|
|
|
import com.moparisthebest.jdbc.util.SqlBuilder;
|
2017-06-08 23:02:12 -04:00
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
import java.io.*;
|
2019-01-15 23:30:00 -05:00
|
|
|
import java.lang.reflect.Method;
|
2018-03-15 00:45:42 -04:00
|
|
|
import java.nio.charset.Charset;
|
2014-04-22 14:40:18 -04:00
|
|
|
import java.sql.*;
|
|
|
|
import java.util.*;
|
2017-06-12 22:57:43 -04:00
|
|
|
//IFJAVA8_START
|
2017-06-30 23:18:51 -04:00
|
|
|
import java.time.*;
|
2017-06-12 22:57:43 -04:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
//IFJAVA8_END
|
2014-04-22 14:40:18 -04:00
|
|
|
|
2019-02-07 01:09:15 -05:00
|
|
|
import static com.moparisthebest.jdbc.InList.defaultInList;
|
2014-04-22 14:40:18 -04:00
|
|
|
import static com.moparisthebest.jdbc.TryClose.tryClose;
|
|
|
|
|
2017-06-30 23:37:36 -04:00
|
|
|
public class QueryMapper implements JdbcMapper {
|
2014-04-22 14:40:18 -04:00
|
|
|
|
2019-02-07 01:09:15 -05:00
|
|
|
public static final Object noBind = PreparedStatementUtil.noBind;
|
2017-06-30 23:37:36 -04:00
|
|
|
public static final ResultSetMapper defaultRsm = new ResultSetMapper();
|
2015-09-25 16:55:58 -04:00
|
|
|
|
2018-09-25 20:23:48 -04:00
|
|
|
protected static final int[] ORACLE_SINGLE_COLUMN_INDEX = new int[]{1};
|
2018-09-25 20:14:08 -04:00
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
//IFJAVA8_START
|
|
|
|
public static final PreparedStatementFactory oracleSingleColumnPsf = (conn, sql) -> conn.prepareStatement(sql, ORACLE_SINGLE_COLUMN_INDEX);
|
|
|
|
public static final PreparedStatementFactory standardReturnGeneratedKeysPsf = (conn, sql) -> conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
|
|
|
public static final PreparedStatementFactory defaultPsf = Connection::prepareStatement;
|
|
|
|
//IFJAVA8_END
|
|
|
|
|
2018-03-15 00:45:42 -04:00
|
|
|
/*IFJAVA6_START
|
2018-10-09 22:53:49 -04:00
|
|
|
public static final PreparedStatementFactory oracleSingleColumnPsf = new PreparedStatementFactory() {
|
|
|
|
@Override
|
|
|
|
public PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException {
|
|
|
|
return conn.prepareStatement(sql, ORACLE_SINGLE_COLUMN_INDEX);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public static final PreparedStatementFactory standardReturnGeneratedKeysPsf = new PreparedStatementFactory() {
|
|
|
|
@Override
|
|
|
|
public PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException {
|
|
|
|
return conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public static final PreparedStatementFactory defaultPsf = new PreparedStatementFactory() {
|
|
|
|
@Override
|
|
|
|
public PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException {
|
|
|
|
return conn.prepareStatement(sql);
|
|
|
|
}
|
|
|
|
};
|
2018-03-15 00:45:42 -04:00
|
|
|
IFJAVA6_END*/
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
protected final ResultSetMapper cm;
|
|
|
|
protected final Connection conn;
|
2017-07-01 02:07:04 -04:00
|
|
|
protected final boolean closeConn;
|
2014-04-22 14:40:18 -04:00
|
|
|
|
2019-01-15 23:30:00 -05:00
|
|
|
protected boolean inListEnabled = false;
|
|
|
|
protected final InList inList;
|
|
|
|
public static final String inListReplace = "{inList}";
|
|
|
|
|
|
|
|
protected QueryMapper(Connection conn, final String jndiName, Factory<Connection> factory, final ResultSetMapper cm, final InList inList) {
|
2017-06-30 23:37:36 -04:00
|
|
|
this.cm = cm == null ? defaultRsm : cm;
|
2017-07-01 02:07:04 -04:00
|
|
|
boolean closeConn = false;
|
|
|
|
if(conn == null) {
|
2017-07-03 03:05:53 -04:00
|
|
|
if(factory == null && jndiName != null)
|
|
|
|
factory = JdbcMapperFactory.connectionFactory(jndiName);
|
2017-07-01 02:07:04 -04:00
|
|
|
if (factory != null) {
|
|
|
|
try {
|
|
|
|
conn = factory.create();
|
|
|
|
closeConn = true;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new RuntimeException("factory failed to create connection", e);
|
|
|
|
}
|
2017-07-03 03:05:53 -04:00
|
|
|
}
|
2017-07-01 02:07:04 -04:00
|
|
|
}
|
|
|
|
if (conn == null)
|
|
|
|
throw new NullPointerException("Connection needs to be non-null for QueryMapper...");
|
2014-04-22 14:40:18 -04:00
|
|
|
this.conn = conn;
|
2019-01-15 23:30:00 -05:00
|
|
|
this.inList = inList.instance(conn);
|
2017-07-01 02:07:04 -04:00
|
|
|
this.closeConn = closeConn;
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
2019-01-15 23:30:00 -05:00
|
|
|
|
|
|
|
protected QueryMapper(Connection conn, final String jndiName, Factory<Connection> factory, final ResultSetMapper cm) {
|
|
|
|
this(conn, jndiName, factory, cm, defaultInList);
|
|
|
|
}
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
public QueryMapper(Connection conn, ResultSetMapper cm) {
|
2017-07-01 02:07:04 -04:00
|
|
|
this(conn, null, null, cm);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public QueryMapper(Connection conn) {
|
|
|
|
this(conn, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public QueryMapper(String jndiName, ResultSetMapper cm) {
|
2017-07-01 02:07:04 -04:00
|
|
|
this(null, jndiName, null, cm);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public QueryMapper(String jndiName) {
|
|
|
|
this(jndiName, null);
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:07:04 -04:00
|
|
|
public QueryMapper(Factory<Connection> factory, ResultSetMapper cm) {
|
|
|
|
this(null, null, factory, cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
public QueryMapper(Factory<Connection> factory) {
|
|
|
|
this(factory, null);
|
|
|
|
}
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
/**
|
|
|
|
* Only meant to be called by implementing classes
|
|
|
|
*/
|
|
|
|
protected QueryMapper() {
|
|
|
|
this.cm = null;
|
|
|
|
this.conn = null;
|
2017-07-01 02:07:04 -04:00
|
|
|
this.closeConn = false;
|
2019-01-15 23:30:00 -05:00
|
|
|
this.inList = defaultInList;
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
2017-07-01 02:07:04 -04:00
|
|
|
if (closeConn) {
|
2014-04-22 14:40:18 -04:00
|
|
|
tryClose(conn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object wrapClob(String s) {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.wrapClob(s);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Object wrapBlob(String s) {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.wrapBlob(s);
|
2018-03-15 00:45:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Object wrapBlob(final String s, final Charset charset) {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.wrapBlob(s, charset);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
2019-01-15 23:30:00 -05:00
|
|
|
// start in list specific code
|
|
|
|
protected PreparedStatement getPreparedStatement(final String sql, final Object... bindObjects) throws SQLException {
|
|
|
|
return getPreparedStatement(sql, defaultPsf, bindObjects);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected PreparedStatement getPreparedStatement(final String sql, final PreparedStatementFactory psf, final Object... bindObjects) throws SQLException {
|
|
|
|
return psf.prepareStatement(conn, prepareInListSql(sql, bindObjects));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static StringBuilder recursiveReplace(final StringBuilder sb, final Object... bindObjects) {
|
|
|
|
if (bindObjects != null && bindObjects.length > 0) {
|
|
|
|
for (Object o : bindObjects) {
|
|
|
|
if (o != null && o != QueryMapper.noBind) {
|
|
|
|
if (o instanceof InList.InListObject) {
|
|
|
|
final int startIndex = sb.indexOf(inListReplace);
|
|
|
|
if (startIndex < -1)
|
|
|
|
return sb; // we've replaced all, maybe an error? meh
|
|
|
|
sb.replace(startIndex, startIndex + inListReplace.length(), o.toString());
|
|
|
|
} else if (o instanceof Object[]) {
|
|
|
|
recursiveReplace(sb, (Object[]) o);
|
|
|
|
} else if (o instanceof Collection) {
|
|
|
|
recursiveReplace(sb, ((Collection) o).toArray());
|
2019-02-07 01:09:15 -05:00
|
|
|
} else if(o instanceof Iterable) {
|
|
|
|
for(final Object o2 : (Iterable) o) {
|
|
|
|
recursiveReplace(sb, o2);
|
|
|
|
}
|
2019-01-15 23:30:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepareInListSql(final String sql, final Object... bindObjects) {
|
|
|
|
return inListEnabled && sql.contains(inListReplace) ? recursiveReplace(new StringBuilder(sql), bindObjects).toString() : sql;
|
|
|
|
}
|
|
|
|
|
2019-02-09 00:06:13 -05:00
|
|
|
@Override
|
|
|
|
public SqlBuilder sqlBuilder() {
|
|
|
|
return SqlBuilder.of(conn, inList);
|
|
|
|
}
|
|
|
|
|
2019-01-15 23:30:00 -05:00
|
|
|
public <T> InList.InListObject inList(final String columnName, final Collection<T> values) throws SQLException {
|
|
|
|
this.inListEnabled = true; // worth checking if it's already this or not?
|
|
|
|
return this.inList.inList(conn, columnName, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> InList.InListObject notInList(final String columnName, final Collection<T> values) throws SQLException {
|
|
|
|
this.inListEnabled = true; // worth checking if it's already this or not?
|
|
|
|
return this.inList.notInList(conn, columnName, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
// end in list specific code
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
public static void setObject(final PreparedStatement ps, final int index, final Object o) throws SQLException {
|
2019-02-07 01:09:15 -05:00
|
|
|
PreparedStatementUtil.setObject(ps, index, o);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int recursiveBind(final PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.recursiveBind(ps, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static PreparedStatement bindStatement(final PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.bind(ps, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
2018-09-21 00:35:20 -04:00
|
|
|
protected static ResultSet bindExecute(final PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.bind(ps, bindObjects).executeQuery();
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// these update the database
|
|
|
|
|
|
|
|
public int executeUpdate(PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
2019-02-07 01:09:15 -05:00
|
|
|
return PreparedStatementUtil.bind(ps, bindObjects).executeUpdate();
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean executeUpdateSuccess(PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
|
|
|
return this.executeUpdate(ps, bindObjects) >= 0;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:35:20 -04:00
|
|
|
public Long insertGetGeneratedKey(final PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
|
|
|
this.executeUpdate(ps, bindObjects);
|
|
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
|
|
rs = ps.getGeneratedKeys();
|
|
|
|
if(rs.next())
|
|
|
|
return ResultSetUtil.getObjectLong(rs, 1);
|
|
|
|
} finally {
|
|
|
|
tryClose(rs);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> T insertGetGeneratedKeyType(final PreparedStatement ps, final TypeReference<T> typeReference, final Object... bindObjects) throws SQLException {
|
|
|
|
this.executeUpdate(ps, bindObjects);
|
|
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
|
|
rs = ps.getGeneratedKeys();
|
|
|
|
if(rs.next())
|
|
|
|
return cm.toType(rs, typeReference);
|
|
|
|
} finally {
|
|
|
|
tryClose(rs);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
public int executeUpdate(String sql, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.executeUpdate(ps, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean executeUpdateSuccess(String sql, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.executeUpdateSuccess(ps, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
private PreparedStatementFactory singleColumnPsf = null;
|
|
|
|
protected PreparedStatementFactory getSingleColumnPreparedStatementFactory() {
|
2018-09-25 20:23:48 -04:00
|
|
|
// this single function is somewhat database specific
|
|
|
|
// sqlite/ms-sql/mysql works with either Statement.RETURN_GENERATED_KEYS or int[]{1}
|
|
|
|
// oracle requires int[]{1} instead, failing on Statement.RETURN_GENERATED_KEYS
|
|
|
|
// postgre requires Statement.RETURN_GENERATED_KEYS instead, failing on int[]{1}
|
|
|
|
|
|
|
|
// so we lazily cache oracleDatabase just in this one function
|
2018-10-09 22:53:49 -04:00
|
|
|
if(singleColumnPsf == null) {
|
|
|
|
if(OptimalInList.isWrapperFor(conn, OptimalInList.oracleConnection))
|
|
|
|
singleColumnPsf = oracleSingleColumnPsf;
|
|
|
|
else
|
|
|
|
singleColumnPsf = standardReturnGeneratedKeysPsf;
|
2018-09-21 00:35:20 -04:00
|
|
|
}
|
2018-10-09 22:53:49 -04:00
|
|
|
return singleColumnPsf;
|
2018-09-21 00:35:20 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
public Long insertGetGeneratedKey(final String sql, final Object... bindObjects) throws SQLException {
|
2018-09-21 00:35:20 -04:00
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-03-08 10:56:10 -05:00
|
|
|
ps = getPreparedStatement(sql, getSingleColumnPreparedStatementFactory(), bindObjects);
|
2018-10-09 22:53:49 -04:00
|
|
|
return this.insertGetGeneratedKey(ps, bindObjects);
|
2018-09-21 00:35:20 -04:00
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
public <T> T insertGetGeneratedKeyType(final String sql, final TypeReference<T> typeReference, final Object... bindObjects) throws SQLException {
|
|
|
|
return insertGetGeneratedKeyType(sql, standardReturnGeneratedKeysPsf, typeReference, bindObjects);
|
2018-09-25 20:38:43 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
public <T> T insertGetGeneratedKeyType(final String sql, final PreparedStatementFactory psf, final TypeReference<T> typeReference, final Object... bindObjects) throws SQLException {
|
2018-09-25 20:38:43 -04:00
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-03-08 10:56:10 -05:00
|
|
|
ps = getPreparedStatement(sql, psf, bindObjects);
|
2018-09-25 20:38:43 -04:00
|
|
|
return this.insertGetGeneratedKeyType(ps, typeReference, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
// these update the database using UpdateableDTOs
|
|
|
|
|
|
|
|
public int updateRows(UpdateableDTO dto) throws SQLException {
|
|
|
|
return dto.updateRow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int updateRows(Collection<UpdateableDTO> dtos) throws SQLException {
|
|
|
|
int count = 0;
|
|
|
|
if (dtos != null)
|
|
|
|
for (UpdateableDTO dto : dtos)
|
|
|
|
count += dto.updateRow(this);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int updateRows(UpdateableDTO[] dtos) throws SQLException {
|
|
|
|
return updateRows(Arrays.asList(dtos));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int insertRows(UpdateableDTO dto) throws SQLException {
|
|
|
|
return dto.insertRow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int insertRows(Collection<UpdateableDTO> dtos) throws SQLException {
|
|
|
|
int count = 0;
|
|
|
|
if (dtos != null)
|
|
|
|
for (UpdateableDTO dto : dtos)
|
|
|
|
count += dto.insertRow(this);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int insertRows(UpdateableDTO[] dtos) throws SQLException {
|
|
|
|
return insertRows(Arrays.asList(dtos));
|
|
|
|
}
|
|
|
|
|
|
|
|
// these grab ResultSets from the database
|
|
|
|
|
|
|
|
public ResultSet toResultSet(PreparedStatement ps, final Object... bindObjects) throws SQLException {
|
|
|
|
return bindExecute(ps, bindObjects);
|
|
|
|
}
|
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
public ResultSet toResultSet(final String sql, final Object... bindObjects) throws SQLException {
|
|
|
|
return toResultSet(sql, defaultPsf, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 22:53:49 -04:00
|
|
|
public ResultSet toResultSet(final String sql, final PreparedStatementFactory psf, final Object... bindObjects) throws SQLException {
|
2014-04-22 14:40:18 -04:00
|
|
|
// works with StatementClosingResultSet
|
|
|
|
boolean error = true;
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
try {
|
2019-03-08 10:56:10 -05:00
|
|
|
ps = getPreparedStatement(sql, psf, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
rs = this.toResultSet(ps, bindObjects);
|
|
|
|
error = false;
|
|
|
|
return new StatementClosingResultSet(rs, ps);
|
|
|
|
} finally {
|
|
|
|
if (error) {
|
|
|
|
tryClose(rs);
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 23:02:12 -04:00
|
|
|
// these are handled specially and not generated because we need it to hold open PreparedStatement until the ResultSetIterable is closed
|
|
|
|
|
2017-06-29 00:00:46 -04:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public <T> T toType(String sql, TypeReference<T> typeReference, final Object... bindObjects) throws SQLException {
|
|
|
|
boolean error = true, closePs = true;
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
T ret = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2017-06-29 00:00:46 -04:00
|
|
|
rs = this.toResultSet(ps, bindObjects);
|
|
|
|
ret = cm.toType(rs, typeReference);
|
|
|
|
if(ret instanceof ResultSetIterable) {
|
|
|
|
ret = (T)((ResultSetIterable)ret).setPreparedStatementToClose(ps);
|
|
|
|
closePs = false;
|
|
|
|
}
|
|
|
|
//IFJAVA8_START
|
|
|
|
else if(ret instanceof Stream) {
|
|
|
|
final PreparedStatement finalPs = ps;
|
|
|
|
ret = (T)((Stream)ret).onClose(() -> tryClose(finalPs));
|
|
|
|
closePs = false;
|
|
|
|
}
|
|
|
|
//IFJAVA8_END
|
|
|
|
else if(ret instanceof ResultSet) {
|
|
|
|
ret = (T)new StatementClosingResultSet(rs, ps);
|
|
|
|
closePs = false;
|
|
|
|
}
|
|
|
|
error = false;
|
|
|
|
return ret;
|
|
|
|
} finally {
|
|
|
|
if (error) {
|
|
|
|
if(ret != null) {
|
|
|
|
if(ret instanceof ResultSet)
|
|
|
|
tryClose((ResultSet)ret);
|
|
|
|
else if(ret instanceof Closeable)
|
|
|
|
tryClose((Closeable)ret);
|
|
|
|
//IFJAVA8_START
|
|
|
|
else if(ret instanceof AutoCloseable)
|
|
|
|
tryClose((AutoCloseable)ret);
|
|
|
|
//IFJAVA8_END
|
|
|
|
}
|
|
|
|
tryClose(rs);
|
|
|
|
tryClose(ps);
|
|
|
|
} else if(closePs)
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 23:02:12 -04:00
|
|
|
public <T> ResultSetIterable<T> toResultSetIterable(String sql, Class<T> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
boolean error = true;
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSetIterable<T> ret = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2017-06-08 23:02:12 -04:00
|
|
|
rs = this.toResultSet(ps, bindObjects);
|
|
|
|
ret = cm.toResultSetIterable(rs, componentType).setPreparedStatementToClose(ps);
|
|
|
|
error = false;
|
|
|
|
return ret;
|
|
|
|
} finally {
|
|
|
|
if (error) {
|
|
|
|
tryClose(ret);
|
|
|
|
tryClose(rs);
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:57:43 -04:00
|
|
|
public <T extends Map<String, V>, V> ResultSetIterable<Map<String, V>> toResultSetIterable(String sql, Class<T> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
2017-06-08 23:02:12 -04:00
|
|
|
boolean error = true;
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSetIterable<Map<String, V>> ret = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2017-06-08 23:02:12 -04:00
|
|
|
rs = this.toResultSet(ps, bindObjects);
|
2017-06-12 22:57:43 -04:00
|
|
|
ret = cm.toResultSetIterable(rs, componentType, mapValType).setPreparedStatementToClose(ps);
|
2017-06-08 23:02:12 -04:00
|
|
|
error = false;
|
|
|
|
return ret;
|
|
|
|
} finally {
|
|
|
|
if (error) {
|
|
|
|
tryClose(ret);
|
|
|
|
tryClose(rs);
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:57:43 -04:00
|
|
|
//IFJAVA8_START
|
|
|
|
public <T> Stream<T> toStream(String sql, Class<T> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
boolean error = true;
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Stream<T> ret = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2017-06-12 22:57:43 -04:00
|
|
|
rs = this.toResultSet(ps, bindObjects);
|
|
|
|
final PreparedStatement finalPs = ps;
|
|
|
|
ret = cm.toStream(rs, componentType).onClose(() -> tryClose(finalPs));
|
|
|
|
error = false;
|
|
|
|
return ret;
|
|
|
|
} finally {
|
|
|
|
if (error) {
|
|
|
|
tryClose(ret);
|
|
|
|
tryClose(rs);
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Stream<Map<String, V>> toStream(String sql, Class<T> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
boolean error = true;
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Stream<Map<String, V>> ret = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2017-06-12 22:57:43 -04:00
|
|
|
rs = this.toResultSet(ps, bindObjects);
|
|
|
|
final PreparedStatement finalPs = ps;
|
|
|
|
ret = cm.toStream(rs, componentType, mapValType).onClose(() -> tryClose(finalPs));
|
|
|
|
error = false;
|
|
|
|
return ret;
|
|
|
|
} finally {
|
|
|
|
if (error) {
|
|
|
|
tryClose(ret);
|
|
|
|
tryClose(rs);
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//IFJAVA8_END
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
// these are standard getters
|
|
|
|
|
|
|
|
public ResultSetMapper getCustomResultSetMapper() {
|
|
|
|
return cm;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Connection getConnection() {
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DO NOT EDIT BELOW THIS LINE, OR CHANGE THIS COMMENT, CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh
|
|
|
|
|
|
|
|
public <T> T toObject(PreparedStatement ps, Class<T> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toObject(bindExecute(ps, bindObjects), componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> T toObject(String sql, Class<T> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toObject(ps, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 23:02:12 -04:00
|
|
|
public <T> ResultSetIterable<T> toResultSetIterable(PreparedStatement ps, Class<T> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toResultSetIterable(bindExecute(ps, bindObjects), componentType);
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:57:43 -04:00
|
|
|
public <T extends Map<String, V>, V> ResultSetIterable<Map<String, V>> toResultSetIterable(PreparedStatement ps, Class<T> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toResultSetIterable(bindExecute(ps, bindObjects), componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
//IFJAVA8_START
|
|
|
|
|
|
|
|
public <T> Stream<T> toStream(PreparedStatement ps, Class<T> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toStream(bindExecute(ps, bindObjects), componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
//IFJAVA8_END
|
|
|
|
|
|
|
|
//IFJAVA8_START
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Stream<Map<String, V>> toStream(PreparedStatement ps, Class<T> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toStream(bindExecute(ps, bindObjects), componentType, mapValType);
|
2017-06-08 23:02:12 -04:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:57:43 -04:00
|
|
|
//IFJAVA8_END
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
public <T extends Map<String, V>, V> Map<String, V> toSingleMap(PreparedStatement ps, Class<T> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toSingleMap(bindExecute(ps, bindObjects), componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Map<String, V> toSingleMap(String sql, Class<T> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toSingleMap(ps, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> Map<String, V> toSingleMap(PreparedStatement ps, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toSingleMap(bindExecute(ps, bindObjects), mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> Map<String, V> toSingleMap(String sql, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toSingleMap(ps, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 00:00:46 -04:00
|
|
|
public <T> T toType(PreparedStatement ps, TypeReference<T> typeReference, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toType(bindExecute(ps, bindObjects), typeReference);
|
|
|
|
}
|
|
|
|
|
2014-04-22 14:40:18 -04:00
|
|
|
public <T extends Collection<E>, E> T toCollection(PreparedStatement ps, final Class<T> collectionType, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toCollection(bindExecute(ps, bindObjects), collectionType, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E> T toCollection(String sql, final Class<T> collectionType, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toCollection(ps, collectionType, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E> T toCollection(PreparedStatement ps, T list, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toCollection(bindExecute(ps, bindObjects), list, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E> T toCollection(String sql, T list, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toCollection(ps, list, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E> T toMap(PreparedStatement ps, T map, Class<K> mapKeyType, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMap(bindExecute(ps, bindObjects), map, mapKeyType, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E> T toMap(String sql, T map, Class<K> mapKeyType, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMap(ps, map, mapKeyType, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Collection<C>, C> T toMapCollection(PreparedStatement ps, final Class<T> returnType, Class<K> mapKeyType, Class<E> collectionType, Class<C> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapCollection(bindExecute(ps, bindObjects), returnType, mapKeyType, collectionType, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Collection<C>, C> T toMapCollection(String sql, final Class<T> returnType, Class<K> mapKeyType, Class<E> collectionType, Class<C> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapCollection(ps, returnType, mapKeyType, collectionType, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Collection<C>, C> T toMapCollection(PreparedStatement ps, T map, Class<K> mapKeyType, Class<E> collectionType, Class<C> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapCollection(bindExecute(ps, bindObjects), map, mapKeyType, collectionType, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Collection<C>, C> T toMapCollection(String sql, T map, Class<K> mapKeyType, Class<E> collectionType, Class<C> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapCollection(ps, map, mapKeyType, collectionType, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> ListIterator<T> toListIterator(PreparedStatement ps, final Class<T> type, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toListIterator(bindExecute(ps, bindObjects), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> ListIterator<T> toListIterator(String sql, final Class<T> type, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toListIterator(ps, type, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> Iterator<T> toIterator(PreparedStatement ps, final Class<T> type, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toIterator(bindExecute(ps, bindObjects), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> Iterator<T> toIterator(String sql, final Class<T> type, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toIterator(ps, type, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> T[] toArray(PreparedStatement ps, final Class<T> type, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toArray(bindExecute(ps, bindObjects), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> T[] toArray(String sql, final Class<T> type, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toArray(ps, type, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <E> List<E> toList(PreparedStatement ps, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toList(bindExecute(ps, bindObjects), componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <E> List<E> toList(String sql, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toList(ps, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E> Map<K, E> toMap(PreparedStatement ps, Class<K> mapKeyType, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMap(bindExecute(ps, bindObjects), mapKeyType, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E> Map<K, E> toMap(String sql, Class<K> mapKeyType, Class<E> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMap(ps, mapKeyType, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E extends List<C>, C> Map<K, E> toMapList(PreparedStatement ps, Class<K> mapKeyType, Class<C> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapList(bindExecute(ps, bindObjects), mapKeyType, componentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E extends List<C>, C> Map<K, E> toMapList(String sql, Class<K> mapKeyType, Class<C> componentType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapList(ps, mapKeyType, componentType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E extends Map<String, V>, V> T toCollectionMap(PreparedStatement ps, final Class<T> collectionType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toCollectionMap(bindExecute(ps, bindObjects), collectionType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E extends Map<String, V>, V> T toCollectionMap(String sql, final Class<T> collectionType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toCollectionMap(ps, collectionType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E extends Map<String, V>, V> T toCollectionMap(PreparedStatement ps, T list, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toCollectionMap(bindExecute(ps, bindObjects), list, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Collection<E>, E extends Map<String, V>, V> T toCollectionMap(String sql, T list, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toCollectionMap(ps, list, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Map<String, V>, V> T toMapMap(PreparedStatement ps, final Class<T> returnType, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapMap(bindExecute(ps, bindObjects), returnType, mapKeyType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Map<String, V>, V> T toMapMap(String sql, final Class<T> returnType, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapMap(ps, returnType, mapKeyType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Map<String, V>, V> T toMapMap(PreparedStatement ps, T map, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapMap(bindExecute(ps, bindObjects), map, mapKeyType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, E>, K, E extends Map<String, V>, V> T toMapMap(String sql, T map, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapMap(ps, map, mapKeyType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, C>, K, C extends Collection<E>, E extends Map<String, V>, V> T toMapCollectionMap(PreparedStatement ps, final Class<T> returnType, Class<K> mapKeyType, Class<C> collectionType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapCollectionMap(bindExecute(ps, bindObjects), returnType, mapKeyType, collectionType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, C>, K, C extends Collection<E>, E extends Map<String, V>, V> T toMapCollectionMap(String sql, final Class<T> returnType, Class<K> mapKeyType, Class<C> collectionType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapCollectionMap(ps, returnType, mapKeyType, collectionType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, C>, K, C extends Collection<E>, E extends Map<String, V>, V> T toMapCollectionMap(PreparedStatement ps, T map, Class<K> mapKeyType, Class<C> collectionType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapCollectionMap(bindExecute(ps, bindObjects), map, mapKeyType, collectionType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<K, C>, K, C extends Collection<E>, E extends Map<String, V>, V> T toMapCollectionMap(String sql, T map, Class<K> mapKeyType, Class<C> collectionType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapCollectionMap(ps, map, mapKeyType, collectionType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> ListIterator<Map<String, V>> toListIteratorMap(PreparedStatement ps, final Class<T> type, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toListIteratorMap(bindExecute(ps, bindObjects), type, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> ListIterator<Map<String, V>> toListIteratorMap(String sql, final Class<T> type, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toListIteratorMap(ps, type, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Iterator<Map<String, V>> toIteratorMap(PreparedStatement ps, final Class<T> type, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toIteratorMap(bindExecute(ps, bindObjects), type, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Iterator<Map<String, V>> toIteratorMap(String sql, final Class<T> type, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toIteratorMap(ps, type, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Map<String, V>[] toArrayMap(PreparedStatement ps, final Class<T> type, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toArrayMap(bindExecute(ps, bindObjects), type, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Map<String, V>, V> Map<String, V>[] toArrayMap(String sql, final Class<T> type, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toArrayMap(ps, type, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <E extends Map<String, V>, V> List<Map<String, V>> toListMap(PreparedStatement ps, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toListMap(bindExecute(ps, bindObjects), componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <E extends Map<String, V>, V> List<Map<String, V>> toListMap(String sql, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toListMap(ps, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E extends Map<String, V>, V> Map<K, Map<String, V>> toMapMap(PreparedStatement ps, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapMap(bindExecute(ps, bindObjects), mapKeyType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E extends Map<String, V>, V> Map<K, Map<String, V>> toMapMap(String sql, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapMap(ps, mapKeyType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E extends Map<String, V>, V> Map<K, List<Map<String, V>>> toMapListMap(PreparedStatement ps, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapListMap(bindExecute(ps, bindObjects), mapKeyType, componentType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, E extends Map<String, V>, V> Map<K, List<Map<String, V>>> toMapListMap(String sql, Class<K> mapKeyType, Class<E> componentType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapListMap(ps, mapKeyType, componentType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> ListIterator<Map<String, V>> toListIteratorMap(PreparedStatement ps, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toListIteratorMap(bindExecute(ps, bindObjects), mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> ListIterator<Map<String, V>> toListIteratorMap(String sql, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toListIteratorMap(ps, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> Iterator<Map<String, V>> toIteratorMap(PreparedStatement ps, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toIteratorMap(bindExecute(ps, bindObjects), mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> Iterator<Map<String, V>> toIteratorMap(String sql, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toIteratorMap(ps, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> List<Map<String, V>> toListMap(PreparedStatement ps, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toListMap(bindExecute(ps, bindObjects), mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <V> List<Map<String, V>> toListMap(String sql, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toListMap(ps, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, V> Map<K, Map<String, V>> toMapMap(PreparedStatement ps, Class<K> mapKeyType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapMap(bindExecute(ps, bindObjects), mapKeyType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, V> Map<K, Map<String, V>> toMapMap(String sql, Class<K> mapKeyType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapMap(ps, mapKeyType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, V> Map<K, List<Map<String, V>>> toMapListMap(PreparedStatement ps, Class<K> mapKeyType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
return cm.toMapListMap(bindExecute(ps, bindObjects), mapKeyType, mapValType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public <K, V> Map<K, List<Map<String, V>>> toMapListMap(String sql, Class<K> mapKeyType, Class<V> mapValType, final Object... bindObjects) throws SQLException {
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
try {
|
2019-01-15 23:30:00 -05:00
|
|
|
ps = getPreparedStatement(sql, bindObjects);
|
2014-04-22 14:40:18 -04:00
|
|
|
return this.toMapListMap(ps, mapKeyType, mapValType, bindObjects);
|
|
|
|
} finally {
|
|
|
|
tryClose(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|