KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > connectionmanager > NoTxConnectionManager


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.connectionmanager;
23
24 import javax.resource.ResourceException JavaDoc;
25 import javax.resource.spi.ConnectionEvent JavaDoc;
26 import javax.resource.spi.ManagedConnection JavaDoc;
27
28 import org.jboss.logging.Logger;
29
30 /**
31  * The NoTxConnectionManager is an simple extension class of the BaseConnectionManager2
32  * for use with jca adapters with no transaction support.
33  * It includes functionality to obtain managed connections from
34  * a ManagedConnectionPool mbean, find the Subject from a SubjectSecurityDomain,
35  * and interact with the CachedConnectionManager for connections held over
36  * transaction and method boundaries. Important mbean references are to a
37  * ManagedConnectionPool supplier (typically a JBossManagedConnectionPool), and a
38  * RARDeployment representing the ManagedConnectionFactory.
39  *
40  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
41  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
42  * @version $Revision: 38338 $
43  */

44 public class NoTxConnectionManager extends BaseConnectionManager2
45 {
46    public NoTxConnectionManager()
47    {
48    }
49
50    /**
51     * Creates a new NoTxConnectionManager instance.
52     * for TESTING ONLY! not a managed operation.
53     *
54     * @param ccm a <code>CachedConnectionManager</code> value
55     * @param poolingStrategy a <code>ManagedConnectionPool</code> value
56     */

57    public NoTxConnectionManager(CachedConnectionManager ccm,
58                                 ManagedConnectionPool poolingStrategy)
59    {
60       super(ccm, poolingStrategy);
61    }
62
63    public ConnectionListener createConnectionListener(ManagedConnection JavaDoc mc, Object JavaDoc context)
64    {
65       ConnectionListener cli = new NoTxConnectionEventListener(mc, poolingStrategy, context, log);
66       mc.addConnectionEventListener(cli);
67       return cli;
68    }
69
70    protected void managedConnectionDisconnected(ConnectionListener cl) throws ResourceException JavaDoc
71    {
72       //if there are no more handles, we can return to pool.
73
if (cl.isManagedConnectionFree())
74          returnManagedConnection(cl, false);
75    }
76
77    private class NoTxConnectionEventListener extends BaseConnectionEventListener
78    {
79       private NoTxConnectionEventListener(final ManagedConnection JavaDoc mc, final ManagedConnectionPool mcp, final Object JavaDoc context, Logger log)
80       {
81          super(mc, mcp, context, log);
82       }
83
84       public void connectionClosed(ConnectionEvent JavaDoc ce)
85       {
86          try
87          {
88             getCcm().unregisterConnection(NoTxConnectionManager.this, ce.getConnectionHandle());
89          }
90          catch (Throwable JavaDoc t)
91          {
92             log.info("Throwable from unregisterConnection", t);
93          }
94          try
95          {
96             unregisterAssociation(this, ce.getConnectionHandle());
97             if (isManagedConnectionFree())
98             {
99                returnManagedConnection(this, false);
100             }
101          }
102          catch (ResourceException JavaDoc re)
103          {
104             log.error("ResourceException while closing connection handle!", re);
105          }
106       }
107
108       public void localTransactionStarted(ConnectionEvent JavaDoc ce)
109       {
110          //nothing to do.
111
}
112
113       public void localTransactionCommitted(ConnectionEvent JavaDoc ce)
114       {
115          //nothing to do.
116
}
117
118       public void localTransactionRolledback(ConnectionEvent JavaDoc ce)
119       {
120          //nothing to do.
121
}
122    }
123 }
124
Popular Tags