use of com.google.firebase.firestore.model.mutation.MutationResult in project firebase-android-sdk by firebase.
the class Datastore method commit.
public Task<List<MutationResult>> commit(List<Mutation> mutations) {
CommitRequest.Builder builder = CommitRequest.newBuilder();
builder.setDatabase(serializer.databaseName());
for (Mutation mutation : mutations) {
builder.addWrites(serializer.encodeMutation(mutation));
}
return channel.runRpc(FirestoreGrpc.getCommitMethod(), builder.build()).continueWith(workerQueue.getExecutor(), task -> {
if (!task.isSuccessful()) {
if (task.getException() instanceof FirebaseFirestoreException && ((FirebaseFirestoreException) task.getException()).getCode() == FirebaseFirestoreException.Code.UNAUTHENTICATED) {
channel.invalidateToken();
}
throw task.getException();
}
CommitResponse response = task.getResult();
SnapshotVersion commitVersion = serializer.decodeVersion(response.getCommitTime());
int count = response.getWriteResultsCount();
ArrayList<MutationResult> results = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
com.google.firestore.v1.WriteResult result = response.getWriteResults(i);
results.add(serializer.decodeMutationResult(result, commitVersion));
}
return results;
});
}
use of com.google.firebase.firestore.model.mutation.MutationResult in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeMutationResult.
public MutationResult decodeMutationResult(com.google.firestore.v1.WriteResult proto, SnapshotVersion commitVersion) {
// NOTE: Deletes don't have an updateTime but the commit timestamp from the containing
// CommitResponse or WriteResponse indicates essentially that the delete happened no later than
// that. For our purposes we don't care exactly when the delete happened so long as we can tell
// when an update on the watch stream is at or later than that change.
SnapshotVersion version = decodeVersion(proto.getUpdateTime());
if (SnapshotVersion.NONE.equals(version)) {
version = commitVersion;
}
int transformResultsCount = proto.getTransformResultsCount();
List<Value> transformResults = new ArrayList<>(transformResultsCount);
for (int i = 0; i < transformResultsCount; i++) {
transformResults.add(proto.getTransformResults(i));
}
return new MutationResult(version, transformResults);
}
use of com.google.firebase.firestore.model.mutation.MutationResult in project firebase-android-sdk by firebase.
the class WriteStream method onNext.
@Override
public void onNext(WriteResponse response) {
lastStreamToken = response.getStreamToken();
if (!handshakeComplete) {
// The first response is the handshake response
handshakeComplete = true;
listener.onHandshakeComplete();
} else {
// A successful first write response means the stream is healthy,
// Note, that we could consider a successful handshake healthy, however,
// the write itself might be causing an error we want to back off from.
backoff.reset();
SnapshotVersion commitVersion = serializer.decodeVersion(response.getCommitTime());
int count = response.getWriteResultsCount();
List<MutationResult> results = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
com.google.firestore.v1.WriteResult result = response.getWriteResults(i);
results.add(serializer.decodeMutationResult(result, commitVersion));
}
listener.onWriteResponse(commitVersion, results);
}
}
use of com.google.firebase.firestore.model.mutation.MutationResult in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method acknowledgeMutationWithTransformResults.
private void acknowledgeMutationWithTransformResults(long documentVersion, Object... transformResult) {
MutationBatch batch = batches.remove(0);
SnapshotVersion version = version(documentVersion);
List<MutationResult> mutationResults = Collections.singletonList(new MutationResult(version, emptyList()));
if (transformResult.length != 0) {
mutationResults = Arrays.stream(transformResult).map(r -> new MutationResult(version, Collections.singletonList(TestUtil.wrap(r)))).collect(Collectors.toList());
}
MutationBatchResult result = MutationBatchResult.create(batch, version, mutationResults, WriteStream.EMPTY_STREAM_TOKEN);
lastChanges = localStore.acknowledgeBatch(result);
}
use of com.google.firebase.firestore.model.mutation.MutationResult in project firebase-android-sdk by firebase.
the class SpecTestCase method doWriteAck.
private void doWriteAck(JSONObject writeAckSpec) throws Exception {
long version = writeAckSpec.getLong("version");
boolean keepInQueue = writeAckSpec.optBoolean("keepInQueue", false);
assertFalse("'keepInQueue=true' is not supported on Android and should only be set in multi-client tests", keepInQueue);
Pair<Mutation, Task<Void>> write = getCurrentOutstandingWrites().remove(0);
validateNextWriteSent(write.first);
MutationResult mutationResult = new MutationResult(version(version), /*transformResults=*/
Collections.emptyList());
queue.runSync(() -> datastore.ackWrite(version(version), singletonList(mutationResult)));
}
Aggregations