001: /*
002: * Created on Jul 10, 2003
003: *
004: * ConnectionImpl.java is used to test the J2EE Connector
005: * as implemented by JOnAS.
006: *
007: */
008: package ersatz.resourceadapter;
009:
010: import javax.resource.ResourceException;
011: import javax.resource.NotSupportedException;
012: import javax.resource.cci.Connection;
013: import javax.resource.cci.Interaction;
014: import javax.resource.cci.ConnectionMetaData;
015: import javax.resource.cci.LocalTransaction;
016: import javax.resource.cci.ResultSetInfo;
017: import javax.resource.spi.ManagedConnection;
018: import javax.resource.spi.ConnectionEvent;
019: import javax.resource.spi.ConnectionRequestInfo;
020:
021: /**
022: * @author Bob Kruse
023: *
024: * Ersatz Resource Adapter
025: *
026: * used to test the J2EE Connector as implemented by JOnAS.
027: *
028: */
029: public class ConnectionImpl implements Connection {
030: public String product = "Ersatz EIS"; // see J2eeConnectorTestBeanClient
031: String version = "1.1";
032: String UserName = "Ersatz"; //
033: private ManagedConnectionImpl mc;
034: public ConnectionRequestInfoImpl crii = null;
035: public LocalTransactionImpl lt;
036: boolean closed = false; // connection is closed
037: String cName = "ConnectionImpl";
038: private boolean autoCommitMode = false;
039:
040: public ConnectionImpl(ManagedConnectionImpl mc) { // constructor for Connection
041: Utility.log(cName + ".constructor");
042: this .mc = mc;
043: }
044:
045: //
046: // close connection handle
047: //
048: public void close() throws ResourceException {
049: Utility.log(cName
050: + ".close with ConnectionEvent.CONNECTION_CLOSED="
051: + ConnectionEvent.CONNECTION_CLOSED);
052: closed = true;
053:
054: if (mc != null) {
055: try {
056: mc.sendEvent(ConnectionEvent.CONNECTION_CLOSED, null,
057: this );
058: mc = null;
059: Utility.log(cName
060: + ".close sendevent 'CONNECTION_CLOSED'");
061: } catch (ResourceException e) {
062: Utility.log(cName + ".close error: unable to close");
063: throw e;
064: }
065: } else {
066: Utility.log(cName + ".close error: mc=null");
067: }
068: return;
069: }
070:
071: //
072: // close physical connection
073: //
074: // The connectionErrorOccurred method indicates that the associated
075: // ManagedConnection instance is now invalid and unusable.
076: // mc.sendEvent method makes the call to connectionErrorOccurred
077: //
078: public void close(int eType) throws ResourceException {
079: Utility.log(cName + ".close(" + eType + ")");
080: closed = true;
081:
082: if (mc != null) {
083: try {
084: mc.sendEvent(eType, null, this );
085: mc = null;
086: Utility.log(cName + ".close(CONNECTION_ERROR_OCCURRED="
087: + ConnectionEvent.CONNECTION_ERROR_OCCURRED
088: + ") to " + "close physical connection");
089: } catch (ResourceException e) {
090: Utility
091: .log(cName
092: + ".close error: unable to close physical connection"
093: + " with 'CONNECTION_ERROR_OCCURRED'");
094: throw e;
095: }
096: } else {
097: Utility.log(cName + ".close error: mc=null already");
098: }
099: return;
100: }
101:
102: public Interaction createInteraction() throws ResourceException {
103: Utility.log(cName + ".createInteraction");
104: InteractionImpl gi = new InteractionImpl(this , mc);
105: // TODO Interaction gi = new Interaction(this, this.mc, lw);
106: return gi;
107: }
108:
109: public ConnectionMetaData getMetaData() throws ResourceException {
110: Utility.log(cName + ".getMetaData");
111: ConnectionMetaDataImpl eisInfo = new ConnectionMetaDataImpl(
112: this , mc);
113: return eisInfo;
114: }
115:
116: public LocalTransaction getLocalTransaction()
117: throws ResourceException {
118: try {
119: lt = (LocalTransactionImpl) mc.getLocalTransaction(true);
120: Utility.log(cName + ".getLocalTransaction lt=" + lt);
121: } catch (Exception e) {
122: Utility.log(cName + ".getLocalTransaction error: "
123: + e.getMessage() + " <<<<<<<<<<<<");
124: }
125: return (lt);
126: }
127:
128: public ResultSetInfo getResultSetInfo() throws ResourceException {
129: Utility.log(cName + ".getResultSetInfo");
130: NotSupportedException nse = new NotSupportedException(
131: "getResultSetInfo is not supported");
132: throw nse;
133: }
134:
135: public void associateConnection(ManagedConnectionImpl mc)
136: throws IllegalStateException {
137: Utility.log(cName + ".associateConnection");
138: this .mc = mc;
139: }
140:
141: public ManagedConnectionImpl getMC() throws ResourceException {
142: if (mc == null)
143: Utility.log(cName + ".getMC mc=" + this .mc);
144: else
145: Utility.log(cName + ".getMC mc=" + this .mc + " mc.xar="
146: + mc.xar + ", mc.xari=" + mc.xari);
147: return this .mc;
148: }
149:
150: public void setAutoCommit(boolean a) {
151: autoCommitMode = a;
152: }
153:
154: public boolean getAutoCommit() {
155: return autoCommitMode;
156: }
157: }
|