KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > adapter > TestConnection


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jca.adapter;
23
24 import javax.resource.ResourceException JavaDoc;
25 import javax.resource.cci.Connection JavaDoc;
26 import javax.resource.cci.ConnectionMetaData JavaDoc;
27 import javax.resource.cci.Interaction JavaDoc;
28 import javax.resource.cci.LocalTransaction JavaDoc;
29 import javax.resource.cci.ResultSetInfo JavaDoc;
30
31 /**
32  * TestConnection.java
33  *
34  *
35  * Created: Sun Mar 10 19:35:48 2002
36  *
37  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
38  * @version
39  */

40 public class TestConnection implements Connection JavaDoc
41 {
42    private TestManagedConnection mc;
43
44    private boolean mcIsNull = true;
45
46    public TestConnection(TestManagedConnection mc)
47    {
48       this.mc = mc;
49       mcIsNull = false;
50    }
51
52    public boolean getMCIsNull()
53    {
54       return mcIsNull;
55    }
56
57    public void setFailInPrepare(final boolean fail, final int xaCode)
58    {
59       mc.setFailInPrepare(fail, xaCode);
60    }
61    
62    public void setFailInStart(final boolean fail, final int xaCode)
63    {
64       
65    }
66    public void setFailInCommit(final boolean fail, final int xaCode)
67    {
68       mc.setFailInCommit(fail, xaCode);
69    }
70
71    public void fireConnectionError()
72    {
73       mc.connectionError(this, new Exception JavaDoc("ConnectionError"));
74    }
75
76    public boolean isInTx()
77    {
78       return mc.isInTx();
79    }
80
81    void setMc(TestManagedConnection mc)
82    {
83       if (mc == null)
84       {
85          mcIsNull = true;
86       } // end of if ()
87
else
88       {
89          this.mc = mc;
90       } // end of else
91
}
92
93    public String JavaDoc getLocalState()
94    {
95       return mc.getLocalState();
96    }
97    
98    public void begin() throws Exception JavaDoc
99    {
100       mc.sendBegin();
101    }
102    
103    public void commit() throws Exception JavaDoc
104    {
105       mc.sendCommit();
106    }
107    
108    public void rollback() throws Exception JavaDoc
109    {
110       mc.sendRollback();
111    }
112    
113    // implementation of javax.resource.cci.Connection interface
114

115    /**
116     *
117     * @exception javax.resource.ResourceException <description>
118     */

119    public void close()
120    {
121       mc.connectionClosed(this);
122       mcIsNull = true;
123    }
124
125    public TestManagedConnection getMC()
126    {
127       return mc;
128    }
129
130    /**
131     *
132     * @return <description>
133     * @exception javax.resource.ResourceException <description>
134     */

135    public Interaction JavaDoc createInteraction() throws ResourceException JavaDoc
136    {
137       // TODO: implement this javax.resource.cci.Connection method
138
return null;
139    }
140
141    /**
142     *
143     * @return <description>
144     * @exception javax.resource.ResourceException <description>
145     */

146    public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc
147    {
148       // TODO: implement this javax.resource.cci.Connection method
149
return null;
150    }
151
152    /**
153     *
154     * @return <description>
155     * @exception javax.resource.ResourceException <description>
156     */

157    public ConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc
158    {
159       // TODO: implement this javax.resource.cci.Connection method
160
return null;
161    }
162
163    /**
164     *
165     * @return <description>
166     * @exception javax.resource.ResourceException <description>
167     */

168    public ResultSetInfo JavaDoc getResultSetInfo() throws ResourceException JavaDoc
169    {
170       // TODO: implement this javax.resource.cci.Connection method
171
return null;
172    }
173
174    /**
175     * Similate a connection error
176     */

177    public void simulateConnectionError() throws Exception JavaDoc
178    {
179       Exception JavaDoc e = new Exception JavaDoc("Simulated exception");
180       mc.connectionError(this, e);
181       throw e;
182    }
183
184 }// TestConnection
185

186
Popular Tags