001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jca.adapter;
023:
024: import javax.resource.ResourceException;
025: import javax.resource.cci.Connection;
026: import javax.resource.cci.ConnectionMetaData;
027: import javax.resource.cci.Interaction;
028: import javax.resource.cci.LocalTransaction;
029: import javax.resource.cci.ResultSetInfo;
030:
031: /**
032: * TestConnection.java
033: *
034: *
035: * Created: Sun Mar 10 19:35:48 2002
036: *
037: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
038: * @version
039: */
040: public class TestConnection implements Connection {
041: private TestManagedConnection mc;
042:
043: private boolean mcIsNull = true;
044:
045: public TestConnection(TestManagedConnection mc) {
046: this .mc = mc;
047: mcIsNull = false;
048: }
049:
050: public boolean getMCIsNull() {
051: return mcIsNull;
052: }
053:
054: public void setFailInPrepare(final boolean fail, final int xaCode) {
055: mc.setFailInPrepare(fail, xaCode);
056: }
057:
058: public void setFailInCommit(final boolean fail, final int xaCode) {
059: mc.setFailInCommit(fail, xaCode);
060: }
061:
062: public void fireConnectionError() {
063: mc.connectionError(this , new Exception("ConnectionError"));
064: }
065:
066: public boolean isInTx() {
067: return mc.isInTx();
068: }
069:
070: void setMc(TestManagedConnection mc) {
071: if (mc == null) {
072: mcIsNull = true;
073: } // end of if ()
074: else {
075: this .mc = mc;
076: } // end of else
077: }
078:
079: public String getLocalState() {
080: return mc.getLocalState();
081: }
082:
083: public void begin() throws Exception {
084: mc.sendBegin();
085: }
086:
087: public void commit() throws Exception {
088: mc.sendCommit();
089: }
090:
091: public void rollback() throws Exception {
092: mc.sendRollback();
093: }
094:
095: // implementation of javax.resource.cci.Connection interface
096:
097: /**
098: *
099: * @exception javax.resource.ResourceException <description>
100: */
101: public void close() {
102: mc.connectionClosed(this );
103: mcIsNull = true;
104: }
105:
106: public TestManagedConnection getMC() {
107: return mc;
108: }
109:
110: /**
111: *
112: * @return <description>
113: * @exception javax.resource.ResourceException <description>
114: */
115: public Interaction createInteraction() throws ResourceException {
116: // TODO: implement this javax.resource.cci.Connection method
117: return null;
118: }
119:
120: /**
121: *
122: * @return <description>
123: * @exception javax.resource.ResourceException <description>
124: */
125: public LocalTransaction getLocalTransaction()
126: throws ResourceException {
127: // TODO: implement this javax.resource.cci.Connection method
128: return null;
129: }
130:
131: /**
132: *
133: * @return <description>
134: * @exception javax.resource.ResourceException <description>
135: */
136: public ConnectionMetaData getMetaData() throws ResourceException {
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 ResultSetInfo getResultSetInfo() throws ResourceException {
147: // TODO: implement this javax.resource.cci.Connection method
148: return null;
149: }
150:
151: /**
152: * Similate a connection error
153: */
154: public void simulateConnectionError() throws Exception {
155: Exception e = new Exception("Simulated exception");
156: mc.connectionError(this , e);
157: throw e;
158: }
159:
160: }// TestConnection
|