Java Code Examples for com.google.firebase.database.Transaction#Handler

The following examples show how to use com.google.firebase.database.Transaction#Handler . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Repo.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
private TransactionData(
    Path path,
    Transaction.Handler handler,
    ValueEventListener outstandingListener,
    TransactionStatus status,
    boolean applyLocally,
    long order) {
  this.path = path;
  this.handler = handler;
  this.outstandingListener = outstandingListener;
  this.status = status;
  this.retryCount = 0;
  this.applyLocally = applyLocally;
  this.order = order;
  this.abortReason = null;
  this.currentInputSnapshot = null;
  this.currentOutputSnapshotRaw = null;
  this.currentOutputSnapshotResolved = null;
}
 
Example 2
Source File: Repo.java    From firebase-admin-java with Apache License 2.0 6 votes vote down vote up
private TransactionData(
    Path path,
    Transaction.Handler handler,
    ValueEventListener outstandingListener,
    TransactionStatus status,
    boolean applyLocally,
    long order) {
  this.path = path;
  this.handler = handler;
  this.outstandingListener = outstandingListener;
  this.status = status;
  this.retryCount = 0;
  this.applyLocally = applyLocally;
  this.order = order;
  this.abortReason = null;
  this.currentInputSnapshot = null;
  this.currentOutputSnapshotRaw = null;
  this.currentOutputSnapshotResolved = null;
}
 
Example 3
Source File: Repo.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
private void runTransactionOnComplete(Transaction.Handler handler, DatabaseError error,
    boolean committed, DataSnapshot snapshot) {
  try {
    handler.onComplete(error, committed, snapshot);
  } catch (Exception e) {
    logger.error("Exception in transaction onComplete callback", e);
  }
}
 
Example 4
Source File: RxValue.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param emitter
 * @param function
 * @return
 */
@NonNull
@CheckReturnValue
public static Transaction.Handler transaction(
        @NonNull final SingleEmitter<DataSnapshot> emitter,
        @NonNull final Function<MutableData, Transaction.Result> function) {
    return new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            try {
                return function.apply(mutableData);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onComplete(@Nullable DatabaseError databaseError,
                               boolean committed,
                               @NonNull DataSnapshot dataSnapshot) {
            if (!emitter.isDisposed()) {
                if (null == databaseError) {
                    emitter.onSuccess(dataSnapshot);
                } else {
                    emitter.onError(databaseError.toException());
                }
            }
        }
    };
}
 
Example 5
Source File: RxDatabaseReference.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param emitter
 * @param function
 * @return
 */
@NonNull
@CheckReturnValue
public static Transaction.Handler transaction(
        @NonNull final SingleEmitter<DataSnapshot> emitter,
        @NonNull final Function<MutableData, Transaction.Result> function) {
    return new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            try {
                return function.apply(mutableData);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onComplete(@Nullable DatabaseError databaseError,
                               boolean committed,
                               @NonNull DataSnapshot dataSnapshot) {
            if (!emitter.isDisposed()) {
                if (null == databaseError) {
                    emitter.onSuccess(dataSnapshot);
                } else {
                    emitter.onError(databaseError.toException());
                }
            }
        }
    };
}