001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.resource.connectionmanager;
023:
024: import javax.resource.ResourceException;
025: import javax.resource.spi.ConnectionEvent;
026: import javax.resource.spi.ManagedConnection;
027:
028: import org.jboss.logging.Logger;
029:
030: /**
031: * The NoTxConnectionManager is an simple extension class of the BaseConnectionManager2
032: * for use with jca adapters with no transaction support.
033: * It includes functionality to obtain managed connections from
034: * a ManagedConnectionPool mbean, find the Subject from a SubjectSecurityDomain,
035: * and interact with the CachedConnectionManager for connections held over
036: * transaction and method boundaries. Important mbean references are to a
037: * ManagedConnectionPool supplier (typically a JBossManagedConnectionPool), and a
038: * RARDeployment representing the ManagedConnectionFactory.
039: *
040: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
041: * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
042: * @version $Revision: 57189 $
043: */
044: public class NoTxConnectionManager extends BaseConnectionManager2 {
045: public NoTxConnectionManager() {
046: }
047:
048: /**
049: * Creates a new NoTxConnectionManager instance.
050: * for TESTING ONLY! not a managed operation.
051: *
052: * @param ccm a <code>CachedConnectionManager</code> value
053: * @param poolingStrategy a <code>ManagedConnectionPool</code> value
054: */
055: public NoTxConnectionManager(CachedConnectionManager ccm,
056: ManagedConnectionPool poolingStrategy) {
057: super (ccm, poolingStrategy);
058: }
059:
060: public ConnectionListener createConnectionListener(
061: ManagedConnection mc, Object context) {
062: ConnectionListener cli = new NoTxConnectionEventListener(mc,
063: poolingStrategy, context, log);
064: mc.addConnectionEventListener(cli);
065: return cli;
066: }
067:
068: protected void managedConnectionDisconnected(ConnectionListener cl)
069: throws ResourceException {
070: //if there are no more handles, we can return to pool.
071: if (cl.isManagedConnectionFree())
072: returnManagedConnection(cl, false);
073: }
074:
075: private class NoTxConnectionEventListener extends
076: BaseConnectionEventListener {
077: private NoTxConnectionEventListener(final ManagedConnection mc,
078: final ManagedConnectionPool mcp, final Object context,
079: Logger log) {
080: super (mc, mcp, context, log);
081: }
082:
083: public void connectionClosed(ConnectionEvent ce) {
084: try {
085: getCcm().unregisterConnection(
086: NoTxConnectionManager.this ,
087: ce.getConnectionHandle());
088: } catch (Throwable t) {
089: log.info("Throwable from unregisterConnection", t);
090: }
091: try {
092: unregisterAssociation(this , ce.getConnectionHandle());
093: if (isManagedConnectionFree()) {
094: returnManagedConnection(this , false);
095: }
096: } catch (ResourceException re) {
097: log
098: .error(
099: "ResourceException while closing connection handle!",
100: re);
101: }
102: }
103:
104: public void localTransactionStarted(ConnectionEvent ce) {
105: //nothing to do.
106: }
107:
108: public void localTransactionCommitted(ConnectionEvent ce) {
109: //nothing to do.
110: }
111:
112: public void localTransactionRolledback(ConnectionEvent ce) {
113: //nothing to do.
114: }
115: }
116: }
|