1 package org.apache.ojb.odmg.locking;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import org.apache.ojb.broker.Identity;
19 import org.apache.ojb.broker.locking.IsolationLevels;
20 import org.apache.ojb.broker.core.proxy.ProxyHelper;
21 import org.apache.ojb.broker.metadata.ClassDescriptor;
22 import org.apache.ojb.odmg.TransactionImpl;
23
24
25
26
27
28
29
30
31
32 public class LockManagerOdmgImpl implements LockManager
33 {
34 private org.apache.ojb.broker.locking.LockManager lm;
35
36 public LockManagerOdmgImpl(org.apache.ojb.broker.locking.LockManager lm)
37 {
38 this.lm = lm;
39 }
40
41 private boolean ignore(int isolationLevel)
42 {
43 return isolationLevel == IsolationLevels.IL_OPTIMISTIC || isolationLevel == IsolationLevels.IL_NONE;
44 }
45
46 public boolean readLock(TransactionImpl tx, Object obj)
47 {
48 Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
49 return readLock(tx, oid, obj);
50 }
51
52 public boolean readLock(TransactionImpl tx, Identity oid, Object obj)
53 {
54 ClassDescriptor cld = tx.getBroker().getClassDescriptor(ProxyHelper.getRealClass(obj));
55 int isolationLevel = cld.getIsolationLevel();
56 return ignore(isolationLevel) ? true : lm.readLock(tx.getGUID(), oid, isolationLevel);
57 }
58
59 public boolean writeLock(TransactionImpl tx, Object obj)
60 {
61 Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
62 return writeLock(tx, oid, obj);
63 }
64
65 public boolean writeLock(TransactionImpl tx, Identity oid, Object obj)
66 {
67 ClassDescriptor cld = tx.getBroker().getClassDescriptor(ProxyHelper.getRealClass(obj));
68 int isolationLevel = cld.getIsolationLevel();
69 return ignore(isolationLevel) ? true : lm.writeLock(tx.getGUID(), oid, isolationLevel);
70 }
71
72 public boolean upgradeLock(TransactionImpl tx, Object obj)
73 {
74 Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
75 return upgradeLock(tx, oid, obj);
76 }
77
78 public boolean upgradeLock(TransactionImpl tx, Identity oid, Object obj)
79 {
80 ClassDescriptor cld = tx.getBroker().getClassDescriptor(ProxyHelper.getRealClass(obj));
81 int isolationLevel = cld.getIsolationLevel();
82 return ignore(isolationLevel) ? true : lm.upgradeLock(tx.getGUID(), oid, isolationLevel);
83 }
84
85 public boolean releaseLock(TransactionImpl tx, Object obj)
86 {
87 Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
88 return releaseLock(tx, oid, obj);
89 }
90
91 public boolean releaseLock(TransactionImpl tx, Identity oid, Object obj)
92 {
93 return lm.releaseLock(tx.getGUID(), oid);
94 }
95
96 public boolean checkRead(TransactionImpl tx, Object obj)
97 {
98 Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
99 return checkRead(tx, oid, obj);
100 }
101
102 public boolean checkRead(TransactionImpl tx, Identity oid, Object obj)
103 {
104 return lm.hasRead(tx.getGUID(), oid);
105 }
106
107 public boolean checkWrite(TransactionImpl tx, Object obj)
108 {
109 Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
110 return checkWrite(tx, oid, obj);
111 }
112
113 public boolean checkWrite(TransactionImpl tx, Identity oid, Object obj)
114 {
115 return lm.hasWrite(tx.getGUID(), oid);
116 }
117 }