提交 c41b599b authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #369 from marschall/jdbc-debug-guards

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