use of org.projectnessie.versioned.Unchanged in project nessie by projectnessie.
the class PersistVersionStore method commit.
@Override
public Hash commit(@Nonnull BranchName branch, @Nonnull Optional<Hash> expectedHead, @Nonnull METADATA metadata, @Nonnull List<Operation<CONTENT>> operations, @Nonnull Callable<Void> validator) throws ReferenceNotFoundException, ReferenceConflictException {
ImmutableCommitAttempt.Builder commitAttempt = ImmutableCommitAttempt.builder().commitToBranch(branch).expectedHead(expectedHead).commitMetaSerialized(serializeMetadata(metadata)).validator(validator);
for (Operation<CONTENT> operation : operations) {
if (operation instanceof Put) {
Put<CONTENT> op = (Put<CONTENT>) operation;
ContentId contentId = ContentId.of(storeWorker.getId(op.getValue()));
commitAttempt.addPuts(KeyWithBytes.of(op.getKey(), contentId, storeWorker.getPayload(op.getValue()), storeWorker.toStoreOnReferenceState(op.getValue())));
if (storeWorker.requiresGlobalState(op.getValue())) {
ByteString newState = storeWorker.toStoreGlobalState(op.getValue());
Optional<ByteString> expectedValue;
if (op.getExpectedValue() != null) {
if (storeWorker.getType(op.getValue()) != storeWorker.getType(op.getExpectedValue())) {
throw new IllegalArgumentException(String.format("Content-type for conditional put-operation for key '%s' for 'value' and 'expectedValue' must be the same, but are '%s' and '%s'.", op.getKey(), storeWorker.getType(op.getValue()), storeWorker.getType(op.getExpectedValue())));
}
if (!contentId.equals(ContentId.of(storeWorker.getId(op.getExpectedValue())))) {
throw new IllegalArgumentException(String.format("Conditional put-operation key '%s' has different content-ids.", op.getKey()));
}
expectedValue = Optional.of(storeWorker.toStoreGlobalState(op.getExpectedValue()));
} else {
expectedValue = Optional.empty();
}
commitAttempt.putExpectedStates(contentId, expectedValue);
commitAttempt.putGlobal(contentId, newState);
} else {
if (op.getExpectedValue() != null) {
throw new IllegalArgumentException(String.format("Content-type '%s' for put-operation for key '%s' does not support global state, expected-value not supported for this content-type.", storeWorker.getType(op.getValue()), op.getKey()));
}
}
} else if (operation instanceof Delete) {
commitAttempt.addDeletes(operation.getKey());
} else if (operation instanceof Unchanged) {
commitAttempt.addUnchanged(operation.getKey());
} else {
throw new IllegalArgumentException(String.format("Unknown operation type '%s'", operation));
}
}
return databaseAdapter.commit(commitAttempt.build());
}
Aggregations