001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.tx;
006:
007: import com.tc.exception.ImplementMe;
008: import com.tc.logging.TCLogger;
009: import com.tc.logging.TCLogging;
010: import com.tc.net.protocol.tcm.ChannelIDProvider;
011: import com.tc.object.ObjectID;
012: import com.tc.object.TCObject;
013: import com.tc.object.dmi.DmiDescriptor;
014: import com.tc.object.session.SessionID;
015:
016: import java.util.ArrayList;
017: import java.util.Collection;
018: import java.util.List;
019: import java.util.Map;
020: import java.util.Set;
021:
022: /**
023: * MockTransactionManager for unit testing.
024: */
025: public class MockTransactionManager implements ClientTransactionManager {
026:
027: private static final TCLogger logger = TCLogging
028: .getLogger(MockTransactionManager.class);
029:
030: private int commitCount;
031: private List begins = new ArrayList();
032:
033: public void clearBegins() {
034: begins.clear();
035: }
036:
037: public List getBegins() {
038: List rv = new ArrayList();
039: rv.addAll(begins);
040: return rv;
041: }
042:
043: public boolean begin(String lock, int type) {
044: // System.err.println(this + ".begin(" + lock + ")");
045:
046: begins.add(new Begin(lock, type));
047: return true;
048: }
049:
050: public void clearCommitCount() {
051: this .commitCount = 0;
052: }
053:
054: public int getCommitCount() {
055: return this .commitCount;
056: }
057:
058: public void createObject(TCObject source) {
059: throw new ImplementMe();
060: }
061:
062: public void createRoot(String name, ObjectID id) {
063: throw new ImplementMe();
064: }
065:
066: public void fieldChanged(TCObject source, String classname,
067: String fieldname, Object newValue, int index) {
068: throw new ImplementMe();
069: }
070:
071: public void logicalInvoke(TCObject source, int name,
072: String methodName, Object[] parameters) {
073: throw new ImplementMe();
074: }
075:
076: public static class Begin {
077: public String lockName;
078: public int lockType;
079:
080: Begin(String name, int type) {
081: this .lockName = name;
082: this .lockType = type;
083: }
084: }
085:
086: public void wait(WaitInvocation call, Object object) {
087: throw new ImplementMe();
088: }
089:
090: public void notify(String lockName, boolean all, Object object)
091: throws UnlockedSharedObjectException {
092: throw new ImplementMe();
093: }
094:
095: public void receivedBatchAcknowledgement(TxnBatchID batchID) {
096: throw new ImplementMe();
097: }
098:
099: public void apply(TxnType txType, List lockIDs,
100: Collection objectChanges, Set lookupObjectIDs, Map newRoots) {
101: throw new ImplementMe();
102: }
103:
104: public void checkWriteAccess(Object context) {
105: //
106: }
107:
108: public void receivedAcknowledgement(SessionID sessionID,
109: TransactionID requestID) {
110: throw new ImplementMe();
111: }
112:
113: public void addReference(TCObject tco) {
114: throw new ImplementMe();
115: }
116:
117: public ChannelIDProvider getChannelIDProvider() {
118: return null;
119: }
120:
121: public boolean isLocked(String lockName, int lockLevel) {
122: throw new ImplementMe();
123: }
124:
125: public void commit(String lockName)
126: throws UnlockedSharedObjectException {
127: if (logger.isDebugEnabled()) {
128: logger.debug("commit(lockName)");
129: }
130: this .commitCount++;
131: }
132:
133: public void wait(String lockName, WaitInvocation call, Object object)
134: throws UnlockedSharedObjectException {
135: throw new ImplementMe();
136: }
137:
138: public void lock(String lockName, int lockLevel) {
139: throw new ImplementMe();
140: }
141:
142: public void unlock(String lockName) {
143: throw new ImplementMe();
144: }
145:
146: public int queueLength(String lockName) {
147: throw new ImplementMe();
148: }
149:
150: public int waitLength(String lockName) {
151: throw new ImplementMe();
152: }
153:
154: public ClientTransaction getTransaction() {
155: throw new ImplementMe();
156: }
157:
158: public void disableTransactionLogging() {
159: return;
160: }
161:
162: public void enableTransactionLogging() {
163: return;
164: }
165:
166: public boolean isTransactionLoggingDisabled() {
167: return true;
168: }
169:
170: public boolean isHeldByCurrentThread(String lockName, int lockLevel) {
171: throw new ImplementMe();
172: }
173:
174: public boolean tryBegin(String lock, WaitInvocation timeout,
175: int lockLevel) {
176: throw new ImplementMe();
177: }
178:
179: public void literalValueChanged(TCObject source, Object newValue,
180: Object oldValue) {
181: throw new ImplementMe();
182: }
183:
184: public void arrayChanged(TCObject src, int startPos, Object array,
185: int length) {
186: throw new ImplementMe();
187: }
188:
189: public void addDmiDescriptor(DmiDescriptor d) {
190: throw new ImplementMe();
191: }
192:
193: public int localHeldCount(String lockName, int lockLevel) {
194: throw new ImplementMe();
195: }
196:
197: public boolean isLockOnTopStack(String lockName) {
198: return false;
199: }
200: }
|