KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > jdbc > ResourceAdapterImpl


1 /*
2
3    Derby - Class org.apache.derby.jdbc.ResourceAdapterImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.jdbc;
23
24 import org.apache.derby.iapi.services.info.JVMInfo;
25
26 import org.apache.derby.iapi.services.context.ContextService;
27 import org.apache.derby.iapi.services.monitor.ModuleControl;
28 import org.apache.derby.iapi.services.monitor.Monitor;
29 import org.apache.derby.iapi.services.sanity.SanityManager;
30
31 import org.apache.derby.iapi.jdbc.ResourceAdapter;
32 //import org.apache.derby.iapi.jdbc.XATransactionResource;
33

34 import org.apache.derby.iapi.error.StandardException;
35 import org.apache.derby.iapi.store.access.AccessFactory;
36 import org.apache.derby.iapi.store.access.xa.XAResourceManager;
37 import org.apache.derby.iapi.store.access.xa.XAXactId;
38
39
40 import java.util.Properties JavaDoc;
41 import java.util.Hashtable JavaDoc;
42 import java.util.Enumeration JavaDoc;
43
44
45 public class ResourceAdapterImpl
46         implements ResourceAdapter, ModuleControl
47 {
48     private boolean active;
49
50     // the real resource manager
51
private XAResourceManager rm;
52
53     // maps Xid to XATransationResource for run time transactions
54
private Hashtable JavaDoc connectionTable;
55
56     /*
57      * Module control
58      */

59
60     public void boot(boolean create, Properties JavaDoc properties)
61         throws StandardException
62     {
63         // we can only run on jdk1.2 or beyond with JTA and JAVA 20 extension
64
// loaded.
65

66         connectionTable = new Hashtable JavaDoc();
67
68         AccessFactory af =
69             (AccessFactory)Monitor.findServiceModule(this, AccessFactory.MODULE);
70
71         rm = (XAResourceManager) af.getXAResourceManager();
72
73         active = true;
74     }
75
76     public void stop()
77     {
78         active = false;
79
80         for (Enumeration JavaDoc e = connectionTable.elements(); e.hasMoreElements(); ) {
81
82             XATransactionState tranState = (XATransactionState) e.nextElement();
83
84             try {
85                 tranState.conn.close();
86             } catch (java.sql.SQLException JavaDoc sqle) {
87             }
88         }
89
90         active = false;
91     }
92
93     public boolean isActive()
94     {
95         return active;
96     }
97
98     /*
99      * Resource Adapter methods
100      */

101
102     public synchronized Object JavaDoc findConnection(XAXactId xid) {
103
104         return connectionTable.get(xid);
105     }
106
107     public synchronized boolean addConnection(XAXactId xid, Object JavaDoc conn) {
108         if (connectionTable.get(xid) != null)
109             return false;
110
111         // put this into the transaction table, if the xid is already
112
// present as an in-doubt transaction, we need to remove it from
113
// the run time list
114
connectionTable.put(xid, conn);
115         return true;
116     }
117
118     public synchronized Object JavaDoc removeConnection(XAXactId xid) {
119
120         return connectionTable.remove(xid);
121
122     }
123
124
125     /**
126         Return the XA Resource manager to the XA Connection
127      */

128     public XAResourceManager getXAResourceManager()
129     {
130         return rm;
131     }
132 }
133
Popular Tags