| 1 |
package jp.co.powerbeans.jdbcdebug.sql; |
| 2 |
|
| 3 |
import java.sql.Connection; |
| 4 |
import java.sql.ResultSet; |
| 5 |
import java.sql.SQLException; |
| 6 |
import java.sql.SQLWarning; |
| 7 |
import java.util.ArrayList; |
| 8 |
import java.util.Iterator; |
| 9 |
|
| 10 |
import jp.co.powerbeans.jdbcdebug.util.Log; |
| 11 |
import jp.co.powerbeans.jdbcdebug.util.Survey; |
| 12 |
|
| 13 |
|
| 14 |
/** |
| 15 |
* <p>タイトル: Statement</p> |
| 16 |
* <p>説明: </p> |
| 17 |
* <p>Created on 2003/10/01</p> |
| 18 |
* @author 門田明彦 |
| 19 |
* @version $Revision: 1.1 $ |
| 20 |
*/ |
| 21 |
public class Statement implements java.sql.Statement { |
| 22 |
|
| 23 |
/** 実 Statement */ |
| 24 |
java.sql.Statement st; |
| 25 |
|
| 26 |
/** バッチSQL */ |
| 27 |
private ArrayList batchSqlList = new ArrayList(); |
| 28 |
|
| 29 |
/** |
| 30 |
* コンストラクタ |
| 31 |
* @param statement |
| 32 |
*/ |
| 33 |
Statement(java.sql.Statement statement) { |
| 34 |
|
| 35 |
st = statement; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* コンストラクタ |
| 40 |
*/ |
| 41 |
private Statement() { |
| 42 |
super(); |
| 43 |
} |
| 44 |
|
| 45 |
/* (non-Javadoc) |
| 46 |
* @see java.sql.Statement#addBatch(java.lang.String) |
| 47 |
*/ |
| 48 |
public void addBatch(String sql) throws SQLException { |
| 49 |
st.addBatch(sql); |
| 50 |
batchSqlList.add(sql); |
| 51 |
} |
| 52 |
|
| 53 |
/* (non-Javadoc) |
| 54 |
* @see java.sql.Statement#cancel() |
| 55 |
*/ |
| 56 |
public void cancel() throws SQLException { |
| 57 |
st.cancel(); |
| 58 |
} |
| 59 |
|
| 60 |
/* (non-Javadoc) |
| 61 |
* @see java.sql.Statement#clearBatch() |
| 62 |
*/ |
| 63 |
public void clearBatch() throws SQLException { |
| 64 |
st.clearBatch(); |
| 65 |
batchSqlList.clear(); |
| 66 |
} |
| 67 |
|
| 68 |
/* (non-Javadoc) |
| 69 |
* @see java.sql.Statement#clearWarnings() |
| 70 |
*/ |
| 71 |
public void clearWarnings() throws SQLException { |
| 72 |
st.clearWarnings(); |
| 73 |
} |
| 74 |
|
| 75 |
/* (non-Javadoc) |
| 76 |
* @see java.sql.Statement#close() |
| 77 |
*/ |
| 78 |
public void close() throws SQLException { |
| 79 |
st.close(); |
| 80 |
} |
| 81 |
|
| 82 |
/* (non-Javadoc) |
| 83 |
* @see java.sql.Statement#execute(java.lang.String, int) |
| 84 |
*/ |
| 85 |
public boolean execute(String sql, int autoGeneratedKeys) |
| 86 |
throws SQLException { |
| 87 |
|
| 88 |
try { |
| 89 |
Survey s = new Survey(); |
| 90 |
boolean r = st.execute(sql, autoGeneratedKeys); |
| 91 |
Log.printlnSqlLog("execute " + sql, s.doEnd()); |
| 92 |
return r; |
| 93 |
} catch (SQLException e) { |
| 94 |
Log.printlnSqlExceptionLog("execute " + sql, e); |
| 95 |
throw e; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/* (non-Javadoc) |
| 100 |
* @see java.sql.Statement#execute(java.lang.String, int[]) |
| 101 |
*/ |
| 102 |
public boolean execute(String sql, int[] columnIndexes) |
| 103 |
throws SQLException { |
| 104 |
|
| 105 |
try { |
| 106 |
Survey s = new Survey(); |
| 107 |
boolean r = st.execute(sql, columnIndexes); |
| 108 |
Log.printlnSqlLog("execute " + sql, s.doEnd()); |
| 109 |
return r; |
| 110 |
} catch (SQLException e) { |
| 111 |
Log.printlnSqlExceptionLog("execute " + sql, e); |
| 112 |
throw e; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/* (non-Javadoc) |
| 117 |
* @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) |
| 118 |
*/ |
| 119 |
public boolean execute(String sql, String[] columnNames) |
| 120 |
throws SQLException { |
| 121 |
|
| 122 |
try { |
| 123 |
Survey s = new Survey(); |
| 124 |
boolean r = st.execute(sql, columnNames); |
| 125 |
Log.printlnSqlLog("execute " + sql, s.doEnd()); |
| 126 |
return r; |
| 127 |
} catch (SQLException e) { |
| 128 |
Log.printlnSqlExceptionLog("execute " + sql, e); |
| 129 |
throw e; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/* (non-Javadoc) |
| 134 |
* @see java.sql.Statement#execute(java.lang.String) |
| 135 |
*/ |
| 136 |
public boolean execute(String sql) throws SQLException { |
| 137 |
|
| 138 |
try { |
| 139 |
Survey s = new Survey(); |
| 140 |
boolean r = st.execute(sql); |
| 141 |
Log.printlnSqlLog("execute " + sql, s.doEnd()); |
| 142 |
return r; |
| 143 |
} catch (SQLException e) { |
| 144 |
Log.printlnSqlExceptionLog("execute" + sql, e); |
| 145 |
throw e; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
/* (non-Javadoc) |
| 150 |
* @see java.sql.Statement#executeBatch() |
| 151 |
*/ |
| 152 |
public int[] executeBatch() throws SQLException { |
| 153 |
try { |
| 154 |
Survey s = new Survey(); |
| 155 |
int[] c = st.executeBatch(); |
| 156 |
|
| 157 |
// 実行したSQLを全て出力 |
| 158 |
int i = 0; |
| 159 |
for(Iterator it = batchSqlList.iterator(); it.hasNext();i++) { |
| 160 |
Log.printlnSqlLog("executeBatch " + it.next() + ", result " + c[i], s.doEnd()); |
| 161 |
} |
| 162 |
return c; |
| 163 |
|
| 164 |
} catch (SQLException e) { |
| 165 |
Log.printlnSqlExceptionLog("executeBatch ", e); |
| 166 |
throw e; |
| 167 |
} finally { |
| 168 |
batchSqlList.clear(); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
/* (non-Javadoc) |
| 173 |
* @see java.sql.Statement#executeQuery(java.lang.String) |
| 174 |
*/ |
| 175 |
public ResultSet executeQuery(String sql) throws SQLException { |
| 176 |
|
| 177 |
try { |
| 178 |
Survey s = new Survey(); |
| 179 |
ResultSet r = st.executeQuery(sql); |
| 180 |
Log.printlnSqlLog("executeQuery " + sql, s.doEnd()); |
| 181 |
return r; |
| 182 |
} catch (SQLException e) { |
| 183 |
Log.printlnSqlExceptionLog("executeQuery " + sql, e); |
| 184 |
throw e; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/* (non-Javadoc) |
| 189 |
* @see java.sql.Statement#executeUpdate(java.lang.String, int) |
| 190 |
*/ |
| 191 |
public int executeUpdate(String sql, int autoGeneratedKeys) |
| 192 |
throws SQLException { |
| 193 |
|
| 194 |
try { |
| 195 |
Survey s = new Survey(); |
| 196 |
int r = st.executeUpdate(sql, autoGeneratedKeys); |
| 197 |
Log.printlnSqlLog("executeUpdate " + sql, s.doEnd()); |
| 198 |
return r; |
| 199 |
} catch (SQLException e) { |
| 200 |
Log.printlnSqlExceptionLog("executeUpdate " + sql, e); |
| 201 |
throw e; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
/* (non-Javadoc) |
| 206 |
* @see java.sql.Statement#executeUpdate(java.lang.String, int[]) |
| 207 |
*/ |
| 208 |
public int executeUpdate(String sql, int[] columnIndexes) |
| 209 |
throws SQLException { |
| 210 |
|
| 211 |
try { |
| 212 |
Survey s = new Survey(); |
| 213 |
int r = st.executeUpdate(sql, columnIndexes); |
| 214 |
Log.printlnSqlLog("executeUpdate " + sql, s.doEnd()); |
| 215 |
return r; |
| 216 |
} catch (SQLException e) { |
| 217 |
Log.printlnSqlExceptionLog("executeUpdate " + sql, e); |
| 218 |
throw e; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
/* (non-Javadoc) |
| 223 |
* @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) |
| 224 |
*/ |
| 225 |
public int executeUpdate(String sql, String[] columnNames) |
| 226 |
throws SQLException { |
| 227 |
|
| 228 |
try { |
| 229 |
Survey s = new Survey(); |
| 230 |
int r = st.executeUpdate(sql, columnNames); |
| 231 |
Log.printlnSqlLog("executeUpdate " + sql, s.doEnd()); |
| 232 |
return r; |
| 233 |
} catch (SQLException e) { |
| 234 |
Log.printlnSqlExceptionLog("executeUpdate " + sql, e); |
| 235 |
throw e; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
/* (non-Javadoc) |
| 240 |
* @see java.sql.Statement#executeUpdate(java.lang.String) |
| 241 |
*/ |
| 242 |
public int executeUpdate(String sql) throws SQLException { |
| 243 |
|
| 244 |
try { |
| 245 |
Survey s = new Survey(); |
| 246 |
int r = st.executeUpdate(sql); |
| 247 |
Log.printlnSqlLog("executeUpdate " + sql, s.doEnd()); |
| 248 |
return r; |
| 249 |
} catch (SQLException e) { |
| 250 |
Log.printlnSqlExceptionLog("executeUpdate " + sql, e); |
| 251 |
throw e; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
/* (non-Javadoc) |
| 256 |
* @see java.sql.Statement#getConnection() |
| 257 |
*/ |
| 258 |
public Connection getConnection() throws SQLException { |
| 259 |
return st.getConnection(); |
| 260 |
} |
| 261 |
|
| 262 |
/* (non-Javadoc) |
| 263 |
* @see java.sql.Statement#getFetchDirection() |
| 264 |
*/ |
| 265 |
public int getFetchDirection() throws SQLException { |
| 266 |
return st.getFetchDirection(); |
| 267 |
} |
| 268 |
|
| 269 |
/* (non-Javadoc) |
| 270 |
* @see java.sql.Statement#getFetchSize() |
| 271 |
*/ |
| 272 |
public int getFetchSize() throws SQLException { |
| 273 |
return st.getFetchSize(); |
| 274 |
} |
| 275 |
|
| 276 |
/* (non-Javadoc) |
| 277 |
* @see java.sql.Statement#getGeneratedKeys() |
| 278 |
*/ |
| 279 |
public ResultSet getGeneratedKeys() throws SQLException { |
| 280 |
return st.getGeneratedKeys(); |
| 281 |
} |
| 282 |
|
| 283 |
/* (non-Javadoc) |
| 284 |
* @see java.sql.Statement#getMaxFieldSize() |
| 285 |
*/ |
| 286 |
public int getMaxFieldSize() throws SQLException { |
| 287 |
return st.getMaxFieldSize(); |
| 288 |
} |
| 289 |
|
| 290 |
/* (non-Javadoc) |
| 291 |
* @see java.sql.Statement#getMaxRows() |
| 292 |
*/ |
| 293 |
public int getMaxRows() throws SQLException { |
| 294 |
return st.getMaxRows(); |
| 295 |
} |
| 296 |
|
| 297 |
/* (non-Javadoc) |
| 298 |
* @see java.sql.Statement#getMoreResults() |
| 299 |
*/ |
| 300 |
public boolean getMoreResults() throws SQLException { |
| 301 |
return st.getMoreResults(); |
| 302 |
} |
| 303 |
|
| 304 |
/* (non-Javadoc) |
| 305 |
* @see java.sql.Statement#getMoreResults(int) |
| 306 |
*/ |
| 307 |
public boolean getMoreResults(int current) throws SQLException { |
| 308 |
return st.getMoreResults(); |
| 309 |
} |
| 310 |
|
| 311 |
/* (non-Javadoc) |
| 312 |
* @see java.sql.Statement#getQueryTimeout() |
| 313 |
*/ |
| 314 |
public int getQueryTimeout() throws SQLException { |
| 315 |
return st.getQueryTimeout(); |
| 316 |
} |
| 317 |
|
| 318 |
/* (non-Javadoc) |
| 319 |
* @see java.sql.Statement#getResultSet() |
| 320 |
*/ |
| 321 |
public ResultSet getResultSet() throws SQLException { |
| 322 |
return st.getResultSet(); |
| 323 |
} |
| 324 |
|
| 325 |
/* (non-Javadoc) |
| 326 |
* @see java.sql.Statement#getResultSetConcurrency() |
| 327 |
*/ |
| 328 |
public int getResultSetConcurrency() throws SQLException { |
| 329 |
return st.getResultSetConcurrency(); |
| 330 |
} |
| 331 |
|
| 332 |
/* (non-Javadoc) |
| 333 |
* @see java.sql.Statement#getResultSetHoldability() |
| 334 |
*/ |
| 335 |
public int getResultSetHoldability() throws SQLException { |
| 336 |
return st.getResultSetHoldability(); |
| 337 |
} |
| 338 |
|
| 339 |
/* (non-Javadoc) |
| 340 |
* @see java.sql.Statement#getResultSetType() |
| 341 |
*/ |
| 342 |
public int getResultSetType() throws SQLException { |
| 343 |
return st.getResultSetType(); |
| 344 |
} |
| 345 |
|
| 346 |
/* (non-Javadoc) |
| 347 |
* @see java.sql.Statement#getUpdateCount() |
| 348 |
*/ |
| 349 |
public int getUpdateCount() throws SQLException { |
| 350 |
return st.getUpdateCount(); |
| 351 |
} |
| 352 |
|
| 353 |
/* (non-Javadoc) |
| 354 |
* @see java.sql.Statement#getWarnings() |
| 355 |
*/ |
| 356 |
public SQLWarning getWarnings() throws SQLException { |
| 357 |
return st.getWarnings(); |
| 358 |
} |
| 359 |
|
| 360 |
/* (non-Javadoc) |
| 361 |
* @see java.sql.Statement#setCursorName(java.lang.String) |
| 362 |
*/ |
| 363 |
public void setCursorName(String name) throws SQLException { |
| 364 |
st.setCursorName(name); |
| 365 |
} |
| 366 |
|
| 367 |
/* (non-Javadoc) |
| 368 |
* @see java.sql.Statement#setEscapeProcessing(boolean) |
| 369 |
*/ |
| 370 |
public void setEscapeProcessing(boolean enable) throws SQLException { |
| 371 |
st.setEscapeProcessing(enable); |
| 372 |
} |
| 373 |
|
| 374 |
/* (non-Javadoc) |
| 375 |
* @see java.sql.Statement#setFetchDirection(int) |
| 376 |
*/ |
| 377 |
public void setFetchDirection(int direction) throws SQLException { |
| 378 |
st.setFetchDirection(direction); |
| 379 |
} |
| 380 |
|
| 381 |
/* (non-Javadoc) |
| 382 |
* @see java.sql.Statement#setFetchSize(int) |
| 383 |
*/ |
| 384 |
public void setFetchSize(int rows) throws SQLException { |
| 385 |
st.setFetchSize(rows); |
| 386 |
} |
| 387 |
|
| 388 |
/* (non-Javadoc) |
| 389 |
* @see java.sql.Statement#setMaxFieldSize(int) |
| 390 |
*/ |
| 391 |
public void setMaxFieldSize(int max) throws SQLException { |
| 392 |
st.setMaxFieldSize(max); |
| 393 |
} |
| 394 |
|
| 395 |
/* (non-Javadoc) |
| 396 |
* @see java.sql.Statement#setMaxRows(int) |
| 397 |
*/ |
| 398 |
public void setMaxRows(int max) throws SQLException { |
| 399 |
st.setMaxRows(max); |
| 400 |
} |
| 401 |
|
| 402 |
/* (non-Javadoc) |
| 403 |
* @see java.sql.Statement#setQueryTimeout(int) |
| 404 |
*/ |
| 405 |
public void setQueryTimeout(int seconds) throws SQLException { |
| 406 |
st.setQueryTimeout(seconds); |
| 407 |
} |
| 408 |
|
| 409 |
/** |
| 410 |
* @return |
| 411 |
* @throws SQLException |
| 412 |
* @see java.sql.Statement#isClosed() |
| 413 |
*/ |
| 414 |
public boolean isClosed() throws SQLException { |
| 415 |
return st.isClosed(); |
| 416 |
} |
| 417 |
|
| 418 |
/** |
| 419 |
* @return |
| 420 |
* @throws SQLException |
| 421 |
* @see java.sql.Statement#isPoolable() |
| 422 |
*/ |
| 423 |
public boolean isPoolable() throws SQLException { |
| 424 |
return st.isPoolable(); |
| 425 |
} |
| 426 |
|
| 427 |
/** |
| 428 |
* @param iface |
| 429 |
* @return |
| 430 |
* @throws SQLException |
| 431 |
* @see java.sql.Wrapper#isWrapperFor(java.lang.Class) |
| 432 |
*/ |
| 433 |
public boolean isWrapperFor(Class<?> iface) throws SQLException { |
| 434 |
return st.isWrapperFor(iface); |
| 435 |
} |
| 436 |
|
| 437 |
/** |
| 438 |
* @param poolable |
| 439 |
* @throws SQLException |
| 440 |
* @see java.sql.Statement#setPoolable(boolean) |
| 441 |
*/ |
| 442 |
public void setPoolable(boolean poolable) throws SQLException { |
| 443 |
st.setPoolable(poolable); |
| 444 |
} |
| 445 |
|
| 446 |
/** |
| 447 |
* @param <T> |
| 448 |
* @param iface |
| 449 |
* @return |
| 450 |
* @throws SQLException |
| 451 |
* @see java.sql.Wrapper#unwrap(java.lang.Class) |
| 452 |
*/ |
| 453 |
public <T> T unwrap(Class<T> iface) throws SQLException { |
| 454 |
return st.unwrap(iface); |
| 455 |
} |
| 456 |
|
| 457 |
} |