KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > otm > connector > JCAKit


1 package org.apache.ojb.otm.connector;
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.Identity;
19 import org.apache.ojb.broker.PBKey;
20 import org.apache.ojb.otm.Kit;
21 import org.apache.ojb.otm.OTMConnection;
22 import org.apache.ojb.otm.copy.ObjectCopyStrategy;
23 import org.apache.ojb.otm.core.Transaction;
24 import org.apache.ojb.otm.lock.map.LockMap;
25 import org.apache.ojb.otm.lock.wait.LockWaitStrategy;
26 import org.apache.ojb.otm.swizzle.Swizzling;
27
28 import javax.naming.Reference JavaDoc;
29 import javax.resource.Referenceable JavaDoc;
30 import javax.resource.ResourceException JavaDoc;
31 import javax.resource.spi.ConnectionManager JavaDoc;
32 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
33 import java.io.Serializable JavaDoc;
34
35 /**
36  * represents the Kit used for JCA
37  *
38  * @author <a HREF="mailto:mattbaird@yahoo.com">Matthew Baird<a>
39  */

40
41 public class JCAKit implements Kit, Serializable JavaDoc, Referenceable JavaDoc
42 {
43     private OTMJCAManagedConnectionFactory m_managedConnectionFactory;
44     private ConnectionManager JavaDoc m_connectionManager;
45     private Reference JavaDoc m_reference;
46
47     public JCAKit(ManagedConnectionFactory JavaDoc mcf, ConnectionManager JavaDoc cm)
48     {
49         Util.log("In JCAKit");
50         m_managedConnectionFactory = (OTMJCAManagedConnectionFactory) mcf;
51
52         if (cm == null)
53             m_connectionManager = new OTMConnectionManager();
54         else
55             m_connectionManager = cm;
56     }
57
58     private Kit getKit()
59     {
60         try
61         {
62             return m_managedConnectionFactory.getKit();
63         }
64         catch (ResourceException JavaDoc e)
65         {
66             throw new OTMConnectionRuntimeException(e);
67         }
68     }
69
70     /**
71      * Kit implementation
72      */

73     public OTMConnection acquireConnection(PBKey pbkey)
74     {
75         Util.log("In JCAKit.getConnection,1");
76         try
77         {
78             OTMConnectionRequestInfo info = new OTMConnectionRequestInfo(pbkey);
79             return (OTMConnection) m_connectionManager.allocateConnection(m_managedConnectionFactory, info);
80         }
81         catch (ResourceException JavaDoc ex)
82         {
83             throw new OTMConnectionRuntimeException(ex);
84         }
85     }
86
87     public Transaction getTransaction(OTMConnection otmConnection)
88     {
89         if (otmConnection instanceof OTMJCAConnection)
90         {
91             return getKit().getTransaction(((OTMJCAConnection)otmConnection).getConnection());
92         }
93         else
94             return getKit().getTransaction(otmConnection);
95     }
96
97     public Swizzling getSwizzlingStrategy()
98     {
99         return getKit().getSwizzlingStrategy();
100     }
101
102     public LockWaitStrategy getLockWaitStrategy()
103     {
104         return getKit().getLockWaitStrategy();
105     }
106
107     public LockMap getLockMap()
108     {
109         return getKit().getLockMap();
110     }
111
112     public ObjectCopyStrategy getCopyStrategy(Identity identity)
113     {
114         return getKit().getCopyStrategy(identity);
115     }
116
117
118     public boolean isImplicitLockingUsed()
119     {
120         return getKit().isImplicitLockingUsed();
121     }
122
123     /**
124      * Referenceable implementation
125      */

126
127     public void setReference(Reference JavaDoc reference)
128     {
129         this.m_reference = reference;
130     }
131
132     public Reference JavaDoc getReference()
133     {
134         return m_reference;
135     }
136 }
137
Popular Tags