android - Create a transaction to update multiple places in Firebase Database -


i'm making app (imaginary) massage center. in activity, user can click button make reservation. 1 customer must able make reservation specific date , time, have use transaction takes account current state of database handle update.

right now, doing following:

public void processviewresult(object object, string tag) {  if (tag.equals("reservation")) {      final reservation reservation = (reservation) object;      database.getreference().runtransaction(new transaction.handler() {         @override         public transaction.result dotransaction(mutabledata mutabledata) {             mutabledata freeslots = mutabledata.child("slots").child(reservation.getdate());             mutabledata userreservations = mutabledata.child("users")                     .child(reservation.getuserid()).child("reservations");             boolean isslotavailable = freeslots.haschild(reservation.gethour());              if (isslotavailable) {                 mutabledata.child(reservation.gethour()).setvalue(null);                 userreservations.child(string.valueof(reservation.hashcode())).setvalue(reservation);                 return transaction.success(mutabledata);             } else {                 return transaction.abort();             }         }          @override         public void oncomplete(databaseerror databaseerror, boolean b, datasnapshot datasnapshot) {             if (databaseerror != null) {                 log.e(this.getclass().getsimplename(), databaseerror.tostring());             } else {                 log.e(this.getclass().getsimplename(), "updated successfully");             }         }     });  } 

}

there several problems approach:

1) since need update both time slots available , reservations made current customer, need snapshot of whole database. if application scaled, inefficient.

2) approach has lot of boilerplate.

can please tell me if there simpler , more elegant solution this?