db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/jca/org/apache/ojb/otm/connector OTMJCAManagedConnectionFactory.java OTMJCAManagedConnection.java OTMConnectionRequestInfo.java OTMConnectionMetaData.java JCAKit.java Util.java OTMConnectionRuntimeException.java OTMJCAConnection.java OTMConnectionManager.java OTMConnectionEventListener.java
Date Tue, 01 Jul 2003 21:04:28 GMT
mattbaird    2003/07/01 14:04:28

  Added:       src/jca/org/apache/ojb/otm/connector
                        OTMJCAManagedConnectionFactory.java
                        OTMJCAManagedConnection.java
                        OTMConnectionRequestInfo.java
                        OTMConnectionMetaData.java JCAKit.java Util.java
                        OTMConnectionRuntimeException.java
                        OTMJCAConnection.java OTMConnectionManager.java
                        OTMConnectionEventListener.java
  Log:
  new OTM JCA connector.
  
  Revision  Changes    Path
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnectionFactory.java
  
  Index: OTMJCAManagedConnectionFactory.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.otm.Kit;
  import org.apache.ojb.otm.OTMConnection;
  import org.apache.ojb.otm.kit.SimpleKit;
  
  import javax.resource.ResourceException;
  import javax.resource.spi.ConnectionManager;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ManagedConnectionFactory;
  import javax.security.auth.Subject;
  import java.io.PrintWriter;
  import java.io.Serializable;
  import java.sql.DriverManager;
  import java.util.Iterator;
  import java.util.Set;
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMJCAManagedConnectionFactory
  		implements ManagedConnectionFactory, Serializable
  {
  	private Kit m_kit;
  
  	private synchronized void initialize()
  	{
  		if (m_kit == null)
  		{
  			m_kit = SimpleKit.getInstance();
  		}
  	}
  
  	public Kit getKit() throws ResourceException
  	{
  		initialize();
  		return m_kit;
  	}
  
  	public OTMJCAManagedConnectionFactory()
  	{
  		Util.log("In OTMJCAManagedConnectionFactory.constructor");
  	}
  
  	public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnectionFactory.createConnectionFactory,1");
  		return new JCAKit(this, cxManager);
  	}
  
  	public Object createConnectionFactory() throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnectionFactory.createManagedFactory,2");
  		return new JCAKit(this, null);
  	}
  
  	/**
  	 * return a new managed connection. This connection is wrapped around the real connection and delegates to it
  	 * to get work done.
  	 * @param subject
  	 * @param info
  	 * @return
  	 */
  	public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo info)
  	{
  		Util.log("In OTMJCAManagedConnectionFactory.createManagedConnection");
  		try
  		{
  			Kit kit = getKit();
  			PBKey key = ((OTMConnectionRequestInfo) info).getPbKey();
  			OTMConnection connection = kit.acquireConnection(key);
  			return new OTMJCAManagedConnection(this, connection, key);
  		}
  		catch (ResourceException e)
  		{
  			throw new OTMConnectionRuntimeException(e.getMessage());
  		}
  	}
  
  	public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo info)
  			throws ResourceException
  	{
  		Util.log("OTMJCAManagedConnectionFactory::matchManagedConnections called with " + connectionSet.size() + " connections.");
  		for (Iterator i = connectionSet.iterator(); i.hasNext();)
  		{
  			Object o = i.next();
  			if (o instanceof OTMJCAManagedConnection)
  			{
  				// all idle connections are identical
  				return (OTMJCAManagedConnection) o;
  			}
  		}
  		Util.log("OTMJCAManagedConnectionFactory::No matched connections");
  		return null;
  	}
  
  	public void setLogWriter(PrintWriter out) throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnectionFactory.setLogWriter");
  	}
  
  	public PrintWriter getLogWriter() throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnectionFactory.getLogWriter");
  		return DriverManager.getLogWriter();
  	}
  
  	public boolean equals(Object obj)
  	{
  		if (obj == null)
  			return false;
  		if (obj instanceof OTMJCAManagedConnectionFactory)
  		{
  			int hash1 = ((OTMJCAManagedConnectionFactory) obj).hashCode();
  			int hash2 = hashCode();
  			return hash1 == hash2;
  		}
  		else
  		{
  			return false;
  		}
  	}
  
  	public int hashCode()
  	{
  		return 1;
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java
  
  Index: OTMJCAManagedConnection.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.otm.OTMConnection;
  import org.apache.ojb.otm.core.Transaction;
  import org.apache.ojb.otm.core.TransactionException;
  
  import javax.resource.NotSupportedException;
  import javax.resource.ResourceException;
  import javax.resource.spi.*;
  import javax.security.auth.Subject;
  import javax.transaction.xa.XAResource;
  import java.io.PrintWriter;
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMJCAManagedConnection implements ManagedConnection, LocalTransaction
  {
  	private PBKey m_pbKey;
  	private OTMJCAManagedConnectionFactory m_managedConnectionFactory;
  	private PrintWriter m_logWriter;
  	private boolean m_destroyed;
  	private final Set m_handles = new HashSet();
  	private final Collection m_connectionEventListeners = new ArrayList();
  
  	/**
  	 * the wrapped connection
  	 */
  	private OTMConnection m_connection;
  
  	OTMJCAManagedConnection(ManagedConnectionFactory mcf, OTMConnection conn, PBKey pbKey)
  	{
  		Util.log("In OTMJCAManagedConnection");
  		m_managedConnectionFactory = (OTMJCAManagedConnectionFactory) mcf;
  		m_pbKey = pbKey;
  		m_connection = conn;
  	}
  
  	public OTMConnection getConnection()
  	{
  		return m_connection;
  	}
  
  	public void setConnection(OTMConnection connection)
  	{
  		m_connection = connection;
  	}
  
  	public String getUserName()
  	{
  		return m_pbKey.getUser();
  	}
  
  	public Object getConnection(Subject subject, ConnectionRequestInfo connectionRequestInfo)
  			throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.getConnection");
  		OTMJCAConnection myCon = new OTMJCAConnection(this);
  		m_handles.add(myCon);
  		return myCon;
  	}
  
  	public void destroy()
  	{
  		Util.log("In OTMJCAManagedConnection.destroy");
  		cleanup();
  		m_destroyed = true;
  	}
  
  	public void cleanup()
  	{
  		Util.log("In OTMJCAManagedConnection.cleanup");
  		synchronized (m_handles)
  		{
  			for (Iterator i = m_handles.iterator(); i.hasNext();)
  			{
  				OTMJCAConnection lc = (OTMJCAConnection) i.next();
  				lc.close();
  				lc.setManagedConnection(null);
  			}
  			m_handles.clear();
  		}
  	}
  
  	void closeHandle(OTMJCAConnection handle)
  	{
  		synchronized (m_handles)
  		{
  			m_handles.remove(handle);
  		}
  		ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
  		ce.setConnectionHandle(handle);
  		Collection copy = null;
  		synchronized (m_connectionEventListeners)
  		{
  			copy = new ArrayList(m_connectionEventListeners);
  		}
  		for (Iterator i = copy.iterator(); i.hasNext();)
  		{
  			ConnectionEventListener cel = (ConnectionEventListener) i.next();
  			cel.connectionClosed(ce);
  		}
  	}
  
  	public void associateConnection(Object connection)
  	{
  		Util.log("In OTMJCAManagedConnection.associateConnection");
  		if (!(connection instanceof OTMJCAConnection))
  		{
  			throw new OTMConnectionRuntimeException("Wrong kind of connection handle to associate" + connection);
  		}
  		((OTMJCAConnection) connection).setManagedConnection(this);
  		synchronized (m_handles)
  		{
  			m_handles.add(connection);
  		}
  	}
  
  	public void addConnectionEventListener(ConnectionEventListener cel)
  	{
  		synchronized (m_connectionEventListeners)
  		{
  			m_connectionEventListeners.add(cel);
  		}
  	}
  
  	public void removeConnectionEventListener(ConnectionEventListener cel)
  	{
  		synchronized (m_connectionEventListeners)
  		{
  			m_connectionEventListeners.remove(cel);
  		}
  	}
  
  	public XAResource getXAResource()
  			throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.getXAResource");
  		throw new NotSupportedException("public XAResource getXAResource()");
  	}
  
  	public LocalTransaction getLocalTransaction()
  	{
  		Util.log("In OTMJCAManagedConnection.getLocalTransaction");
  		return this;
  	}
  
  	public ManagedConnectionMetaData getMetaData()
  			throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.getMetaData");
  		return new OTMConnectionMetaData(this);
  	}
  
  	public void setLogWriter(PrintWriter out)
  			throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.setLogWriter");
  		m_logWriter = out;
  	}
  
  	public PrintWriter getLogWriter()
  			throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.getLogWriter");
  		return m_logWriter;
  	}
  
  	boolean isDestroyed()
  	{
  		Util.log("In OTMJCAManagedConnection.isDestroyed");
  		return m_destroyed;
  	}
  
  	protected void broadcastConnectionError(Exception e)
  	{
  		ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
  		Collection copy = null;
  		synchronized (m_connectionEventListeners)
  		{
  			copy = new ArrayList(m_connectionEventListeners);
  		}
  		for (Iterator i = copy.iterator(); i.hasNext();)
  		{
  			ConnectionEventListener cel = (ConnectionEventListener) i.next();
  			cel.connectionErrorOccurred(ce);
  		}
  	}
  
  	ManagedConnectionFactory getManagedConnectionFactory()
  	{
  		Util.log("In OTMJCAManagedConnection.getManagedConnectionFactory");
  		return m_managedConnectionFactory;
  	}
  
  	public void begin() throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.begin");
  		try
  		{
  			Transaction transaction = m_managedConnectionFactory.getKit().getTransaction(m_connection);
  			Util.log("transaction is: " + transaction);
  			transaction.begin();
  		}
  		catch (TransactionException e)
  		{
  			throw new ResourceException(e.getMessage());
  		}
  	}
  
  	public void commit() throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.commit");
  		Transaction transaction = m_managedConnectionFactory.getKit().getTransaction(m_connection);
  		try
  		{
  			Util.log("transaction is: " + transaction);
  			transaction.commit();
  		}
  		catch (TransactionException e)
  		{
  			transaction.rollback();
  			throw new ResourceException(e.getMessage());
  		}
  	}
  
  	public void rollback() throws ResourceException
  	{
  		Util.log("In OTMJCAManagedConnection.rollback");
  		try
  		{
  			Transaction transaction = m_managedConnectionFactory.getKit().getTransaction(m_connection);
  			Util.log("transaction is: " + transaction);
  			transaction.rollback();
  		}
  		catch (TransactionException e)
  		{
  			throw new ResourceException(e.getMessage());
  		}
  	}
  
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMConnectionRequestInfo.java
  
  Index: OTMConnectionRequestInfo.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  
  import javax.resource.spi.ConnectionRequestInfo;
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMConnectionRequestInfo
  		implements ConnectionRequestInfo
  {
  	private PBKey m_pbKey;
  
  	public OTMConnectionRequestInfo(PBKey pbkey)
  	{
  		Util.log("In OTMConnectionRequestInfo");
  		m_pbKey = pbkey;
  	}
  
  	public PBKey getPbKey()
  	{
  		if (m_pbKey == null)
  			return PersistenceBrokerFactory.getDefaultKey();
  		else
  			return m_pbKey;
  	}
  
  	public boolean equals(Object o)
  	{
  		if (this == o) return true;
  		if (!(o instanceof OTMConnectionRequestInfo)) return false;
  
  		final OTMConnectionRequestInfo otmConnectionRequestInfo = (OTMConnectionRequestInfo) o;
  
  		if (m_pbKey != null ? !m_pbKey.equals(otmConnectionRequestInfo.m_pbKey) : otmConnectionRequestInfo.m_pbKey != null) return false;
  
  		return true;
  	}
  
  	public int hashCode()
  	{
  		return (m_pbKey != null ? m_pbKey.hashCode() : 0);
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMConnectionMetaData.java
  
  Index: OTMConnectionMetaData.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.resource.ResourceException;
  import javax.resource.spi.ManagedConnectionMetaData;
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMConnectionMetaData implements ManagedConnectionMetaData
  {
  
  	private OTMJCAManagedConnection mc;
  
  	public OTMConnectionMetaData(OTMJCAManagedConnection mc)
  	{
  		System.out.println("In OTMConnectionMetaData.constructor");
  		this.mc = mc;
  	}
  
  	public String getEISProductName()
  			throws ResourceException
  	{
  		Util.log("In OTMConnectionMetaData.getEISProductName");
  		return "Apache OJB";
  	}
  
  	public String getEISProductVersion()
  			throws ResourceException
  	{
  		Util.log("In OTMConnectionMetaData.getEISProductVersion");
  		return "1.0";
  
  	}
  
  	public int getMaxConnections()
  			throws ResourceException
  	{
  		Util.log("In OTMConnectionMetaData.getMaxConnections");
  		return 50;	//MBAIRD: Remove this hardcoding.
  	}
  
  	public String getUserName()
  			throws ResourceException
  	{
  		return mc.getUserName();
  	}
  
  
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/JCAKit.java
  
  Index: JCAKit.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.otm.Kit;
  import org.apache.ojb.otm.OTMConnection;
  import org.apache.ojb.otm.copy.ObjectCopyStrategy;
  import org.apache.ojb.otm.core.Transaction;
  import org.apache.ojb.otm.lock.map.LockMap;
  import org.apache.ojb.otm.lock.wait.LockWaitStrategy;
  import org.apache.ojb.otm.swizzle.Swizzling;
  
  import javax.naming.Reference;
  import javax.resource.Referenceable;
  import javax.resource.ResourceException;
  import javax.resource.spi.ConnectionManager;
  import javax.resource.spi.ManagedConnectionFactory;
  import java.io.Serializable;
  
  /**
   * represents the Kit used for JCA
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class JCAKit implements Kit, Serializable, Referenceable
  {
  	private OTMJCAManagedConnectionFactory m_managedConnectionFactory;
  	private ConnectionManager m_connectionManager;
  	private Reference m_reference;
  
  	public JCAKit(ManagedConnectionFactory mcf, ConnectionManager cm)
  	{
  		Util.log("In JCAKit");
  		m_managedConnectionFactory = (OTMJCAManagedConnectionFactory) mcf;
  
  		if (cm == null)
  			m_connectionManager = new OTMConnectionManager();
  		else
  			m_connectionManager = cm;
  	}
  
  	private Kit getKit()
  	{
  		try
  		{
  			return m_managedConnectionFactory.getKit();
  		}
  		catch (ResourceException e)
  		{
  			throw new OTMConnectionRuntimeException(e);
  		}
  	}
  
  	/**
  	 * Kit implementation
  	 */
  	public OTMConnection acquireConnection(PBKey pbkey)
  	{
  		Util.log("In JCAKit.getConnection,1");
  		try
  		{
  			OTMConnectionRequestInfo info = new OTMConnectionRequestInfo(pbkey);
  			return (OTMConnection) m_connectionManager.allocateConnection(m_managedConnectionFactory, info);
  		}
  		catch (ResourceException ex)
  		{
  			throw new OTMConnectionRuntimeException(ex);
  		}
  	}
  
  	public Transaction getTransaction(OTMConnection otmConnection)
  	{
  		return getKit().getTransaction(otmConnection);
  	}
  
  	public Swizzling getSwizzlingStrategy()
  	{
  		return getKit().getSwizzlingStrategy();
  	}
  
  	public LockWaitStrategy getLockWaitStrategy()
  	{
  		return getKit().getLockWaitStrategy();
  	}
  
  	public LockMap getLockMap()
  	{
  		return getKit().getLockMap();
  	}
  
  	public ObjectCopyStrategy getCopyStrategy(Identity identity)
  	{
  		return getKit().getCopyStrategy(identity);
  	}
  
  
  	public boolean isImplicitLockingUsed()
  	{
  		return getKit().isImplicitLockingUsed();
  	}
  
  	/**
  	 * Referenceable implementation
  	 */
  
  	public void setReference(Reference reference)
  	{
  		this.m_reference = reference;
  	}
  
  	public Reference getReference()
  	{
  		return m_reference;
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/Util.java
  
  Index: Util.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class Util
  {
  	private static final boolean VERBOSE = false;
  
  	public static final void log(String toLog)
  	{
  		if (VERBOSE)
  			System.out.println(toLog);
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMConnectionRuntimeException.java
  
  Index: OTMConnectionRuntimeException.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMConnectionRuntimeException extends RuntimeException
  {
  	public OTMConnectionRuntimeException()
  	{
  	}
  
  	public OTMConnectionRuntimeException(String message)
  	{
  		super(message);
  	}
  
  	public OTMConnectionRuntimeException(String message, Throwable cause)
  	{
  		super(message, cause);
  	}
  
  	public OTMConnectionRuntimeException(Throwable cause)
  	{
  		super(cause);
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java
  
  Index: OTMJCAConnection.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  import org.apache.ojb.otm.EditingContext;
  import org.apache.ojb.otm.OTMConnection;
  import org.apache.ojb.otm.lock.LockingException;
  
  import java.util.Iterator;
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMJCAConnection implements OTMConnection
  {
  	private OTMJCAManagedConnection m_managedConnection;
  
  	public OTMJCAConnection(OTMJCAManagedConnection mc)
  	{
  		Util.log("In OTMJCAConnection");
  		this.m_managedConnection = mc;
  	}
  
  	public OTMJCAManagedConnection getManagedConnection()
  	{
  		return m_managedConnection;
  	}
  
  	public void setManagedConnection(OTMJCAManagedConnection managedConnection)
  	{
  		m_managedConnection = managedConnection;
  	}
  
  	public void makePersistent(Object o) throws LockingException
  	{
  		m_managedConnection.getConnection().makePersistent(o);
  	}
  
  	public void deletePersistent(Object o) throws LockingException
  	{
  		m_managedConnection.getConnection().deletePersistent(o);
  	}
  
  	public void lockForWrite(Object o) throws LockingException
  	{
  		m_managedConnection.getConnection().lockForWrite(o);
  	}
  
  	public Object getObjectByIdentity(Identity identity) throws LockingException
  	{
  		return m_managedConnection.getConnection().getObjectByIdentity(identity);
  	}
  
  	public Object getObjectByIdentity(Identity identity, int i) throws LockingException
  	{
  		return m_managedConnection.getConnection().getObjectByIdentity(identity, i);
  	}
  
  	public Iterator getIteratorByQuery(Query query)
  	{
  		return m_managedConnection.getConnection().getIteratorByQuery(query);
  	}
  
  	public Iterator getIteratorByQuery(Query query, int i)
  	{
  		return m_managedConnection.getConnection().getIteratorByQuery(query, i);
  	}
  
  	public Identity getIdentity(Object o)
  	{
  		return m_managedConnection.getConnection().getIdentity(o);
  	}
  
  	public ClassDescriptor getDescriptorFor(Class aClass)
  	{
  		return m_managedConnection.getConnection().getDescriptorFor(aClass);
  	}
  
  	public EditingContext getEditingContext()
  	{
  		return m_managedConnection.getConnection().getEditingContext();
  	}
  
  	public void invalidate(Identity identity) throws LockingException
  	{
  		m_managedConnection.getConnection().invalidate(identity);
  	}
  
  	public EnhancedOQLQuery newOQLQuery()
  	{
  		return m_managedConnection.getConnection().newOQLQuery();
  	}
  
  	public int getCount(Query query)
  	{
  		return m_managedConnection.getConnection().getCount(query);
  	}
  
  	public void close()
  	{
  		//m_managedConnection.getConnection().close();
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMConnectionManager.java
  
  Index: OTMConnectionManager.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.resource.ResourceException;
  import javax.resource.spi.ConnectionManager;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ManagedConnectionFactory;
  import java.io.Serializable;
  
  /**
   * @author matthew.baird
   *
   */
  public class OTMConnectionManager
  		implements ConnectionManager, Serializable
  {
  
  	public OTMConnectionManager()
  	{
  		Util.log("In OTMConnectionManager");
  	}
  
  	public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo info)
  			throws ResourceException
  	{
  		Util.log("In OTMConnectionManager.allocateConnection");
  		ManagedConnection mc = mcf.createManagedConnection(null, info);
  		return mc.getConnection(null, info);
  	}
  }
  
  
  
  1.1                  db-ojb/src/jca/org/apache/ojb/otm/connector/OTMConnectionEventListener.java
  
  Index: OTMConnectionEventListener.java
  ===================================================================
  package org.apache.ojb.otm.connector;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.resource.spi.ConnectionEvent;
  import javax.resource.spi.ConnectionEventListener;
  import java.util.Vector;
  
  /**
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class OTMConnectionEventListener implements ConnectionEventListener
  {
  	private Vector m_listeners = null;
  
  	public OTMConnectionEventListener()
  	{
  		m_listeners = new Vector();
  	}
  
  	void sendEvent(ConnectionEvent ce)
  	{
  		Vector list = (Vector) m_listeners.clone();
  		int size = list.size();
  		for (int i = 0; i < size; i++)
  		{
  			ConnectionEventListener l =
  					(ConnectionEventListener) list.elementAt(i);
  			switch (ce.getId())
  			{
  				case ConnectionEvent.CONNECTION_CLOSED:
  					l.connectionClosed(ce);
  					break;
  				case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
  					l.localTransactionStarted(ce);
  					break;
  				case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
  					l.localTransactionCommitted(ce);
  					break;
  				case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
  					l.localTransactionRolledback(ce);
  					break;
  				case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
  					l.connectionErrorOccurred(ce);
  					break;
  				default:
  					throw new IllegalArgumentException("Illegal eventType: " + ce.getId());
  			}
  		}
  	}
  
  	void addConnectorListener(ConnectionEventListener l)
  	{
  		m_listeners.addElement(l);
  	}
  
  	void removeConnectorListener(ConnectionEventListener l)
  	{
  		m_listeners.removeElement(l);
  	}
  
  	public void connectionClosed(ConnectionEvent event)
  	{
  		// do nothing. The event is sent by the ConnectionImpl class
  	}
  
  	public void connectionErrorOccurred(ConnectionEvent event)
  	{
  		sendEvent(event);
  	}
  
  	public void localTransactionCommitted(ConnectionEvent event)
  	{
  		sendEvent(event);
  	}
  
  	public void localTransactionStarted(ConnectionEvent event)
  	{
  		sendEvent(event);
  	}
  
  	public void localTransactionRolledback(ConnectionEvent event)
  	{
  		sendEvent(event);
  	}
  }
  
  
  

Mime
View raw message