Skip to content

Commit 5c1a935

Browse files
authored
Remove the deprecated RunTransaction function (#544)
* Remove deprecated RunTransaction. * Add newline to the end of the file. * Add release notes. * run format_code.py
1 parent 54849d0 commit 5c1a935

File tree

11 files changed

+50
-73
lines changed

11 files changed

+50
-73
lines changed

firestore/src/android/firestore_android.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,25 +440,18 @@ WriteBatch FirestoreInternal::batch() const {
440440
return WriteBatch(new WriteBatchInternal(mutable_this(), result));
441441
}
442442

443-
Future<void> FirestoreInternal::RunTransaction(TransactionFunction* update,
444-
bool is_lambda) {
443+
Future<void> FirestoreInternal::RunTransaction(
444+
std::function<Error(Transaction&, std::string&)> update) {
445+
auto* lambda_update = new LambdaTransactionFunction(Move(update));
445446
Env env = GetEnv();
446447
Local<Object> transaction_function =
447-
TransactionInternal::Create(env, this, update);
448+
TransactionInternal::Create(env, this, lambda_update);
448449
Local<Task> task = env.Call(obj_, kRunTransaction, transaction_function);
449450

450451
if (!env.ok()) return {};
451452

452-
auto* completion =
453-
static_cast<LambdaTransactionFunction*>(is_lambda ? update : nullptr);
454453
return promises_->NewFuture<void>(env, AsyncFn::kRunTransaction, task,
455-
completion);
456-
}
457-
458-
Future<void> FirestoreInternal::RunTransaction(
459-
std::function<Error(Transaction&, std::string&)> update) {
460-
auto* lambda_update = new LambdaTransactionFunction(Move(update));
461-
return RunTransaction(lambda_update, /*is_lambda=*/true);
454+
lambda_update);
462455
}
463456

464457
Future<void> FirestoreInternal::DisableNetwork() {

firestore/src/android/firestore_android.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ namespace firestore {
2929
class Firestore;
3030
class ListenerRegistrationInternal;
3131
class Transaction;
32-
class TransactionFunction;
3332
class WriteBatch;
3433

3534
template <typename EnumT>
@@ -93,11 +92,6 @@ class FirestoreInternal {
9392

9493
WriteBatch batch() const;
9594

96-
// Runs transaction atomically.
97-
// TODO(b/191969448): Remove the is_lambda parameter if possible.
98-
Future<void> RunTransaction(TransactionFunction* update,
99-
bool is_lambda = false);
100-
10195
Future<void> RunTransaction(
10296
std::function<Error(Transaction&, std::string&)> update);
10397

firestore/src/android/lambda_transaction_function.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "app/src/assert.h"
1111
#include "firestore/src/android/firestore_android.h"
1212
#include "firestore/src/android/promise_android.h"
13+
#include "firestore/src/common/transaction_function.h"
1314
#include "firestore/src/include/firebase/firestore/transaction.h"
1415

1516
namespace firebase {

firestore/src/android/transaction_android.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "app/meta/move.h"
1010
#include "app/src/embedded_file.h"
1111
#include "firestore/src/android/wrapper.h"
12+
#include "firestore/src/common/transaction_function.h"
1213
#include "firestore/src/include/firebase/firestore/document_reference.h"
1314
#include "firestore/src/include/firebase/firestore/field_value.h"
1415
#include "firestore/src/include/firebase/firestore/map_field_value.h"

firestore/src/common/firestore.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@ WriteBatch Firestore::batch() const {
260260
return internal_->batch();
261261
}
262262

263-
Future<void> Firestore::RunTransaction(TransactionFunction* update) {
264-
if (!internal_) return FailedFuture<void>();
265-
return internal_->RunTransaction(update);
266-
}
267-
268263
Future<void> Firestore::RunTransaction(
269264
std::function<Error(Transaction&, std::string&)> update) {
270265
FIREBASE_ASSERT_MESSAGE(update, "invalid update parameter is passed in.");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2021 Google LLC
2+
3+
#ifndef FIREBASE_FIRESTORE_SRC_COMMON_TRANSACTION_FUNCTION_H_
4+
#define FIREBASE_FIRESTORE_SRC_COMMON_TRANSACTION_FUNCTION_H_
5+
6+
#include <string>
7+
8+
#include "firebase/firestore/firestore_errors.h"
9+
10+
namespace firebase {
11+
namespace firestore {
12+
13+
class Transaction;
14+
15+
/**
16+
* An interface for providing code to be executed within a transaction
17+
* context.
18+
*/
19+
class TransactionFunction {
20+
public:
21+
virtual ~TransactionFunction() {}
22+
23+
/**
24+
* Subclass should override this method and put the transaction logic here.
25+
*
26+
* @param[in] transaction The transaction to run this function with.
27+
* @param[out] error_message You can set error message with this parameter.
28+
* @return Either Error::kErrorOk if successful or the error code from Error
29+
* that most closely matches the failure.
30+
*/
31+
virtual Error Apply(Transaction& transaction, std::string& error_message) = 0;
32+
};
33+
34+
} // namespace firestore
35+
} // namespace firebase
36+
37+
#endif // FIREBASE_FIRESTORE_SRC_COMMON_TRANSACTION_FUNCTION_H_

firestore/src/include/firebase/firestore.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,26 +253,6 @@ class Firestore {
253253
virtual Future<void> RunTransaction(
254254
std::function<Error(Transaction&, std::string&)> update);
255255

256-
/**
257-
* Executes the given update and then attempts to commit the changes applied
258-
* within the transaction. If any document read within the transaction has
259-
* changed, the update function will be retried. If it fails to commit after 5
260-
* attempts, the transaction will fail.
261-
*
262-
* @param update The function to execute within the transaction context.
263-
* (Ownership is not transferred; you are responsible for making sure that
264-
* transaction is valid as long as the Future has not yet completed.)
265-
*
266-
* @return A Future that will be resolved when the transaction finishes.
267-
*
268-
* @deprecated This method was originally added to support the STLPort C++
269-
* runtime on Android. Firebase support for STLPort has been removed, and
270-
* consequently this method is deprecated and will be removed in a future
271-
* release.
272-
*/
273-
FIREBASE_DEPRECATED virtual Future<void> RunTransaction(
274-
TransactionFunction* update);
275-
276256
/**
277257
* Sets the log verbosity of all Firestore instances.
278258
*

firestore/src/include/firebase/firestore/transaction.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,6 @@ class Transaction {
137137
mutable TransactionInternal* internal_ = nullptr;
138138
};
139139

140-
/**
141-
* An interface for providing code to be executed within a transaction
142-
* context.
143-
*
144-
* @see Firestore::RunTransaction(TransactionFunction*)
145-
*/
146-
class TransactionFunction {
147-
public:
148-
virtual ~TransactionFunction() {}
149-
150-
/**
151-
* Subclass should override this method and put the transaction logic here.
152-
*
153-
* @param[in] transaction The transaction to run this function with.
154-
* @param[out] error_message You can set error message with this parameter.
155-
* @return Either Error::kErrorOk if successful or the error code from Error
156-
* that most closely matches the failure.
157-
*/
158-
virtual Error Apply(Transaction& transaction, std::string& error_message) = 0;
159-
};
160-
161140
} // namespace firestore
162141
} // namespace firebase
163142

firestore/src/main/firestore_main.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,6 @@ WriteBatch FirestoreInternal::batch() const {
151151
return MakePublic(firestore_core_->GetBatch());
152152
}
153153

154-
Future<void> FirestoreInternal::RunTransaction(TransactionFunction* update) {
155-
return RunTransaction(
156-
[update](Transaction& transaction, std::string& error_message) {
157-
return update->Apply(transaction, error_message);
158-
});
159-
}
160-
161154
Future<void> FirestoreInternal::RunTransaction(
162155
std::function<Error(Transaction&, std::string&)> update) {
163156
auto executor = transaction_executor_;

firestore/src/main/firestore_main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace firestore {
2828
class Firestore;
2929
class ListenerRegistrationInternal;
3030
class Transaction;
31-
class TransactionFunction;
3231
class WriteBatch;
3332

3433
namespace util {
@@ -69,7 +68,6 @@ class FirestoreInternal {
6968

7069
Future<void> RunTransaction(
7170
std::function<Error(Transaction&, std::string&)> update);
72-
Future<void> RunTransaction(TransactionFunction* update);
7371

7472
Future<void> DisableNetwork();
7573

0 commit comments

Comments
 (0)