use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippetsIT method testAddDocWithAutoGenId.
@Test
public void testAddDocWithAutoGenId() throws Exception {
String autoId = manageDataSnippets.addDocumentDataWithAutoGeneratedId();
City city = new City("Tokyo");
city.setCountry("Japan");
DocumentReference docRef = db.collection("cities").document(autoId);
assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
}
use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippetsIT method testUpdateSimpleDocument.
@Test
public void testUpdateSimpleDocument() throws Exception {
manageDataSnippets.updateSimpleDocument();
DocumentReference docRef = db.collection("cities").document("DC");
City city = new City("Washington D.C.");
city.setCapital(true);
assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
}
use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.
the class RetrieveDataSnippets method prepareExamples.
/**
* Create cities collection and add sample documents.
*/
void prepareExamples() throws Exception {
// [START fs_retrieve_create_examples]
CollectionReference cities = db.collection("cities");
List<ApiFuture<WriteResult>> futures = new ArrayList<>();
futures.add(cities.document("SF").set(new City("San Francisco", "CA", "USA", false, 860000L)));
futures.add(cities.document("LA").set(new City("Los Angeles", "CA", "USA", false, 3900000L)));
futures.add(cities.document("DC").set(new City("Washington D.C.", null, "USA", true, 680000L)));
futures.add(cities.document("TOK").set(new City("Tokyo", null, "Japan", true, 9000000L)));
futures.add(cities.document("BJ").set(new City("Beijing", null, "China", true, 21500000L)));
// (optional) block on operation
ApiFutures.allAsList(futures).get();
// [END fs_retrieve_create_examples]
}
use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippets method updateSimpleDocument.
/**
* 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]
}
use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippets method addDocumentDataAfterAutoGeneratingId.
/**
* Add data to a document after generating the document id.
*
* @return auto generated id
*/
String addDocumentDataAfterAutoGeneratingId() throws Exception {
City data = new City();
// [START fs_add_doc_data_after_auto_id]
// Add document data after generating an id.
DocumentReference addedDocRef = db.collection("cities").document();
System.out.println("Added document with ID: " + addedDocRef.getId());
// later...
ApiFuture<WriteResult> writeResult = addedDocRef.set(data);
// [END fs_add_doc_data_after_auto_id]
// writeResult.get() blocks on operation
System.out.println("Update time : " + writeResult.get().getUpdateTime());
return addedDocRef.getId();
}
Aggregations