1 23 24 29 30 package com.sun.jdo.spi.persistence.support.sqlstore.impl; 31 32 import com.sun.jdo.api.persistence.support.*; 33 import com.sun.jdo.spi.persistence.utility.I18NHelper; 34 35 import java.util.Collection ; 36 import java.util.Properties ; 37 import java.util.ResourceBundle ; 38 39 41 42 public class PersistenceManagerWrapper implements PersistenceManager { 43 44 private PersistenceManagerWrapper prev = null; 46 47 private PersistenceManagerImpl pm = null; 49 50 private boolean isValid = false; 52 53 56 private final static ResourceBundle messages = I18NHelper.loadBundle( 57 "com.sun.jdo.spi.persistence.support.sqlstore.Bundle", PersistenceManagerWrapper.class.getClassLoader()); 59 60 PersistenceManagerWrapper(PersistenceManagerImpl pm) { 62 this.pm = pm; 63 prev = pm.getCurrentWrapper(); 64 pm.pushCurrentWrapper(this); 65 isValid = true; 66 } 67 68 72 public boolean isClosed() { 73 if (isValid) { 74 return pm.isClosed(); 75 } else { 76 return true; 77 } 78 } 79 80 85 public void close() { 86 if (isValid) { 87 isValid = false; 88 pm.popCurrentWrapper(prev); 89 pm = null; 90 prev = null; 91 } else { 92 throw new JDOUserException(I18NHelper.getMessage(messages, 93 "jdo.persistencemanagerwrapper.invalidpm")); } 95 } 96 97 101 public Transaction currentTransaction() { 102 if (isValid) { 103 return pm.currentTransaction(); 104 } else { 105 throw new JDOUserException(I18NHelper.getMessage(messages, 106 "jdo.persistencemanagerwrapper.invalidpm")); } 108 } 109 110 113 public Query newQuery() { 114 if (isValid) { 115 return pm.newQuery(); 116 } else { 117 throw new JDOUserException(I18NHelper.getMessage(messages, 118 "jdo.persistencemanagerwrapper.invalidpm")); } 120 } 121 122 129 public Query newQuery(Object compiled) { 130 if (isValid) { 131 return pm.newQuery(compiled); 132 } else { 133 throw new JDOUserException(I18NHelper.getMessage(messages, 134 "jdo.persistencemanagerwrapper.invalidpm")); } 136 } 137 138 142 public Query newQuery(Class cls) { 143 if (isValid) { 144 return pm.newQuery(cls); 145 } else { 146 throw new JDOUserException(I18NHelper.getMessage(messages, 147 "jdo.persistencemanagerwrapper.invalidpm")); } 149 } 150 151 157 public Query newQuery(Class cls, Collection cln) { 158 if (isValid) { 159 return pm.newQuery(cls, cln); 160 } else { 161 throw new JDOUserException(I18NHelper.getMessage(messages, 162 "jdo.persistencemanagerwrapper.invalidpm")); } 164 } 165 166 172 public Query newQuery(Class cls, String filter) { 173 if (isValid) { 174 return pm.newQuery(cls, filter); 175 } else { 176 throw new JDOUserException(I18NHelper.getMessage(messages, 177 "jdo.persistencemanagerwrapper.invalidpm")); } 179 } 180 181 188 public Query newQuery(Class cls, Collection cln, String filter) { 189 if (isValid) { 190 return pm.newQuery(cls, cln, filter); 191 } else { 192 throw new JDOUserException(I18NHelper.getMessage(messages, 193 "jdo.persistencemanagerwrapper.invalidpm")); } 195 } 196 197 206 public Collection getExtent(Class persistenceCapableClass, boolean subclasses) { 207 if (isValid) { 208 return pm.getExtent(persistenceCapableClass, subclasses); 209 } else { 210 throw new JDOUserException(I18NHelper.getMessage(messages, 211 "jdo.persistencemanagerwrapper.invalidpm")); } 213 } 214 215 227 public Object getObjectById(Object oid) { 228 if (isValid) { 229 return pm.getObjectById(oid); 230 } else { 231 throw new JDOUserException(I18NHelper.getMessage(messages, 232 "jdo.persistencemanagerwrapper.invalidpm")); } 234 } 235 236 261 public Object getObjectById (Object oid, boolean validate) { 262 if (isValid) { 263 return pm.getObjectById(oid, validate); 264 } else { 265 throw new JDOUserException(I18NHelper.getMessage(messages, 266 "jdo.persistencemanagerwrapper.invalidpm")); } 268 } 269 270 277 public Object getObjectId(Object pc) { 278 if (isValid) { 279 return pm.getObjectId(pc); 280 } else { 281 throw new JDOUserException(I18NHelper.getMessage(messages, 282 "jdo.persistencemanagerwrapper.invalidpm")); } 284 } 285 286 293 public Object getTransactionalInstance(Object pc) { 294 if (isValid) { 295 return pm.getTransactionalInstance(pc); 296 } else { 297 throw new JDOUserException(I18NHelper.getMessage(messages, 298 "jdo.persistencemanagerwrapper.invalidpm")); } 300 } 301 302 311 public void makePersistent(Object pc) { 312 if (isValid) { 313 pm.makePersistent(pc); 314 } else { 315 throw new JDOUserException(I18NHelper.getMessage(messages, 316 "jdo.persistencemanagerwrapper.invalidpm")); } 318 } 319 320 324 public void makePersistent(Object [] pcs) { 325 if (isValid) { 326 pm.makePersistent(pcs); 327 } else { 328 throw new JDOUserException(I18NHelper.getMessage(messages, 329 "jdo.persistencemanagerwrapper.invalidpm")); } 331 } 332 333 337 public void makePersistent(Collection pcs) { 338 if (isValid) { 339 pm.makePersistent(pcs); 340 } else { 341 throw new JDOUserException(I18NHelper.getMessage(messages, 342 "jdo.persistencemanagerwrapper.invalidpm")); } 344 } 345 346 358 public void deletePersistent(Object pc) { 359 if (isValid) { 360 pm.deletePersistent(pc); 361 } else { 362 throw new JDOUserException(I18NHelper.getMessage(messages, 363 "jdo.persistencemanagerwrapper.invalidpm")); } 365 } 366 367 371 public void deletePersistent(Object [] pcs) { 372 if (isValid) { 373 pm.deletePersistent(pcs); 374 } else { 375 throw new JDOUserException(I18NHelper.getMessage(messages, 376 "jdo.persistencemanagerwrapper.invalidpm")); } 378 } 379 380 384 public void deletePersistent(Collection pcs) { 385 if (isValid) { 386 pm.deletePersistent(pcs); 387 } else { 388 throw new JDOUserException(I18NHelper.getMessage(messages, 389 "jdo.persistencemanagerwrapper.invalidpm")); } 391 } 392 393 399 public PersistenceManagerFactory getPersistenceManagerFactory() { 400 if (isValid) { 401 return pm.getPersistenceManagerFactory(); 402 } else { 403 throw new JDOUserException(I18NHelper.getMessage(messages, 404 "jdo.persistencemanagerwrapper.invalidpm")); } 406 } 407 408 414 public void setUserObject(Object o) { 415 if (isValid) { 416 pm.setUserObject(o); 417 } else { 418 throw new JDOUserException(I18NHelper.getMessage(messages, 419 "jdo.persistencemanagerwrapper.invalidpm")); } 421 } 422 423 429 public Object getUserObject() { 430 if (isValid) { 431 return pm.getUserObject(); 432 } else { 433 throw new JDOUserException(I18NHelper.getMessage(messages, 434 "jdo.persistencemanagerwrapper.invalidpm")); } 436 } 437 438 446 public Properties getProperties() { 447 if (isValid) { 448 return pm.getProperties(); 449 } else { 450 throw new JDOUserException(I18NHelper.getMessage(messages, 451 "jdo.persistencemanagerwrapper.invalidpm")); } 453 } 454 455 462 public boolean getSupersedeDeletedInstance () { 463 if (isValid) { 464 return pm.getSupersedeDeletedInstance(); 465 } else { 466 throw new JDOUserException(I18NHelper.getMessage(messages, 467 "jdo.persistencemanagerwrapper.invalidpm")); } 469 } 470 471 472 476 public void setSupersedeDeletedInstance (boolean flag) { 477 if (isValid) { 478 pm.setSupersedeDeletedInstance(flag); 479 } else { 480 throw new JDOUserException(I18NHelper.getMessage(messages, 481 "jdo.persistencemanagerwrapper.invalidpm")); } 483 } 484 485 495 public boolean getRequireCopyObjectId() { 496 if (isValid) { 497 return pm.getRequireCopyObjectId(); 498 } else { 499 throw new JDOUserException(I18NHelper.getMessage(messages, 500 "jdo.persistencemanagerwrapper.invalidpm")); } 502 } 503 504 505 515 public void setRequireCopyObjectId (boolean flag) { 516 if (isValid) { 517 pm.setRequireCopyObjectId(flag); 518 } else { 519 throw new JDOUserException(I18NHelper.getMessage(messages, 520 "jdo.persistencemanagerwrapper.invalidpm")); } 522 } 523 524 533 public boolean getRequireTrackedSCO() { 534 if (isValid) { 535 return pm.getRequireTrackedSCO(); 536 } else { 537 throw new JDOUserException(I18NHelper.getMessage(messages, 538 "jdo.persistencemanagerwrapper.invalidpm")); } 540 } 541 542 550 public void setRequireTrackedSCO (boolean flag) { 551 if (isValid) { 552 pm.setRequireTrackedSCO(flag); 553 } else { 554 throw new JDOUserException(I18NHelper.getMessage(messages, 555 "jdo.persistencemanagerwrapper.invalidpm")); } 557 } 558 559 560 565 public Class getObjectIdClass(Class cls) { 566 if (isValid) { 567 return pm.getObjectIdClass(cls); 568 } else { 569 throw new JDOUserException(I18NHelper.getMessage(messages, 570 "jdo.persistencemanagerwrapper.invalidpm")); } 572 } 573 574 575 586 public Object newSCOInstance(Class type, Object owner, String fieldName) { 587 if (isValid) { 588 return pm.newSCOInstance(type, owner, fieldName); 589 } else { 590 throw new JDOUserException(I18NHelper.getMessage(messages, 591 "jdo.persistencemanagerwrapper.invalidpm")); } 593 } 594 595 596 612 public Object newCollectionInstance(Class type, Object owner, String fieldName, 613 Class elementType, boolean allowNulls, int initialSize) { 614 if (isValid) { 615 return pm.newCollectionInstance(type, owner, fieldName, elementType, allowNulls, initialSize); 616 } else { 617 throw new JDOUserException(I18NHelper.getMessage(messages, 618 "jdo.persistencemanagerwrapper.invalidpm")); } 620 } 621 622 623 public PersistenceManager getPersistenceManager() { 624 return (PersistenceManager) pm; 625 } 626 } 627 | Popular Tags |