db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r431668 - in /db/ojb/trunk/proposals/otm/jca: ./ org/ org/apache/ org/apache/ojb/ org/apache/ojb/otm/ org/apache/ojb/otm/connector/
Date Tue, 15 Aug 2006 18:46:15 GMT
Author: arminw
Date: Tue Aug 15 11:46:14 2006
New Revision: 431668

URL: http://svn.apache.org/viewvc?rev=431668&view=rev
Log:
move OTM stuff to archive

Added:
    db/ojb/trunk/proposals/otm/jca/
    db/ojb/trunk/proposals/otm/jca/org/
    db/ojb/trunk/proposals/otm/jca/org/apache/
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/JCAKit.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionEventListener.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionManager.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionMetaData.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRequestInfo.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRuntimeException.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnectionFactory.java
    db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/Util.java

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/JCAKit.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/JCAKit.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/JCAKit.java (added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/JCAKit.java Tue Aug 15 11:46:14
2006
@@ -0,0 +1,151 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.PBKey;
+import org.apache.ojb.broker.PersistenceConfiguration;
+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 OTMConnection acquireConnection(PersistenceConfiguration persistenceConf)
+    {
+        Util.log("In JCAKit.getConnection,1");
+		try
+		{
+			OTMConnectionRequestInfo info = new OTMConnectionRequestInfo(persistenceConf.getKey());
+			return (OTMConnection) m_connectionManager.allocateConnection(m_managedConnectionFactory,
info);
+		}
+		catch (ResourceException ex)
+		{
+			throw new OTMConnectionRuntimeException(ex);
+		}
+    }
+
+	public Transaction getTransaction(OTMConnection otmConnection)
+	{
+		if (otmConnection instanceof OTMJCAConnection)
+		{
+			return getKit().getTransaction(((OTMJCAConnection)otmConnection).getConnection());
+		}
+		else
+			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;
+	}
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionEventListener.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionEventListener.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionEventListener.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionEventListener.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,101 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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);
+	}
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionManager.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionManager.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionManager.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionManager.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,45 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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);
+	}
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionMetaData.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionMetaData.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionMetaData.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionMetaData.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,66 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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();
+	}
+
+
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRequestInfo.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRequestInfo.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRequestInfo.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRequestInfo.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,63 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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);
+	}
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRuntimeException.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRuntimeException.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRuntimeException.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMConnectionRuntimeException.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,45 @@
+package org.apache.ojb.otm.connector;
+
+import org.apache.ojb.broker.OJBRuntimeException;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
+ */
+
+public class OTMConnectionRuntimeException extends OJBRuntimeException
+{
+	public OTMConnectionRuntimeException()
+	{
+	}
+
+	public OTMConnectionRuntimeException(String message)
+	{
+		super(message);
+	}
+
+	public OTMConnectionRuntimeException(String message, Throwable cause)
+	{
+		super(message, cause);
+	}
+
+	public OTMConnectionRuntimeException(Throwable cause)
+	{
+		super(cause);
+	}
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java (added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java Tue
Aug 15 11:46:14 2006
@@ -0,0 +1,228 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.cache.ObjectCache;
+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.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.odmg.OQLQuery;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ *
+ * Wraps the OTMConnection and associates/disassociates the connection
+ * handle.
+ *
+ * kudos to David Jencks for inspiration, and pointers.
+ *
+ * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
+ * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
+ */
+
+public class OTMJCAConnection implements OTMConnection
+{
+	private OTMJCAManagedConnection m_managedConnection;
+	private boolean m_closed = false;
+
+	public OTMJCAConnection(OTMJCAManagedConnection mc)
+	{
+		Util.log("In OTMJCAConnection");
+		this.m_managedConnection = mc;
+	}
+
+	void setManagedConnection(OTMJCAManagedConnection managedConnection)
+	{
+		m_managedConnection = managedConnection;
+	}
+
+	public void makePersistent(Object o) throws LockingException
+	{
+		isValidUnderlyingConnection();
+		m_managedConnection.getConnection().makePersistent(o);
+	}
+
+	public void deletePersistent(Object o) throws LockingException
+	{
+		isValidUnderlyingConnection();
+		m_managedConnection.getConnection().deletePersistent(o);
+	}
+
+	public void lockForWrite(Object o) throws LockingException
+	{
+		isValidUnderlyingConnection();
+		m_managedConnection.getConnection().lockForWrite(o);
+	}
+
+	public Object getObjectByIdentity(Identity identity) throws LockingException
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getObjectByIdentity(identity);
+	}
+
+	public Object getObjectByIdentity(Identity identity, int i) throws LockingException
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getObjectByIdentity(identity, i);
+	}
+
+	public Iterator getIteratorByQuery(Query query)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getIteratorByQuery(query);
+	}
+
+	public Iterator getIteratorByQuery(Query query, int i)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getIteratorByQuery(query, i);
+	}
+
+	public Iterator getIteratorByOQLQuery(OQLQuery query)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getIteratorByOQLQuery(query);
+	}
+
+	public Iterator getIteratorByOQLQuery(OQLQuery query, int lock)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getIteratorByOQLQuery(query, lock);
+	}
+
+    public Collection getCollectionByQuery(Query query, int lock)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getCollectionByQuery(query, lock);
+	}
+
+    public Collection getCollectionByQuery(Query query)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getCollectionByQuery(query);
+	}
+
+    public Identity getIdentity(Object o)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getIdentity(o);
+	}
+
+	public ClassDescriptor getDescriptorFor(Class aClass)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getDescriptorFor(aClass);
+	}
+
+	public EditingContext getEditingContext()
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getEditingContext();
+	}
+
+	public void invalidate(Identity identity) throws LockingException
+	{
+		isValidUnderlyingConnection();
+		m_managedConnection.getConnection().invalidate(identity);
+	}
+
+	public void invalidateAll() throws LockingException
+	{
+		isValidUnderlyingConnection();
+		m_managedConnection.getConnection().invalidateAll();
+	}
+
+	public EnhancedOQLQuery newOQLQuery()
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().newOQLQuery();
+	}
+
+	public EnhancedOQLQuery newOQLQuery(int lock)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().newOQLQuery(lock);
+	}
+
+	public int getCount(Query query)
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().getCount(query);
+	}
+
+    public void refresh(Object object)
+	{
+		isValidUnderlyingConnection();
+		m_managedConnection.getConnection().refresh(object);
+	}
+
+    public void close()
+	{
+		m_closed = true;
+		if (m_managedConnection != null)
+		{
+			m_managedConnection.closeHandle(this);
+		}
+		m_managedConnection = null;
+	}
+
+	public boolean isClosed()
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().isClosed();
+	}
+
+	public ObjectCache serviceObjectCache()
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection().serviceObjectCache();
+	}
+
+	private void isValidUnderlyingConnection() throws OTMConnectionRuntimeException
+	{
+		if (m_closed)
+		{
+			throw new OTMConnectionRuntimeException("OTMConnection handle is closed and unusable.");
+		}
+		if (m_managedConnection == null)
+		{
+			throw new OTMConnectionRuntimeException("Connection handle is not currently associated
with a ManagedConnection");
+		}
+	}
+
+	OTMConnection getConnection()
+	{
+		isValidUnderlyingConnection();
+		return m_managedConnection.getConnection();
+	}
+
+    public Transaction getTransaction()
+    {
+        return this.m_managedConnection.getTransaction();
+    }
+
+    public void setTransaction(Transaction t)
+    {
+        this.m_managedConnection.setTransaction(t);
+    }
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,383 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.ConnectionEvent;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.LocalTransaction;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ManagedConnectionMetaData;
+import javax.security.auth.Subject;
+import javax.transaction.xa.XAResource;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ *
+ * @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();
+    private boolean m_managed = false;
+    /**
+     * the wrapped connection
+     */
+    private OTMConnection m_connection;
+    private Transaction m_tx;
+
+    OTMJCAManagedConnection(ManagedConnectionFactory mcf, OTMConnection conn, PBKey pbKey)
+    {
+        Util.log("In OTMJCAManagedConnection");
+        m_managedConnectionFactory = (OTMJCAManagedConnectionFactory) mcf;
+        m_pbKey = pbKey;
+        m_connection = conn;
+    }
+
+    /**
+     * get the underlying wrapped connection
+     * @return OTMConnection raw connection to the OTM.
+     */
+    OTMConnection getConnection()
+    {
+        if (m_connection == null)
+        {
+            OTMConnectionRuntimeException ex = new OTMConnectionRuntimeException("Connection
is null.");
+            sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+        }
+        return m_connection;
+    }
+
+    public Transaction getTransaction()
+    {
+        return this.m_tx;
+    }
+
+    public void setTransaction(Transaction tx)
+    {
+        if (this.m_tx != null) throw new IllegalStateException("Connection already has Transaction");
+        this.m_tx = tx;
+    }
+
+    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);
+        synchronized (m_handles)
+        {
+            m_handles.add(myCon);
+        }
+        return myCon;
+    }
+
+    public void destroy()
+    {
+        Util.log("In OTMJCAManagedConnection.destroy");
+        cleanup();
+        m_connection.close();
+        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.setManagedConnection(null);
+            }
+            m_handles.clear();
+        }
+    }
+
+    void closeHandle(OTMJCAConnection handle)
+    {
+        synchronized (m_handles)
+        {
+            m_handles.remove(handle);
+        }
+        sendEvents(ConnectionEvent.CONNECTION_CLOSED, null, handle);
+    }
+
+    public void associateConnection(Object connection)
+    {
+        Util.log("In OTMJCAManagedConnection.associateConnection");
+        if (connection == null)
+        {
+            throw new OTMConnectionRuntimeException("Cannot associate a null connection");
+        }
+        if (!(connection instanceof OTMJCAConnection))
+        {
+            throw new OTMConnectionRuntimeException("Cannot associate a connection of type:
" + connection.getClass().getName() + " to a handle that manages: " + OTMJCAConnection.class.getName());
+        }
+        ((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() not supported
in this release.");
+    }
+
+    /**
+     * the OTMConnection is the transaction
+     * @return
+     */
+    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;
+    }
+
+    ManagedConnectionFactory getManagedConnectionFactory()
+    {
+        Util.log("In OTMJCAManagedConnection.getManagedConnectionFactory");
+        return m_managedConnectionFactory;
+    }
+
+    public void begin() throws ResourceException
+    {
+        Util.log("In OTMJCAManagedConnection.begin");
+        if (!isManaged())
+        {
+            try
+            {
+                m_tx = m_managedConnectionFactory.getKit().getTransaction(m_connection);
+                m_tx.begin();
+                setManaged(true);
+            }
+            catch (TransactionException e)
+            {
+                ResourceException ex = new ResourceException(e.getMessage());
+                sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+                throw ex;
+            }
+        }
+        else
+        {
+            ResourceException ex = new ResourceException("You probably called begin again
without calling Commit or Rollback, OTM does not support nested Local Transactions.");
+            sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+            throw ex;
+        }
+    }
+
+    public void commit() throws ResourceException
+    {
+        Util.log("In OTMJCAManagedConnection.commit");
+        if (isManaged())
+        {
+            try
+            {
+                setManaged(false);
+                m_tx.commit();
+            }
+            catch (TransactionException e)
+            {
+                m_tx.rollback();
+                ResourceException ex = new ResourceException(e.getMessage());
+                sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+                throw ex;
+            }
+        }
+        else
+        {
+            ResourceException ex = new ResourceException("Cannot call commit when you are
not in a Local Transaction.");
+            sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+            throw ex;
+        }
+    }
+
+    public void rollback() throws ResourceException
+    {
+        Util.log("In OTMJCAManagedConnection.rollback");
+        if (isManaged())
+        {
+            try
+            {
+                m_tx.rollback();
+                setManaged(false);
+            }
+            catch (TransactionException e)
+            {
+                ResourceException ex = new ResourceException(e.getMessage());
+                sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+                throw ex;
+            }
+        }
+        else
+        {
+            ResourceException ex = new ResourceException("Cannot call rollback when you are
not in a Local Transaction.");
+            sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null);
+            throw ex;
+        }
+    }
+
+    private boolean isManaged()
+    {
+        return m_managed;
+    }
+
+    private void setManaged(boolean flag)
+    {
+        m_managed = flag;
+    }
+
+    /**
+     * Section 6.5.6 of the JCA 1.5 spec instructs ManagedConnection instances to notify
connection listeners with
+     * close/error and local transaction-related events to its registered set of listeners.
+     *
+     * The events for begin/commit/rollback are only sent if the application server did NOT
+     * initiate the actions.
+     *
+     * This method dispatchs all events to the listeners based on the eventType
+     * @param eventType as enumerated in the ConnectionEvents interface
+     * @param ex an optional exception if we are sending an error message
+     * @param connectionHandle an optional connectionHandle if we have access to it.
+     */
+    void sendEvents(int eventType, Exception ex, Object connectionHandle)
+    {
+        ConnectionEvent ce = null;
+        if (ex == null)
+        {
+            ce = new ConnectionEvent(this, eventType);
+        }
+        else
+        {
+            ce = new ConnectionEvent(this, eventType, ex);
+        }
+        ce.setConnectionHandle(connectionHandle);
+        Collection copy = null;
+        synchronized (m_connectionEventListeners)
+        {
+            copy = new ArrayList(m_connectionEventListeners);
+        }
+        switch (ce.getId())
+        {
+            case ConnectionEvent.CONNECTION_CLOSED:
+                for (Iterator i = copy.iterator(); i.hasNext();)
+                {
+                    ConnectionEventListener cel = (ConnectionEventListener) i.next();
+                    cel.connectionClosed(ce);
+                }
+                break;
+            case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
+                for (Iterator i = copy.iterator(); i.hasNext();)
+                {
+                    ConnectionEventListener cel = (ConnectionEventListener) i.next();
+                    cel.localTransactionStarted(ce);
+                }
+                break;
+            case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
+                for (Iterator i = copy.iterator(); i.hasNext();)
+                {
+                    ConnectionEventListener cel = (ConnectionEventListener) i.next();
+                    cel.localTransactionCommitted(ce);
+                }
+                break;
+            case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
+                for (Iterator i = copy.iterator(); i.hasNext();)
+                {
+                    ConnectionEventListener cel = (ConnectionEventListener) i.next();
+                    cel.localTransactionRolledback(ce);
+                }
+                break;
+            case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
+                for (Iterator i = copy.iterator(); i.hasNext();)
+                {
+                    ConnectionEventListener cel = (ConnectionEventListener) i.next();
+                    cel.connectionErrorOccurred(ce);
+                }
+                break;
+            default:
+                throw new IllegalArgumentException("Illegal eventType: " + ce.getId());
+        }
+    }
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnectionFactory.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnectionFactory.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnectionFactory.java
(added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnectionFactory.java
Tue Aug 15 11:46:14 2006
@@ -0,0 +1,153 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.PBKey;
+import org.apache.ojb.broker.PersistenceConfiguration;
+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();
+            if(true)
+            {
+                // TODO: Fix this! aquireConnection needs a PC instance
+                throw new UnsupportedOperationException("TODO: Fix this! aquireConnection
needs a PC instance");
+            }
+			OTMConnection connection = kit.acquireConnection(null);
+			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;
+	}
+}

Added: db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/Util.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/Util.java?rev=431668&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/Util.java (added)
+++ db/ojb/trunk/proposals/otm/jca/org/apache/ojb/otm/connector/Util.java Tue Aug 15 11:46:14
2006
@@ -0,0 +1,32 @@
+package org.apache.ojb.otm.connector;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ * @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);
+	}
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message