KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ersatz > resourceadapter > ConnectionImpl


1 /*
2  * Created on Jul 10, 2003
3  *
4  * ConnectionImpl.java is used to test the J2EE Connector
5  * as implemented by JOnAS.
6  *
7  */

8 package ersatz.resourceadapter;
9
10 import javax.resource.ResourceException;
11 import javax.resource.NotSupportedException;
12 import javax.resource.cci.Connection;
13 import javax.resource.cci.Interaction;
14 import javax.resource.cci.ConnectionMetaData;
15 import javax.resource.cci.LocalTransaction;
16 import javax.resource.cci.ResultSetInfo;
17 import javax.resource.spi.ManagedConnection;
18 import javax.resource.spi.ConnectionEvent;
19 import javax.resource.spi.ConnectionRequestInfo;
20
21 /**
22  * @author Bob Kruse
23  *
24  * Ersatz Resource Adapter
25  *
26  * used to test the J2EE Connector as implemented by JOnAS.
27  *
28  */

29 public class ConnectionImpl
30         implements Connection
31 {
32     public String product="Ersatz EIS"; // see J2eeConnectorTestBeanClient
33
String version="1.1";
34     String UserName="Ersatz"; //
35
private ManagedConnectionImpl mc;
36     public ConnectionRequestInfoImpl crii = null;
37     public LocalTransactionImpl lt;
38     boolean closed = false; // connection is closed
39
String cName = "ConnectionImpl";
40     private boolean autoCommitMode = false;
41
42     public ConnectionImpl(ManagedConnectionImpl mc) { // constructor for Connection
43
Utility.log(cName+".constructor");
44         this.mc=mc;
45     }
46     //
47
// close connection handle
48
//
49
public void close() throws ResourceException
50     {
51         Utility.log(cName
52             +".close with ConnectionEvent.CONNECTION_CLOSED="
53             +ConnectionEvent.CONNECTION_CLOSED);
54         closed = true;
55         
56         if (mc != null) {
57             try {
58                 mc.sendEvent(ConnectionEvent.CONNECTION_CLOSED, null, this);
59                 mc=null;
60                 Utility.log(cName
61                        +".close sendevent 'CONNECTION_CLOSED'");
62             } catch (ResourceException e) {
63                 Utility.log(cName+".close error: unable to close");
64                 throw e;
65             }
66         } else {
67             Utility.log(cName+".close error: mc=null");
68         }
69         return;
70     }
71     //
72
// close physical connection
73
//
74
// The connectionErrorOccurred method indicates that the associated
75
// ManagedConnection instance is now invalid and unusable.
76
// mc.sendEvent method makes the call to connectionErrorOccurred
77
//
78
public void close(int eType) throws ResourceException
79     {
80         Utility.log(cName+".close("+eType+")");
81         closed = true;
82         
83         if (mc != null) {
84             try {
85                 mc.sendEvent(eType, null, this);
86                 mc=null;
87                 Utility.log(cName
88                        +".close(CONNECTION_ERROR_OCCURRED="
89                        +ConnectionEvent.CONNECTION_ERROR_OCCURRED+") to "
90                        +"close physical connection");
91             } catch (ResourceException e) {
92                 Utility.log(cName
93                        +".close error: unable to close physical connection"
94                        +" with 'CONNECTION_ERROR_OCCURRED'");
95                 throw e;
96             }
97         } else {
98             Utility.log(cName+".close error: mc=null already");
99         }
100         return;
101     }
102     public Interaction createInteraction() throws ResourceException
103     {
104       Utility.log(cName+".createInteraction");
105       InteractionImpl gi=new InteractionImpl(this, mc);
106       // TODO Interaction gi = new Interaction(this, this.mc, lw);
107
return gi;
108     }
109     public ConnectionMetaData getMetaData() throws ResourceException
110     {
111         Utility.log(cName+".getMetaData");
112         ConnectionMetaDataImpl eisInfo = new ConnectionMetaDataImpl(this, mc);
113         return eisInfo;
114     }
115     public LocalTransaction getLocalTransaction()
116                 throws ResourceException
117     {
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     public ResultSetInfo getResultSetInfo() throws ResourceException
128     {
129         Utility.log(cName+".getResultSetInfo");
130         NotSupportedException nse = new NotSupportedException("getResultSetInfo is not supported");
131         throw nse;
132     }
133     public void associateConnection(ManagedConnectionImpl mc) throws IllegalStateException
134     {
135         Utility.log(cName+".associateConnection");
136         this.mc=mc;
137     }
138     public ManagedConnectionImpl getMC() throws ResourceException
139     {
140         if (mc==null)
141             Utility.log(cName+".getMC mc="+this.mc);
142         else
143             Utility.log(cName+".getMC mc="+this.mc+" mc.xar="+mc.xar+", mc.xari="+mc.xari);
144         return this.mc;
145     }
146     public void setAutoCommit(boolean a) {
147         autoCommitMode=a;
148     }
149     public boolean getAutoCommit() {
150         return autoCommitMode;
151     }
152 }
153
Popular Tags