001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: MCInfo.java 9649 2006-10-02 08:21:28Z coqp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.resource;
027:
028: import java.util.ArrayList;
029: import java.util.Iterator;
030: import java.util.List;
031: import java.util.Vector;
032:
033: import javax.resource.ResourceException;
034: import javax.resource.spi.ManagedConnection;
035: import javax.transaction.Synchronization;
036: import javax.transaction.xa.XAResource;
037:
038: /**
039: * A ManagedConnection and its Information
040: *
041: * @author sebastien.chassande@inrialpes.fr
042: * @author Eric.Hardesty@bull.com
043: */
044: public class MCInfo {
045: /**
046: * The managedConnection
047: */
048: public ManagedConnection mc;
049:
050: /**
051: * The list of used Connections
052: */
053: public Vector usedCs = null;
054:
055: /**
056: * The event used for the later enlisting into transaction
057: */
058: public RMEImpl rme = null;
059:
060: /**
061: * Has the ResourceManagerEvent Listener been called
062: */
063: public boolean rmeCalled = false;
064:
065: /**
066: * Is the the managedConnection is inside a local transaction
067: */
068: public boolean localTransaction = false;
069:
070: /**
071: * If local transaction is used, then here is the LocalXAWrapper to use
072: * instead of an XA object
073: */
074: public LocalXAWrapper lw = null;
075:
076: /**
077: * The Context linked to the managedConnection instance
078: * There are three state possible
079: * global transaction : ctx= the reference to the transaction instance
080: * local transaction: ctx=null / localTransaction = true
081: * other ctx = null;
082: */
083: public Object ctx;
084:
085: /**
086: * The current Synchronisation object used for the later enlisting into
087: * the global transaction
088: */
089: public Synchronization synchro = null;
090:
091: /**
092: * This vector will hold any necessary preparedStatements for this
093: * ManagedConnection.
094: */
095: public List pStmts = null;
096:
097: /**
098: * Has the ConnectionEventListener been set
099: */
100: public boolean connectionEventListener = false;
101:
102: /**
103: * Constructor for the MCInfo object
104: * @param mc ManagedConnection to associate with
105: */
106: public MCInfo(ManagedConnection mc) {
107: this .mc = mc;
108: localTransaction = false;
109: usedCs = new Vector();
110: pStmts = new ArrayList();
111: }
112:
113: /**
114: * Gets the State attribute of the MCInfo object
115: *
116: * @param prefix String to print out
117: * @return The State value
118: */
119: public String getState(String prefix) {
120: String res = prefix + "* mc=" + mc + "\n";
121: res += prefix + "Context=" + ctx + "\n";
122: res += prefix + "size of usedCs:" + usedCs.size() + "\n";
123: for (int i = 0; i < usedCs.size(); i++) {
124: res += prefix + "\t" + usedCs.elementAt(i).toString()
125: + "\n";
126: }
127: synchronized (pStmts) {
128: res += prefix + "size of pStmts:" + pStmts.size() + "\n";
129: for (Iterator it = pStmts.iterator(); it.hasNext();) {
130: res += prefix + "\t" + it.next() + "\n";
131: }
132: }
133: return res;
134: }
135:
136: /**
137: * Gets the State attribute of the MCInfo object
138: * @return String current state
139: */
140: public String getState() {
141: return getState("");
142: }
143:
144: /**
145: * Determine if there is a pStmt to remove
146: * The method calling this code should use synchronized block
147: * @return int offset of the first free entry
148: */
149: public int findFreeStmt() {
150: int offset = -1;
151: int size = pStmts.size();
152: PreparedStatementWrapper psw = null;
153: if (pStmts != null) {
154: for (int i = 0; i < size; i++) {
155: psw = (PreparedStatementWrapper) pStmts.get(i);
156: if (psw.isClosed()) {
157: offset = i;
158: break;
159: }
160: }
161: }
162: return offset;
163: }
164:
165: /**
166: * Fowards the detroy call on the ManagedConnection
167: * @throws Exception if an Exception occurs
168: */
169: public void destroy() throws Exception {
170: mc.destroy();
171: }
172:
173: /**
174: * Gets the associated XAResource
175: * @return XAResource associated with this object
176: * @throws ResourceException if an Exception occurs
177: */
178: public XAResource getXAResource() throws ResourceException {
179: if (lw != null) {
180: return lw;
181: } else {
182: return mc.getXAResource();
183: }
184: }
185: }
|