use of org.roguewave.grpc.util.GRPCFirebaseClientFactory 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 org.roguewave.grpc.util.GRPCFirebaseClientFactory in project grpc-gcp-java by GoogleCloudPlatform.
the class BatchGetDocuments method batchGetDocumentsCall.
public void batchGetDocumentsCall() {
List<String> docList = new ArrayList<String>();
System.out.println("\n :: Batch Retrieve Documents :: \n");
Scanner sc = new Scanner(System.in);
String input = "initial";
FirestoreGrpc.FirestoreStub firestoreStub = new GRPCFirebaseClientFactory().createFirebaseClient().getFirestoreStub();
DrawDocument dd = new DrawDocument();
while (!input.matches("DONE")) {
System.out.print("Enter Document Id (Enter DONE when finished): ");
input = sc.next();
if (!input.matches("DONE")) {
docList.add("projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + input);
}
}
BatchGetDocumentsRequest batchGetDocsRequest = BatchGetDocumentsRequest.newBuilder().setDatabase("projects/firestoretestclient/databases/(default)").addAllDocuments(docList).build();
final CountDownLatch finishLatch = new CountDownLatch(1);
StreamObserver respStream = new StreamObserver() {
@Override
public void onNext(Object resp) {
BatchGetDocumentsResponse response = (BatchGetDocumentsResponse) resp;
Document doc = response.getFound();
dd.draw(doc);
}
@Override
public void onError(Throwable throwable) {
System.out.println("Error During Call: " + throwable.getMessage());
finishLatch.countDown();
}
@Override
public void onCompleted() {
Menu menu = new Menu();
menu.draw();
finishLatch.countDown();
}
};
try {
firestoreStub.batchGetDocuments(batchGetDocsRequest, respStream);
finishLatch.await(1, TimeUnit.MINUTES);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
}
}
use of org.roguewave.grpc.util.GRPCFirebaseClientFactory 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 org.roguewave.grpc.util.GRPCFirebaseClientFactory in project grpc-gcp-java by GoogleCloudPlatform.
the class DeleteDocument method deleteDocumentCall.
public void deleteDocumentCall() {
Scanner sc = new Scanner(System.in);
System.out.println("\n :: Deleting a Document ::\n");
System.out.print("Enter Document Name: ");
String docName = "projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + sc.next();
FirestoreGrpc.FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
DeleteDocumentRequest delReq = DeleteDocumentRequest.newBuilder().setName(docName).build();
try {
blockingStub.deleteDocument(delReq);
System.out.println("Finished call...");
} catch (Exception e) {
System.out.println("Error executing blocking stub call: " + (e.getMessage() + "\n" + e.getCause().toString()));
}
Menu menu = new Menu();
menu.draw();
}
use of org.roguewave.grpc.util.GRPCFirebaseClientFactory 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();
}
Aggregations