001: /*
002:
003: Derby - Class org.apache.derby.jdbc.ResourceAdapterImpl
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.jdbc;
023:
024: import org.apache.derby.iapi.services.info.JVMInfo;
025:
026: import org.apache.derby.iapi.services.context.ContextService;
027: import org.apache.derby.iapi.services.monitor.ModuleControl;
028: import org.apache.derby.iapi.services.monitor.Monitor;
029: import org.apache.derby.iapi.services.sanity.SanityManager;
030:
031: import org.apache.derby.iapi.jdbc.ResourceAdapter; //import org.apache.derby.iapi.jdbc.XATransactionResource;
032:
033: import org.apache.derby.iapi.error.StandardException;
034: import org.apache.derby.iapi.store.access.AccessFactory;
035: import org.apache.derby.iapi.store.access.xa.XAResourceManager;
036: import org.apache.derby.iapi.store.access.xa.XAXactId;
037:
038: import java.util.Properties;
039: import java.util.Hashtable;
040: import java.util.Enumeration;
041:
042: public class ResourceAdapterImpl implements ResourceAdapter,
043: ModuleControl {
044: private boolean active;
045:
046: // the real resource manager
047: private XAResourceManager rm;
048:
049: // maps Xid to XATransationResource for run time transactions
050: private Hashtable connectionTable;
051:
052: /*
053: * Module control
054: */
055:
056: public void boot(boolean create, Properties properties)
057: throws StandardException {
058: // we can only run on jdk1.2 or beyond with JTA and JAVA 20 extension
059: // loaded.
060:
061: connectionTable = new Hashtable();
062:
063: AccessFactory af = (AccessFactory) Monitor.findServiceModule(
064: this , AccessFactory.MODULE);
065:
066: rm = (XAResourceManager) af.getXAResourceManager();
067:
068: active = true;
069: }
070:
071: public void stop() {
072: active = false;
073:
074: for (Enumeration e = connectionTable.elements(); e
075: .hasMoreElements();) {
076:
077: XATransactionState tranState = (XATransactionState) e
078: .nextElement();
079:
080: try {
081: tranState.conn.close();
082: } catch (java.sql.SQLException sqle) {
083: }
084: }
085:
086: active = false;
087: }
088:
089: public boolean isActive() {
090: return active;
091: }
092:
093: /*
094: * Resource Adapter methods
095: */
096:
097: public synchronized Object findConnection(XAXactId xid) {
098:
099: return connectionTable.get(xid);
100: }
101:
102: public synchronized boolean addConnection(XAXactId xid, Object conn) {
103: if (connectionTable.get(xid) != null)
104: return false;
105:
106: // put this into the transaction table, if the xid is already
107: // present as an in-doubt transaction, we need to remove it from
108: // the run time list
109: connectionTable.put(xid, conn);
110: return true;
111: }
112:
113: public synchronized Object removeConnection(XAXactId xid) {
114:
115: return connectionTable.remove(xid);
116:
117: }
118:
119: /**
120: Return the XA Resource manager to the XA Connection
121: */
122: public XAResourceManager getXAResourceManager() {
123: return rm;
124: }
125: }
|