001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo;
012:
013: import com.versant.core.server.QueryResultWrapper;
014: import com.versant.core.server.CompiledQuery;
015:
016: import javax.jdo.Transaction;
017: import javax.jdo.PersistenceManager;
018: import javax.jdo.Query;
019: import javax.jdo.PersistenceManagerFactory;
020: import javax.jdo.Extent;
021: import javax.jdo.spi.PersistenceCapable;
022:
023: import javax.transaction.Synchronization;
024: import javax.transaction.xa.XAException;
025: import javax.transaction.xa.XAResource;
026: import javax.transaction.xa.Xid;
027:
028: import java.sql.Connection;
029: import java.util.Collection;
030: import java.util.List;
031:
032: import com.versant.core.common.BindingSupportImpl;
033: import com.versant.core.common.OID;
034: import com.versant.core.common.State;
035: import com.versant.core.common.*;
036: import com.versant.core.storagemanager.ExecuteQueryReturn;
037:
038: /**
039: * This is a proxy for VersantPersistenceManagerImp with all methods
040: * synchronized for multithreaded access.
041: *
042: * @see PMProxy
043: * @see UnsynchronizedPMProxy
044: */
045: public final class SynchronizedPMProxy extends PMProxy {
046:
047: private VersantPersistenceManagerImp realPM;
048:
049: public SynchronizedPMProxy(VersantPersistenceManagerImp realPM) {
050: this .realPM = realPM;
051: }
052:
053: public synchronized QueryResultWrapper executeQuery(
054: CompiledQuery cq, Object[] params) {
055: return realPM.getStorageManager().executeQuery(realPM, null,
056: cq, params);
057: }
058:
059: public QueryResultContainer getNextQueryResult(
060: QueryResultWrapper aQrs, int skipAmount) {
061: return realPM.getStorageManager().fetchNextQueryResult(realPM,
062: ((ExecuteQueryReturn) aQrs).getRunningQuery(),
063: skipAmount);
064: }
065:
066: public synchronized void flushIfDepOn(int[] bits) {
067: realPM.flushIfDepOn(bits);
068: }
069:
070: public synchronized void processLocalCacheReferenceQueue() {
071: realPM.processLocalCacheReferenceQueue();
072: }
073:
074: public synchronized void addToCache(StatesReturned container) {
075: realPM.addToCache(container);
076: }
077:
078: public synchronized void closeQuery(QueryResultWrapper qrw) {
079: realPM.getStorageManager().closeQuery(
080: ((ExecuteQueryReturn) qrw).getRunningQuery());
081: }
082:
083: public synchronized QueryResultContainer getAbsolute(
084: QueryResultWrapper qrsIF, int index, int fetchAmount) {
085: return realPM.getStorageManager().fetchRandomAccessQueryResult(
086: realPM, ((ExecuteQueryReturn) qrsIF).getRunningQuery(),
087: index, fetchAmount);
088: }
089:
090: public synchronized int getResultCount(QueryResultWrapper qrsIF) {
091: return realPM.getStorageManager().getRandomAccessQueryCount(
092: realPM, ((ExecuteQueryReturn) qrsIF).getRunningQuery());
093: }
094:
095: public synchronized QueryResultContainer getAllQueryResults(
096: CompiledQuery cq, Object[] params) {
097: return realPM.getStorageManager().executeQueryAll(realPM, null,
098: cq, params);
099: }
100:
101: public synchronized void setMasterOnDetail(
102: PersistenceCapable detail, int managedFieldNo,
103: PersistenceCapable master, boolean removeFromCurrentMaster) {
104: realPM.setMasterOnDetail(detail, managedFieldNo, master,
105: removeFromCurrentMaster);
106: }
107:
108: public synchronized Object getObjectField(PersistenceCapable pc,
109: int fieldNo) {
110: return realPM.getObjectField(pc, fieldNo);
111: }
112:
113: public synchronized int getQueryRowCount(CompiledQuery cq,
114: Object[] params) {
115: return realPM.getStorageManager().executeQueryCount(null, cq,
116: params);
117: }
118:
119: public synchronized Object getOptimisticLockingValue(Object o) {
120: checkClosed();
121: return realPM.getOptimisticLockingValue(o);
122: }
123:
124: public synchronized void setPmCacheRefType(Object pc, int type) {
125: checkClosed();
126: realPM.setPmCacheRefType(pc, type);
127: }
128:
129: public synchronized void setPmCacheRefType(Object[] pcs, int type) {
130: checkClosed();
131: realPM.setPmCacheRefType(pcs, type);
132: }
133:
134: public synchronized void setPmCacheRefType(Collection col, int type) {
135: checkClosed();
136: realPM.setPmCacheRefType(col, type);
137: }
138:
139: public synchronized void setPmCacheRefType(int type) {
140: checkClosed();
141: realPM.setPmCacheRefType(type);
142: }
143:
144: public synchronized int getPmCacheRefType() {
145: checkClosed();
146: return realPM.getPmCacheRefType();
147: }
148:
149: /**
150: * If default fetch group fields will be intercepted on a
151: * Persistent-Non-Transaction instance. If this is disabled then such a
152: * instance will not be 'refreshed' if accessed in a datastore transaction.
153: */
154: public synchronized boolean isInterceptDfgFieldAccess() {
155: return realPM.isInterceptDfgFieldAccess();
156: }
157:
158: public synchronized void setInterceptDfgFieldAccess(
159: boolean interceptDfgFieldAccess) {
160: realPM.setInterceptDfgFieldAccess(interceptDfgFieldAccess);
161: }
162:
163: public synchronized VersantPersistenceManagerImp getRealPM() {
164: checkClosed();
165: return realPM;
166: }
167:
168: VersantPersistenceManagerImp getRealPMNoCheck() {
169: return realPM;
170: }
171:
172: public synchronized void resetPM() {
173: realPM = null;
174: }
175:
176: public synchronized boolean isRealPMNull() {
177: return realPM == null;
178: }
179:
180: public synchronized List versantAllDirtyInstances() {
181: checkClosed();
182: return realPM.versantAllDirtyInstances();
183: }
184:
185: private void checkClosed() {
186: if (realPM == null) {
187: throw BindingSupportImpl.getInstance().invalidOperation(
188: "The pm is closed");
189: }
190: }
191:
192: public synchronized boolean isDirty() {
193: checkClosed();
194: return realPM.isDirty();
195: }
196:
197: public synchronized void cancelQueryExecution() {
198: checkClosed();
199: realPM.cancelQueryExecution();
200: }
201:
202: public synchronized Object getObjectByIDString(String value,
203: boolean toValidate) {
204: checkClosed();
205: return realPM.getObjectByIDString(value, toValidate);
206: }
207:
208: public synchronized void loadFetchGroup(Object pc, String name) {
209: checkClosed();
210: realPM.loadFetchGroup(pc, name);
211: }
212:
213: public synchronized void flush() {
214: checkClosed();
215: realPM.flush();
216: }
217:
218: public synchronized void flush(boolean retainState) {
219: checkClosed();
220: realPM.flush(retainState);
221: }
222:
223: public synchronized void makeTransientRecursive(Object pc) {
224: checkClosed();
225: realPM.makeTransientRecursive(pc);
226: }
227:
228: public synchronized Connection getJdbcConnection(String datastore) {
229: checkClosed();
230: return realPM.getJdbcConnection(datastore);
231: }
232:
233: public synchronized String getConnectionURL(String dataStore) {
234: checkClosed();
235: return realPM.getConnectionURL(dataStore);
236: }
237:
238: public synchronized String getConnectionDriverName(String dataStore) {
239: checkClosed();
240: return realPM.getConnectionDriverName(dataStore);
241: }
242:
243: public synchronized boolean isClosed() {
244: return realPM == null;
245: }
246:
247: public synchronized void close() {
248: if (realPM == null) {
249: return;
250: }
251: realPM.close();
252: }
253:
254: public synchronized Transaction currentTransaction() {
255: checkClosed();
256: return this ;
257: }
258:
259: public synchronized void evict(Object o) {
260: checkClosed();
261: realPM.evict(o);
262: }
263:
264: public synchronized void evictAll(Object[] objects) {
265: checkClosed();
266: realPM.evictAll(objects);
267: }
268:
269: public synchronized void evictAll(Collection collection) {
270: checkClosed();
271: realPM.evictAll(collection);
272: }
273:
274: public synchronized void evictAll() {
275: checkClosed();
276: realPM.evictAll();
277: }
278:
279: public synchronized void refresh(Object o) {
280: checkClosed();
281: realPM.refresh(o);
282: }
283:
284: public synchronized void refreshAll(Object[] objects) {
285: checkClosed();
286: realPM.refreshAll(objects);
287: }
288:
289: public synchronized void refreshAll(Collection collection) {
290: checkClosed();
291: realPM.refreshAll(collection);
292: }
293:
294: public synchronized void refreshAll() {
295: checkClosed();
296: realPM.refreshAll();
297: }
298:
299: public synchronized Query newQuery() {
300: checkClosed();
301: return realPM.newQuery();
302: }
303:
304: public synchronized Query newQuery(Object o) {
305: checkClosed();
306: return realPM.newQuery(o);
307: }
308:
309: public synchronized Query newQuery(String s, Object o) {
310: checkClosed();
311: return realPM.newQuery(s, o);
312: }
313:
314: public synchronized Query newQuery(Class aClass) {
315: checkClosed();
316: return realPM.newQuery(aClass);
317: }
318:
319: public synchronized Query newQuery(Extent extent) {
320: checkClosed();
321: return realPM.newQuery(extent);
322: }
323:
324: public synchronized Query newQuery(Class aClass,
325: Collection collection) {
326: checkClosed();
327: return realPM.newQuery(aClass, collection);
328: }
329:
330: public synchronized Query newQuery(Class aClass, String s) {
331: checkClosed();
332: return realPM.newQuery(aClass, s);
333: }
334:
335: public synchronized Query newQuery(Class aClass,
336: Collection collection, String s) {
337: checkClosed();
338: return realPM.newQuery(aClass, collection, s);
339: }
340:
341: public synchronized Query newQuery(Extent extent, String s) {
342: checkClosed();
343: return realPM.newQuery(extent, s);
344: }
345:
346: public synchronized Extent getExtent(Class aClass, boolean b) {
347: checkClosed();
348: return realPM.getExtent(aClass, b);
349: }
350:
351: public synchronized Object getObjectById(Object o, boolean b) {
352: checkClosed();
353: return realPM.getObjectById(o, b);
354: }
355:
356: public synchronized Object getObjectId(Object o) {
357: checkClosed();
358: return realPM.getObjectId(o);
359: }
360:
361: public synchronized Object getTransactionalObjectId(Object o) {
362: checkClosed();
363: return realPM.getTransactionalObjectId(o);
364: }
365:
366: public synchronized Object newObjectIdInstance(Class aClass,
367: String s) {
368: checkClosed();
369: return realPM.newObjectIdInstance(aClass, s);
370: }
371:
372: public synchronized void makePersistent(Object o) {
373: checkClosed();
374: realPM.makePersistent(o);
375: }
376:
377: public synchronized void makePersistentAll(Object[] objects) {
378: checkClosed();
379: realPM.makePersistentAll(objects);
380: }
381:
382: public synchronized void makePersistentAll(Collection collection) {
383: checkClosed();
384: realPM.makePersistentAll(collection);
385: }
386:
387: public synchronized void deletePersistent(Object o) {
388: checkClosed();
389: realPM.deletePersistent(o);
390: }
391:
392: public synchronized void deletePersistentAll(Object[] objects) {
393: checkClosed();
394: realPM.deletePersistentAll(objects);
395: }
396:
397: public synchronized void deletePersistentAll(Collection collection) {
398: checkClosed();
399: realPM.deletePersistentAll(collection);
400: }
401:
402: public synchronized void makeTransient(Object o) {
403: checkClosed();
404: realPM.makeTransient(o);
405: }
406:
407: public synchronized void makeTransientAll(Object[] objects) {
408: checkClosed();
409: realPM.makeTransientAll(objects);
410: }
411:
412: public synchronized void makeTransientAll(Collection collection) {
413: checkClosed();
414: realPM.makeTransientAll(collection);
415: }
416:
417: public synchronized void makeTransactional(Object o) {
418: checkClosed();
419: realPM.makeTransactional(o);
420: }
421:
422: public synchronized void makeTransactionalAll(Object[] objects) {
423: checkClosed();
424: realPM.makeTransactionalAll(objects);
425: }
426:
427: public synchronized void makeTransactionalAll(Collection collection) {
428: checkClosed();
429: realPM.makeTransactionalAll(collection);
430: }
431:
432: public synchronized void makeNontransactional(Object o) {
433: checkClosed();
434: realPM.makeNontransactional(o);
435: }
436:
437: public synchronized void makeNontransactionalAll(Object[] objects) {
438: checkClosed();
439: realPM.makeNontransactionalAll(objects);
440: }
441:
442: public synchronized void makeNontransactionalAll(
443: Collection collection) {
444: checkClosed();
445: realPM.makeNontransactionalAll(collection);
446: }
447:
448: public synchronized void retrieve(Object o) {
449: checkClosed();
450: realPM.retrieve(o);
451: }
452:
453: public synchronized void retrieveAll(Collection pcs, boolean DFGOnly) {
454: checkClosed();
455: realPM.retrieveAll(pcs, DFGOnly);
456: }
457:
458: public synchronized void retrieveAll(Object[] pcs, boolean DFGOnly) {
459: checkClosed();
460: realPM.retrieveAll(pcs, DFGOnly);
461: }
462:
463: public synchronized void retrieveAll(Collection collection) {
464: checkClosed();
465: realPM.retrieveAll(collection);
466: }
467:
468: public synchronized void retrieveAll(Object[] objects) {
469: checkClosed();
470: realPM.retrieveAll(objects);
471: }
472:
473: public synchronized void setUserObject(Object o) {
474: checkClosed();
475: realPM.setUserObject(o);
476: }
477:
478: public synchronized Object getUserObject() {
479: checkClosed();
480: return realPM.getUserObject();
481: }
482:
483: public synchronized PersistenceManagerFactory getPersistenceManagerFactory() {
484: checkClosed();
485: return realPM.getPersistenceManagerFactory();
486: }
487:
488: public synchronized Class getObjectIdClass(Class aClass) {
489: checkClosed();
490: return realPM.getObjectIdClass(aClass);
491: }
492:
493: public synchronized void setMultithreaded(boolean b) {
494: checkClosed();
495: realPM.setMultithreaded(b);
496: }
497:
498: public synchronized boolean getMultithreaded() {
499: checkClosed();
500: return realPM.getMultithreaded();
501: }
502:
503: public synchronized void setIgnoreCache(boolean b) {
504: checkClosed();
505: realPM.setIgnoreCache(b);
506: }
507:
508: public synchronized boolean getIgnoreCache() {
509: checkClosed();
510: return realPM.getIgnoreCache();
511: }
512:
513: public synchronized void commit(Xid xid, boolean b)
514: throws XAException {
515: checkClosed();
516: realPM.commit(xid, b);
517: }
518:
519: public synchronized void end(Xid xid, int i) throws XAException {
520: checkClosed();
521: realPM.end(xid, i);
522: }
523:
524: public synchronized void forget(Xid xid) throws XAException {
525: checkClosed();
526: realPM.forget(xid);
527: }
528:
529: public synchronized int getTransactionTimeout() throws XAException {
530: checkClosed();
531: return realPM.getTransactionTimeout();
532: }
533:
534: public synchronized boolean isSameRM(XAResource xaResource)
535: throws XAException {
536: if (realPM == null)
537: return false;
538: return realPM.isSameRM(xaResource);
539: }
540:
541: public synchronized int prepare(Xid xid) throws XAException {
542: checkClosed();
543: return realPM.prepare(xid);
544: }
545:
546: public synchronized Xid[] recover(int i) throws XAException {
547: checkClosed();
548: return realPM.recover(i);
549: }
550:
551: public synchronized void rollback(Xid xid) throws XAException {
552: checkClosed();
553: realPM.rollback(xid);
554: }
555:
556: public synchronized boolean setTransactionTimeout(int i)
557: throws XAException {
558: checkClosed();
559: return realPM.setTransactionTimeout(i);
560: }
561:
562: public synchronized void start(Xid xid, int i) throws XAException {
563: checkClosed();
564: realPM.start(xid, i);
565: }
566:
567: public synchronized void afterCompletion(int i) {
568: checkClosed();
569: realPM.afterCompletion(i);
570: }
571:
572: public synchronized void beforeCompletion() {
573: checkClosed();
574: realPM.beforeCompletion();
575: }
576:
577: public synchronized OID getInternalOID(final PersistenceCapable pc) {
578: checkClosed();
579: return realPM.getInternalOID(pc);
580: }
581:
582: public synchronized PCStateMan getInternalSM(
583: final PersistenceCapable pc) {
584: checkClosed();
585: return realPM.getInternalSM(pc);
586: }
587:
588: public synchronized PCStateMan getInternalSM(OID oid) {
589: checkClosed();
590: return realPM.getInternalSM(oid);
591: }
592:
593: public synchronized State getInternaleState(PersistenceCapable pc) {
594: checkClosed();
595: return realPM.getInternaleState(pc);
596: }
597:
598: public synchronized void addTxStateObject(PCStateMan stateObject) {
599: checkClosed();
600: realPM.addTxStateObject(stateObject);
601: }
602:
603: public synchronized void removeTxStateObject(PCStateMan stateObject) {
604: checkClosed();
605: realPM.removeTxStateObject(stateObject);
606: }
607:
608: public synchronized boolean isOptimistic() {
609: checkClosed();
610: return realPM.getOptimistic();
611: }
612:
613: public synchronized boolean isRetainValues() {
614: checkClosed();
615: return realPM.getRetainValues();
616: }
617:
618: public synchronized boolean isRestoreValues() {
619: checkClosed();
620: return realPM.getRestoreValues();
621: }
622:
623: public synchronized boolean isActive() {
624: checkClosed();
625: return realPM.isActive();
626: }
627:
628: public synchronized void begin() {
629: checkClosed();
630: realPM.begin();
631: }
632:
633: public synchronized void commit() {
634: checkClosed();
635: realPM.commit();
636: }
637:
638: public synchronized boolean getNontransactionalRead() {
639: checkClosed();
640: return realPM.getNontransactionalRead();
641: }
642:
643: public synchronized boolean getNontransactionalWrite() {
644: checkClosed();
645: return realPM.getNontransactionalWrite();
646: }
647:
648: public synchronized boolean getOptimistic() {
649: checkClosed();
650: return realPM.getOptimistic();
651: }
652:
653: public synchronized PersistenceManager getPersistenceManager() {
654: checkClosed();
655: return this ;
656: }
657:
658: public synchronized boolean getRestoreValues() {
659: checkClosed();
660: return realPM.getRestoreValues();
661: }
662:
663: public synchronized boolean getRetainValues() {
664: checkClosed();
665: return realPM.getRetainValues();
666: }
667:
668: public synchronized Synchronization getSynchronization() {
669: checkClosed();
670: return realPM.getSynchronization();
671: }
672:
673: public synchronized void rollback() {
674: checkClosed();
675: realPM.rollback();
676: }
677:
678: public synchronized void setNontransactionalRead(boolean b) {
679: checkClosed();
680: realPM.setNontransactionalRead(b);
681: }
682:
683: public synchronized void setNontransactionalWrite(boolean b) {
684: checkClosed();
685: realPM.setNontransactionalWrite(b);
686: }
687:
688: public synchronized void setOptimistic(boolean b) {
689: checkClosed();
690: realPM.setOptimistic(b);
691: }
692:
693: public synchronized void setRestoreValues(boolean b) {
694: checkClosed();
695: realPM.setRestoreValues(b);
696: }
697:
698: public synchronized void setRetainValues(boolean b) {
699: checkClosed();
700: realPM.setRetainValues(b);
701: }
702:
703: public synchronized void setSynchronization(
704: Synchronization synchronization) {
705: checkClosed();
706: realPM.setSynchronization(synchronization);
707: }
708:
709: public synchronized void setDatastoreTxLocking(int mode) {
710: checkClosed();
711: realPM.setDatastoreTxLocking(mode);
712: }
713:
714: public synchronized int getDatastoreTxLocking() {
715: checkClosed();
716: return realPM.getDatastoreTxLocking();
717: }
718:
719: public synchronized void setRetainConnectionInOptTx(boolean on) {
720: checkClosed();
721: realPM.setRetainConnectionInOptTx(on);
722: }
723:
724: public synchronized Object getObjectByIdFromCache(Object oid) {
725: checkClosed();
726: return realPM.getObjectByIdFromCache(oid);
727: }
728:
729: public synchronized boolean isHollow(Object pc) {
730: checkClosed();
731: return realPM.isHollow(pc);
732: }
733:
734: public synchronized boolean hasIdentity(Object pc) {
735: checkClosed();
736: return realPM.hasIdentity(pc);
737: }
738:
739: public synchronized Object newObjectIdInstance(Class pcClass,
740: String str, boolean resolved) {
741: checkClosed();
742: return realPM.newObjectIdInstance(pcClass, str, resolved);
743: }
744:
745: public synchronized Object getObjectByIDString(String value,
746: boolean toValidate, boolean resolved) {
747: checkClosed();
748: return realPM.getObjectByIDString(value, toValidate, resolved);
749: }
750:
751: public synchronized void logEvent(int level, String description,
752: int ms) {
753: checkClosed();
754: realPM.logEvent(level, description, ms);
755: }
756:
757: public synchronized Query versantNewNamedQuery(Class cls,
758: String queryName) {
759: checkClosed();
760: return realPM.versantNewNamedQuery(cls, queryName);
761: }
762:
763: public synchronized boolean isCheckModelConsistencyOnCommit() {
764: checkClosed();
765: return realPM.isCheckModelConsistencyOnCommit();
766: }
767:
768: public synchronized void setCheckModelConsistencyOnCommit(boolean on) {
769: checkClosed();
770: realPM.setCheckModelConsistencyOnCommit(on);
771: }
772:
773: public synchronized void checkModelConsistency() {
774: checkClosed();
775: realPM.checkModelConsistency();
776: }
777:
778: public synchronized int getObjectsById(Object[] oids, int length,
779: Object[] data, int stateFieldNo, int classMetaDataIndex) {
780: checkClosed();
781: return realPM.getObjectsById(oids, length, data, stateFieldNo,
782: classMetaDataIndex);
783: }
784:
785: public synchronized Collection versantDetachCopy(Collection pcs,
786: String fetchGroup) {
787: checkClosed();
788: return realPM.versantDetachCopy(pcs, fetchGroup);
789: }
790:
791: public synchronized Collection versantAttachCopy(
792: Collection detached, boolean makeTransactional) {
793: checkClosed();
794: return realPM.versantAttachCopy(detached, makeTransactional);
795: }
796:
797: public synchronized Collection versantAttachCopy(
798: Collection detached, boolean makeTransactional,
799: boolean shallow) {
800: return realPM.versantAttachCopy(detached, makeTransactional,
801: shallow);
802: }
803:
804: public synchronized void evictFromL2CacheAfterCommit(Object o) {
805: checkClosed();
806: realPM.evictFromL2CacheAfterCommit(o);
807: }
808:
809: public synchronized void evictAllFromL2CacheAfterCommit(Object[] a) {
810: checkClosed();
811: realPM.evictAllFromL2CacheAfterCommit(a);
812: }
813:
814: public synchronized void evictAllFromL2CacheAfterCommit(Collection c) {
815: checkClosed();
816: realPM.evictAllFromL2CacheAfterCommit(c);
817: }
818:
819: public synchronized void evictAllFromL2CacheAfterCommit(Class cls,
820: boolean includeSubclasses) {
821: checkClosed();
822: realPM.evictAllFromL2CacheAfterCommit(cls, includeSubclasses);
823: }
824:
825: public synchronized void evictAllFromL2CacheAfterCommit() {
826: checkClosed();
827: realPM.evictAllFromL2CacheAfterCommit();
828: }
829:
830: public void addLifecycleListener(LifecycleListener listener,
831: Class[] classes) {
832: checkClosed();
833: realPM.addLifecycleListener(listener, classes);
834: }
835:
836: public void removeLifecycleListener(LifecycleListener listener) {
837: checkClosed();
838: realPM.removeLifecycleListener(listener);
839: }
840:
841: }
|