Skip to content

Commit 2931f24

Browse files
committed
Create adapter to reduce duplication
And to remove clutter around the sqlite transaction.
1 parent 496e614 commit 2931f24

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

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

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,33 @@ RemoteDocumentCache getRemoteDocumentCache() {
142142
return remoteDocumentCache;
143143
}
144144

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+
145167
@Override
146168
void runTransaction(String action, Runnable operation) {
147169
Logger.debug(TAG, "Starting transaction: %s", action);
148170
db.beginTransactionWithListener(
149-
new SQLiteTransactionListener() {
150-
@Override
151-
public void onBegin() {
152-
referenceDelegate.onTransactionStarted();
153-
}
154-
155-
@Override
156-
public void onCommit() {
157-
referenceDelegate.onTransactionCommitted();
158-
}
159-
160-
@Override
161-
public void onRollback() {}
162-
});
171+
new ReferenceDelegateToSQLiteTransactionListenerAdapter(referenceDelegate));
163172
try {
164173
operation.run();
165174

@@ -175,20 +184,7 @@ <T> T runTransaction(String action, Supplier<T> operation) {
175184
Logger.debug(TAG, "Starting transaction: %s", action);
176185
T value = null;
177186
db.beginTransactionWithListener(
178-
new SQLiteTransactionListener() {
179-
@Override
180-
public void onBegin() {
181-
referenceDelegate.onTransactionStarted();
182-
}
183-
184-
@Override
185-
public void onCommit() {
186-
referenceDelegate.onTransactionCommitted();
187-
}
188-
189-
@Override
190-
public void onRollback() {}
191-
});
187+
new ReferenceDelegateToSQLiteTransactionListenerAdapter(referenceDelegate));
192188
try {
193189
value = operation.get();
194190

0 commit comments

Comments
 (0)