View Javadoc
1 /* ==================================================================== 2 * License: 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * 3. The end-user documentation included with the redistribution, 17 * if any, must include the following acknowledgment: 18 * "This product includes software developed by 19 * Robert Half International (http://www.rhi.com/)." 20 * Alternately, this acknowledgment may appear in the software itself, 21 * if and wherever such third-party acknowledgments normally appear. 22 * 23 * 4. The names "Parc", "RHI", and "Robert Half International" must 24 * not be used to endorse or promote products derived from this 25 * software without prior written permission. For written 26 * permission, please contact pete.mckinstry@rhi.com. 27 * 28 * 5. Products derived from this software may not be called "PARC", 29 * nor may "PARC" appear in their name, without prior written 30 * permission of Robert Half International. 31 * 32 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 33 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 36 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 39 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 41 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 42 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 43 * SUCH DAMAGE. 44 * ==================================================================== 45 * 46 */ 47 package com.rhi.architecture.db; 48 49 import com.rhi.architecture.logging.LogUtil; 50 import com.rhi.architecture.logging.Logger; 51 52 import org.exolab.castor.jdo.ClassNotPersistenceCapableException; 53 import org.exolab.castor.jdo.Database; 54 import org.exolab.castor.jdo.DuplicateIdentityException; 55 import org.exolab.castor.jdo.LockNotGrantedException; 56 import org.exolab.castor.jdo.OQLQuery; 57 import org.exolab.castor.jdo.ObjectNotFoundException; 58 import org.exolab.castor.jdo.ObjectNotPersistentException; 59 import org.exolab.castor.jdo.PersistenceException; 60 import org.exolab.castor.jdo.Query; 61 import org.exolab.castor.jdo.QueryException; 62 import org.exolab.castor.jdo.TransactionAbortedException; 63 import org.exolab.castor.jdo.TransactionNotInProgressException; 64 import org.exolab.castor.persist.PersistenceInfoGroup; 65 import org.exolab.castor.persist.spi.Complex; 66 67 /*** 68 * Database wrapper - it is package private on purpose. It should not 69 * be used other than from the Factory. 70 * 71 * @author Pete McKinstry 72 * @copyright 2002, Robert Half Int'l., Inc. All rights reserved. 73 * 74 * @since 1.0 75 */ 76 class PooledDatabase implements Database { 77 78 private static Logger log = 79 LogUtil.getLogger(PooledDatabase.class.getName()); 80 81 private Database db; 82 private boolean closeFlag; 83 84 /*** 85 * Default Constructor 86 * 87 * @param db 88 * @since 1.0 89 */ 90 public PooledDatabase(Database db) { 91 this.db = db; 92 this.closeFlag = false; 93 } 94 95 /*** 96 * @return String 97 * @see org.exolab.castor.jdo.Database#getDatabaseName() 98 */ 99 public String getDatabaseName() { 100 return (db==null)?null:db.getDatabaseName(); 101 } 102 103 /*** 104 * reset() 105 */ 106 public void reset() { 107 this.closeFlag = false; 108 } 109 110 /*** 111 * the isClosed() returns a hard coded true, so that 112 * if clients are using it w/in a finally to check if 113 * close() should be called, their code will work ok. 114 * may be better ot use a flag that is truly conditional. 115 * i'll have to think about that.... 116 * @return 117 */ 118 public boolean isClosed() { 119 return closeFlag; 120 } 121 122 /*** 123 * the close on this managed DB class is a no-op. 124 * the close is handled by the Factory, so when a 125 * client calls this method, it does nothing. 126 * @throws PersistenceException 127 */ 128 public void close() throws PersistenceException { 129 // no op - managed 130 closeFlag = true; 131 } 132 133 /*** 134 * Real isClosed(). used by factory. 135 * @return 136 */ 137 public boolean realIsClosed() { 138 return db.isClosed(); 139 } 140 141 /*** 142 * The realClose() method is used by the factory to shutdown the 143 * Database. 144 * @throws PersistenceException 145 */ 146 public void realClose() throws PersistenceException { 147 db.close(); 148 } 149 150 //------------------------------------------------------- 151 // All methods below are deferred to real Database implementation 152 // class. See Castor docs for details on these methods. 153 // ------------------------------------------------------- 154 155 /*** 156 * @return 157 * @see org.exolab.castor.jdo.Database#getOQLQuery() 158 */ 159 public OQLQuery getOQLQuery() { 160 return db.getOQLQuery(); 161 } 162 163 /*** 164 * @param oql 165 * @return 166 * @throws QueryException 167 * @see org.exolab.castor.jdo.Database#getOQLQuery(java.lang.String) 168 */ 169 public OQLQuery getOQLQuery(String oql) throws QueryException { 170 return db.getOQLQuery(); 171 } 172 173 /*** 174 * @return 175 * @see org.exolab.castor.jdo.Database#getQuery() 176 */ 177 public Query getQuery() { 178 return db.getQuery(); 179 } 180 181 /*** 182 * @return 183 * @see org.exolab.castor.jdo.Database#getScope() 184 */ 185 public PersistenceInfoGroup getScope() { 186 return db.getScope(); 187 } 188 189 /*** 190 * @param type 191 * @param identity 192 * @return 193 * @throws TransactionNotInProgressException 194 * @throws ObjectNotFoundException 195 * @throws LockNotGrantedException 196 * @throws PersistenceException 197 * @see org.exolab.castor.jdo.Database#load(java.lang.Class, java.lang.Object) 198 */ 199 public Object load(Class type, Object identity) 200 throws 201 TransactionNotInProgressException, 202 ObjectNotFoundException, 203 LockNotGrantedException, 204 PersistenceException { 205 return db.load(type, identity); 206 } 207 208 /*** 209 * @param type 210 * @param identity 211 * @return 212 * @throws ObjectNotFoundException 213 * @throws LockNotGrantedException 214 * @throws TransactionNotInProgressException 215 * @throws PersistenceException 216 * @see org.exolab.castor.jdo.Database#load(java.lang.Class, org.exolab.castor.persist.spi.Complex) 217 */ 218 public Object load(Class type, Complex identity) 219 throws 220 ObjectNotFoundException, 221 LockNotGrantedException, 222 TransactionNotInProgressException, 223 PersistenceException { 224 return db.load(type, identity); 225 } 226 227 /*** 228 * @param type 229 * @param identity 230 * @param accessMode 231 * @return 232 * @throws TransactionNotInProgressException 233 * @throws ObjectNotFoundException 234 * @throws LockNotGrantedException 235 * @throws PersistenceException 236 * @see org.exolab.castor.jdo.Database#load(java.lang.Class, java.lang.Object, short) 237 */ 238 public Object load(Class type, Object identity, short accessMode) 239 throws 240 TransactionNotInProgressException, 241 ObjectNotFoundException, 242 LockNotGrantedException, 243 PersistenceException { 244 return db.load(type, identity, accessMode); 245 } 246 247 /*** 248 * @param type 249 * @param identity 250 * @param accessMode 251 * @return 252 * @throws ObjectNotFoundException 253 * @throws LockNotGrantedException 254 * @throws TransactionNotInProgressException 255 * @throws PersistenceException 256 * @see org.exolab.castor.jdo.Database#load(java.lang.Class, org.exolab.castor.persist.spi.Complex, short) 257 */ 258 public Object load(Class type, Complex identity, short accessMode) 259 throws 260 ObjectNotFoundException, 261 LockNotGrantedException, 262 TransactionNotInProgressException, 263 PersistenceException { 264 return db.load(type, identity, accessMode); 265 } 266 267 /*** 268 * @param type 269 * @param identity 270 * @param object 271 * @return 272 * @throws ObjectNotFoundException 273 * @throws LockNotGrantedException 274 * @throws TransactionNotInProgressException 275 * @throws PersistenceException 276 * @see org.exolab.castor.jdo.Database#load(java.lang.Class, java.lang.Object, java.lang.Object) 277 */ 278 public Object load(Class type, Object identity, Object object) 279 throws 280 ObjectNotFoundException, 281 LockNotGrantedException, 282 TransactionNotInProgressException, 283 PersistenceException { 284 return db.load(type, identity, object); 285 } 286 287 /*** 288 * @param object 289 * @throws ClassNotPersistenceCapableException 290 * @throws DuplicateIdentityException 291 * @throws TransactionNotInProgressException 292 * @throws PersistenceException 293 * @see org.exolab.castor.jdo.Database#create(java.lang.Object) 294 */ 295 public void create(Object object) 296 throws 297 ClassNotPersistenceCapableException, 298 DuplicateIdentityException, 299 TransactionNotInProgressException, 300 PersistenceException { 301 db.create(object); 302 } 303 304 /*** 305 * @param object 306 * @throws ObjectNotPersistentException 307 * @throws LockNotGrantedException 308 * @throws TransactionNotInProgressException 309 * @throws PersistenceException 310 * @see org.exolab.castor.jdo.Database#remove(java.lang.Object) 311 */ 312 public void remove(Object object) 313 throws 314 ObjectNotPersistentException, 315 LockNotGrantedException, 316 TransactionNotInProgressException, 317 PersistenceException { 318 db.remove(object); 319 } 320 321 /*** 322 * @param object 323 * @throws ClassNotPersistenceCapableException 324 * @throws TransactionNotInProgressException 325 * @throws PersistenceException 326 * @see org.exolab.castor.jdo.Database#update(java.lang.Object) 327 */ 328 public void update(Object object) 329 throws 330 ClassNotPersistenceCapableException, 331 TransactionNotInProgressException, 332 PersistenceException { 333 db.update(object); 334 } 335 336 /*** 337 * @param object 338 * @throws LockNotGrantedException 339 * @throws ObjectNotPersistentException 340 * @throws TransactionNotInProgressException 341 * @throws PersistenceException 342 * @see org.exolab.castor.jdo.Database#lock(java.lang.Object) 343 */ 344 public void lock(Object object) 345 throws 346 LockNotGrantedException, 347 ObjectNotPersistentException, 348 TransactionNotInProgressException, 349 PersistenceException { 350 db.lock(object); 351 } 352 353 /*** 354 * @throws PersistenceException 355 * @see org.exolab.castor.jdo.Database#begin() 356 */ 357 public void begin() throws PersistenceException { 358 db.begin(); 359 } 360 361 /*** 362 * @return 363 * @see org.exolab.castor.jdo.Database#isAutoStore() 364 */ 365 public boolean isAutoStore() { 366 return db.isAutoStore(); 367 } 368 369 /*** 370 * @param autoStore 371 * @see org.exolab.castor.jdo.Database#setAutoStore(boolean) 372 */ 373 public void setAutoStore(boolean autoStore) { 374 db.setAutoStore(autoStore); 375 } 376 377 /*** 378 * @throws TransactionNotInProgressException 379 * @throws TransactionAbortedException 380 * @see org.exolab.castor.jdo.Database#commit() 381 */ 382 public void commit() 383 throws TransactionNotInProgressException, TransactionAbortedException { 384 db.commit(); 385 } 386 387 /*** 388 * @throws TransactionNotInProgressException 389 * @see org.exolab.castor.jdo.Database#rollback() 390 */ 391 public void rollback() throws TransactionNotInProgressException { 392 db.rollback(); 393 } 394 395 /*** 396 * @return 397 * @see org.exolab.castor.jdo.Database#isActive() 398 */ 399 public boolean isActive() { 400 return db.isActive(); 401 } 402 403 /*** 404 * @param object 405 * @return 406 * @see org.exolab.castor.jdo.Database#isPersistent(java.lang.Object) 407 */ 408 public boolean isPersistent(Object object) { 409 return db.isPersistent(object); 410 } 411 412 /*** 413 * @param object 414 * @return 415 * @see org.exolab.castor.jdo.Database#getIdentity(java.lang.Object) 416 */ 417 public Object getIdentity(Object object) { 418 return db.getIdentity(object); 419 } 420 421 /*** 422 * @return 423 * @see org.exolab.castor.jdo.Database#getClassLoader() 424 */ 425 public ClassLoader getClassLoader() { 426 return db.getClassLoader(); 427 } 428 429 /*** 430 * @param object 431 * 432 * @see org.exolab.castor.jdo.Database#makePersistent(Object) 433 * @deprecated 434 * @throws ClassNotPersistenceCapableException 435 * @throws DuplicateIdentityException 436 * @throws PersistenceException 437 */ 438 public void makePersistent(Object object) 439 throws 440 ClassNotPersistenceCapableException, 441 DuplicateIdentityException, 442 PersistenceException { 443 db.makePersistent(object); 444 } 445 446 /*** 447 * @param object 448 * 449 * @see org.exolab.castor.jdo.Database#deletePersistent(Object) 450 * @deprecated 451 * @throws ObjectNotPersistentException 452 * @throws LockNotGrantedException 453 * @throws PersistenceException 454 */ 455 public void deletePersistent(Object object) 456 throws 457 ObjectNotPersistentException, 458 LockNotGrantedException, 459 PersistenceException { 460 db.deletePersistent(object); 461 } 462 463 /*** 464 * 465 * @see org.exolab.castor.jdo.Database#checkpoint() 466 * @deprecated 467 * @throws TransactionNotInProgressException 468 * @throws TransactionAbortedException 469 */ 470 public void checkpoint() 471 throws TransactionNotInProgressException, TransactionAbortedException { 472 db.checkpoint(); 473 } 474 475 }

This page was automatically generated by Maven