001: package org.apache.ojb.otm.connector;
002:
003: /* Copyright 2003-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.ojb.broker.Identity;
019: import org.apache.ojb.broker.PBKey;
020: import org.apache.ojb.otm.Kit;
021: import org.apache.ojb.otm.OTMConnection;
022: import org.apache.ojb.otm.copy.ObjectCopyStrategy;
023: import org.apache.ojb.otm.core.Transaction;
024: import org.apache.ojb.otm.lock.map.LockMap;
025: import org.apache.ojb.otm.lock.wait.LockWaitStrategy;
026: import org.apache.ojb.otm.swizzle.Swizzling;
027:
028: import javax.naming.Reference;
029: import javax.resource.Referenceable;
030: import javax.resource.ResourceException;
031: import javax.resource.spi.ConnectionManager;
032: import javax.resource.spi.ManagedConnectionFactory;
033: import java.io.Serializable;
034:
035: /**
036: * represents the Kit used for JCA
037: *
038: * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
039: */
040:
041: public class JCAKit implements Kit, Serializable, Referenceable {
042: private OTMJCAManagedConnectionFactory m_managedConnectionFactory;
043: private ConnectionManager m_connectionManager;
044: private Reference m_reference;
045:
046: public JCAKit(ManagedConnectionFactory mcf, ConnectionManager cm) {
047: Util.log("In JCAKit");
048: m_managedConnectionFactory = (OTMJCAManagedConnectionFactory) mcf;
049:
050: if (cm == null)
051: m_connectionManager = new OTMConnectionManager();
052: else
053: m_connectionManager = cm;
054: }
055:
056: private Kit getKit() {
057: try {
058: return m_managedConnectionFactory.getKit();
059: } catch (ResourceException e) {
060: throw new OTMConnectionRuntimeException(e);
061: }
062: }
063:
064: /**
065: * Kit implementation
066: */
067: public OTMConnection acquireConnection(PBKey pbkey) {
068: Util.log("In JCAKit.getConnection,1");
069: try {
070: OTMConnectionRequestInfo info = new OTMConnectionRequestInfo(
071: pbkey);
072: return (OTMConnection) m_connectionManager
073: .allocateConnection(m_managedConnectionFactory,
074: info);
075: } catch (ResourceException ex) {
076: throw new OTMConnectionRuntimeException(ex);
077: }
078: }
079:
080: public Transaction getTransaction(OTMConnection otmConnection) {
081: if (otmConnection instanceof OTMJCAConnection) {
082: return getKit().getTransaction(
083: ((OTMJCAConnection) otmConnection).getConnection());
084: } else
085: return getKit().getTransaction(otmConnection);
086: }
087:
088: public Swizzling getSwizzlingStrategy() {
089: return getKit().getSwizzlingStrategy();
090: }
091:
092: public LockWaitStrategy getLockWaitStrategy() {
093: return getKit().getLockWaitStrategy();
094: }
095:
096: public LockMap getLockMap() {
097: return getKit().getLockMap();
098: }
099:
100: public ObjectCopyStrategy getCopyStrategy(Identity identity) {
101: return getKit().getCopyStrategy(identity);
102: }
103:
104: public boolean isImplicitLockingUsed() {
105: return getKit().isImplicitLockingUsed();
106: }
107:
108: /**
109: * Referenceable implementation
110: */
111:
112: public void setReference(Reference reference) {
113: this .m_reference = reference;
114: }
115:
116: public Reference getReference() {
117: return m_reference;
118: }
119: }
|