use of com.yahoo.document.TestAndSetCondition in project vespa by vespa-engine.
the class RestApi method createUpdateOperation.
private VespaXMLFeedReader.Operation createUpdateOperation(HttpRequest request, String id, String condition, Optional<Boolean> create) {
final VespaXMLFeedReader.Operation operationUpdate = singleDocumentParser.parseUpdate(request.getData(), id);
if (condition != null && !condition.isEmpty()) {
operationUpdate.getDocumentUpdate().setCondition(new TestAndSetCondition(condition));
}
create.ifPresent(c -> operationUpdate.getDocumentUpdate().setCreateIfNonExistent(c));
return operationUpdate;
}
use of com.yahoo.document.TestAndSetCondition in project vespa by vespa-engine.
the class OperationHandlerImpl method delete.
@Override
public void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException {
SyncSession syncSession = syncSessions.alloc();
Response response;
try {
Instant startTime = Instant.now();
DocumentId id = new DocumentId(restUri.generateFullId());
DocumentRemove documentRemove = new DocumentRemove(id);
setRoute(syncSession, route);
if (condition != null && !condition.isEmpty()) {
documentRemove.setCondition(new TestAndSetCondition(condition));
}
syncSession.remove(documentRemove);
metricsHelper.reportSuccessful(DocumentOperationType.REMOVE, startTime);
return;
} catch (DocumentAccessException documentException) {
if (documentException.hasConditionNotMetError()) {
response = Response.createErrorResponse(412, "Condition not met: " + documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_CONDITION_NOT_MET);
} else {
response = Response.createErrorResponse(400, documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_EXCPETION);
}
} catch (Exception e) {
response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED);
} finally {
syncSessions.free(syncSession);
}
metricsHelper.reportFailure(DocumentOperationType.REMOVE, DocumentOperationStatus.fromHttpStatusCode(response.getStatus()));
throw new RestApiException(response);
}
Aggregations