Mercurial > hg > Members > tatsuki > bench > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java @ 127:b2c1fd513feb
push index thread add read log
author | one |
---|---|
date | Mon, 13 Oct 2014 03:22:16 +0900 |
parents | 5df5505e1c1e |
children | 6e9a8d26e0cf |
rev | line source |
---|---|
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
2 |
45 | 3 import java.util.Iterator; |
103 | 4 |
5 import fj.data.List; | |
6 import fj.data.TreeMap; | |
45 | 7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result; | |
54 | 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; |
110 | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; |
54 | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
53 | 13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
45 | 15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.AtomicReservableReference.Reservation; |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
110 | 20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
21 |
86 | 22 public class DefaultTransactionManager implements TransactionManager |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
23 { |
86 | 24 private final AtomicReservableReference<TreeContext> repository; |
25 private final TreeContext tip; | |
45 | 26 private final ChangeListWriter writer; |
27 private final String uuid; | |
28 | |
86 | 29 public DefaultTransactionManager(ChangeListWriter _writer,TreeContext _tip, |
30 AtomicReservableReference<TreeContext> _repository,String _uuid) | |
45 | 31 { |
32 repository = _repository; | |
54 | 33 tip = _tip; |
45 | 34 writer = _writer; |
35 uuid = _uuid; | |
36 } | |
37 | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
38 @Override |
111 | 39 public Either<Error,TransactionManager> commit(TreeNode _newRoot,final TreeOperationLog _log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
40 { |
81 | 41 ChangeSet cs = tip.getChangeSet(); |
54 | 42 long currentRevision = cs.revision(); |
45 | 43 long nextRevision = currentRevision + 1; |
44 | |
59
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
45 final String _treeName = cs.getTreeName(); |
45 | 46 ChangeList list = new ChangeList(){ |
47 @Override | |
53 | 48 public Iterator<TreeOperation> iterator(){ |
45 | 49 return _log.iterator(); |
50 } | |
59
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
51 @Override |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
52 public String getTreeName(){ |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
53 return _treeName; |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
54 } |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
55 @Override |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
56 public String uuid(){ |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
57 return uuid; |
57e965b73c9e
Implement getTreeName method in ChangeSet and ChangeList interface.
one
parents:
54
diff
changeset
|
58 } |
127 | 59 @Override |
60 public int getLogSize() { | |
61 return _log.length(); | |
62 } | |
45 | 63 }; |
64 | |
103 | 65 DefaultChangeSet newCs = new DefaultChangeSet(_newRoot,cs,list,uuid, _treeName, nextRevision,index); |
86 | 66 DefaultTreeContext newContext = new DefaultTreeContext(_newRoot,newCs); |
54 | 67 |
68 @SuppressWarnings("rawtypes") | |
69 Reservation reservation = repository.makeReservation(tip,newContext); | |
45 | 70 if(reservation == null){ |
71 return DefaultEither.newA((Error)new DefaultError()); | |
72 } | |
73 Result r = writer.write(list); | |
74 if(r == Result.SUCCESS){ | |
75 reservation.confirm(); | |
86 | 76 TransactionManager txManager = new DefaultTransactionManager(writer,newContext,repository,uuid); |
45 | 77 return DefaultEither.newB(txManager); |
78 } | |
79 return DefaultEither.newA((Error)new DefaultError()); | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
80 } |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
81 |
45 | 82 @Override |
83 public String getUUID() | |
84 { | |
85 return uuid; | |
86 } | |
87 | |
88 @Override | |
89 public long getRevision() | |
90 { | |
81 | 91 ChangeSet cs = tip.getChangeSet(); |
54 | 92 return cs.revision(); |
45 | 93 } |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
diff
changeset
|
94 } |