01: package org.apache.ojb.otm.lock;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * <javadoc>
30: *
31: * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
32: *
33: */
34: public class IsolationFactory {
35:
36: private static final TransactionIsolation READ_UNCOMMITTED_ISOLATION = new ReadUncommittedIsolation();
37: private static final TransactionIsolation READ_COMMITTED_ISOLATION = new ReadCommittedIsolation();
38: private static final TransactionIsolation REPEATABLE_READ_ISOLATION = new RepeatableReadIsolation();
39: private static final TransactionIsolation SERIALIZABLE_ISOLATION = new SerializableIsolation();
40:
41: /**
42: *
43: * Fetches the isolation level of given class from its ClassDescriptor.
44: *
45: */
46: public static TransactionIsolation getIsolationLevel(
47: PersistenceBroker pb, ObjectLock lock) {
48: /*
49: arminw: use real object class instead of top-level class
50: to match isolation level of given class
51: */
52: // Class clazz = lock.getTargetIdentity().getObjectsTopLevelClass();
53: Class clazz = lock.getTargetIdentity().getObjectsRealClass();
54: ClassDescriptor classDescriptor = pb.getClassDescriptor(clazz);
55: int isolationLevel = classDescriptor.getIsolationLevel();
56:
57: TransactionIsolation isolation = null;
58: switch (isolationLevel) {
59:
60: case IsolationLevels.IL_READ_UNCOMMITTED:
61: isolation = READ_UNCOMMITTED_ISOLATION;
62: break;
63:
64: case IsolationLevels.IL_READ_COMMITTED:
65: isolation = READ_COMMITTED_ISOLATION;
66: break;
67:
68: case IsolationLevels.IL_REPEATABLE_READ:
69: isolation = REPEATABLE_READ_ISOLATION;
70: break;
71:
72: case IsolationLevels.IL_SERIALIZABLE:
73: isolation = SERIALIZABLE_ISOLATION;
74: break;
75:
76: default:
77: throw new UnknownIsolationException("Isolation level "
78: + isolationLevel + " is not supported");
79: }
80:
81: return isolation;
82: }
83:
84: }
|