Skip to content

Commit b2146b9

Browse files
committed
Remove adapter in favour of an extra private member...
... instantiated as an anon implementation of the interface.
1 parent 2931f24 commit b2146b9

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ public static String databaseName(String persistenceKey, DatabaseId databaseId)
7676
private final SQLiteQueryCache queryCache;
7777
private final SQLiteRemoteDocumentCache remoteDocumentCache;
7878
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+
};
7994

8095
public SQLitePersistence(
8196
Context context, String persistenceKey, DatabaseId databaseId, LocalSerializer serializer) {
@@ -142,33 +157,10 @@ RemoteDocumentCache getRemoteDocumentCache() {
142157
return remoteDocumentCache;
143158
}
144159

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-
167160
@Override
168161
void runTransaction(String action, Runnable operation) {
169162
Logger.debug(TAG, "Starting transaction: %s", action);
170-
db.beginTransactionWithListener(
171-
new ReferenceDelegateToSQLiteTransactionListenerAdapter(referenceDelegate));
163+
db.beginTransactionWithListener(transactionListener);
172164
try {
173165
operation.run();
174166

@@ -183,8 +175,7 @@ void runTransaction(String action, Runnable operation) {
183175
<T> T runTransaction(String action, Supplier<T> operation) {
184176
Logger.debug(TAG, "Starting transaction: %s", action);
185177
T value = null;
186-
db.beginTransactionWithListener(
187-
new ReferenceDelegateToSQLiteTransactionListenerAdapter(referenceDelegate));
178+
db.beginTransactionWithListener(transactionListener);
188179
try {
189180
value = operation.get();
190181

0 commit comments

Comments
 (0)