myRef.orderByChild("name").equalTo("abc").runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
Student s = mutableData.getValue(Student.class);
if (s == null) {
return Transaction.success(mutableData);
}
s.setAge(20);
// Set value and report transaction success
mutableData.setValue(s);
return Transaction.success(mutableData);
}
@Override
public void onComplete(DatabaseError databaseError, boolean b,
DataSnapshot dataSnapshot) {
// Transaction completed
Log.d(TAG, "postTransaction:onComplete:" + databaseError);
}
});