1 29 30 package com.caucho.sql; 31 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import java.io.InputStream ; 36 import java.io.Reader ; 37 import java.math.BigDecimal ; 38 import java.net.URL ; 39 import java.sql.*; 40 import java.util.Calendar ; 41 import java.util.logging.Logger ; 42 43 46 public class UserPreparedStatement extends UserStatement 47 implements PreparedStatement { 48 protected final static Logger log = Log.open(UserPreparedStatement.class); 49 protected static L10N L = new L10N(UserPreparedStatement.class); 50 51 protected PreparedStatement _pstmt; 52 protected PreparedStatementCacheItem _cacheItem; 53 54 private boolean _isClosed; 55 56 UserPreparedStatement(UserConnection conn, 57 PreparedStatement pStmt, 58 PreparedStatementCacheItem cacheItem) 59 { 60 super(conn, pStmt); 61 62 _pstmt = pStmt; 63 _cacheItem = cacheItem; 64 65 if (pStmt == null) 66 throw new NullPointerException (); 67 } 68 69 UserPreparedStatement(UserConnection conn, 70 PreparedStatement pStmt) 71 { 72 this(conn, pStmt, null); 73 } 74 75 78 public PreparedStatement getPreparedStatement() 79 { 80 return _pstmt; 81 } 82 83 86 public ResultSet executeQuery() 87 throws SQLException 88 { 89 return _pstmt.executeQuery(); 90 } 91 92 95 public int executeUpdate() 96 throws SQLException 97 { 98 return _pstmt.executeUpdate(); 99 } 100 101 104 public boolean execute() 105 throws SQLException 106 { 107 return _pstmt.execute(); 108 } 109 110 113 public void addBatch() 114 throws SQLException 115 { 116 _pstmt.addBatch(); 117 } 118 119 122 public void clearParameters() 123 throws SQLException 124 { 125 _pstmt.clearParameters(); 126 } 127 128 131 public ResultSetMetaData getMetaData() 132 throws SQLException 133 { 134 return _pstmt.getMetaData(); 135 } 136 137 140 public ParameterMetaData getParameterMetaData() 141 throws SQLException 142 { 143 return _pstmt.getParameterMetaData(); 144 } 145 146 149 public void setNull(int parameterIndex, int sqlType) 150 throws SQLException 151 { 152 _pstmt.setNull(parameterIndex, sqlType); 153 } 154 155 158 public void setNull(int parameterIndex, int sqlType, String typeName) 159 throws SQLException 160 { 161 _pstmt.setNull(parameterIndex, sqlType, typeName); 162 } 163 164 167 public void setBoolean(int index, boolean value) 168 throws SQLException 169 { 170 _pstmt.setBoolean(index, value); 171 } 172 173 176 public void setByte(int index, byte value) 177 throws SQLException 178 { 179 _pstmt.setByte(index, value); 180 } 181 182 185 public void setShort(int index, short value) 186 throws SQLException 187 { 188 _pstmt.setShort(index, value); 189 } 190 191 194 public void setInt(int index, int value) 195 throws SQLException 196 { 197 _pstmt.setInt(index, value); 198 } 199 200 203 public void setLong(int index, long value) 204 throws SQLException 205 { 206 _pstmt.setLong(index, value); 207 } 208 209 212 public void setFloat(int index, float value) 213 throws SQLException 214 { 215 _pstmt.setFloat(index, value); 216 } 217 218 221 public void setDouble(int index, double value) 222 throws SQLException 223 { 224 _pstmt.setDouble(index, value); 225 } 226 227 230 public void setBigDecimal(int index, BigDecimal value) 231 throws SQLException 232 { 233 _pstmt.setBigDecimal(index, value); 234 } 235 236 239 public void setString(int index, String value) 240 throws SQLException 241 { 242 _pstmt.setString(index, value); 243 } 244 245 248 public void setBytes(int index, byte []value) 249 throws SQLException 250 { 251 _pstmt.setBytes(index, value); 252 } 253 254 257 public void setDate(int index, Date value) 258 throws SQLException 259 { 260 _pstmt.setDate(index, value); 261 } 262 263 266 public void setDate(int index, Date value, Calendar cal) 267 throws SQLException 268 { 269 _pstmt.setDate(index, value, cal); 270 } 271 272 275 public void setTime(int index, Time value) 276 throws SQLException 277 { 278 _pstmt.setTime(index, value); 279 } 280 281 284 public void setTime(int index, Time value, Calendar cal) 285 throws SQLException 286 { 287 _pstmt.setTime(index, value, cal); 288 } 289 290 293 public void setTimestamp(int index, Timestamp value) 294 throws SQLException 295 { 296 _pstmt.setTimestamp(index, value); 297 } 298 299 302 public void setTimestamp(int index, Timestamp value, Calendar cal) 303 throws SQLException 304 { 305 _pstmt.setTimestamp(index, value, cal); 306 } 307 308 311 public void setAsciiStream(int index, InputStream value, int length) 312 throws SQLException 313 { 314 _pstmt.setAsciiStream(index, value, length); 315 } 316 317 320 public void setUnicodeStream(int index, InputStream value, int length) 321 throws SQLException 322 { 323 _pstmt.setUnicodeStream(index, value, length); 324 } 325 326 329 public void setBinaryStream(int index, InputStream value, int length) 330 throws SQLException 331 { 332 _pstmt.setBinaryStream(index, value, length); 333 } 334 335 338 public void setCharacterStream(int index, Reader value, int length) 339 throws SQLException 340 { 341 _pstmt.setCharacterStream(index, value, length); 342 } 343 344 347 public void setObject(int index, Object value, int type, int scale) 348 throws SQLException 349 { 350 _pstmt.setObject(index, value, type, scale); 351 } 352 353 356 public void setObject(int index, Object value, int type) 357 throws SQLException 358 { 359 _pstmt.setObject(index, value, type); 360 } 361 362 365 public void setObject(int index, Object value) 366 throws SQLException 367 { 368 _pstmt.setObject(index, value); 369 } 370 371 374 public void setRef(int index, Ref value) 375 throws SQLException 376 { 377 _pstmt.setRef(index, value); 378 } 379 380 383 public void setBlob(int index, Blob value) 384 throws SQLException 385 { 386 _pstmt.setBlob(index, value); 387 } 388 389 392 public void setClob(int index, Clob value) 393 throws SQLException 394 { 395 _pstmt.setClob(index, value); 396 } 397 398 401 public void setArray(int index, Array value) 402 throws SQLException 403 { 404 _pstmt.setArray(index, value); 405 } 406 407 410 public void setURL(int index, URL value) 411 throws SQLException 412 { 413 _pstmt.setURL(index, value); 414 } 415 416 419 public void close() 420 throws SQLException 421 { 422 synchronized (this) { 423 if (_isClosed) 424 return; 425 _isClosed = true; 426 } 427 428 clearParameters(); 429 430 if (_cacheItem == null) 431 super.close(); 432 else if (_isChanged) 433 _cacheItem.destroy(); 434 else 435 _cacheItem.toIdle(); 436 } 437 438 public String toString() 439 { 440 return "UserPreparedStatement[" + _pstmt + "]"; 441 } 442 } 443 | Popular Tags |