com.mockrunner.mock.connector.cci.MockConnection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jca Show documentation
Show all versions of mockrunner-jca Show documentation
Mock classes for Java Connector Architecture
package com.mockrunner.mock.connector.cci;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.resource.ResourceException;
import javax.resource.cci.Connection;
import javax.resource.cci.ConnectionMetaData;
import javax.resource.cci.Interaction;
import javax.resource.cci.LocalTransaction;
import javax.resource.cci.ResultSetInfo;
import com.mockrunner.connector.InteractionHandler;
/**
* Mock implementation of Connection
.
*/
public class MockConnection implements Connection
{
private boolean closed;
private InteractionHandler interactionHandler;
private ConnectionMetaData metaData;
private LocalTransaction localTransaction;
private ResultSetInfo resultSetInfo;
private List interactions;
public MockConnection()
{
closed = false;
metaData = new MockConnectionMetaData();
localTransaction = new MockLocalTransaction();
resultSetInfo = new MockResultSetInfo();
interactions = new ArrayList();
}
/**
* Returns the {@link MockLocalTransaction}. If the underlying
* LocalTransaction
is not an instance of
* {@link MockLocalTransaction}, this method returns null
.
* Otherwise it returns the same object as {@link #getLocalTransaction}.
* @return the {@link MockLocalTransaction}
*/
public MockLocalTransaction getMockLocalTransaction()
{
if(localTransaction instanceof MockLocalTransaction)
{
return (MockLocalTransaction) localTransaction;
}
return null;
}
/**
* Returns the list of all created Interaction
objects.
*
* @return the list Interaction
objects
*/
public List getInteractionList()
{
return Collections.unmodifiableList(interactions);
}
public void close() throws ResourceException
{
for(int ii = 0; ii < interactions.size(); ii++)
{
((Interaction)interactions.get(ii)).close();
}
closed = true;
}
public Interaction createInteraction() throws ResourceException
{
Interaction interaction = new MockInteraction(this);
interactions.add(interaction);
return interaction;
}
public LocalTransaction getLocalTransaction() throws ResourceException
{
return localTransaction;
}
public ConnectionMetaData getMetaData() throws ResourceException
{
return metaData;
}
public ResultSetInfo getResultSetInfo() throws ResourceException
{
return resultSetInfo;
}
/**
* Returns if this Connection
is closed.
* @return true
if this Interaction
is closed,
* false
otherwise
*/
public boolean isClosed()
{
return closed;
}
public InteractionHandler getInteractionHandler()
{
return interactionHandler;
}
/**
* Sets this connections ResultSetInfo
* @param resultSetInfo the ResultSetInfo
*/
public void setResultSetInfo(ResultSetInfo resultSetInfo)
{
this.resultSetInfo = resultSetInfo;
}
/**
* Sets this connections InteractionHandler
* @param interactionHandler the InteractionHandler
*/
public void setInteractionHandler(InteractionHandler interactionHandler)
{
this.interactionHandler = interactionHandler;
}
/**
* Sets this connections meta data
* @param metaData the meta data
*/
public void setMetaData(ConnectionMetaData metaData)
{
this.metaData = metaData;
}
/**
* Sets the LocalTransaction
* @param localTransaction the LocalTransaction
*/
public void setLocalTransaction(LocalTransaction localTransaction)
{
this.localTransaction = localTransaction;
}
}