diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/CachingQueryMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/CachingQueryMapper.java index cb68996..5408afa 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/CachingQueryMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/CachingQueryMapper.java @@ -118,6 +118,28 @@ public class CachingQueryMapper extends QueryMapper { return ps; } + protected PreparedStatement getInsertPreparedStatement(final String sql, final int[] columnIndexes) throws SQLException { + PreparedStatement ps = cache.get(sql); + if (ps == null) { + //System.out.println("cache miss"); + ps = conn.prepareStatement(sql, columnIndexes); + cache.put(sql, ps); + } + //else System.out.println("cache hit"); + return ps; + } + + protected PreparedStatement getInsertPreparedStatement(final String sql, final String[] columnNames) throws SQLException { + PreparedStatement ps = cache.get(sql); + if (ps == null) { + //System.out.println("cache miss"); + ps = conn.prepareStatement(sql, columnNames); + cache.put(sql, ps); + } + //else System.out.println("cache hit"); + return ps; + } + public void clearCache(boolean close) { //System.out.println("cache size: "+cache.size()); for (PreparedStatement ps : cache.values()) @@ -157,6 +179,16 @@ public class CachingQueryMapper extends QueryMapper { return super.insertGetGeneratedKeyType(getInsertPreparedStatement(sql, Statement.RETURN_GENERATED_KEYS), typeReference, bindObjects); } + @Override + public T insertGetGeneratedKeyType(String sql, int[] columnIndexes, TypeReference typeReference, Object... bindObjects) throws SQLException { + return super.insertGetGeneratedKeyType(getInsertPreparedStatement(sql, columnIndexes), typeReference, bindObjects); + } + + @Override + public T insertGetGeneratedKeyType(String sql, String[] columnNames, TypeReference typeReference, Object... bindObjects) throws SQLException { + return super.insertGetGeneratedKeyType(getInsertPreparedStatement(sql, columnNames), typeReference, bindObjects); + } + // these grab ResultSets from the database @Override diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/ListQueryMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/ListQueryMapper.java index 4fa6802..b1370f3 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/ListQueryMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/ListQueryMapper.java @@ -302,6 +302,16 @@ public class ListQueryMapper extends QueryMapper { return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), typeReference, bindObjects); } + @Override + public T insertGetGeneratedKeyType(String sql, int[] columnIndexes, TypeReference typeReference, Object... bindObjects) throws SQLException { + return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), columnIndexes, typeReference, bindObjects); + } + + @Override + public T insertGetGeneratedKeyType(String sql, String[] columnNames, TypeReference typeReference, Object... bindObjects) throws SQLException { + return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), columnNames, typeReference, bindObjects); + } + // DO NOT EDIT BELOW THIS LINE, OR CHANGE THIS COMMENT, CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh @Override diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/NullQueryMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/NullQueryMapper.java index eac3ad7..3e869cd 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/NullQueryMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/NullQueryMapper.java @@ -105,7 +105,7 @@ public class NullQueryMapper extends QueryMapper { } @Override - public Long insertGetGeneratedKey(PreparedStatement ps, Object... bindObjects) throws SQLException { + public Long insertGetGeneratedKey(PreparedStatement ps, Object... bindObjects) { try { return delegate.insertGetGeneratedKey(ps, bindObjects); } catch (Throwable e) { @@ -115,7 +115,7 @@ public class NullQueryMapper extends QueryMapper { } @Override - public T insertGetGeneratedKeyType(PreparedStatement ps, TypeReference typeReference, Object... bindObjects) throws SQLException { + public T insertGetGeneratedKeyType(PreparedStatement ps, TypeReference typeReference, Object... bindObjects) { try { return delegate.insertGetGeneratedKeyType(ps, typeReference, bindObjects); } catch (Throwable e) { @@ -145,7 +145,7 @@ public class NullQueryMapper extends QueryMapper { } @Override - public Long insertGetGeneratedKey(String sql, Object... bindObjects) throws SQLException { + public Long insertGetGeneratedKey(String sql, Object... bindObjects) { try { return delegate.insertGetGeneratedKey(sql, bindObjects); } catch (Throwable e) { @@ -155,7 +155,7 @@ public class NullQueryMapper extends QueryMapper { } @Override - public T insertGetGeneratedKeyType(String sql, TypeReference typeReference, Object... bindObjects) throws SQLException { + public T insertGetGeneratedKeyType(String sql, TypeReference typeReference, Object... bindObjects) { try { return delegate.insertGetGeneratedKeyType(sql, typeReference, bindObjects); } catch (Throwable e) { @@ -164,6 +164,26 @@ public class NullQueryMapper extends QueryMapper { return null; } + @Override + public T insertGetGeneratedKeyType(String sql, int[] columnIndexes, TypeReference typeReference, Object... bindObjects) { + try { + return delegate.insertGetGeneratedKeyType(sql, columnIndexes, typeReference, bindObjects); + } catch (Throwable e) { + if (verbose) e.printStackTrace(); + } + return null; + } + + @Override + public T insertGetGeneratedKeyType(String sql, String[] columnNames, TypeReference typeReference, Object... bindObjects) { + try { + return delegate.insertGetGeneratedKeyType(sql, columnNames, typeReference, bindObjects); + } catch (Throwable e) { + if (verbose) e.printStackTrace(); + } + return null; + } + // these update the database using UpdateableDTOs @Override diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java index ecf1e39..4c6b3f0 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java @@ -341,7 +341,7 @@ public class QueryMapper implements JdbcMapper { // so we lazily cache oracleDatabase just in this one function if(oracleDatabase == null) - oracleDatabase = conn.isWrapperFor(OptimalInList.oracleConnection); + oracleDatabase = OptimalInList.isWrapperFor(conn, OptimalInList.oracleConnection); PreparedStatement ps = null; try { @@ -362,6 +362,26 @@ public class QueryMapper implements JdbcMapper { } } + public T insertGetGeneratedKeyType(final String sql, final int[] columnIndexes, final TypeReference typeReference, final Object... bindObjects) throws SQLException { + PreparedStatement ps = null; + try { + ps = conn.prepareStatement(sql, columnIndexes); + return this.insertGetGeneratedKeyType(ps, typeReference, bindObjects); + } finally { + tryClose(ps); + } + } + + public T insertGetGeneratedKeyType(final String sql, final String[] columnNames, final TypeReference typeReference, final Object... bindObjects) throws SQLException { + PreparedStatement ps = null; + try { + ps = conn.prepareStatement(sql, columnNames); + return this.insertGetGeneratedKeyType(ps, typeReference, bindObjects); + } finally { + tryClose(ps); + } + } + // these update the database using UpdateableDTOs public int updateRows(UpdateableDTO dto) throws SQLException {