@@ -94,6 +94,13 @@ public class ForestDBStore implements Store, EncryptableStore, Constants {
9494 private boolean readOnly = false ;
9595 private SymmetricKey encryptionKey ;
9696
97+ private ThreadLocal <Integer > transactionLevel4Thread = new ThreadLocal <Integer >() {
98+ @ Override
99+ protected Integer initialValue () {
100+ return 0 ;
101+ }
102+ };
103+
97104 // Native method for deriving PBDDF2-SHA256 key:
98105 private static native byte [] nativeDerivePBKDF2SHA256Key (String password , byte [] salt , int rounds );
99106
@@ -249,7 +256,7 @@ public long getLastSequence() {
249256
250257 @ Override
251258 public boolean inTransaction () {
252- return forest . isInTransaction () ;
259+ return transactionLevel4Thread . get () > 0 ;
253260 }
254261
255262 @ Override
@@ -1226,6 +1233,7 @@ private DocumentChange changeWithNewRevision(RevisionInternal inRev,
12261233 private boolean beginTransaction () {
12271234 try {
12281235 forest .beginTransaction ();
1236+ transactionLevel4Thread .set (transactionLevel4Thread .get () + 1 );
12291237 } catch (ForestException e ) {
12301238 Log .e (TAG , "Failed to begin transaction" , e );
12311239 return false ;
@@ -1235,6 +1243,7 @@ private boolean beginTransaction() {
12351243
12361244 private boolean endTransaction (boolean commit ) {
12371245 try {
1246+ transactionLevel4Thread .set (transactionLevel4Thread .get () - 1 );
12381247 forest .endTransaction (commit );
12391248 } catch (ForestException e ) {
12401249 Log .e (TAG , "Failed to end transaction" , e );
0 commit comments