Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTransactionManager.cs @ 17:01a08cf4b2d9
Liq Files
author | Kazuma |
---|---|
date | Mon, 07 Nov 2016 01:05:24 +0900 |
parents | abe0c247f5a5 |
children |
comparison
equal
deleted
inserted
replaced
16:8f1ce942abfc | 17:01a08cf4b2d9 |
---|---|
1 using System.Collections.Generic; | |
2 using System.Collections; | |
3 using System; | |
4 | |
5 public class DefaultTransactionManager : TransactionManager { | |
6 private AtomicReference<TreeContext> repository; | |
7 private TreeContext tip; | |
8 private ChangeListWriter writer; | |
9 private string uuid; | |
10 | |
11 | |
12 public DefaultTransactionManager(ChangeListWriter _writer, TreeContext _tip, AtomicReference<TreeContext> _repository, string _uuid) { | |
13 repository = _repository; | |
14 tip = _tip; | |
15 writer = _writer; | |
16 uuid = _uuid; | |
17 } | |
18 | |
19 public Either<Error, TransactionManager> commit(TreeNode newRoot, TreeOperationLog _log) { | |
20 long currentRevision = tip.getRevision(); | |
21 long nextRevision = currentRevision + 1; | |
22 | |
23 string _treeName = tip.getTreeName(); | |
24 // 通信時に必要? | |
25 ChangeList list = new InnerChangeList(_log, _treeName, uuid); | |
26 | |
27 InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); | |
28 // traverser.createIndex(); | |
29 TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, _treeName, nextRevision,traverser); | |
30 // compare and setがどういう役割か?Javaで | |
31 if (repository.CompareAndSet(newTreeContext, newTreeContext.prev())) { // CompareAndSetが成功した場合に処理を実行 | |
32 TransactionManager txManager = new DefaultTransactionManager(writer, newTreeContext, repository, uuid); | |
33 return DefaultEither<Error, TransactionManager>.newB(txManager); | |
34 } | |
35 | |
36 return DefaultEither<Error, TransactionManager>.newA((Error) new DefaultError()); | |
37 } | |
38 | |
39 public Either<Error, TransactionManager> firstcommit(TreeNode _newRoot, TreeOperationLog _log) { | |
40 return commit(_newRoot,_log); | |
41 } | |
42 | |
43 public string getUUID() { | |
44 return uuid; | |
45 } | |
46 | |
47 public long getRevision() { | |
48 return tip.getRevision(); | |
49 } | |
50 | |
51 public class InnerChangeList : ChangeList{ | |
52 | |
53 TreeOperationLog log; | |
54 string treeName; | |
55 string uuid; | |
56 | |
57 | |
58 IEnumerator IEnumerable.GetEnumerator() | |
59 { | |
60 // call the generic version of the method | |
61 return this.GetEnumerator(); | |
62 } | |
63 | |
64 public IEnumerator<TreeOperation> GetEnumerator() | |
65 { | |
66 return iterator (); | |
67 } | |
68 | |
69 | |
70 public InnerChangeList(TreeOperationLog _log, string _treeName, string _uuid){ | |
71 this.log = _log; | |
72 this.treeName = _treeName; | |
73 this.uuid = _uuid; | |
74 } | |
75 | |
76 public IEnumerator<TreeOperation> iterator() { | |
77 return log.GetEnumerator(); | |
78 } | |
79 | |
80 public string getTreeName() { | |
81 return treeName; | |
82 } | |
83 | |
84 public TreeOperationLog getLog() { | |
85 return log; | |
86 } | |
87 | |
88 public string uuids() { | |
89 return uuid; | |
90 } | |
91 } | |
92 | |
93 } | |
94 |