001: package com.mockrunner.mock.connector.cci;
002:
003: import java.util.ArrayList;
004: import java.util.Collections;
005: import java.util.List;
006:
007: import javax.resource.ResourceException;
008: import javax.resource.cci.Connection;
009: import javax.resource.cci.ConnectionMetaData;
010: import javax.resource.cci.Interaction;
011: import javax.resource.cci.LocalTransaction;
012: import javax.resource.cci.ResultSetInfo;
013:
014: import com.mockrunner.connector.InteractionHandler;
015:
016: /**
017: * Mock implementation of <code>Connection</code>.
018: */
019: public class MockConnection implements Connection {
020: private boolean closed;
021: private InteractionHandler interactionHandler;
022: private ConnectionMetaData metaData;
023: private LocalTransaction localTransaction;
024: private ResultSetInfo resultSetInfo;
025: private List interactions;
026:
027: public MockConnection() {
028: closed = false;
029: metaData = new MockConnectionMetaData();
030: localTransaction = new MockLocalTransaction();
031: resultSetInfo = new MockResultSetInfo();
032: interactions = new ArrayList();
033: }
034:
035: /**
036: * Returns the {@link MockLocalTransaction}. If the underlying
037: * <code>LocalTransaction</code> is not an instance of
038: * {@link MockLocalTransaction}, this method returns <code>null</code>.
039: * Otherwise it returns the same object as {@link #getLocalTransaction}.
040: * @return the {@link MockLocalTransaction}
041: */
042: public MockLocalTransaction getMockLocalTransaction() {
043: if (localTransaction instanceof MockLocalTransaction) {
044: return (MockLocalTransaction) localTransaction;
045: }
046: return null;
047: }
048:
049: /**
050: * Returns the list of all created <code>Interaction</code> objects.
051: *
052: * @return the list <code>Interaction</code> objects
053: */
054: public List getInteractionList() {
055: return Collections.unmodifiableList(interactions);
056: }
057:
058: public void close() throws ResourceException {
059: for (int ii = 0; ii < interactions.size(); ii++) {
060: ((Interaction) interactions.get(ii)).close();
061: }
062: closed = true;
063: }
064:
065: public Interaction createInteraction() throws ResourceException {
066: Interaction interaction = new MockInteraction(this );
067: interactions.add(interaction);
068: return interaction;
069: }
070:
071: public LocalTransaction getLocalTransaction()
072: throws ResourceException {
073: return localTransaction;
074: }
075:
076: public ConnectionMetaData getMetaData() throws ResourceException {
077: return metaData;
078: }
079:
080: public ResultSetInfo getResultSetInfo() throws ResourceException {
081: return resultSetInfo;
082: }
083:
084: /**
085: * Returns if this <code>Connection</code> is closed.
086: * @return <code>true</code> if this <code>Interaction</code> is closed,
087: * <code>false</code> otherwise
088: */
089: public boolean isClosed() {
090: return closed;
091: }
092:
093: public InteractionHandler getInteractionHandler() {
094: return interactionHandler;
095: }
096:
097: /**
098: * Sets this connections <code>ResultSetInfo</code>
099: * @param resultSetInfo the <code>ResultSetInfo</code>
100: */
101: public void setResultSetInfo(ResultSetInfo resultSetInfo) {
102: this .resultSetInfo = resultSetInfo;
103: }
104:
105: /**
106: * Sets this connections <code>InteractionHandler</code>
107: * @param interactionHandler the <code>InteractionHandler</code>
108: */
109: public void setInteractionHandler(
110: InteractionHandler interactionHandler) {
111: this .interactionHandler = interactionHandler;
112: }
113:
114: /**
115: * Sets this connections meta data
116: * @param metaData the meta data
117: */
118: public void setMetaData(ConnectionMetaData metaData) {
119: this .metaData = metaData;
120: }
121:
122: /**
123: * Sets the <code>LocalTransaction</code>
124: * @param localTransaction the <code>LocalTransaction</code>
125: */
126: public void setLocalTransaction(LocalTransaction localTransaction) {
127: this.localTransaction = localTransaction;
128: }
129: }
|