本文整理汇总了Java中com.google.firebase.database.DatabaseReference.updateChildren方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseReference.updateChildren方法的具体用法?Java DatabaseReference.updateChildren怎么用?Java DatabaseReference.updateChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.database.DatabaseReference
的用法示例。
在下文中一共展示了DatabaseReference.updateChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearCart
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
private void clearCart() {
if (!isCartEmpty) {
DatabaseReference myRefClear = FirebaseDatabase.getInstance().getReference("users").child(user.getUid());
myRefClear.child(user.getUid()).push();
// As firebase does not accept keys with empty values, I'm putting a dummy item with empty Strings and -1 as ints
// Quantity of items in cart is not realtime database quantity but the quantity the user wants
ArrayList<ShoppingItem> cart = new ArrayList<>();
cart.add(new ShoppingItem(-1, "", "", "", -1, -1));
Map<String, Object> cartItems = new HashMap<>();
cartItems.put("cartItems", cart);
// Adding a isCartEmpty State Variable for cart window display
Map<String, Object> cartState = new HashMap<>();
cartState.put("isCartEmpty", Boolean.TRUE);
// Updating the database for the user
myRefClear.updateChildren(cartItems);
myRefClear.updateChildren(cartState);
isCartEmpty = true;
}
}
示例2: sendMessage
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
/**
* Allows to sendMessage a message that will be stored on the server.
*
* @param message Message to be stored.
*/
public void sendMessage(Message message) {
if (message == null) {
throw new IllegalArgumentException("Cannot upload a null message to firebase");
}
Date time = message.getTime();
String messageId = String.valueOf(message.getUid());
DatabaseReference messageRef = databaseReference.child(FirebaseNodes.MESSAGES).child(message.getTo()).child(messageId);
Map<String, Object> messageUpload = new HashMap<>();
messageUpload.put("/" + FirebaseNodes.MEX_FROM, message.getFrom());
messageUpload.put("/" + FirebaseNodes.MEX_SENDER, message.getSender());
messageUpload.put("/" + FirebaseNodes.MEX_ADDRESSEE, message.getAddressee());
messageUpload.put("/" + FirebaseNodes.MEX, message.getMessage());
messageUpload.put("/" + FirebaseNodes.MEX_CHALLENGE_TYPE, message.getChallengeType());
messageUpload.put("/" + FirebaseNodes.MEX_TYPE, message.getType());
messageUpload.put("/" + FirebaseNodes.MEX_FIRST_VALUE, message.getFirstValue());
messageUpload.put("/" + FirebaseNodes.MEX_SECOND_VALUE, message.getSecondValue());
messageUpload.put("/" + FirebaseNodes.MEX_UID, message.getUid());
messageUpload.put("/" + FirebaseNodes.MEX_TIME, time);
messageRef.updateChildren(messageUpload);
}
示例3: updateChildren
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public <T> void updateChildren(DatabaseReference databaseReference,
@NonNull final ObservableEmitter<T> emitter, Map<String, Object> childUpdates) {
if (isNetworkAvailable) {
databaseReference.updateChildren(childUpdates, (databaseError, databaseReference1) -> {
if (emitter.isDisposed()) {
return;
}
if (databaseError == null) {
emitter.onComplete();
} else {
emitter.onError(new Throwable(databaseError.getMessage()));
}
});
} else {
databaseReference.updateChildren(childUpdates);
emitter.onComplete();
}
}
示例4: addChallengeNode
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
/**
* Creates a challenge under "challenges" node given the names of the opponents and
* the desired name of the challenge.
*
* @param user1 First challenger.
* @param user2 Second challenger.
* @param challengeName Name of the challenge.
*/
public void addChallengeNode(String user1, String user2, String challengeName) {
if (user1 == null || user2 == null || challengeName == null) {
throw new IllegalArgumentException("Challenge node parameters can't be null");
} else if (user1.isEmpty() || user2.isEmpty() || challengeName.isEmpty()) {
throw new IllegalArgumentException("Challenge node parameters can't be empty");
}
DatabaseReference challengeRef = databaseReference.child(FirebaseNodes.CHALLENGES).child(challengeName);
Map<String, Object> challengeUpload = new HashMap<>();
challengeUpload.put("/" + user1 + "/" + FirebaseNodes.ChallengeStatus.FINISH, false);
challengeUpload.put("/" + user1 + "/" + FirebaseNodes.ChallengeStatus.ABORT, false);
challengeUpload.put("/" + user1 + "/" + FirebaseNodes.ChallengeStatus.IN_ROOM, false);
challengeUpload.put("/" + user1 + "/" + FirebaseNodes.ChallengeStatus.READY, false);
challengeUpload.put("/" + user2 + "/" + FirebaseNodes.ChallengeStatus.FINISH, false);
challengeUpload.put("/" + user2 + "/" + FirebaseNodes.ChallengeStatus.ABORT, false);
challengeUpload.put("/" + user2 + "/" + FirebaseNodes.ChallengeStatus.IN_ROOM, false);
challengeUpload.put("/" + user2 + "/" + FirebaseNodes.ChallengeStatus.READY, false);
challengeRef.updateChildren(challengeUpload);
}
示例5: testUpdateChangesAreStoredCorrectlyInServer
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUpdateChangesAreStoredCorrectlyInServer()
throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
final DatabaseReference writer = refs.get(0);
final DatabaseReference reader = refs.get(1);
new WriteFuture(writer,
new MapBuilder().put("a", 1).put("b", 2).put("c", 3).put("d", 4).build()).timedGet();
final Semaphore semaphore = new Semaphore(0);
writer.updateChildren(MapBuilder.of("a", 42),
new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
assertNull(error);
semaphore.release(1);
}
});
TestHelpers.waitFor(semaphore);
DataSnapshot snap = TestHelpers.getSnap(reader);
Map<String, Object> expected = new MapBuilder().put("a", 42L).put("b", 2L).put("c", 3L)
.put("d", 4L).build();
Object result = snap.getValue();
TestHelpers.assertDeepEquals(expected, result);
}
示例6: testUpdateAffectPriorityRemotely
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUpdateAffectPriorityRemotely()
throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
DatabaseReference reader = refs.get(0);
DatabaseReference writer = refs.get(1);
new WriteFuture(writer, new MapBuilder().put("a", 1).put("b", 2).put("c", 3).build(), "testpri")
.timedGet();
DataSnapshot snap = TestHelpers.getSnap(reader);
assertEquals("testpri", snap.getPriority());
final Semaphore semaphore = new Semaphore(0);
writer.updateChildren(MapBuilder.of("a", 4),
new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
assertNull(error);
semaphore.release(1);
}
});
TestHelpers.waitFor(semaphore);
snap = TestHelpers.getSnap(reader);
assertEquals("testpri", snap.getPriority());
}
示例7: addCrisisToDatabase
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public void addCrisisToDatabase(Crisis inputCrisis){
DatabaseReference crisisNode = mDatabase.child("crisis");
DatabaseReference newCrisisNode = crisisNode.push();
inputCrisis.setCrisisID(newCrisisNode.getKey());
newCrisisNode.updateChildren(inputCrisis.toMap());
}
示例8: testPriorityUpdate
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testPriorityUpdate() throws InterruptedException {
List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
final DatabaseReference writer = refs.get(0);
final DatabaseReference reader = refs.get(1);
Map<String, Object> writeValue = new MapBuilder().put("a", 5).put(".priority", "pri1").build();
Map<String, Object> updateValue = new MapBuilder().put("a", 6).put(".priority", "pri2")
.put("b", new MapBuilder().put(".priority", "pri3").put("c", 10).build()).build();
final Semaphore semaphore = new Semaphore(0);
writer.setValueAsync(writeValue);
writer.updateChildren(updateValue, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
assertNull(error);
semaphore.release(1);
}
});
TestHelpers.waitFor(semaphore);
DataSnapshot snap = TestHelpers.getSnap(reader);
assertEquals(6L, snap.child("a").getValue());
assertEquals("pri2", snap.getPriority());
assertEquals("pri3", snap.child("b").getPriority());
assertEquals(10L, snap.child("b/c").getValue());
}
示例9: insert
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
private void insert(DataSnapshot dataSnapshot,OnPaidOperationListener listener, final Book bookApi, DatabaseReference ref){
if(bookApi.getId() == null ){ //Here we generate our id
bookApi.setId(ref.push().getKey());
}
ref.updateChildren(Collections.singletonMap(bookApi.getId(), (Object) bookApi));
listener.onInsertBook(true);
}
示例10: push
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
/**
* Push the thread to firebase.
**/
public Promise<BThread, BError, Void> push(){
if (DEBUG) Timber.v("push");
final DeferredObject<BThread, BError, Void> deferred = new DeferredObject<>();
DatabaseReference ref = null;
if (StringUtils.isNotEmpty(model.getEntityID()))
{
ref = FirebasePaths.threadRef(model.getEntityID());
}
else
{
// Creating a new entry for this thread.
ref = FirebasePaths.threadRef().push();
model.setEntityID(ref.getKey());
// Updating the database.
DaoCore.updateEntity(model);
}
ref.updateChildren(serialize(), new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
if (firebaseError != null)
{
deferred.reject(getFirebaseError(firebaseError));
}
else deferred.resolve(model);
}
});
return deferred.promise();
}
示例11: updateLocation
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public static Location updateLocation(Location Loc) {
DatabaseReference NewRef = LocationRef.child(String.valueOf(Loc.getID()));
Map<String, Object> LocUpdates = new HashMap<String, Object >();
LocUpdates.put(String.valueOf(Loc.getID()),Loc);
NewRef.updateChildren(LocUpdates);
return Loc;
}
示例12: updateProduct_Type
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public static Product_Type updateProduct_Type(Product_Type Pro) {
DatabaseReference NewRef = Product_TypeRef.child(String.valueOf(Pro.getID()));
Map<String, Object> ProUpdates = new HashMap<String, Object >();
ProUpdates.put(String.valueOf(Pro.getID()),Pro);
NewRef.updateChildren(ProUpdates);
return Pro;
}
示例13: updateOperation
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public static Operation updateOperation(Operation Opt) {
DatabaseReference NewRef = OperationRef.child(String.valueOf(Opt.getID()));
Map<String, Object> OptUpdates = new HashMap<String, Object >();
OptUpdates.put(String.valueOf(Opt.getID()),Opt);
NewRef.updateChildren(OptUpdates);
return Opt;
}
示例14: createOrUpdatePost
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public void createOrUpdatePost(Post post) {
try {
DatabaseReference databaseReference = database.getReference();
Map<String, Object> postValues = post.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/posts/" + post.getId(), postValues);
databaseReference.updateChildren(childUpdates);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
示例15: updateAddress
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public static Address updateAddress(Address Addr) {
DatabaseReference NewRef = AddressRef.child(String.valueOf(Addr.getID()));
Map<String, Object> AddrUpdates = new HashMap<String, Object >();
AddrUpdates.put(String.valueOf(Addr.getID()),Addr);
NewRef.updateChildren(AddrUpdates);
return Addr;
}