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.common.Utils;
014:
015: import javax.jdo.Transaction;
016: import javax.jdo.PersistenceManager;
017: import javax.jdo.Query;
018: import javax.jdo.PersistenceManagerFactory;
019: import javax.jdo.Extent;
020: import javax.jdo.spi.PersistenceCapable;
021:
022: import javax.transaction.Synchronization;
023: import javax.transaction.xa.XAException;
024: import javax.transaction.xa.XAResource;
025: import javax.transaction.xa.Xid;
026:
027: import java.sql.Connection;
028: import java.util.Collection;
029: import java.util.List;
030:
031: import com.versant.core.common.OID;
032: import com.versant.core.common.*;
033:
034: /**
035: * Base class for proxies for VersantPersistenceManagerImp. This solves the case
036: * where a client closes the pm and it returns to the pool, but the client
037: * keeps a pc instance from the closed pm around. Synchronization is also
038: * provided by a synchronized subclass.
039: *
040: * Note that all the methods from the interfaces are repeated here as abstract
041: * because the IBM VMs barf otherwise.
042: *
043: * @see SynchronizedPMProxy
044: * @see UnsynchronizedPMProxy
045: */
046: public abstract class PMProxy implements VersantPersistenceManager,
047: Transaction, VersantPMInternal
048:
049: , XAResource, Synchronization
050:
051: {
052:
053: public abstract void setPmCacheRefType(Object pc, int type);
054:
055: public abstract void setPmCacheRefType(Object[] pcs, int type);
056:
057: public abstract void setPmCacheRefType(Collection col, int type);
058:
059: public abstract void setPmCacheRefType(int type);
060:
061: public abstract int getPmCacheRefType();
062:
063: public abstract boolean isInterceptDfgFieldAccess();
064:
065: public abstract void setInterceptDfgFieldAccess(
066: boolean interceptDfgFieldAccess);
067:
068: public abstract VersantPersistenceManagerImp getRealPM();
069:
070: /**
071: * Do not check to see if the PM has been closed.
072: */
073: abstract VersantPersistenceManagerImp getRealPMNoCheck();
074:
075: public abstract void resetPM();
076:
077: public abstract List versantAllDirtyInstances();
078:
079: public abstract boolean isDirty();
080:
081: public abstract void cancelQueryExecution();
082:
083: public abstract Object getObjectByIDString(String value,
084: boolean toValidate);
085:
086: public abstract void loadFetchGroup(Object pc, String name);
087:
088: public abstract void flush();
089:
090: public abstract void flush(boolean retainState);
091:
092: public abstract void makeTransientRecursive(Object pc);
093:
094: public abstract Connection getJdbcConnection(String datastore);
095:
096: public abstract String getConnectionURL(String dataStore);
097:
098: public abstract String getConnectionDriverName(String dataStore);
099:
100: public abstract boolean isClosed();
101:
102: public abstract void close();
103:
104: public abstract Transaction currentTransaction();
105:
106: public abstract void evict(Object o);
107:
108: public abstract void evictAll(Object[] objects);
109:
110: public abstract void evictAll(Collection collection);
111:
112: public abstract void evictAll();
113:
114: public abstract void refresh(Object o);
115:
116: public abstract void refreshAll(Object[] objects);
117:
118: public abstract void refreshAll(Collection collection);
119:
120: public abstract void refreshAll();
121:
122: public abstract Query newQuery();
123:
124: public abstract Query newQuery(Object o);
125:
126: public abstract Query newQuery(String s, Object o);
127:
128: public abstract Query newQuery(Class aClass);
129:
130: public abstract Query newQuery(Extent extent);
131:
132: public abstract Query newQuery(Class aClass, Collection collection);
133:
134: public abstract Query newQuery(Class aClass, String s);
135:
136: public abstract Query newQuery(Class aClass, Collection collection,
137: String s);
138:
139: public abstract Query newQuery(Extent extent, String s);
140:
141: public abstract Extent getExtent(Class aClass, boolean b);
142:
143: public abstract Object getObjectById(Object o, boolean b);
144:
145: public abstract Object getObjectId(Object o);
146:
147: public abstract Object getTransactionalObjectId(Object o);
148:
149: public abstract Object newObjectIdInstance(Class aClass, String s);
150:
151: public abstract void makePersistent(Object o);
152:
153: public abstract void makePersistentAll(Object[] objects);
154:
155: public abstract void makePersistentAll(Collection collection);
156:
157: public abstract void deletePersistent(Object o);
158:
159: public abstract void deletePersistentAll(Object[] objects);
160:
161: public abstract void deletePersistentAll(Collection collection);
162:
163: public abstract void makeTransient(Object o);
164:
165: public abstract void makeTransientAll(Object[] objects);
166:
167: public abstract void makeTransientAll(Collection collection);
168:
169: public abstract void makeTransactional(Object o);
170:
171: public abstract void makeTransactionalAll(Object[] objects);
172:
173: public abstract void makeTransactionalAll(Collection collection);
174:
175: public abstract void makeNontransactional(Object o);
176:
177: public abstract void makeNontransactionalAll(Object[] objects);
178:
179: public abstract void makeNontransactionalAll(Collection collection);
180:
181: public abstract void retrieve(Object o);
182:
183: public abstract void retrieveAll(Collection pcs, boolean DFGOnly);
184:
185: public abstract void retrieveAll(Object[] pcs, boolean DFGOnly);
186:
187: public abstract void retrieveAll(Collection collection);
188:
189: public abstract void retrieveAll(Object[] objects);
190:
191: public abstract void setUserObject(Object o);
192:
193: public abstract Object getUserObject();
194:
195: public abstract PersistenceManagerFactory getPersistenceManagerFactory();
196:
197: public abstract Class getObjectIdClass(Class aClass);
198:
199: public abstract void setMultithreaded(boolean b);
200:
201: public abstract boolean getMultithreaded();
202:
203: public abstract void setIgnoreCache(boolean b);
204:
205: public abstract boolean getIgnoreCache();
206:
207: public abstract void commit(Xid xid, boolean b) throws XAException;
208:
209: public abstract void end(Xid xid, int i) throws XAException;
210:
211: public abstract void forget(Xid xid) throws XAException;
212:
213: public abstract int getTransactionTimeout() throws XAException;
214:
215: public abstract boolean isSameRM(XAResource xaResource)
216: throws XAException;
217:
218: public abstract int prepare(Xid xid) throws XAException;
219:
220: public abstract Xid[] recover(int i) throws XAException;
221:
222: public abstract void rollback(Xid xid) throws XAException;
223:
224: public abstract boolean setTransactionTimeout(int i)
225: throws XAException;
226:
227: public abstract void start(Xid xid, int i) throws XAException;
228:
229: public abstract void afterCompletion(int i);
230:
231: public abstract void beforeCompletion();
232:
233: public abstract OID getInternalOID(final PersistenceCapable pc);
234:
235: public abstract PCStateMan getInternalSM(final PersistenceCapable pc);
236:
237: public abstract boolean isActive();
238:
239: public abstract void begin();
240:
241: public abstract void commit();
242:
243: public abstract boolean getNontransactionalRead();
244:
245: public abstract boolean getNontransactionalWrite();
246:
247: public abstract boolean getOptimistic();
248:
249: public abstract PersistenceManager getPersistenceManager();
250:
251: public abstract boolean getRestoreValues();
252:
253: public abstract boolean getRetainValues();
254:
255: public abstract Synchronization getSynchronization();
256:
257: public abstract void rollback();
258:
259: public abstract void setNontransactionalRead(boolean b);
260:
261: public abstract void setNontransactionalWrite(boolean b);
262:
263: public abstract void setOptimistic(boolean b);
264:
265: public abstract void setRestoreValues(boolean b);
266:
267: public abstract void setRetainValues(boolean b);
268:
269: public abstract void setSynchronization(
270: Synchronization synchronization);
271:
272: public abstract void setDatastoreTxLocking(int mode);
273:
274: public abstract int getDatastoreTxLocking();
275:
276: public abstract void setRetainConnectionInOptTx(boolean on);
277:
278: public abstract Object getObjectByIdFromCache(Object oid);
279:
280: public abstract boolean isHollow(Object pc);
281:
282: public abstract boolean hasIdentity(Object pc);
283:
284: public abstract Object newObjectIdInstance(Class pcClass,
285: String str, boolean resolved);
286:
287: public abstract Object getObjectByIDString(String value,
288: boolean toValidate, boolean resolved);
289:
290: public abstract void logEvent(int level, String description, int ms);
291:
292: public abstract Query versantNewNamedQuery(Class cls,
293: String queryName);
294:
295: public abstract boolean isCheckModelConsistencyOnCommit();
296:
297: public abstract void setCheckModelConsistencyOnCommit(boolean on);
298:
299: public abstract void checkModelConsistency();
300:
301: /**
302: * Get a user friendly string identifying this PM for use in error
303: * messages and so on.
304: */
305: public String toMsgString() {
306: StringBuffer s = new StringBuffer();
307: s.append("0x");
308: s.append(Integer.toHexString(System.identityHashCode(this )));
309: VersantPersistenceManagerImp realPM = getRealPMNoCheck();
310: if (realPM == null) {
311: s.append(" CLOSED");
312: } else {
313: Object userObject = realPM.getUserObject();
314: if (userObject != null) {
315: s.append(' ');
316: s.append(Utils.toString(userObject));
317: }
318: }
319: return s.toString();
320: }
321:
322: /**
323: * Include identity hashcode to help clients identify the PM they are
324: * using.
325: */
326: public String toString() {
327: return "PM " + toMsgString();
328: }
329:
330: public abstract int getObjectsById(Object[] oids, int length,
331: Object[] data, int stateFieldNo, int classMetaDataIndex);
332:
333: public abstract Collection versantDetachCopy(Collection pcs,
334: String fetchGroup);
335:
336: public abstract Collection versantAttachCopy(Collection detached,
337: boolean makeTransactional);
338:
339: public abstract Collection versantAttachCopy(Collection detached,
340: boolean makeTransactional, boolean shallow);
341:
342: public abstract void evictFromL2CacheAfterCommit(Object o);
343:
344: public abstract void evictAllFromL2CacheAfterCommit(Object[] a);
345:
346: public abstract void evictAllFromL2CacheAfterCommit(Collection c);
347:
348: public abstract void evictAllFromL2CacheAfterCommit(Class cls,
349: boolean includeSubclasses);
350:
351: public abstract void evictAllFromL2CacheAfterCommit();
352:
353: public final PersistenceCapable cast2persistent(Object o) { // see VersantPersistenceManagerImp.checkPersCapable
354: try {
355: return (PersistenceCapable) o;
356: } catch (ClassCastException e) {
357: throw BindingSupportImpl.getInstance().invalidOperation(
358: "The supplied instance is not of type "
359: + PersistenceCapable.class.getName() + " ("
360: + o.getClass().getName() + ")");
361: }
362: }
363:
364: }
|