@@ -76,6 +76,21 @@ public static String databaseName(String persistenceKey, DatabaseId databaseId)
76
76
private final SQLiteQueryCache queryCache ;
77
77
private final SQLiteRemoteDocumentCache remoteDocumentCache ;
78
78
private final SQLiteLruReferenceDelegate referenceDelegate ;
79
+ private final SQLiteTransactionListener transactionListener =
80
+ new SQLiteTransactionListener () {
81
+ @ Override
82
+ public void onBegin () {
83
+ referenceDelegate .onTransactionStarted ();
84
+ }
85
+
86
+ @ Override
87
+ public void onCommit () {
88
+ referenceDelegate .onTransactionCommitted ();
89
+ }
90
+
91
+ @ Override
92
+ public void onRollback () {}
93
+ };
79
94
80
95
public SQLitePersistence (
81
96
Context context , String persistenceKey , DatabaseId databaseId , LocalSerializer serializer ) {
@@ -142,33 +157,10 @@ RemoteDocumentCache getRemoteDocumentCache() {
142
157
return remoteDocumentCache ;
143
158
}
144
159
145
- private static class ReferenceDelegateToSQLiteTransactionListenerAdapter
146
- implements SQLiteTransactionListener {
147
- private ReferenceDelegate instance ;
148
-
149
- ReferenceDelegateToSQLiteTransactionListenerAdapter (ReferenceDelegate instance ) {
150
- this .instance = instance ;
151
- }
152
-
153
- @ Override
154
- public void onBegin () {
155
- instance .onTransactionStarted ();
156
- }
157
-
158
- @ Override
159
- public void onCommit () {
160
- instance .onTransactionCommitted ();
161
- }
162
-
163
- @ Override
164
- public void onRollback () {}
165
- }
166
-
167
160
@ Override
168
161
void runTransaction (String action , Runnable operation ) {
169
162
Logger .debug (TAG , "Starting transaction: %s" , action );
170
- db .beginTransactionWithListener (
171
- new ReferenceDelegateToSQLiteTransactionListenerAdapter (referenceDelegate ));
163
+ db .beginTransactionWithListener (transactionListener );
172
164
try {
173
165
operation .run ();
174
166
@@ -183,8 +175,7 @@ void runTransaction(String action, Runnable operation) {
183
175
<T > T runTransaction (String action , Supplier <T > operation ) {
184
176
Logger .debug (TAG , "Starting transaction: %s" , action );
185
177
T value = null ;
186
- db .beginTransactionWithListener (
187
- new ReferenceDelegateToSQLiteTransactionListenerAdapter (referenceDelegate ));
178
+ db .beginTransactionWithListener (transactionListener );
188
179
try {
189
180
value = operation .get ();
190
181
0 commit comments