001: package com.mockrunner.mock.connector.cci;
002:
003: import javax.resource.ResourceException;
004: import javax.resource.cci.LocalTransaction;
005:
006: /**
007: * Mock implementation of <code>LocalTransaction</code>.
008: */
009: public class MockLocalTransaction implements LocalTransaction {
010: private boolean beginCalled;
011: private boolean commitCalled;
012: private boolean rollbackCalled;
013: private int beginCalls;
014: private int commitCalls;
015: private int rollbackCalls;
016:
017: public MockLocalTransaction() {
018: reset();
019: }
020:
021: /**
022: * Resets the transaction state. Sets the number of overall
023: * begin, commit and rollback calls to <code>0</code>.
024: */
025: public void reset() {
026: beginCalled = false;
027: commitCalled = false;
028: rollbackCalled = false;
029: beginCalls = 0;
030: commitCalls = 0;
031: rollbackCalls = 0;
032: }
033:
034: /**
035: * Starts the transaction. The flags <code>wasCommitCalled</code>
036: * and <code>wasRollbackCalled</code> are reset to <code>false</code>.
037: * This method does not reset the number of overall calls.
038: */
039: public void begin() throws ResourceException {
040: beginCalled = true;
041: commitCalled = false;
042: rollbackCalled = false;
043: beginCalls++;
044: }
045:
046: /**
047: * Commits the transaction.
048: */
049: public void commit() throws ResourceException {
050: commitCalled = true;
051: commitCalls++;
052: }
053:
054: /**
055: * Rolls back the transaction.
056: */
057: public void rollback() throws ResourceException {
058: rollbackCalled = true;
059: rollbackCalls++;
060: }
061:
062: /**
063: * Returns if {@link #begin} was called.
064: * @return was {@link #begin} called
065: */
066: public boolean wasBeginCalled() {
067: return beginCalled;
068: }
069:
070: /**
071: * Returns if {@link #commit} was called.
072: * @return was {@link #commit} called
073: */
074: public boolean wasCommitCalled() {
075: return commitCalled;
076: }
077:
078: /**
079: * Returns if {@link #rollback} was called.
080: * @return was {@link #rollback} called
081: */
082: public boolean wasRollbackCalled() {
083: return rollbackCalled;
084: }
085:
086: /**
087: * Returns the number of overall {@link #begin} calls.
088: * @return the number of overall {@link #begin} calls
089: */
090: public int getNumberBeginCalls() {
091: return beginCalls;
092: }
093:
094: /**
095: * Returns the number of overall {@link #commit} calls.
096: * @return the number of overall {@link #commit} calls
097: */
098: public int getNumberCommitCalls() {
099: return commitCalls;
100: }
101:
102: /**
103: * Returns the number of overall {@link #rollback} calls.
104: * @return the number of overall {@link #rollback} calls
105: */
106: public int getNumberRollbackCalls() {
107: return rollbackCalls;
108: }
109: }
|