use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class UpdateDocument method updateDocumentCall.
public void updateDocumentCall() {
System.out.println("\n:: Updating a Document ::\n");
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
Scanner sc = new Scanner(System.in);
System.out.print("Enter Document Name: ");
String docName = sc.next();
GetDocumentRequest getDocumentRequest = GetDocumentRequest.newBuilder().setName("projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + docName).build();
Document doc;
try {
doc = blockingStub.getDocument(getDocumentRequest);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
return;
}
HashMap<String, Value> fieldsMap;
MakeFieldsMap mfm = new MakeFieldsMap();
fieldsMap = mfm.makeFieldsMap();
doc = doc.toBuilder().putAllFields(fieldsMap).build();
Iterator it = fieldsMap.entrySet().iterator();
DocumentMask docMask = DocumentMask.newBuilder().build();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
docMask = docMask.toBuilder().addFieldPaths(pair.getKey().toString()).build();
}
UpdateDocumentRequest updateDocumentRequest = UpdateDocumentRequest.newBuilder().setDocument(doc).setMask(docMask).build();
try {
blockingStub.updateDocument(updateDocumentRequest);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
return;
}
System.out.println("Success!");
Menu menu = new Menu();
menu.draw();
}
use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class Commit method commitCall.
public void commitCall() {
System.out.println("\n:: Committing Transaction ::\n");
if (Main.transactionId == null) {
System.out.println("WARNING: No current transaction open, run BeginTransaction first...");
return;
} else {
System.out.println("Found Transaction ID '" + Main.transactionId.toString() + "'. Committing....");
}
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
CommitRequest commitRequest = CommitRequest.newBuilder().setTransaction(Main.transactionId).setDatabase("projects/firestoretestclient/databases/(default)").build();
try {
blockingStub.commit(commitRequest);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
return;
}
System.out.println("Success!");
Menu menu = new Menu();
menu.draw();
}
use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class RunQuery method runQueryCall.
public void runQueryCall() {
System.out.println(":: Running a Query ::");
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
DrawDocument dd = new DrawDocument();
Scanner sc = new Scanner(System.in);
System.out.print("Enter field to query: ");
String queryField = sc.next();
StructuredQuery.FieldReference fr = StructuredQuery.FieldReference.newBuilder().setFieldPath(queryField).build();
StructuredQuery.Projection proj = StructuredQuery.Projection.newBuilder().addFields(fr).build();
StructuredQuery sq = StructuredQuery.newBuilder().setSelect(proj).build();
RunQueryRequest runQueryRequest = RunQueryRequest.newBuilder().setStructuredQuery(sq).setParent("projects/firestoretestclient/databases/(default)/documents").build();
Iterator<RunQueryResponse> runQueryResponse;
try {
runQueryResponse = blockingStub.runQuery(runQueryRequest);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
return;
}
System.out.println("Result set:\n");
while (runQueryResponse.hasNext()) {
RunQueryResponse response = runQueryResponse.next();
Document doc = response.getDocument();
dd.draw(doc);
}
System.out.println("Done!");
Menu menu = new Menu();
menu.draw();
}
use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class ListDocuments method listDocumentsCall.
public void listDocumentsCall() {
System.out.println("\n:: Listing all Documents ::\n");
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
ListDocumentsRequest ldr = ListDocumentsRequest.newBuilder().setParent("projects/firestoretestclient/databases/(default)/documents").setCollectionId("GrpcTestData").build();
try {
ListDocumentsResponse listDocumentsResponse = blockingStub.listDocuments(ldr);
List<Document> allDocs = listDocumentsResponse.getDocumentsList();
DrawDocument dd = new DrawDocument();
for (Document doc : allDocs) {
dd.draw(doc);
}
Menu menu = new Menu();
menu.draw();
System.out.println("Finished call...");
} catch (Exception e) {
System.out.println("Error executing streaming stub call: " + (e.getMessage() + "\n" + e.getCause().toString()));
}
}
use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class BeginTransaction method beginTransactionCall.
public void beginTransactionCall() {
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
TransactionOptions tOpts = TransactionOptions.newBuilder().build();
BeginTransactionRequest beginTransactionRequest = BeginTransactionRequest.newBuilder().setDatabase("projects/firestoretestclient/databases/(default)").setOptions(tOpts).build();
BeginTransactionResponse response;
try {
response = blockingStub.beginTransaction(beginTransactionRequest);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
return;
}
System.out.println("Began Transaction: " + response.getTransaction().toString());
Main.transactionId = response.getTransaction();
Menu menu = new Menu();
menu.draw();
}
Aggregations