KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > resource > MCInfo


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: MCInfo.java,v 1.10 2005/05/10 12:55:34 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.resource;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import javax.resource.ResourceException JavaDoc;
34 import javax.resource.spi.ManagedConnection JavaDoc;
35 import javax.transaction.Synchronization JavaDoc;
36 import javax.transaction.xa.XAResource JavaDoc;
37
38 /**
39  * A ManagedConnection and its Information
40  *
41  * @author sebastien.chassande@inrialpes.fr
42  * @author Eric.Hardesty@bull.com
43  */

44 public class MCInfo {
45     /**
46      * The managedConnection
47      */

48     public ManagedConnection JavaDoc mc;
49
50     /**
51      * The list of used Connections
52      */

53     public Vector JavaDoc usedCs = null;
54
55     /**
56      * The event used for the later enlisting into transaction
57      */

58     public RMEImpl rme = null;
59
60     /**
61      * Has the ResourceManagerEvent Listener been called
62      */

63     public boolean rmeCalled = false;
64
65     /**
66      * Is the the managedConnection is inside a local transaction
67      */

68     public boolean localTransaction = false;
69
70     /**
71      * If local transaction is used, then here is the LocalXAWrapper to use
72      * instead of an XA object
73      */

74     public LocalXAWrapper lw = null;
75
76     /**
77      * The Context linked to the managedConnection instance
78      * There are three state possible
79      * global transaction : ctx= the reference to the transaction instance
80      * local transaction: ctx=null / localTransaction = true
81      * other ctx = null;
82      */

83     public Object JavaDoc ctx;
84
85     /**
86      * The current Synchronisation object used for the later enlisting into
87      * the global transaction
88      */

89     public Synchronization JavaDoc synchro = null;
90
91     /**
92      * This vector will hold any necessary preparedStatements for this
93      * ManagedConnection.
94      */

95     public List JavaDoc pStmts = null;
96
97
98     /**
99      * Has the ConnectionEventListener been set
100      */

101     public boolean connectionEventListener = false;
102
103     /**
104      * Constructor for the MCInfo object
105      * @param mc ManagedConnection to associate with
106      */

107     public MCInfo(ManagedConnection JavaDoc mc) {
108         this.mc = mc;
109         localTransaction = false;
110         usedCs = new Vector JavaDoc();
111         pStmts = new ArrayList JavaDoc();
112     }
113
114
115     /**
116      * Gets the State attribute of the MCInfo object
117      *
118      * @param prefix String to print out
119      * @return The State value
120      */

121     public String JavaDoc getState(String JavaDoc prefix) {
122         String JavaDoc res = prefix + "* mc=" + mc + "\n";
123         res += prefix + "Context=" + ctx + "\n";
124         res += prefix + "size of usedCs:" + usedCs.size() + "\n";
125         for (int i = 0; i < usedCs.size(); i++) {
126             res += prefix + "\t" + usedCs.elementAt(i).toString() + "\n";
127         }
128         res += prefix + "size of pStmts:" + pStmts.size() + "\n";
129         for (Iterator JavaDoc it = pStmts.iterator(); it.hasNext();) {
130             res += prefix + "\t" + it.next() + "\n";
131         }
132         return res;
133     }
134
135
136     /**
137      * Gets the State attribute of the MCInfo object
138      * @return String current state
139      */

140     public String JavaDoc 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 JavaDoc {
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 JavaDoc getXAResource() throws ResourceException JavaDoc {
179         if (lw != null) {
180             return lw;
181         } else {
182             return mc.getXAResource();
183         }
184     }
185 }
186
187
188
Popular Tags