// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package jcademo.raoutbound.multcp_cci;

import javax.resource.ResourceException;
import javax.resource.cci.ConnectionMetaData;
import javax.resource.cci.Interaction;
import javax.resource.cci.LocalTransaction;
import javax.resource.cci.ResultSetInfo;

public class TestConnectionImpl implements TestConnection {
	private MulTCPManagedConnection mc;
	private boolean debug;
	// create
	public TestConnectionImpl(MulTCPManagedConnection mc, boolean debug) {
		this.mc = mc;
		this.debug = debug;
		if(debug) {
			System.out.println("Connection created");
		}
	}
	// business logic
	@Override
	public int add(int a, int b) throws ResourceException {
		return mc.add(a, b);
	}
	// close
	@Override
	public void close() {
		if(debug) {
			System.out.println("Connection closed");
		}
		mc.close();
		mc = null;
	}
	// CCI support
	@Override
	public Interaction createInteraction() {
		return new CCI_Interaction(this);
	}
	// transaction support
	@Override
	public LocalTransaction getLocalTransaction() throws ResourceException {
		throw new ResourceException("Transaction not supported");
	}
	// meta data support
	@Override
	public ConnectionMetaData getMetaData() throws ResourceException {
		throw new ResourceException("Meta data not supported");
	}
	// result set info support
	@Override
	public ResultSetInfo getResultSetInfo() throws ResourceException {
		throw new ResourceException("Result set info not supported");
	}
}
