本文整理汇总了Java中com.google.firebase.database.Transaction.Handler方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.Handler方法的具体用法?Java Transaction.Handler怎么用?Java Transaction.Handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.database.Transaction
的用法示例。
在下文中一共展示了Transaction.Handler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TransactionData
import com.google.firebase.database.Transaction; //导入方法依赖的package包/类
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;
}
示例2: subscribe
import com.google.firebase.database.Transaction; //导入方法依赖的package包/类
@Override public void subscribe(final CompletableEmitter emitter) {
final Transaction.Handler handler = new Transaction.Handler() {
@Override public Transaction.Result doTransaction(MutableData mutableData) {
try {
return task.apply(mutableData);
} catch (Exception e) {
//TODO: Is this enough?
throw new RuntimeException(e);
}
}
@Override public void onComplete(DatabaseError databaseError, boolean committed,
DataSnapshot dataSnapshot) {
if (!emitter.isDisposed()) {
if (null == databaseError) {
emitter.onComplete();
} else {
emitter.onError(databaseError.toException());
}
}
}
};
ref.runTransaction(handler, fireLocalEvents);
}
示例3: runTransactionOnComplete
import com.google.firebase.database.Transaction; //导入方法依赖的package包/类
private void runTransactionOnComplete(Transaction.Handler handler, DatabaseError error,
boolean committed, DataSnapshot snapshot) {
try {
handler.onComplete(error, committed, snapshot);
} catch (Exception e) {
operationLogger.error("Exception in transaction onComplete callback", e);
}
}
示例4: transaction
import com.google.firebase.database.Transaction; //导入方法依赖的package包/类
/**
* @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());
}
}
}
};
}