当前位置: 首页>>代码示例>>Java>>正文


Java ApiFuture.get方法代码示例

本文整理汇总了Java中com.google.api.core.ApiFuture.get方法的典型用法代码示例。如果您正苦于以下问题:Java ApiFuture.get方法的具体用法?Java ApiFuture.get怎么用?Java ApiFuture.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.core.ApiFuture的用法示例。


在下文中一共展示了ApiFuture.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrieveAllDocuments

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
void retrieveAllDocuments() throws Exception {
  // [START fs_get_all]
  // asynchronously retrieve all users
  ApiFuture<QuerySnapshot> query = db.collection("users").get();
  // ...
  // query.get() blocks on response
  QuerySnapshot querySnapshot = query.get();
  List<DocumentSnapshot> documents = querySnapshot.getDocuments();
  for (DocumentSnapshot document : documents) {
    System.out.println("User: " + document.getId());
    System.out.println("First: " + document.getString("first"));
    if (document.contains("middle")) {
      System.out.println("Middle: " + document.getString("middle"));
    }
    System.out.println("Last: " + document.getString("last"));
    System.out.println("Born: " + document.getLong("born"));
  }
  // [END fs_get_all]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:20,代码来源:Quickstart.java

示例2: testGetError

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
@Test
public void testGetError() throws Exception {
  Task<String> task = Tasks.forException(new RuntimeException("test"));
  ApiFuture<String> future = new TaskToApiFuture<>(task);
  try {
    future.get();
  } catch (ExecutionException e) {
    assertEquals("test", e.getCause().getMessage());
  }
  assertFalse(future.isCancelled());
  assertTrue(future.isDone());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:13,代码来源:TaskToApiFutureTest.java

示例3: runAQuery

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
void runAQuery() throws Exception {
  // [START fs_add_query]
  // asynchronously query for all users born before 1900
  ApiFuture<QuerySnapshot> query =
      db.collection("users").whereLessThan("born", 1900).get();
  // ...
  // query.get() blocks on response
  QuerySnapshot querySnapshot = query.get();
  List<DocumentSnapshot> documents = querySnapshot.getDocuments();
  for (DocumentSnapshot document : documents) {
    System.out.println("User: " + document.getId());
    System.out.println("First: " + document.getString("first"));
    if (document.contains("middle")) {
      System.out.println("Middle: " + document.getString("middle"));
    }
    System.out.println("Last: " + document.getString("last"));
    System.out.println("Born: " + document.getLong("born"));
  }
  // [END fs_add_query]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:Quickstart.java

示例4: updateSimpleDocument

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
/** Partially update a document using the .update(field1, value1..) method. */
void updateSimpleDocument() throws Exception {
  db.collection("cities").document("DC").set(new City("Washington D.C.")).get();
  // [START fs_update_doc]
  // Update an existing document
  DocumentReference docRef = db.collection("cities").document("DC");

  // (async) Update one field
  ApiFuture<WriteResult> future = docRef.update("capital", true);

  // ...
  WriteResult result = future.get();
  System.out.println("Write result: " + result);
  // [END fs_update_doc]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:16,代码来源:ManageDataSnippets.java

示例5: updateNestedFields

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
/** Partial update nested fields of a document. */
void updateNestedFields() throws Exception {
  //CHECKSTYLE OFF: VariableDeclarationUsageDistance
  // [START fs_update_nested_fields]
  // Create an initial document to update
  DocumentReference frankDocRef = db.collection("users").document("frank");
  Map<String, Object> initialData = new HashMap<>();
  initialData.put("name", "Frank");
  initialData.put("age", 12);

  Map<String, Object> favorites = new HashMap<>();
  favorites.put("food", "Pizza");
  favorites.put("color", "Blue");
  favorites.put("subject", "Recess");
  initialData.put("favorites", favorites);

  ApiFuture<WriteResult> initialResult = frankDocRef.set(initialData);
  // Confirm that data has been successfully saved by blocking on the operation
  initialResult.get();

  // Update age and favorite color
  Map<String, Object> updates = new HashMap<>();
  updates.put("age", 13);
  updates.put("favorites.color", "Red");

  // Async update document
  ApiFuture<WriteResult> writeResult = frankDocRef.update(updates);
  // ...
  System.out.println("Update time : " + writeResult.get().getUpdateTime());
  // [END fs_update_nested_fields]
  //CHECKSTYLE ON: VariableDeclarationUsageDistance
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:33,代码来源:ManageDataSnippets.java

示例6: writeBatch

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
/** Write documents in a batch. */
void writeBatch() throws Exception {
  db.collection("cities").document("SF").set(new City()).get();
  db.collection("cities").document("LA").set(new City()).get();

  // [START fs_write_batch]
  // Get a new write batch
  WriteBatch batch = db.batch();
  // Set the value of 'NYC'
  DocumentReference nycRef = db.collection("cities").document("NYC");
  batch.set(nycRef, new City());

  // Update the population of 'SF'
  DocumentReference sfRef = db.collection("cities").document("SF");
  batch.update(sfRef, "population", 1000000L);

  // Delete the city 'LA'
  DocumentReference laRef = db.collection("cities").document("LA");
  batch.delete(laRef);

  // asynchronously commit the batch
  ApiFuture<List<WriteResult>> future = batch.commit();
  // ...
  // future.get() blocks on batch commit operation
  for (WriteResult result :future.get()) {
    System.out.println("Update time : " + result.getUpdateTime());
  }
  // [END fs_write_batch]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:30,代码来源:ManageDataSnippets.java

示例7: deleteAllDocuments

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
private void deleteAllDocuments() throws Exception {
  ApiFuture<QuerySnapshot> future = db.collection("users").get();
  QuerySnapshot querySnapshot = future.get();
  for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
    // block on delete operation
    db.document("users/" + doc.getId()).delete().get();
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:QuickstartIT.java

示例8: getResults

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
private List<String> getResults(Query query) throws Exception {
  // asynchronously retrieve query results
  ApiFuture<QuerySnapshot> future = query.get();
  // block on response
  QuerySnapshot querySnapshot = future.get();
  List<String> docIds = new ArrayList<>();
  for (DocumentSnapshot document : querySnapshot.getDocuments()) {
    docIds.add(document.getId());
  }
  return docIds;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:12,代码来源:QueryDataSnippetsIT.java

示例9: deleteAllDocuments

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
private static void deleteAllDocuments() throws Exception {
  ApiFuture<QuerySnapshot> future = db.collection("cities").get();
  QuerySnapshot querySnapshot = future.get();
  for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
    // block on delete operation
    db.collection("cities").document(doc.getId()).delete().get();
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:QueryDataSnippetsIT.java

示例10: testSimpleTransaction

import com.google.api.core.ApiFuture; //导入方法依赖的package包/类
@Test
public void testSimpleTransaction() throws Exception {
  DocumentReference docRef = db.collection("cities").document("SF");
  ApiFuture<Void> future = manageDataSnippets.runSimpleTransaction();
  future.get();
  Map<String, Object> data = getDocumentDataAsMap(docRef);
  assertEquals(data.get("population"), 860000L + 1L);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:ManageDataSnippetsIT.java


注:本文中的com.google.api.core.ApiFuture.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。