[英]How to run the multiple transactions in Firestore database? I am facing issue in that
I am trying to run the multiple transactions in firestore database in android. 我正在尝试在Android的Firestore数据库中运行多个事务。 but they are not working all at one time.
但他们不能一次全部工作。 only transaction is working right now that is of DocumentReference PostRef.
现在只有DocumentReference PostRef的事务正在运行。
please assist in running multiple transactions. 请协助进行多个交易。
db.runTransaction(new Transaction.Function<Void>() {
@Override
public Void apply(Transaction transaction) throws FirebaseFirestoreException {
DocumentSnapshot documentSnapshot1 = transaction.get(PostRef);
boolean l2 = documentSnapshot1.getBoolean("l2");
if(l2 == false) {
transaction.update(PostRef, "l2", true);
return null;
}
DocumentSnapshot documentSnapshot2 = transaction.get(PostUserRef);
long l11 = documentSnapshot2.getLong("l1");
{ transaction.update(PostRef, "l1", l11+1);
}
DocumentSnapshot snapshot = transaction.get(likesRef);
boolean l1 = snapshot.getBoolean("l1");
if (l1 == false) {
transaction.update(likesRef, "l1", true);
//2 transactions to update userprofile
return null;
} else
{
throw new FirebaseFirestoreException("You already liked",
FirebaseFirestoreException.Code.ABORTED);
}
}
})
我要做的是将多个事务设置为一个函数,然后在onclick事件中调用这些函数,然后执行所需的功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.