Search in sources :

Example 16 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest 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();
}
Also used : CommitRequest(com.google.firestore.v1beta1.CommitRequest) GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) Menu(org.roguewave.grpc.util.gfx.Menu)

Example 17 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class FirestoreTest method arrayRemoveWithPojo.

@Test
public void arrayRemoveWithPojo() throws ExecutionException, InterruptedException {
    doReturn(commitResponse(1, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    DocumentReference doc = firestoreMock.document("coll/doc");
    doc.update("array", FieldValue.arrayRemove(SINGLE_FIELD_OBJECT)).get();
    CommitRequest expectedRequest = commit(update(Collections.emptyMap(), new ArrayList<>()), transform("array", arrayRemove(SINGLE_FIELD_VALUE)));
    CommitRequest actualRequest = commitCapture.getValue();
    assertEquals(expectedRequest, actualRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 18 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method setDocumentWithFloat.

@Test
public void setDocumentWithFloat() throws Exception {
    doReturn(commitResponse(1, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.set(documentReference, LocalFirestoreHelper.SINGLE_FLOAT_MAP);
    List<Write> writes = new ArrayList<>();
    writes.add(set(LocalFirestoreHelper.SINGLE_FLOAT_PROTO));
    assertEquals(1, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    for (int i = 0; i < writeResults.size(); ++i) {
        assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
    }
    CommitRequest commitRequest = commitCapture.getValue();
    assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) Write(com.google.firestore.v1.Write) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 19 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class DocumentReferenceTest method updateNestedDocument.

@Test
public void updateNestedDocument() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    Map<String, Object> nestedObject = new HashMap<>();
    nestedObject.put("a", "b");
    nestedObject.put("c.d", "e");
    nestedObject.put("f.g.h", "i");
    Map<String, Value> expandedObject = new HashMap<>();
    expandedObject.put("a", string("b"));
    expandedObject.put("c", object("d", string("e")));
    expandedObject.put("f", object("g", object("h", string("i"))));
    documentReference.update(nestedObject).get();
    CommitRequest expectedCommit = commit(update(expandedObject, new ArrayList<>(nestedObject.keySet())));
    assertCommitEquals(expectedCommit, commitCapture.getValue());
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) HashMap(java.util.HashMap) Value(com.google.firestore.v1.Value) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 20 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class DocumentReferenceTest method updateDocumentWithPreconditions.

@Test
public void updateDocumentWithPreconditions() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    Precondition options = Precondition.updatedAt(Timestamp.ofTimeSecondsAndNanos(479978400, 123000000));
    documentReference.update(SINGLE_FIELD_MAP, options).get();
    documentReference.update(options, "foo", "bar").get();
    com.google.firestore.v1.Precondition.Builder precondition = com.google.firestore.v1.Precondition.newBuilder();
    precondition.getUpdateTimeBuilder().setSeconds(479978400).setNanos(123000000);
    CommitRequest expectedCommit = commit(update(SINGLE_FIELD_PROTO, Collections.singletonList("foo"), precondition.build()));
    for (CommitRequest request : commitCapture.getAllValues()) {
        assertCommitEquals(expectedCommit, request);
    }
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)85 CommitRequest (com.google.spanner.v1.CommitRequest)47 CommitRequest (com.google.firestore.v1.CommitRequest)40 CommitResponse (com.google.firestore.v1.CommitResponse)40 ArrayList (java.util.ArrayList)26 Connection (java.sql.Connection)23 ByteString (com.google.protobuf.ByteString)14 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)12 SQLException (java.sql.SQLException)12 Statement (java.sql.Statement)12 CopyManager (org.postgresql.copy.CopyManager)11 BaseConnection (org.postgresql.core.BaseConnection)11 ExecuteBatchDmlRequest (com.google.spanner.v1.ExecuteBatchDmlRequest)10 ArrayValue (com.google.firestore.v1.ArrayValue)9 MapValue (com.google.firestore.v1.MapValue)9 Value (com.google.firestore.v1.Value)9 Write (com.google.firestore.v1.Write)9 StringReader (java.io.StringReader)9 HashMap (java.util.HashMap)9 AbstractMessage (com.google.protobuf.AbstractMessage)8