mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-27 19:32:19 -05:00
Add overloads for QueryMapper.insertGetGeneratedKeyType
This commit is contained in:
parent
d9a83a5edf
commit
7524893ed7
@ -118,6 +118,28 @@ public class CachingQueryMapper extends QueryMapper {
|
|||||||
return ps;
|
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) {
|
public void clearCache(boolean close) {
|
||||||
//System.out.println("cache size: "+cache.size());
|
//System.out.println("cache size: "+cache.size());
|
||||||
for (PreparedStatement ps : cache.values())
|
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);
|
return super.insertGetGeneratedKeyType(getInsertPreparedStatement(sql, Statement.RETURN_GENERATED_KEYS), typeReference, bindObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T insertGetGeneratedKeyType(String sql, int[] columnIndexes, TypeReference<T> typeReference, Object... bindObjects) throws SQLException {
|
||||||
|
return super.insertGetGeneratedKeyType(getInsertPreparedStatement(sql, columnIndexes), typeReference, bindObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T insertGetGeneratedKeyType(String sql, String[] columnNames, TypeReference<T> typeReference, Object... bindObjects) throws SQLException {
|
||||||
|
return super.insertGetGeneratedKeyType(getInsertPreparedStatement(sql, columnNames), typeReference, bindObjects);
|
||||||
|
}
|
||||||
|
|
||||||
// these grab ResultSets from the database
|
// these grab ResultSets from the database
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -302,6 +302,16 @@ public class ListQueryMapper extends QueryMapper {
|
|||||||
return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), typeReference, bindObjects);
|
return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), typeReference, bindObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T insertGetGeneratedKeyType(String sql, int[] columnIndexes, TypeReference<T> typeReference, Object... bindObjects) throws SQLException {
|
||||||
|
return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), columnIndexes, typeReference, bindObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T insertGetGeneratedKeyType(String sql, String[] columnNames, TypeReference<T> 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
|
// DO NOT EDIT BELOW THIS LINE, OR CHANGE THIS COMMENT, CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,7 +105,7 @@ public class NullQueryMapper extends QueryMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long insertGetGeneratedKey(PreparedStatement ps, Object... bindObjects) throws SQLException {
|
public Long insertGetGeneratedKey(PreparedStatement ps, Object... bindObjects) {
|
||||||
try {
|
try {
|
||||||
return delegate.insertGetGeneratedKey(ps, bindObjects);
|
return delegate.insertGetGeneratedKey(ps, bindObjects);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -115,7 +115,7 @@ public class NullQueryMapper extends QueryMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T insertGetGeneratedKeyType(PreparedStatement ps, TypeReference<T> typeReference, Object... bindObjects) throws SQLException {
|
public <T> T insertGetGeneratedKeyType(PreparedStatement ps, TypeReference<T> typeReference, Object... bindObjects) {
|
||||||
try {
|
try {
|
||||||
return delegate.insertGetGeneratedKeyType(ps, typeReference, bindObjects);
|
return delegate.insertGetGeneratedKeyType(ps, typeReference, bindObjects);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -145,7 +145,7 @@ public class NullQueryMapper extends QueryMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long insertGetGeneratedKey(String sql, Object... bindObjects) throws SQLException {
|
public Long insertGetGeneratedKey(String sql, Object... bindObjects) {
|
||||||
try {
|
try {
|
||||||
return delegate.insertGetGeneratedKey(sql, bindObjects);
|
return delegate.insertGetGeneratedKey(sql, bindObjects);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -155,7 +155,7 @@ public class NullQueryMapper extends QueryMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T insertGetGeneratedKeyType(String sql, TypeReference<T> typeReference, Object... bindObjects) throws SQLException {
|
public <T> T insertGetGeneratedKeyType(String sql, TypeReference<T> typeReference, Object... bindObjects) {
|
||||||
try {
|
try {
|
||||||
return delegate.insertGetGeneratedKeyType(sql, typeReference, bindObjects);
|
return delegate.insertGetGeneratedKeyType(sql, typeReference, bindObjects);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -164,6 +164,26 @@ public class NullQueryMapper extends QueryMapper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T insertGetGeneratedKeyType(String sql, int[] columnIndexes, TypeReference<T> typeReference, Object... bindObjects) {
|
||||||
|
try {
|
||||||
|
return delegate.insertGetGeneratedKeyType(sql, columnIndexes, typeReference, bindObjects);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (verbose) e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T insertGetGeneratedKeyType(String sql, String[] columnNames, TypeReference<T> 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
|
// these update the database using UpdateableDTOs
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -341,7 +341,7 @@ public class QueryMapper implements JdbcMapper {
|
|||||||
|
|
||||||
// so we lazily cache oracleDatabase just in this one function
|
// so we lazily cache oracleDatabase just in this one function
|
||||||
if(oracleDatabase == null)
|
if(oracleDatabase == null)
|
||||||
oracleDatabase = conn.isWrapperFor(OptimalInList.oracleConnection);
|
oracleDatabase = OptimalInList.isWrapperFor(conn, OptimalInList.oracleConnection);
|
||||||
|
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
@ -362,6 +362,26 @@ public class QueryMapper implements JdbcMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> T insertGetGeneratedKeyType(final String sql, final int[] columnIndexes, final TypeReference<T> 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> T insertGetGeneratedKeyType(final String sql, final String[] columnNames, final TypeReference<T> 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
|
// these update the database using UpdateableDTOs
|
||||||
|
|
||||||
public int updateRows(UpdateableDTO dto) throws SQLException {
|
public int updateRows(UpdateableDTO dto) throws SQLException {
|
||||||
|
Loading…
Reference in New Issue
Block a user