1 2 12 package com.versant.core.ejb; 13 14 import com.versant.core.metadata.ModelMetaData; 15 import com.versant.core.metadata.ClassMetaData; 16 import com.versant.core.metadata.FetchGroup; 17 import com.versant.core.metadata.FieldMetaData; 18 import com.versant.core.jdo.*; 19 import com.versant.core.storagemanager.StorageManager; 20 import com.versant.core.storagemanager.ApplicationContext; 21 import com.versant.core.common.*; 22 import com.versant.core.ejb.common.EntrySet; 23 import com.versant.core.ejb.common.IdentityEntry; 24 25 import javax.jdo.*; 26 import javax.jdo.spi.PersistenceCapable; 27 import javax.persistence.EntityManager; 28 import javax.persistence.Query; 29 import javax.persistence.EntityNotFoundException; 30 import javax.persistence.TransactionRequiredException; 31 import javax.transaction.Synchronization ; 32 import java.util.*; 33 import java.lang.reflect.Field ; 34 import java.sql.Connection ; 35 36 39 public class EntityManagerImp implements EntityManager, Transaction, 40 ApplicationContext, PersistenceContext { 41 public final StorageManager storageMan; 42 ModelMetaData modelMetaData; 43 private EMProxy proxy; 44 47 private Set<StateManagerImp> txObjects = new HashSet<StateManagerImp>(); 48 private LocalCache cache = new LocalCache(); 49 52 private final DeletePacket toBeDeleted; 53 56 public final StatesToStore storeOidStateContainer; 57 private boolean txActive; 58 61 private int newOidCounter; 62 63 public EntityManagerImp(StorageManager sm, ModelMetaData modelMetaData) { 64 this.storageMan = sm; 65 this.modelMetaData = modelMetaData; 66 toBeDeleted = new DeletePacket(modelMetaData); 67 storeOidStateContainer = new StatesToStore(modelMetaData); 68 } 69 70 public Transaction getTransaction() { 71 return this; 72 } 73 74 78 public boolean isStateRequired(OID oid, FetchGroup fetchGroup) { 79 return true; 87 } 88 89 public void close() { 90 } 91 92 public void isOpen() { 93 } 94 95 117 public void persist(Object entity) { 118 if (entity == null) return; 119 checkForActiveTransaction(); 120 121 final IdentityEntry tailPointer = new IdentityEntry("HEAD"); 123 EntrySet mergeSet = new EntrySet() { 124 public IdentityEntry tail = tailPointer; 125 126 public Entry createEntry(Object key) { 127 IdentityEntry ne = new IdentityEntry(key); 128 tail.nextEntry = ne; 129 tail = ne; 130 return ne; 131 } 132 }; 133 134 mergeSet.add(entity); 135 for (IdentityEntry ie = tailPointer.nextEntry; ie != null; ie = ie.nextEntry) { 136 persistImp(ie.getKey(), mergeSet); 137 } 138 } 139 140 143 public void addToCache(StatesReturned container) { 144 for (Iterator i = container.iterator(); i.hasNext(); ) { 145 com.versant.core.common.EntrySet.Entry e = (com.versant.core.common.EntrySet.Entry)i.next(); 146 cache.add((OID)e.getKey(), (State)e.getValue()); 147 } 148 } 149 150 private void persistImp(Object entity, EntrySet mergeSet) { 151 if (entity == null) return; 152 LifeCycleStatus lfs = getLifeCycleStatus(entity); 153 switch(lfs) { 154 case NEW: 155 manage(entity).persistReferences(mergeSet); 156 break; 157 case MANAGED: 158 getStateManager((PersistenceCapable) entity).persistReferences(mergeSet); 159 break; 160 case DETACHED: 161 throw new IllegalArgumentException ( 162 "The supplied instance is a detached instance. " + 163 "Please make use of the 'merge' operation."); 164 } 165 } 166 167 171 private void checkForActiveTransaction() { 172 if (!txActive) throw new TransactionRequiredException(); 173 } 174 175 180 private StateManagerImp manage(Object entity) { 181 StateManagerImp sm = new StateManagerImp(proxy, modelMetaData); 182 sm.manageNew((PersistenceCapable) entity, cache, newOidCounter++); 183 txObjects.add(sm); 184 return sm; 185 } 186 187 191 private void manageReferences(Object entity) { 192 } 194 195 199 public LifeCycleStatus getLifeCycleStatus(Object entity) { 200 if (!(entity instanceof PersistenceCapable)) { 201 throw new IllegalArgumentException ("The supplied instance '" 202 + entity.getClass().getName() + "' is not a manageble type"); 203 } 204 PersistenceCapable pc = (PersistenceCapable) entity; 205 PersistenceManager pm = pc.jdoGetPersistenceManager(); 206 if (pm == null) { 207 if ((entity instanceof VersantDetachable) 208 && ((VersantDetachable)entity).versantGetDetachedStateManager() != null) { 209 return LifeCycleStatus.DETACHED; 210 } 211 return LifeCycleStatus.NEW; 212 } 213 214 if (pm != this) { 215 throw new IllegalArgumentException ("The supplied entity is not " + 216 "managed does by this EntityManager"); 217 } 218 219 StateManagerImp em = getStateManager(pc); 220 if (em.isRemoved()) { 221 return LifeCycleStatus.REMOVED; 222 } 223 return LifeCycleStatus.MANAGED; 224 } 225 226 private void detachOnCommit() { 227 VersantDetachedStateManager vdsm = new VersantDetachedStateManager(); 228 Iterator iter = cache.getCacheIterator(); 229 while (iter.hasNext()) { 230 LocalCache.CacheEntry entry = (LocalCache.CacheEntry) iter.next(); 231 if (entry.getValue() instanceof StateManagerImp) { 232 ((StateManagerImp) entry.getValue()).detachOnCommit(vdsm); 233 } 234 } 235 } 236 237 240 private StateManagerImp getStateManager(PersistenceCapable pc) { 241 StateManagerImp em = null; 242 try { 243 Field f = pc.getClass().getDeclaredField("jdoStateManager"); 244 f.setAccessible(true); 245 em = (StateManagerImp) f.get(pc); 246 } catch (Exception e) { 247 e.printStackTrace(System.out); 248 } 249 return em; 250 } 251 252 283 public <T> T merge(T entity) { 284 final IdentityEntry tailPointer = new IdentityEntry("HEAD"); 286 EntrySet mergeSet = new EntrySet() { 287 public IdentityEntry tail = tailPointer; 288 289 public Entry createEntry(Object key) { 290 IdentityEntry ne = new IdentityEntry(key); 291 tail.nextEntry = ne; 292 tail = ne; 293 return ne; 294 } 295 }; 296 297 mergeSet.add(entity); 298 T result = (T) mergeInternal(entity, mergeSet).pc; 299 getStateManager((PersistenceCapable) result).mergeReferences(mergeSet); 300 301 for (IdentityEntry ie = tailPointer.nextEntry.nextEntry; ie != null; ie = ie.nextEntry) { 302 mergeInternal(ie.getKey(), mergeSet).mergeReferences(mergeSet); 303 } 304 305 return result; 306 } 307 308 314 public StateManagerImp mergeInternal(Object entity, EntrySet mergeSet) { 315 IdentityEntry e = (IdentityEntry) mergeSet.addAndReturnEntry(entity); 316 if (e.value != null) { 317 return (StateManagerImp) e.value; 318 } 319 switch(getLifeCycleStatus(entity)) { 320 case NEW: 321 return (StateManagerImp) (e.value = manage(entity)); 322 case MANAGED: 323 checkManagedBy(entity); 324 return (StateManagerImp) (e.value = getStateManager((PersistenceCapable)entity)); 325 case DETACHED: 326 VersantDetachable de = (VersantDetachable) entity; 327 OID oid = extractOID(de.versantGetOID()); 328 StateManagerImp sm = getObjectById(oid); 329 330 if (sm.cmd.optimisticLockingField != null && 332 !de.versantGetVersion().equals(sm.getOptimisticLockingValue())) { 333 throw new RuntimeException ("Conncurrent update"); 334 } 335 336 mergeFromDetached(de, sm); 337 return (StateManagerImp) (e.value = sm); 338 case REMOVED: 339 throw new IllegalStateException ( 340 "'merge' operation not allowed on '" 341 + getLifeCycleStatus(entity) + "' instances"); 342 default: 343 throw BindingSupportImpl.getInstance().internal("Unhandled lifecycle state '" +getLifeCycleStatus(entity)+"'"); 344 345 } 346 } 347 348 public <T> T mergeImp(T entity, EntrySet mergeSet) { 349 switch(getLifeCycleStatus(entity)) { 350 case NEW: 351 return (T)manage(entity).mergeReferences(mergeSet).pc; 352 case MANAGED: 353 checkManagedBy(entity); 354 return (T)getStateManager((PersistenceCapable)entity).mergeReferences(mergeSet).pc; 355 case DETACHED: 356 VersantDetachable de = (VersantDetachable) entity; 357 OID oid = extractOID(de.versantGetOID()); 358 StateManagerImp sm = getObjectById(oid); 359 360 if (sm.cmd.optimisticLockingField != null && 362 !de.versantGetVersion().equals(sm.getOptimisticLockingValue())) { 363 throw new RuntimeException ("Conncurrent update"); 364 } 365 mergeFromDetached(de, sm); 366 sm.mergeReferences(mergeSet); 367 return (T) sm.pc; 368 case REMOVED: 369 throw new IllegalStateException ( 370 "'merge' operation not allowed on '" 371 + getLifeCycleStatus(entity) + "' instances"); 372 default: 373 throw BindingSupportImpl.getInstance().internal("Unhandled lifecycle state '" +getLifeCycleStatus(entity)+"'"); 374 375 } 376 } 377 378 381 private void mergeFromDetached(VersantDetachable de, StateManagerImp sm) { 382 if (de.versantIsDirty()) { 384 VersantDetachedStateManager dsm = de.versantGetDetachedStateManager(); 385 AttachStateManager asm = new AttachStateManager(); 386 asm.setSm(sm); 387 try { 388 de.jdoReplaceStateManager(asm); 389 FieldMetaData[] mFields = sm.cmd.managedFields; 390 for (int i = 0; i < mFields.length; i++) { 391 FieldMetaData mField = mFields[i]; 392 if (de.versantIsDirty(mField.managedFieldNo)) { 393 de.jdoProvideField(mField.managedFieldNo); 394 } 395 } 396 } finally { 397 de.jdoReplaceStateManager(dsm); 398 } 399 } 400 } 401 402 408 private<T> T createManagedInstanceFrom(T t) { 409 return null; 410 } 411 412 416 private void checkManagedBy(Object managedVal) throws UserException { 417 } 419 420 427 public StateManagerImp getObjectById(OID oid) { 428 StateManagerImp sm = getSmFromCache(oid); 429 if (sm == null) { 430 ClassMetaData cmd = oid.getAvailableClassMetaData(); 431 StatesReturned sr = null; 432 try { 433 sr = storageMan.fetch(this, oid, null, cmd.fetchGroups[0], null); 434 } catch (JDOObjectNotFoundException e) { 435 throw throwEntityNotFound(oid); 436 } 437 sm = new StateManagerImp(proxy, modelMetaData); 438 oid = sr.getDirectOID(); 439 440 sm.manage(oid, sr.get(oid), cache); 441 } 442 return sm; 443 } 444 445 public StateManagerImp manage(OID oid, State state) { 446 StateManagerImp sm = new StateManagerImp(proxy, modelMetaData); 447 sm.manage(oid, state, cache); 448 return sm; 449 } 450 451 public void fetchState(StateManagerImp sm, FetchGroup fg) { 452 StatesReturned sr = null; 453 try { 454 sr = storageMan.fetch(this, sm.oid, null, fg, null); 455 } catch (JDOObjectNotFoundException e) { 456 throw throwEntityNotFound(sm.oid); 457 } 458 sm.updateState(sr.get(sm.oid)); 459 } 460 461 public Object getObjectByIdForState(OID oid, int stateFieldNo, int navClassIndex, OID fromOID) { 462 try { 463 PersistenceCapable pc = null; 464 FieldMetaData fmd = fromOID.getAvailableClassMetaData().stateFields[stateFieldNo]; 465 if (fmd.embedded) { 466 if (true) throw new RuntimeException (); 467 } else { 477 StateManagerImp sm = getObjectById(oid); 478 pc = sm.pc; 479 } 480 return pc; 481 } catch (Exception e) { 482 handleException(e); 483 return null; 484 } 485 } 486 487 public OID extractOID(Object oid) { 488 if (oid instanceof VersantOid) { 489 return modelMetaData.convertJDOGenieOIDtoOID((VersantOid)oid); 490 } else { 491 return modelMetaData.convertFromAppIdToOID(oid); 492 } 493 } 494 495 private OID convertNewToActual(OID oid) { 496 if (!oid.isNew()) { 497 oid.getAvailableClassMetaData(); 498 return oid; 499 } 500 return oid.getAvailableOID(); 501 } 502 503 509 private <T> T findManagedInstanceforDetached(T detached) { 510 return null; 511 } 512 513 public void remove(Object entity) { 514 checkForActiveTransaction(); 515 LifeCycleStatus lfs = getLifeCycleStatus(entity); 516 switch (lfs) { 517 case DETACHED: 518 case REMOVED: 519 throw new IllegalArgumentException ("May not remove 'DETACHED' or 'REMOVED' instances"); 520 case MANAGED: 521 StateManagerImp sm = getStateManager((PersistenceCapable) entity); 522 sm.remove(); 523 break; 524 case NEW: 525 526 break; 527 default: 528 throw new RuntimeException ("Unhandled lifecycle state: '" 529 + lfs + "'"); 530 } 531 } 532 533 public Object find(String entityName, Object primaryKey) { 534 return null; 535 } 536 537 public <T> T find(Class <T> entityClass, Object primaryKey) { 538 ClassMetaData cmd = modelMetaData.getClassMetaData(entityClass); 539 if (cmd == null) { 540 throw new IllegalArgumentException ("The class '" 541 + entityClass.getName() 542 + "' is not a persistable class"); 543 } 544 OID oid = cmd.createOID(false).fillFromIDObject(primaryKey); 545 StateManagerImp sm = getSmFromCache(oid); 546 if (sm == null) { 547 StatesReturned sr = null; 548 try { 549 sr = storageMan.fetch(this, oid, null, cmd.fetchGroups[0], null); 550 } catch (JDOObjectNotFoundException e) { 551 throw throwEntityNotFound(entityClass, primaryKey); 552 } 553 sm = new StateManagerImp(proxy, modelMetaData); 554 oid = sr.getDirectOID(); 555 sm.manage(oid, sr.get(oid), cache); 556 } 557 return (T) sm.getPersistenceCapable(); 558 } 559 560 private StateManagerImp getSmFromCache(OID oid) { 561 Object o = cache.get(oid); 562 if (o == null) return null; 563 if (o instanceof StateManagerImp) return (StateManagerImp) o; 564 if (o instanceof State) { 565 return manage(oid, (State) o); 566 } 567 throw BindingSupportImpl.getInstance().internal( 568 "Unhandled instance type '" + o.getClass().getName() + "' in local cache"); 569 570 } 571 572 private static RuntimeException throwEntityNotFound(Class entityClass, Object primaryKey) { 573 return new EntityNotFoundException("Entity '" 574 + entityClass.getName() + "' with id '" + primaryKey + "' can not be found."); 575 } 576 577 private static RuntimeException throwEntityNotFound(OID oid) { 578 return new EntityNotFoundException("Entity '" 579 + oid.getAvailableClassMetaData().qname + "' with id '" + oid 580 + "' can not be found."); 581 } 582 583 public void flush() { 584 checkForActiveTransaction(); 585 StatesReturned sc = null; 586 try { 587 prepareForStore(true); 589 sc = storageMan.store(storeOidStateContainer, toBeDeleted, false, 591 StorageManager.STORE_OPTION_FLUSH, false); 592 postStore(sc, true); 593 } catch (Exception e) { 594 handleException(e); 595 } finally { 596 if (sc != null) { 597 sc.clear(); 598 } 599 storeOidStateContainer.clear(); 600 toBeDeleted.clear(); 601 txObjects.clear(); 602 } 603 } 604 605 public void refresh(Object entity) { 606 } 607 608 public boolean contains(Object entity) { 609 return false; } 611 612 public Query createQuery(String ejbqlString) { 613 return new VersantEjbQueryImp(proxy, ejbqlString); 614 } 615 616 public Query createNamedQuery(String name) { 617 return null; 618 } 619 620 public Query createNativeQuery(String sqlString) { 621 return null; 622 } 623 624 public Query createNativeQuery(String sqlString, Class resultClass) { 625 return null; 626 } 627 628 public Query createNativeQuery(String sqlString, String resultSetMapping) { 629 return null; 630 } 631 632 public void begin() { 633 if (txActive) { 634 throw new RuntimeException ("The transaction is alread active"); 635 } 636 if (proxy != null) { 637 throw new RuntimeException ("The em was not reset correctly at end of previous transaction."); 638 } 639 storageMan.begin(true); 640 proxy = new EMProxy(this); 641 txActive = true; 642 } 643 644 649 public void commit() { 650 checkForActiveTransaction(); 651 StatesReturned sc = null; 652 try { 653 prepareForStore(true); 655 sc = storageMan.store(storeOidStateContainer, toBeDeleted, false, 657 StorageManager.STORE_OPTION_COMMIT, 658 false); 659 postStore(sc, false); 660 txActive = false; 661 } catch (Exception e) { 662 handleException(e); 663 } finally { 664 if (proxy != null) { 665 proxy.detach(); 666 proxy = null; 667 } 668 if (sc != null) { 669 sc.clear(); 670 } 671 storeOidStateContainer.clear(); 672 toBeDeleted.clear(); 673 txObjects.clear(); 674 } 675 detachOnCommit(); 676 cache.clear(); 677 } 678 679 private void postStore(StatesReturned sc, boolean flush) { 680 for (Iterator<StateManagerImp> iterator = txObjects.iterator(); iterator.hasNext();) { 682 iterator.next().postStore(sc, flush); 683 } 684 } 685 686 690 private void handleException(Exception e) { 691 e.printStackTrace(System.out); 692 throw new RuntimeException (e); 693 } 694 695 700 private void prepareForStore(boolean commit) { 701 storeOidStateContainer.clear(); 702 toBeDeleted.clear(); 703 for (Iterator<StateManagerImp> iterator = txObjects.iterator(); iterator.hasNext();) { 704 iterator.next().prepareCommitOrFlush(commit, toBeDeleted, storeOidStateContainer); 705 } 706 } 707 708 public void rollback() { 709 if (!txActive) { 710 throw new RuntimeException ("There is no active transaction"); 711 } 712 if (proxy != null) { 713 proxy.detach(); 714 } 715 } 716 717 public boolean isActive() { 718 return txActive; 719 } 720 721 public void setNontransactionalRead(boolean b) { 722 } 724 725 public boolean getNontransactionalRead() { 726 return false; } 728 729 public void setNontransactionalWrite(boolean b) { 730 } 732 733 public boolean getNontransactionalWrite() { 734 return false; } 736 737 public void setRetainValues(boolean b) { 738 } 740 741 public boolean getRetainValues() { 742 return false; } 744 745 public void setRestoreValues(boolean b) { 746 } 748 749 public boolean getRestoreValues() { 750 return false; } 752 753 public void setOptimistic(boolean b) { 754 } 756 757 public boolean getOptimistic() { 758 return false; } 760 761 public void setSynchronization(Synchronization synchronization) { 762 } 764 765 public Synchronization getSynchronization() { 766 return null; } 768 769 public PersistenceManager getPersistenceManager() { 770 return this; 771 } 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 public boolean isClosed() { 802 return false; } 804 805 public Transaction currentTransaction() { 806 return null; } 808 809 public void evict(Object o) { 810 } 812 813 public void evictAll(Object [] objects) { 814 } 816 817 public void evictAll(Collection collection) { 818 } 820 821 public void evictAll() { 822 } 824 825 public void refreshAll(Object [] objects) { 826 } 828 829 public void refreshAll(Collection collection) { 830 } 832 833 public void refreshAll() { 834 } 836 837 public javax.jdo.Query newQuery() { 838 return null; } 840 841 public javax.jdo.Query newQuery(Object o) { 842 return null; } 844 845 public javax.jdo.Query newQuery(String s, Object o) { 846 return null; } 848 849 public javax.jdo.Query newQuery(Class aClass) { 850 return null; } 852 853 public javax.jdo.Query newQuery(Extent extent) { 854 return null; } 856 857 public javax.jdo.Query newQuery(Class aClass, Collection collection) { 858 return null; } 860 861 public javax.jdo.Query newQuery(Class aClass, String s) { 862 return null; } 864 865 public javax.jdo.Query newQuery(Class aClass, Collection collection, String s) { 866 return null; } 868 869 public javax.jdo.Query newQuery(Extent extent, String s) { 870 return null; } 872 873 public Extent getExtent(Class aClass, boolean b) { 874 return null; } 876 877 public Object getObjectById(Object o, boolean b) { 878 if (o instanceof OID) { 879 return getObjectById((OID) o); 880 } 881 else { 882 throw BindingSupportImpl.getInstance().unsupported("unsupported operation"); 883 } 884 } 885 886 public Object getObjectId(Object o) { 887 return null; } 889 890 public Object getTransactionalObjectId(Object o) { 891 return null; } 893 894 public Object newObjectIdInstance(Class aClass, String s) { 895 return null; } 897 898 public void makePersistent(Object o) { 899 } 901 902 public void makePersistentAll(Object [] objects) { 903 } 905 906 public void makePersistentAll(Collection collection) { 907 } 909 910 public void deletePersistent(Object o) { 911 } 913 914 public void deletePersistentAll(Object [] objects) { 915 } 917 918 public void deletePersistentAll(Collection collection) { 919 } 921 922 public void makeTransient(Object o) { 923 } 925 926 public void makeTransientAll(Object [] objects) { 927 } 929 930 public void makeTransientAll(Collection collection) { 931 } 933 934 public void makeTransactional(Object o) { 935 } 937 938 public void makeTransactionalAll(Object [] objects) { 939 } 941 942 public void makeTransactionalAll(Collection collection) { 943 } 945 946 public void makeNontransactional(Object o) { 947 } 949 950 public void makeNontransactionalAll(Object [] objects) { 951 } 953 954 public void makeNontransactionalAll(Collection collection) { 955 } 957 958 public void retrieve(Object o) { 959 } 961 962 public void retrieveAll(Collection collection) { 963 } 965 966 public void retrieveAll(Collection collection, boolean b) { 967 } 969 970 public void retrieveAll(Object [] objects) { 971 } 973 974 public void retrieveAll(Object [] objects, boolean b) { 975 } 977 978 public void setUserObject(Object o) { 979 } 981 982 public Object getUserObject() { 983 return null; } 985 986 public PersistenceManagerFactory getPersistenceManagerFactory() { 987 return null; } 989 990 public Class getObjectIdClass(Class aClass) { 991 return null; } 993 994 public void setMultithreaded(boolean b) { 995 } 997 998 public boolean getMultithreaded() { 999 return false; } 1001 1002 public void setIgnoreCache(boolean b) { 1003 } 1005 1006 public boolean getIgnoreCache() { 1007 return false; } 1009 1010 public void addToTxList(StateManagerImp sm) { 1011 if (txActive) { 1012 txObjects.add(sm); 1013 } 1014 } 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 public boolean isInterceptDfgFieldAccess() { 1035 return false; } 1037 1038 public void setInterceptDfgFieldAccess(boolean interceptDfgFieldAccess) { 1039 } 1041 1042 public void cancelQueryExecution() { 1043 } 1045 1046 public boolean isDirty() { 1047 return !txObjects.isEmpty(); 1048 } 1049 1050 public Object getObjectByIDString(String value, boolean toValidate) { 1051 return null; } 1053 1054 public Object newObjectIdInstance(Class pcClass, String str, boolean resolved) { 1055 return null; } 1057 1058 public Object getObjectByIDString(String value, boolean toValidate, boolean resolved) { 1059 return null; } 1061 1062 public void loadFetchGroup(Object pc, String name) { 1063 } 1065 1066 public void flush(boolean retainValues) { 1067 } 1069 1070 public Connection getJdbcConnection(String datastore) { 1071 return null; } 1073 1074 public String getConnectionURL(String dataStore) { 1075 return null; } 1077 1078 public String getConnectionDriverName(String dataStore) { 1079 return null; } 1081 1082 public void makeTransientRecursive(Object pc) { 1083 } 1085 1086 public List versantAllDirtyInstances() { 1087 if (txObjects.isEmpty()) return Collections.EMPTY_LIST; 1088 return new ArrayList(txObjects); 1089 } 1090 1091 public void flushIfDepOn(int[] cmdBits) { 1092 flush(); 1093 } 1094 1095 public void setDatastoreTxLocking(int mode) { 1096 int policy; 1097 switch (mode) { 1098 case VersantPersistenceManager.LOCKING_NONE: 1099 policy = StorageManager.LOCK_POLICY_NONE; 1100 break; 1101 case VersantPersistenceManager.LOCKING_FIRST: 1102 policy = StorageManager.LOCK_POLICY_FIRST; 1103 break; 1104 case VersantPersistenceManager.LOCKING_ALL: 1105 policy = StorageManager.LOCK_POLICY_ALL; 1106 break; 1107 default: 1108 throw BindingSupportImpl.getInstance().invalidOperation( 1109 "Invalid datastoreTxLocking mode: " + mode); 1110 } 1111 storageMan.setLockingPolicy(policy); 1112 } 1113 1114 public int getDatastoreTxLocking() { 1115 switch (storageMan.getLockingPolicy()) { 1116 case StorageManager.LOCK_POLICY_NONE: 1117 return VersantPersistenceManager.LOCKING_NONE; 1118 case StorageManager.LOCK_POLICY_FIRST: 1119 return VersantPersistenceManager.LOCKING_FIRST; 1120 case StorageManager.LOCK_POLICY_ALL: 1121 return VersantPersistenceManager.LOCKING_ALL; 1122 } 1123 return VersantPersistenceManager.LOCKING_NONE; 1124 } 1125 1126 public Object getObjectByIdFromCache(Object oid) { 1127 return null; 1128 } 1129 1130 public boolean isHollow(Object pc) { 1131 return false; 1132 } 1133 1134 public boolean hasIdentity(Object pc) { 1135 return false; 1136 } 1137 1138 public void logEvent(int level, String description, int ms) { 1139 } 1141 1142 public int getObjectsById(Object [] oids, int length, Object [] data, int stateFieldNo, int classMetaDataIndex) { 1143 return 0; } 1145 1146 public javax.jdo.Query versantNewNamedQuery(Class cls, String queryName) { 1147 return null; } 1149 1150 public Collection versantDetachCopy(Collection pcs, String fetchGroup) { 1151 return null; } 1153 1154 public boolean isCheckModelConsistencyOnCommit() { 1155 return false; } 1157 1158 public void setCheckModelConsistencyOnCommit(boolean on) { 1159 } 1161 1162 public void checkModelConsistency() { 1163 } 1165 1166 public Collection versantAttachCopy(Collection detached, boolean makeTransactional) { 1167 return null; } 1169 1170 public Collection versantAttachCopy(Collection detached, boolean makeTransactional, boolean shallow) { 1171 return null; } 1173 1174 public void setPmCacheRefType(Object pc, int type) { 1175 } 1177 1178 public void setPmCacheRefType(Object [] pcs, int type) { 1179 } 1181 1182 public void setPmCacheRefType(Collection col, int type) { 1183 } 1185 1186 public void setPmCacheRefType(int type) { 1187 } 1189 1190 public int getPmCacheRefType() { 1191 return 0; } 1193 1194 public void setRetainConnectionInOptTx(boolean on) { 1195 } 1197 1198 public void evictFromL2CacheAfterCommit(Object o) { 1199 } 1201 1202 public void evictAllFromL2CacheAfterCommit(Object [] a) { 1203 } 1205 1206 public void evictAllFromL2CacheAfterCommit(Collection c) { 1207 } 1209 1210 public void evictAllFromL2CacheAfterCommit(Class cls, boolean includeSubclasses) { 1211 } 1213 1214 public void evictAllFromL2CacheAfterCommit() { 1215 } 1217 1218 public Object getOptimisticLockingValue(Object o) { 1219 return null; } 1221 1222 public void addLifecycleListener(LifecycleListener listener, Class [] classes) { 1223 } 1225 1226 public void removeLifecycleListener(LifecycleListener listener) { 1227 } 1229 1230 public OID getInternalOID(PersistenceCapable pc) { 1231 return getStateManager(pc).getOID(); 1232 } 1233 1234 public PCStateMan getInternalSM(PersistenceCapable pc) { 1235 throw new RuntimeException ("NOT IMPLEMENTED"); 1236 } 1237 1238 1239 public StorageManager getStorageManager() { 1240 return storageMan; 1241 } 1242 1243 1244 1250 public void convertPcParamsToOID(Object [] params) { 1251 if (params == null) return; 1252 int n = params.length; 1253 for (int i = 0; i < n; i++) { 1254 Object param = params[i]; 1255 if (param == null) continue; 1256 if (param instanceof Collection) { 1257 List l = new ArrayList((Collection)param); 1258 for (int j = 0; j < l.size(); j++) { 1259 Object o = (Object )l.get(j); 1260 o = convertPcParamsToOIDImp(o, i); 1261 if (o instanceof OID) { 1262 l.set(j, o); 1263 } 1264 } 1265 params[i] = l; 1266 } else { 1267 params[i] = convertPcParamsToOIDImp(param, i); 1268 } 1269 } 1270 } 1271 1272 private Object convertPcParamsToOIDImp(Object param, int paramIndex) { 1273 if (param == null) return param; 1274 if (param instanceof PersistenceCapable) { 1275 PersistenceCapable pc = (PersistenceCapable)param; 1276 if (pc.jdoGetPersistenceManager() != proxy) { 1277 if (pc.jdoGetPersistenceManager() != null) { 1278 throw BindingSupportImpl.getInstance().invalidOperation("PC parameter " + paramIndex + " is managed by " + pc.jdoGetPersistenceManager() + 1279 " (this is " + proxy + "): " + 1280 pc.getClass() + ": " + Utils.toString(pc)); 1281 } else { 1282 throw BindingSupportImpl.getInstance().invalidOperation("PC parameter " + paramIndex + " is transient: " + 1283 pc.getClass() + ": " + Utils.toString(pc)); 1284 } 1285 } 1286 param = getInternalOID((PersistenceCapable)param); 1287 } else if (param instanceof VersantOid) { 1288 OID oid = modelMetaData.convertJDOGenieOIDtoOID((VersantOid)param); 1290 param = convertNewToActual(oid); 1291 } else { 1292 ClassMetaData cmd = 1293 modelMetaData.getClassMetaDataForObjectIdClass( 1294 param.getClass()); 1295 if (cmd != null) { OID oid = cmd.createOID(false); 1297 oid.fillFromPK(param); 1298 param = oid; 1299 } 1300 } 1301 return param; 1302 } 1303} 1304 | Popular Tags |