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.OID;
014:
015: import javax.jdo.spi.PersistenceCapable;
016: import javax.jdo.spi.StateManager;
017: import javax.jdo.PersistenceManager;
018:
019: /**
020: * Wraps a VersantStateManager adding synchronizing all methods on a lock
021: * object. This is used for thread safe PMs.
022: */
023: public final class SynchronizedStateManagerProxy implements
024: VersantStateManager {
025:
026: private final Object lock;
027: private final PCStateMan sm;
028:
029: public SynchronizedStateManagerProxy(Object lock, PCStateMan sm) {
030: this .lock = lock;
031: this .sm = sm;
032: }
033:
034: public OID getOID() {
035: return sm.getOID();
036: }
037:
038: public PersistenceCapable getPersistenceCapable() {
039: return sm.getPersistenceCapable();
040: }
041:
042: public void makeDirty(PersistenceCapable persistenceCapable,
043: int managedFieldNo) {
044: synchronized (lock) {
045: sm.makeDirty(persistenceCapable, managedFieldNo);
046: }
047: }
048:
049: public byte replacingFlags(PersistenceCapable pc) {
050: synchronized (lock) {
051: return sm.replacingFlags(pc);
052: }
053: }
054:
055: public StateManager replacingStateManager(PersistenceCapable pc,
056: StateManager smp) {
057: synchronized (lock) {
058: return sm.replacingStateManager(pc, smp);
059: }
060: }
061:
062: public boolean isDirty(PersistenceCapable pc) {
063: synchronized (lock) {
064: return sm.isDirty(pc);
065: }
066: }
067:
068: public boolean isTransactional(PersistenceCapable pc) {
069: synchronized (lock) {
070: return sm.isTransactional(pc);
071: }
072: }
073:
074: public boolean isPersistent(PersistenceCapable pc) {
075: synchronized (lock) {
076: return sm.isPersistent(pc);
077: }
078: }
079:
080: public boolean isNew(PersistenceCapable pc) {
081: synchronized (lock) {
082: return sm.isNew(pc);
083: }
084: }
085:
086: public boolean isDeleted(PersistenceCapable pc) {
087: synchronized (lock) {
088: return sm.isDeleted(pc);
089: }
090: }
091:
092: public PersistenceManager getPersistenceManager(
093: PersistenceCapable pc) {
094: synchronized (lock) {
095: return sm.getPersistenceManager(pc);
096: }
097: }
098:
099: public void makeDirty(PersistenceCapable pc, String fieldName) {
100: synchronized (lock) {
101: sm.makeDirty(pc, fieldName);
102: }
103: }
104:
105: public Object getObjectId(PersistenceCapable pc) {
106: synchronized (lock) {
107: return sm.getObjectId(pc);
108: }
109: }
110:
111: public Object getTransactionalObjectId(PersistenceCapable pc) {
112: synchronized (lock) {
113: return sm.getTransactionalObjectId(pc);
114: }
115: }
116:
117: public boolean isLoaded(PersistenceCapable pc, int field) {
118: synchronized (lock) {
119: return sm.isLoaded(pc, field);
120: }
121: }
122:
123: public void preSerialize(PersistenceCapable pc) {
124: synchronized (lock) {
125: sm.preSerialize(pc);
126: }
127: }
128:
129: public synchronized boolean getBooleanField(PersistenceCapable pc,
130: int field, boolean currentValue) {
131: synchronized (lock) {
132: return sm.getBooleanField(pc, field, currentValue);
133: }
134: }
135:
136: public char getCharField(PersistenceCapable pc, int field,
137: char currentValue) {
138: synchronized (lock) {
139: return sm.getCharField(pc, field, currentValue);
140: }
141: }
142:
143: public byte getByteField(PersistenceCapable pc, int field,
144: byte currentValue) {
145: synchronized (lock) {
146: return sm.getByteField(pc, field, currentValue);
147: }
148: }
149:
150: public short getShortField(PersistenceCapable pc, int field,
151: short currentValue) {
152: synchronized (lock) {
153: return sm.getShortField(pc, field, currentValue);
154: }
155: }
156:
157: public int getIntField(PersistenceCapable pc, int field,
158: int currentValue) {
159: synchronized (lock) {
160: return sm.getIntField(pc, field, currentValue);
161: }
162: }
163:
164: public long getLongField(PersistenceCapable pc, int field,
165: long currentValue) {
166: synchronized (lock) {
167: return sm.getLongField(pc, field, currentValue);
168: }
169: }
170:
171: public float getFloatField(PersistenceCapable pc, int field,
172: float currentValue) {
173: synchronized (lock) {
174: return sm.getFloatField(pc, field, currentValue);
175: }
176: }
177:
178: public double getDoubleField(PersistenceCapable pc, int field,
179: double currentValue) {
180: synchronized (lock) {
181: return sm.getDoubleField(pc, field, currentValue);
182: }
183: }
184:
185: public String getStringField(PersistenceCapable pc, int field,
186: String currentValue) {
187: synchronized (lock) {
188: return sm.getStringField(pc, field, currentValue);
189: }
190: }
191:
192: public Object getObjectField(PersistenceCapable pc, int field,
193: Object currentValue) {
194: synchronized (lock) {
195: return sm.getObjectField(pc, field, currentValue);
196: }
197: }
198:
199: public void setBooleanField(PersistenceCapable pc, int field,
200: boolean currentValue, boolean newValue) {
201: synchronized (lock) {
202: sm.setBooleanField(pc, field, currentValue, newValue);
203: }
204: }
205:
206: public void setCharField(PersistenceCapable pc, int field,
207: char currentValue, char newValue) {
208: synchronized (lock) {
209: sm.setCharField(pc, field, currentValue, newValue);
210: }
211: }
212:
213: public void setByteField(PersistenceCapable pc, int field,
214: byte currentValue, byte newValue) {
215: synchronized (lock) {
216: sm.setByteField(pc, field, currentValue, newValue);
217: }
218: }
219:
220: public void setShortField(PersistenceCapable pc, int field,
221: short currentValue, short newValue) {
222: synchronized (lock) {
223: sm.setShortField(pc, field, currentValue, newValue);
224: }
225: }
226:
227: public void setIntField(PersistenceCapable pc, int field,
228: int currentValue, int newValue) {
229: synchronized (lock) {
230: sm.setIntField(pc, field, currentValue, newValue);
231: }
232: }
233:
234: public void setLongField(PersistenceCapable pc, int field,
235: long currentValue, long newValue) {
236: synchronized (lock) {
237: sm.setLongField(pc, field, currentValue, newValue);
238: }
239: }
240:
241: public void setFloatField(PersistenceCapable pc, int field,
242: float currentValue, float newValue) {
243: synchronized (lock) {
244: sm.setFloatField(pc, field, currentValue, newValue);
245: }
246: }
247:
248: public void setDoubleField(PersistenceCapable pc, int field,
249: double currentValue, double newValue) {
250: synchronized (lock) {
251: sm.setDoubleField(pc, field, currentValue, newValue);
252: }
253: }
254:
255: public void setStringField(PersistenceCapable pc, int field,
256: String currentValue, String newValue) {
257: synchronized (lock) {
258: sm.setStringField(pc, field, currentValue, newValue);
259: }
260: }
261:
262: public void setObjectField(PersistenceCapable pc, int field,
263: Object currentValue, Object newValue) {
264: synchronized (lock) {
265: sm.setObjectField(pc, field, currentValue, newValue);
266: }
267: }
268:
269: public void providedBooleanField(PersistenceCapable pc, int field,
270: boolean currentValue) {
271: synchronized (lock) {
272: sm.providedBooleanField(pc, field, currentValue);
273: }
274: }
275:
276: public void providedCharField(PersistenceCapable pc, int field,
277: char currentValue) {
278: synchronized (lock) {
279: sm.providedCharField(pc, field, currentValue);
280: }
281: }
282:
283: public void providedByteField(PersistenceCapable pc, int field,
284: byte currentValue) {
285: synchronized (lock) {
286: sm.providedByteField(pc, field, currentValue);
287: }
288: }
289:
290: public void providedShortField(PersistenceCapable pc, int field,
291: short currentValue) {
292: synchronized (lock) {
293: sm.providedShortField(pc, field, currentValue);
294: }
295: }
296:
297: public void providedIntField(PersistenceCapable pc, int field,
298: int currentValue) {
299: synchronized (lock) {
300: sm.providedIntField(pc, field, currentValue);
301: }
302: }
303:
304: public void providedLongField(PersistenceCapable pc, int field,
305: long currentValue) {
306: synchronized (lock) {
307: sm.providedLongField(pc, field, currentValue);
308: }
309: }
310:
311: public void providedFloatField(PersistenceCapable pc, int field,
312: float currentValue) {
313: synchronized (lock) {
314: sm.providedFloatField(pc, field, currentValue);
315: }
316: }
317:
318: public void providedDoubleField(PersistenceCapable pc, int field,
319: double currentValue) {
320: synchronized (lock) {
321: sm.providedDoubleField(pc, field, currentValue);
322: }
323: }
324:
325: public void providedStringField(PersistenceCapable pc, int field,
326: String currentValue) {
327: synchronized (lock) {
328: sm.providedStringField(pc, field, currentValue);
329: }
330: }
331:
332: public void providedObjectField(PersistenceCapable pc, int field,
333: Object currentValue) {
334: synchronized (lock) {
335: sm.providedObjectField(pc, field, currentValue);
336: }
337: }
338:
339: public boolean replacingBooleanField(PersistenceCapable pc,
340: int field) {
341: synchronized (lock) {
342: return sm.replacingBooleanField(pc, field);
343: }
344: }
345:
346: public char replacingCharField(PersistenceCapable pc, int field) {
347: synchronized (lock) {
348: return sm.replacingCharField(pc, field);
349: }
350: }
351:
352: public byte replacingByteField(PersistenceCapable pc, int field) {
353: synchronized (lock) {
354: return sm.replacingByteField(pc, field);
355: }
356: }
357:
358: public short replacingShortField(PersistenceCapable pc, int field) {
359: synchronized (lock) {
360: return sm.replacingShortField(pc, field);
361: }
362: }
363:
364: public int replacingIntField(PersistenceCapable pc, int field) {
365: synchronized (lock) {
366: return sm.replacingIntField(pc, field);
367: }
368: }
369:
370: public long replacingLongField(PersistenceCapable pc, int field) {
371: synchronized (lock) {
372: return sm.replacingLongField(pc, field);
373: }
374: }
375:
376: public float replacingFloatField(PersistenceCapable pc, int field) {
377: synchronized (lock) {
378: return sm.replacingFloatField(pc, field);
379: }
380: }
381:
382: public double replacingDoubleField(PersistenceCapable pc, int field) {
383: synchronized (lock) {
384: return sm.replacingDoubleField(pc, field);
385: }
386: }
387:
388: public String replacingStringField(PersistenceCapable pc, int field) {
389: synchronized (lock) {
390: return sm.replacingStringField(pc, field);
391: }
392: }
393:
394: public Object replacingObjectField(PersistenceCapable pc, int field) {
395: synchronized (lock) {
396: return sm.replacingObjectField(pc, field);
397: }
398: }
399:
400: public void fillNewAppPKField(int fieldNo) {
401: synchronized (lock) {
402: sm.fillNewAppPKField(fieldNo);
403: }
404: }
405:
406: }
|