KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > tx > ClientTransactionFactoryImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.tx;
5
6 import com.tc.net.protocol.tcm.ChannelIDProvider;
7 import com.tc.object.lockmanager.api.LockID;
8 import com.tc.object.logging.RuntimeLogger;
9
10 /**
11  * @author steve
12  */

13 public class ClientTransactionFactoryImpl implements ClientTransactionFactory {
14   private long transactionID = 0;
15   private final RuntimeLogger runtimeLogger;
16   private final ChannelIDProvider cidProvider;
17
18   public ClientTransactionFactoryImpl(RuntimeLogger runtimeLogger, ChannelIDProvider cidProvider) {
19     this.runtimeLogger = runtimeLogger;
20     this.cidProvider = cidProvider;
21   }
22
23   public ClientTransaction newInstance() {
24     return new ClientTransactionImpl(nextTransactionID(), runtimeLogger, cidProvider);
25   }
26
27   public ClientTransaction newNullInstance(LockID id, TxnType type) {
28     ClientTransaction tc = new NullClientTransaction(nextTransactionID(), cidProvider);
29     tc.setTransactionContext(new TransactionContext(id, type, new LockID[] { id }));
30     return tc;
31   }
32
33   private synchronized TransactionID nextTransactionID() {
34     return new TransactionID(transactionID++);
35   }
36 }
Popular Tags