| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
package net.admin4j.jdbc.driver.sql; |
| 15 | |
|
| 16 | |
import java.sql.Connection; |
| 17 | |
import java.sql.DriverManager; |
| 18 | |
import java.sql.ResultSet; |
| 19 | |
import java.sql.SQLException; |
| 20 | |
import java.sql.SQLWarning; |
| 21 | |
import java.sql.Statement; |
| 22 | |
|
| 23 | |
import net.admin4j.jdbc.driver.SqlStatementTimerFactory; |
| 24 | |
import net.admin4j.timer.TaskTimer; |
| 25 | |
import net.admin4j.util.annotate.PackageRestrictions; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
@PackageRestrictions({"net.admin4j","java","javax"}) |
| 33 | |
public abstract class StatementWrapper30Base implements Statement { |
| 34 | |
|
| 35 | |
private ConnectionWrapper30Base connectionWrapper; |
| 36 | |
private Statement statement; |
| 37 | |
private StackTraceElement[] creationStackTrace; |
| 38 | 180057 | private boolean closed = false; |
| 39 | |
|
| 40 | 180057 | public StatementWrapper30Base(ConnectionWrapper30Base connection, Statement statement) { |
| 41 | 180057 | SQLWrappingUtils.notNull(statement, "Null statement not allowed."); |
| 42 | 180057 | SQLWrappingUtils.notNull(connection, "Null connection wrapper not allowed."); |
| 43 | 180057 | this.statement = statement; |
| 44 | 180057 | this.connectionWrapper = connection; |
| 45 | 180057 | } |
| 46 | |
|
| 47 | |
protected Statement getUnderlyingStatement() { |
| 48 | 240762 | return this.statement; |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void addBatch(String sql) throws SQLException { |
| 52 | 9 | this.statement.addBatch(sql); |
| 53 | |
|
| 54 | 9 | } |
| 55 | |
|
| 56 | |
public void cancel() throws SQLException { |
| 57 | 9 | this.statement.cancel(); |
| 58 | |
|
| 59 | 9 | } |
| 60 | |
|
| 61 | |
public void clearBatch() throws SQLException { |
| 62 | 9 | this.statement.clearBatch(); |
| 63 | |
|
| 64 | 9 | } |
| 65 | |
|
| 66 | |
public void clearWarnings() throws SQLException { |
| 67 | 9 | this.statement.clearWarnings(); |
| 68 | |
|
| 69 | 9 | } |
| 70 | |
|
| 71 | |
public void close() throws SQLException { |
| 72 | 120021 | this.statement.close(); |
| 73 | 120021 | closed = true; |
| 74 | 120021 | } |
| 75 | |
|
| 76 | |
public boolean execute(String sql) throws SQLException { |
| 77 | |
|
| 78 | 21 | TaskTimer timer = null; |
| 79 | |
try { |
| 80 | 21 | timer = SqlStatementTimerFactory.start(sql, |
| 81 | |
this.getConnectionWrapper().getDriverContext(), |
| 82 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 83 | 21 | return this.statement.execute(sql); |
| 84 | |
} |
| 85 | |
finally { |
| 86 | 21 | if (timer != null) timer.stop(); |
| 87 | |
} |
| 88 | |
} |
| 89 | |
|
| 90 | |
public boolean execute(String sql, int autoGeneratedKeys) |
| 91 | |
throws SQLException { |
| 92 | |
|
| 93 | 9 | TaskTimer timer = null; |
| 94 | |
try { |
| 95 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 96 | |
this.getConnectionWrapper().getDriverContext(), |
| 97 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 98 | 9 | return this.statement.execute(sql, autoGeneratedKeys); |
| 99 | |
} |
| 100 | |
finally { |
| 101 | 9 | if (timer != null) timer.stop(); |
| 102 | |
} |
| 103 | |
} |
| 104 | |
|
| 105 | |
public boolean execute(String sql, int[] columnIndexes) throws SQLException { |
| 106 | |
|
| 107 | 9 | TaskTimer timer = null; |
| 108 | |
try { |
| 109 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 110 | |
this.getConnectionWrapper().getDriverContext(), |
| 111 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 112 | 9 | return this.statement.execute(sql, columnIndexes); |
| 113 | |
} |
| 114 | |
finally { |
| 115 | 9 | if (timer != null) timer.stop(); |
| 116 | |
} |
| 117 | |
} |
| 118 | |
|
| 119 | |
public boolean execute(String sql, String[] columnNames) |
| 120 | |
throws SQLException { |
| 121 | |
|
| 122 | 9 | TaskTimer timer = null; |
| 123 | |
try { |
| 124 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 125 | |
this.getConnectionWrapper().getDriverContext(), |
| 126 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 127 | 9 | return this.statement.execute(sql, columnNames); |
| 128 | |
} |
| 129 | |
finally { |
| 130 | 9 | if (timer != null) timer.stop(); |
| 131 | |
} |
| 132 | |
} |
| 133 | |
|
| 134 | |
public int[] executeBatch() throws SQLException { |
| 135 | 9 | return this.statement.executeBatch(); |
| 136 | |
} |
| 137 | |
|
| 138 | |
public ResultSet executeQuery(String sql) throws SQLException { |
| 139 | |
|
| 140 | 9 | TaskTimer timer = null; |
| 141 | |
try { |
| 142 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 143 | |
this.getConnectionWrapper().getDriverContext(), |
| 144 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 145 | 9 | return this.statement.executeQuery(sql); |
| 146 | |
} |
| 147 | |
finally { |
| 148 | 9 | if (timer != null) timer.stop(); |
| 149 | |
} |
| 150 | |
} |
| 151 | |
|
| 152 | |
public int executeUpdate(String sql) throws SQLException { |
| 153 | |
|
| 154 | 9 | TaskTimer timer = null; |
| 155 | |
try { |
| 156 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 157 | |
this.getConnectionWrapper().getDriverContext(), |
| 158 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 159 | 9 | return this.statement.executeUpdate(sql); |
| 160 | |
} |
| 161 | |
finally { |
| 162 | 9 | if (timer != null) timer.stop(); |
| 163 | |
} |
| 164 | |
} |
| 165 | |
|
| 166 | |
public int executeUpdate(String sql, int autoGeneratedKeys) |
| 167 | |
throws SQLException { |
| 168 | |
|
| 169 | 9 | TaskTimer timer = null; |
| 170 | |
try { |
| 171 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 172 | |
this.getConnectionWrapper().getDriverContext(), |
| 173 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 174 | 9 | return this.statement.executeUpdate(sql, autoGeneratedKeys); |
| 175 | |
} |
| 176 | |
finally { |
| 177 | 9 | if (timer != null) timer.stop(); |
| 178 | |
} |
| 179 | |
} |
| 180 | |
|
| 181 | |
public int executeUpdate(String sql, int[] columnIndexes) |
| 182 | |
throws SQLException { |
| 183 | |
|
| 184 | 9 | TaskTimer timer = null; |
| 185 | |
try { |
| 186 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 187 | |
this.getConnectionWrapper().getDriverContext(), |
| 188 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 189 | 9 | return this.statement.executeUpdate(sql, columnIndexes); |
| 190 | |
} |
| 191 | |
finally { |
| 192 | 9 | if (timer != null) timer.stop(); |
| 193 | |
} |
| 194 | |
} |
| 195 | |
|
| 196 | |
public int executeUpdate(String sql, String[] columnNames) |
| 197 | |
throws SQLException { |
| 198 | |
|
| 199 | 9 | TaskTimer timer = null; |
| 200 | |
try { |
| 201 | 9 | timer = SqlStatementTimerFactory.start(sql, |
| 202 | |
this.getConnectionWrapper().getDriverContext(), |
| 203 | |
this.getConnectionWrapper().registerSqlStatement(sql)); |
| 204 | 9 | return this.statement.executeUpdate(sql, columnNames); |
| 205 | |
} |
| 206 | |
finally { |
| 207 | 9 | if (timer != null) timer.stop(); |
| 208 | |
} |
| 209 | |
} |
| 210 | |
|
| 211 | |
public Connection getConnection() throws SQLException { |
| 212 | 9 | return this.connectionWrapper; |
| 213 | |
} |
| 214 | |
|
| 215 | |
public int getFetchDirection() throws SQLException { |
| 216 | 9 | return this.statement.getFetchDirection(); |
| 217 | |
} |
| 218 | |
|
| 219 | |
public int getFetchSize() throws SQLException { |
| 220 | 9 | return this.statement.getFetchSize(); |
| 221 | |
} |
| 222 | |
|
| 223 | |
public ResultSet getGeneratedKeys() throws SQLException { |
| 224 | 9 | return this.statement.getGeneratedKeys(); |
| 225 | |
} |
| 226 | |
|
| 227 | |
public int getMaxFieldSize() throws SQLException { |
| 228 | 9 | return this.statement.getMaxFieldSize(); |
| 229 | |
} |
| 230 | |
|
| 231 | |
public int getMaxRows() throws SQLException { |
| 232 | 9 | return this.statement.getMaxRows(); |
| 233 | |
} |
| 234 | |
|
| 235 | |
public boolean getMoreResults() throws SQLException { |
| 236 | 9 | return this.statement.getMoreResults(); |
| 237 | |
} |
| 238 | |
|
| 239 | |
public boolean getMoreResults(int current) throws SQLException { |
| 240 | 9 | return this.statement.getMoreResults(current); |
| 241 | |
} |
| 242 | |
|
| 243 | |
public int getQueryTimeout() throws SQLException { |
| 244 | 9 | return this.statement.getQueryTimeout(); |
| 245 | |
} |
| 246 | |
|
| 247 | |
public ResultSet getResultSet() throws SQLException { |
| 248 | 9 | return this.statement.getResultSet(); |
| 249 | |
} |
| 250 | |
|
| 251 | |
public int getResultSetConcurrency() throws SQLException { |
| 252 | 9 | return this.statement.getResultSetConcurrency(); |
| 253 | |
} |
| 254 | |
|
| 255 | |
public int getResultSetHoldability() throws SQLException { |
| 256 | 9 | return this.statement.getResultSetHoldability(); |
| 257 | |
} |
| 258 | |
|
| 259 | |
public int getResultSetType() throws SQLException { |
| 260 | 9 | return this.statement.getResultSetType(); |
| 261 | |
} |
| 262 | |
|
| 263 | |
public int getUpdateCount() throws SQLException { |
| 264 | 9 | return this.statement.getUpdateCount(); |
| 265 | |
} |
| 266 | |
|
| 267 | |
public SQLWarning getWarnings() throws SQLException { |
| 268 | 9 | return this.statement.getWarnings(); |
| 269 | |
} |
| 270 | |
|
| 271 | |
public void setCursorName(String name) throws SQLException { |
| 272 | 9 | this.statement.setCursorName(name); |
| 273 | |
|
| 274 | 9 | } |
| 275 | |
|
| 276 | |
public void setEscapeProcessing(boolean enable) throws SQLException { |
| 277 | 9 | this.statement.setEscapeProcessing(enable); |
| 278 | |
|
| 279 | 9 | } |
| 280 | |
|
| 281 | |
public void setFetchDirection(int direction) throws SQLException { |
| 282 | 9 | this.statement.setFetchDirection(direction); |
| 283 | |
|
| 284 | 9 | } |
| 285 | |
|
| 286 | |
public void setFetchSize(int rows) throws SQLException { |
| 287 | 9 | this.statement.setFetchSize(rows); |
| 288 | |
|
| 289 | 9 | } |
| 290 | |
|
| 291 | |
public void setMaxFieldSize(int max) throws SQLException { |
| 292 | 9 | this.statement.setMaxFieldSize(max); |
| 293 | |
|
| 294 | 9 | } |
| 295 | |
|
| 296 | |
public void setMaxRows(int max) throws SQLException { |
| 297 | 9 | this.statement.setMaxRows(max); |
| 298 | |
|
| 299 | 9 | } |
| 300 | |
|
| 301 | |
public void setQueryTimeout(int seconds) throws SQLException { |
| 302 | 9 | this.statement.setQueryTimeout(seconds); |
| 303 | |
|
| 304 | 9 | } |
| 305 | |
|
| 306 | |
protected void finalize() throws Throwable { |
| 307 | 174906 | if (!this.closed) { |
| 308 | 55004 | DriverManager.getLogWriter().println("Leaked database statement closed."); |
| 309 | 0 | this.close(); |
| 310 | |
} |
| 311 | 119902 | super.finalize(); |
| 312 | 119902 | } |
| 313 | |
|
| 314 | |
public StackTraceElement[] getCreationStackTrace() { |
| 315 | 0 | return creationStackTrace; |
| 316 | |
} |
| 317 | |
|
| 318 | |
protected ConnectionWrapper30Base getConnectionWrapper() { |
| 319 | 180228 | return connectionWrapper; |
| 320 | |
} |
| 321 | |
|
| 322 | |
} |