提交 093560a1 authored 作者: Philippe Marschall's avatar Philippe Marschall

Add guards to JDBC debug code

Some of the existing JDBC code is missing guards around debug
statements that allocate strings.
上级 9ecfb9eb
...@@ -61,7 +61,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -61,7 +61,9 @@ public class JdbcArray extends TraceObject implements Array {
@Override @Override
public Object getArray(Map<String, Class<?>> map) throws SQLException { public Object getArray(Map<String, Class<?>> map) throws SQLException {
try { try {
debugCode("getArray("+quoteMap(map)+");"); if (isDebugEnabled()) {
debugCode("getArray("+quoteMap(map)+");");
}
JdbcConnection.checkMap(map); JdbcConnection.checkMap(map);
checkClosed(); checkClosed();
return get(); return get();
...@@ -82,7 +84,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -82,7 +84,9 @@ public class JdbcArray extends TraceObject implements Array {
@Override @Override
public Object getArray(long index, int count) throws SQLException { public Object getArray(long index, int count) throws SQLException {
try { try {
debugCode("getArray(" + index + ", " + count + ");"); if (isDebugEnabled()) {
debugCode("getArray(" + index + ", " + count + ");");
}
checkClosed(); checkClosed();
return get(index, count); return get(index, count);
} catch (Exception e) { } catch (Exception e) {
...@@ -104,7 +108,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -104,7 +108,9 @@ public class JdbcArray extends TraceObject implements Array {
public Object getArray(long index, int count, Map<String, Class<?>> map) public Object getArray(long index, int count, Map<String, Class<?>> map)
throws SQLException { throws SQLException {
try { try {
debugCode("getArray(" + index + ", " + count + ", " + quoteMap(map)+");"); if (isDebugEnabled()) {
debugCode("getArray(" + index + ", " + count + ", " + quoteMap(map)+");");
}
checkClosed(); checkClosed();
JdbcConnection.checkMap(map); JdbcConnection.checkMap(map);
return get(index, count); return get(index, count);
...@@ -175,7 +181,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -175,7 +181,9 @@ public class JdbcArray extends TraceObject implements Array {
@Override @Override
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException { public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
try { try {
debugCode("getResultSet("+quoteMap(map)+");"); if (isDebugEnabled()) {
debugCode("getResultSet("+quoteMap(map)+");");
}
checkClosed(); checkClosed();
JdbcConnection.checkMap(map); JdbcConnection.checkMap(map);
return getResultSet(get(), 0); return getResultSet(get(), 0);
...@@ -197,7 +205,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -197,7 +205,9 @@ public class JdbcArray extends TraceObject implements Array {
@Override @Override
public ResultSet getResultSet(long index, int count) throws SQLException { public ResultSet getResultSet(long index, int count) throws SQLException {
try { try {
debugCode("getResultSet("+index+", " + count+");"); if (isDebugEnabled()) {
debugCode("getResultSet("+index+", " + count+");");
}
checkClosed(); checkClosed();
return getResultSet(get(index, count), index - 1); return getResultSet(get(index, count), index - 1);
} catch (Exception e) { } catch (Exception e) {
...@@ -221,7 +231,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -221,7 +231,9 @@ public class JdbcArray extends TraceObject implements Array {
public ResultSet getResultSet(long index, int count, public ResultSet getResultSet(long index, int count,
Map<String, Class<?>> map) throws SQLException { Map<String, Class<?>> map) throws SQLException {
try { try {
debugCode("getResultSet("+index+", " + count+", " + quoteMap(map)+");"); if (isDebugEnabled()) {
debugCode("getResultSet("+index+", " + count+", " + quoteMap(map)+");");
}
checkClosed(); checkClosed();
JdbcConnection.checkMap(map); JdbcConnection.checkMap(map);
return getResultSet(get(index, count), index - 1); return getResultSet(get(index, count), index - 1);
......
...@@ -882,7 +882,9 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne ...@@ -882,7 +882,9 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne
@Override @Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException { public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
try { try {
debugCode("setTypeMap(" + quoteMap(map) + ");"); if (isDebugEnabled()) {
debugCode("setTypeMap(" + quoteMap(map) + ");");
}
checkMap(map); checkMap(map);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1044,7 +1046,9 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne ...@@ -1044,7 +1046,9 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne
public void rollback(Savepoint savepoint) throws SQLException { public void rollback(Savepoint savepoint) throws SQLException {
try { try {
JdbcSavepoint sp = convertSavepoint(savepoint); JdbcSavepoint sp = convertSavepoint(savepoint);
debugCode("rollback(" + sp.getTraceObjectName() + ");"); if (isDebugEnabled()) {
debugCode("rollback(" + sp.getTraceObjectName() + ");");
}
checkClosedForWrite(); checkClosedForWrite();
try { try {
sp.rollback(); sp.rollback();
......
...@@ -1272,7 +1272,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements ...@@ -1272,7 +1272,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements
public int executeUpdate(String sql, int autoGeneratedKeys) public int executeUpdate(String sql, int autoGeneratedKeys)
throws SQLException { throws SQLException {
try { try {
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");"); if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
}
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1291,8 +1293,10 @@ public class JdbcPreparedStatement extends JdbcStatement implements ...@@ -1291,8 +1293,10 @@ public class JdbcPreparedStatement extends JdbcStatement implements
public int executeUpdate(String sql, int[] columnIndexes) public int executeUpdate(String sql, int[] columnIndexes)
throws SQLException { throws SQLException {
try { try {
debugCode("executeUpdate(" + quote(sql) + ", " + if (isDebugEnabled()) {
quoteIntArray(columnIndexes) + ");"); debugCode("executeUpdate(" + quote(sql) + ", " +
quoteIntArray(columnIndexes) + ");");
}
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1310,8 +1314,10 @@ public class JdbcPreparedStatement extends JdbcStatement implements ...@@ -1310,8 +1314,10 @@ public class JdbcPreparedStatement extends JdbcStatement implements
public int executeUpdate(String sql, String[] columnNames) public int executeUpdate(String sql, String[] columnNames)
throws SQLException { throws SQLException {
try { try {
debugCode("executeUpdate(" + quote(sql) + ", " + if (isDebugEnabled()) {
quoteArray(columnNames) + ");"); debugCode("executeUpdate(" + quote(sql) + ", " +
quoteArray(columnNames) + ");");
}
throw DbException.get( throw DbException.get(
ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
...@@ -1330,7 +1336,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements ...@@ -1330,7 +1336,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements
public boolean execute(String sql, int autoGeneratedKeys) public boolean execute(String sql, int autoGeneratedKeys)
throws SQLException { throws SQLException {
try { try {
debugCode("execute(" + quote(sql) + ", " + autoGeneratedKeys + ");"); if (isDebugEnabled()) {
debugCode("execute(" + quote(sql) + ", " + autoGeneratedKeys + ");");
}
throw DbException.get( throw DbException.get(
ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
...@@ -1348,7 +1356,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements ...@@ -1348,7 +1356,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements
@Override @Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException { public boolean execute(String sql, int[] columnIndexes) throws SQLException {
try { try {
debugCode("execute(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");"); if (isDebugEnabled()) {
debugCode("execute(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
}
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1366,7 +1376,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements ...@@ -1366,7 +1376,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements
public boolean execute(String sql, String[] columnNames) public boolean execute(String sql, String[] columnNames)
throws SQLException { throws SQLException {
try { try {
debugCode("execute(" + quote(sql) + ", " + quoteArray(columnNames) + ");"); if (isDebugEnabled()) {
debugCode("execute(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
}
throw DbException.get( throw DbException.get(
ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -1018,8 +1018,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -1018,8 +1018,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public Blob getBlob(int columnIndex) throws SQLException { public Blob getBlob(int columnIndex) throws SQLException {
try { try {
int id = getNextId(TraceObject.BLOB); int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, if (isDebugEnabled()) {
id, "getBlob(" + columnIndex + ")"); debugCodeAssign("Blob", TraceObject.BLOB,
id, "getBlob(" + columnIndex + ")");
}
Value v = get(columnIndex); Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -1039,8 +1041,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -1039,8 +1041,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public Blob getBlob(String columnLabel) throws SQLException { public Blob getBlob(String columnLabel) throws SQLException {
try { try {
int id = getNextId(TraceObject.BLOB); int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, if (isDebugEnabled()) {
id, "getBlob(" + quote(columnLabel) + ")"); debugCodeAssign("Blob", TraceObject.BLOB,
id, "getBlob(" + quote(columnLabel) + ")");
}
Value v = get(columnLabel); Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -1133,7 +1137,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -1133,7 +1137,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public Clob getClob(int columnIndex) throws SQLException { public Clob getClob(int columnIndex) throws SQLException {
try { try {
int id = getNextId(TraceObject.CLOB); int id = getNextId(TraceObject.CLOB);
debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + columnIndex + ")"); if (isDebugEnabled()) {
debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + columnIndex + ")");
}
Value v = get(columnIndex); Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -1153,8 +1159,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -1153,8 +1159,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public Clob getClob(String columnLabel) throws SQLException { public Clob getClob(String columnLabel) throws SQLException {
try { try {
int id = getNextId(TraceObject.CLOB); int id = getNextId(TraceObject.CLOB);
debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + if (isDebugEnabled()) {
quote(columnLabel) + ")"); debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" +
quote(columnLabel) + ")");
}
Value v = get(columnLabel); Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -1174,7 +1182,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -1174,7 +1182,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public Array getArray(int columnIndex) throws SQLException { public Array getArray(int columnIndex) throws SQLException {
try { try {
int id = getNextId(TraceObject.ARRAY); int id = getNextId(TraceObject.ARRAY);
debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + columnIndex + ")"); if (isDebugEnabled()) {
debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + columnIndex + ")");
}
Value v = get(columnIndex); Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -1194,8 +1204,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -1194,8 +1204,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public Array getArray(String columnLabel) throws SQLException { public Array getArray(String columnLabel) throws SQLException {
try { try {
int id = getNextId(TraceObject.ARRAY); int id = getNextId(TraceObject.ARRAY);
debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + if (isDebugEnabled()) {
quote(columnLabel) + ")"); debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" +
quote(columnLabel) + ")");
}
Value v = get(columnLabel); Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -3449,7 +3461,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -3449,7 +3461,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public NClob getNClob(int columnIndex) throws SQLException { public NClob getNClob(int columnIndex) throws SQLException {
try { try {
int id = getNextId(TraceObject.CLOB); int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnIndex + ")"); if (isDebugEnabled()) {
debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnIndex + ")");
}
Value v = get(columnIndex); Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
...@@ -3469,7 +3483,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -3469,7 +3483,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public NClob getNClob(String columnLabel) throws SQLException { public NClob getNClob(String columnLabel) throws SQLException {
try { try {
int id = getNextId(TraceObject.CLOB); int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnLabel + ")"); if (isDebugEnabled()) {
debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnLabel + ")");
}
Value v = get(columnLabel); Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id); return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) { } catch (Exception e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论