11use std:: { fs, sync:: MutexGuard } ;
22
33use crate :: {
4- btree:: { spec:: BTreePair , BTree , BTreeIterator , ValueTrait } ,
5- collection:: {
6- xact:: { Transaction , TransactionOperations } ,
7- xlog:: XLogOperation ,
8- } ,
4+ btree:: { BTree , ValueTrait } ,
5+ collection:: xact:: { Transaction , TransactionOperations } ,
96 dustdata_config,
10- error:: { Error , Result } ,
7+ error:: Error ,
118} ;
129
1310pub struct LockTransaction < ' lock , T : ValueTrait > {
@@ -19,50 +16,6 @@ pub struct LockTransaction<'lock, T: ValueTrait> {
1916}
2017
2118impl < ' lock , T : ValueTrait > Transaction < T > for LockTransaction < ' lock , T > {
22- fn get ( & mut self , key : & str ) -> Result < Option < T > > {
23- self . btree . get ( & key. to_string ( ) )
24- }
25-
26- fn insert ( & mut self , key : & str , value : T ) -> Result < ( ) > {
27- self . xact_op . write ( XLogOperation :: Insert {
28- key : key. to_string ( ) ,
29- value : value. clone ( ) ,
30- } ) ?;
31-
32- self . btree . insert ( key. to_string ( ) , value)
33- }
34-
35- fn delete ( & mut self , key : & str ) -> Result < ( ) > {
36- self . xact_op . write ( XLogOperation :: Delete {
37- key : key. to_string ( ) ,
38- } ) ?;
39-
40- self . btree . delete ( & key. to_string ( ) )
41- }
42-
43- fn update ( & mut self , key : & str , new_value : T ) -> Result < ( ) > {
44- self . xact_op . write ( XLogOperation :: Update {
45- key : key. to_string ( ) ,
46- new_value : new_value. clone ( ) ,
47- } ) ?;
48-
49- self . btree . delete ( & key. to_string ( ) ) ?;
50- self . btree . insert ( key. to_string ( ) , new_value) ?;
51-
52- Ok ( ( ) )
53- }
54-
55- fn iter ( & mut self ) -> BTreeIterator < ' _ , String , T > {
56- self . btree . iter ( )
57- }
58-
59- fn find_by_pattern < ' a > (
60- & ' a mut self ,
61- pattern : & ' a str ,
62- ) -> Box < ( dyn Iterator < Item = BTreePair < String , T > > + ' a ) > {
63- Box :: new ( self . btree . find_pattern ( pattern) )
64- }
65-
6619 fn rollback ( self ) { }
6720
6821 fn xid ( & self ) -> u64 {
@@ -72,6 +25,10 @@ impl<'lock, T: ValueTrait> Transaction<T> for LockTransaction<'lock, T> {
7225 fn log ( & mut self ) -> & mut TransactionOperations < T > {
7326 & mut self . xact_op
7427 }
28+
29+ fn btree ( & mut self ) -> & mut BTree < String , T > {
30+ & mut self . btree
31+ }
7532}
7633
7734impl < ' a , T : ValueTrait > Drop for LockTransaction < ' a , T > {
0 commit comments