KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > otm > lock > IsolationFactory


1 package org.apache.ojb.otm.lock;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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
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      * Fetches the isolation level of given class from its ClassDescriptor.
50      *
51      */

52     public static TransactionIsolation getIsolationLevel (PersistenceBroker pb,
53                                                           ObjectLock lock)
54     {
55         /*
56         arminw: use real object class instead of top-level class
57         to match isolation level of given class
58         */

59         // Class clazz = lock.getTargetIdentity().getObjectsTopLevelClass();
60
Class JavaDoc 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 }
92
Popular Tags