001: /*
002: * Created on Jul 10, 2003
003: *
004: * ConnectionImpl.java is used to test the J2EE Connector
005: * as implemented by JOnAS. This class implements the Connection Interface
006: * and ConnectionMetaData Interface (cci) classes.
007: *
008: */
009: package fictional.resourceadapter;
010:
011: import javax.resource.ResourceException;
012: import javax.resource.NotSupportedException;
013: import javax.resource.cci.*;
014: import javax.resource.spi.ManagedConnection;
015: import javax.resource.spi.ConnectionEvent;
016: import org.objectweb.jonas.common.Log;
017: import org.objectweb.util.monolog.api.Logger;
018: import org.objectweb.util.monolog.api.BasicLevel;
019:
020: /**
021: * @author Bob Kruse
022: *
023: * Jtest Resource Adapter
024: *
025: * used to test the J2EE Connector as implemented by JOnAS.
026: *
027: */
028: public class ConnectionImpl implements Connection, ConnectionMetaData,
029: java.io.Serializable {
030: public String product = "Fictional EIS"; // see J2eeConnectorTestBeanClient
031: String version = "1.1";
032: String UserName = "Fictional_User_Name"; //
033: private ManagedConnection mc;
034: public LocalTransactionImpl lt;
035: boolean closed = false; // connection is closed
036: private Logger logger = null;
037: String cName = "";
038: private boolean autoCommitMode = false;
039:
040: //
041: // *****************
042: // Connection methods
043: // *****************
044: //
045: public ConnectionImpl(Object mc) { // constructor for Connection
046: if (logger == null) {
047: logger = Log.getLogger("fictional.resourceadapter");
048: }
049: logger.log(BasicLevel.DEBUG, impl(this ) + ".constructor");
050: this .mc = (ManagedConnection) mc;
051: }
052:
053: private String impl(Object obj) {
054: if (obj instanceof Connection) {
055: return "ConnectionImpl";
056: } else if (obj instanceof ConnectionImpl) {
057: return "Connection";
058: } else if (obj instanceof ConnectionMetaData) {
059: return "ConnectionMetaData";
060: } else
061: return "ConnectionImpl. Is this an error";
062: }
063:
064: //
065: // close connection handle
066: //
067: public void close() throws ResourceException {
068: logger.log(BasicLevel.DEBUG, impl(this )
069: + ".close with ConnectionEvent.CONNECTION_CLOSED="
070: + ConnectionEvent.CONNECTION_CLOSED);
071: closed = true;
072:
073: if (mc != null) {
074: try {
075: JtestResourceAdapter omc = (JtestResourceAdapter) mc;
076: omc.sendEvent(ConnectionEvent.CONNECTION_CLOSED, null,
077: this );
078: mc = null;
079: logger.log(BasicLevel.DEBUG, impl(this )
080: + ".close sendevent 'CONNECTION_CLOSED'");
081: } catch (ResourceException e) {
082: logger.log(BasicLevel.DEBUG, impl(this )
083: + ".close error: unable to close");
084: throw e;
085: }
086: } else {
087: logger.log(BasicLevel.DEBUG, impl(this )
088: + ".close error: mc=null");
089: }
090: return;
091: }
092:
093: //
094: // close physical connection
095: //
096: // The connectionErrorOccurred method indicates that the associated
097: // ManagedConnection instance is now invalid and unusable.
098: // mc.sendEvent method makes the call to connectionErrorOccurred
099: //
100: public void close(int eType) throws ResourceException {
101: logger.log(BasicLevel.DEBUG, impl(this ) + ".close(" + eType
102: + ")");
103: closed = true;
104:
105: if (mc != null) {
106: try {
107: JtestResourceAdapter omc = (JtestResourceAdapter) mc;
108: omc.sendEvent(eType, null, this );
109: mc = null;
110: logger.log(BasicLevel.DEBUG, impl(this )
111: + ".close(CONNECTION_ERROR_OCCURRED="
112: + ConnectionEvent.CONNECTION_ERROR_OCCURRED
113: + ") to " + "close physical connection");
114: } catch (ResourceException e) {
115: logger
116: .log(
117: BasicLevel.DEBUG,
118: impl(this )
119: + ".close error: unable to close physical connection"
120: + " with 'CONNECTION_ERROR_OCCURRED'");
121: throw e;
122: }
123: } else {
124: logger.log(BasicLevel.DEBUG, impl(this )
125: + ".close error: mc=null already");
126: }
127: return;
128: }
129:
130: public Interaction createInteraction() throws ResourceException {
131: logger.log(BasicLevel.DEBUG, impl(this ) + ".createInteraction");
132: Interaction gi = new JtestInteraction(this , mc);
133: // TODO Interaction gi = new Interaction(this, this.mc, lw);
134: return gi;
135: }
136:
137: public ConnectionMetaData getMetaData() throws ResourceException {
138: logger.log(BasicLevel.DEBUG, impl(this ) + ".getMetaData");
139: ConnectionMetaData eisInfo = (ConnectionMetaData) new ConnectionImpl(
140: mc);
141: return eisInfo;
142: }
143:
144: public LocalTransaction getLocalTransaction()
145: throws ResourceException {
146: try {
147: JtestResourceAdapter jmc = (JtestResourceAdapter) mc;
148: lt = (LocalTransactionImpl) jmc.getLocalTransaction(true);
149: logger.log(BasicLevel.DEBUG, impl(this )
150: + ".getLocalTransaction lt=" + lt);
151: } catch (Exception e) {
152: logger.log(BasicLevel.DEBUG, impl(this )
153: + ".getLocalTransaction error: " + e.getMessage()
154: + " <<<<<<<<<<<<");
155: }
156: return (lt);
157: }
158:
159: public ResultSetInfo getResultSetInfo() throws ResourceException {
160: logger.log(BasicLevel.DEBUG, impl(this ) + ".getResultSetInfo");
161: NotSupportedException nse = new NotSupportedException(
162: "getResultSetInfo is not supported");
163: throw nse;
164: }
165:
166: public void associateConnection(ManagedConnection mc)
167: throws IllegalStateException {
168: logger.log(BasicLevel.DEBUG, impl(this )
169: + ".associateConnection");
170: this .mc = mc;
171: }
172:
173: public ManagedConnection getMC() throws ResourceException {
174: logger.log(BasicLevel.DEBUG, impl(this ) + ".getMC mc="
175: + this .mc);
176: return this .mc;
177: }
178:
179: public void setAutoCommit(boolean a) {
180: autoCommitMode = a;
181: }
182:
183: public boolean getAutoCommit() {
184: return autoCommitMode;
185: }
186:
187: //
188: // **********************
189: // ConnectionMetaData methods
190: // **********************
191: //
192: // The method getUserName returns the user name for an active connection as
193: // known to the underlying EIS instance. The name corresponds the resource
194: // principal under whose security context a connection to the EIS
195: // instance has been established. (page 109 CA 1.0)
196: //
197: public String getEISProductName() throws ResourceException {
198: return (product);
199: }
200:
201: public String getEISProductVersion() throws ResourceException {
202: return (version);
203: }
204:
205: public String getUserName() throws ResourceException {
206: return (UserName);
207: }
208: }
|