1myRef.orderByChild("name").equalTo("abc").runTransaction(new Transaction.Handler() {
2 @Override
3 public Transaction.Result doTransaction(MutableData mutableData) {
4 Student s = mutableData.getValue(Student.class);
5 if (s == null) {
6 return Transaction.success(mutableData);
7 }
8
9 s.setAge(20);
10 // Set value and report transaction success
11 mutableData.setValue(s);
12 return Transaction.success(mutableData);
13 }
14
15 @Override
16 public void onComplete(DatabaseError databaseError, boolean b,
17 DataSnapshot dataSnapshot) {
18 // Transaction completed
19 Log.d(TAG, "postTransaction:onComplete:" + databaseError);
20 }
21});
22