1 | |
package org.apache.ojb.otm.lock; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.metadata.ClassDescriptor; |
19 | |
import org.apache.ojb.broker.locking.IsolationLevels; |
20 | |
import org.apache.ojb.broker.PersistenceBroker; |
21 | |
import org.apache.ojb.otm.lock.isolation.ReadCommittedIsolation; |
22 | |
import org.apache.ojb.otm.lock.isolation.ReadUncommittedIsolation; |
23 | |
import org.apache.ojb.otm.lock.isolation.RepeatableReadIsolation; |
24 | |
import org.apache.ojb.otm.lock.isolation.SerializableIsolation; |
25 | |
import org.apache.ojb.otm.lock.isolation.TransactionIsolation; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class IsolationFactory |
35 | |
{ |
36 | |
|
37 | |
private static final TransactionIsolation READ_UNCOMMITTED_ISOLATION |
38 | |
= new ReadUncommittedIsolation(); |
39 | |
private static final TransactionIsolation READ_COMMITTED_ISOLATION |
40 | |
= new ReadCommittedIsolation(); |
41 | |
private static final TransactionIsolation REPEATABLE_READ_ISOLATION |
42 | |
= new RepeatableReadIsolation(); |
43 | |
private static final TransactionIsolation SERIALIZABLE_ISOLATION |
44 | |
= new SerializableIsolation(); |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public static TransactionIsolation getIsolationLevel (PersistenceBroker pb, |
53 | |
ObjectLock lock) |
54 | |
{ |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
Class clazz = lock.getTargetIdentity().getObjectsRealClass(); |
61 | |
ClassDescriptor classDescriptor = pb.getClassDescriptor(clazz); |
62 | |
int isolationLevel = classDescriptor.getIsolationLevel(); |
63 | |
|
64 | |
TransactionIsolation isolation = null; |
65 | |
switch (isolationLevel) { |
66 | |
|
67 | |
case IsolationLevels.IL_READ_UNCOMMITTED: |
68 | |
isolation = READ_UNCOMMITTED_ISOLATION; |
69 | |
break; |
70 | |
|
71 | |
case IsolationLevels.IL_READ_COMMITTED: |
72 | |
isolation = READ_COMMITTED_ISOLATION; |
73 | |
break; |
74 | |
|
75 | |
case IsolationLevels.IL_REPEATABLE_READ: |
76 | |
isolation = REPEATABLE_READ_ISOLATION; |
77 | |
break; |
78 | |
|
79 | |
case IsolationLevels.IL_SERIALIZABLE: |
80 | |
isolation = SERIALIZABLE_ISOLATION; |
81 | |
break; |
82 | |
|
83 | |
default: |
84 | |
throw new UnknownIsolationException( |
85 | |
"Isolation level " + isolationLevel + " is not supported"); |
86 | |
} |
87 | |
|
88 | |
return isolation; |
89 | |
} |
90 | |
|
91 | |
} |