use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class JsonReader method readSingleDocument.
/**
* Reads a single operation. The operation is not expected to be part of an array.
* @param operationType the type of operation (update or put)
* @param docIdString document ID.
* @return the document
*/
public DocumentOperation readSingleDocument(DocumentParser.SupportedOperation operationType, String docIdString) {
DocumentId docId = new DocumentId(docIdString);
final DocumentParseInfo documentParseInfo;
try {
DocumentParser documentParser = new DocumentParser(parser);
documentParseInfo = documentParser.parse(Optional.of(docId)).get();
} catch (IOException e) {
state = END_OF_FEED;
throw new RuntimeException(e);
}
documentParseInfo.operationType = operationType;
VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader();
DocumentOperation operation = vespaJsonDocumentReader.createDocumentOperation(getDocumentTypeFromString(documentParseInfo.documentId.getDocType(), typeManager), documentParseInfo);
operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.condition));
return operation;
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class SingleDocumentParser method parse.
private VespaXMLFeedReader.Operation parse(InputStream inputStream, String docId, DocumentParser.SupportedOperation supportedOperation) {
final JsonReader reader = new JsonReader(docMan, inputStream, jsonFactory);
final DocumentOperation documentOperation = reader.readSingleDocument(supportedOperation, docId);
VespaXMLFeedReader.Operation operation = new VespaXMLFeedReader.Operation();
try {
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (supportedOperation == DocumentParser.SupportedOperation.PUT) {
operation.setDocument(((DocumentPut) documentOperation).getDocument());
} else {
operation.setDocumentUpdate((DocumentUpdate) documentOperation);
}
// (A potentially empty) test-and-set condition is always set by JsonReader
operation.setCondition(documentOperation.getCondition());
return operation;
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class VespaJsonDocumentReader method createDocumentOperation.
public DocumentOperation createDocumentOperation(DocumentType documentType, DocumentParseInfo documentParseInfo) {
final DocumentOperation documentOperation;
try {
switch(documentParseInfo.operationType) {
case PUT:
documentOperation = new DocumentPut(new Document(documentType, documentParseInfo.documentId));
readPut(documentParseInfo.fieldsBuffer, (DocumentPut) documentOperation);
verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
break;
case REMOVE:
documentOperation = new DocumentRemove(documentParseInfo.documentId);
break;
case UPDATE:
documentOperation = new DocumentUpdate(documentType, documentParseInfo.documentId);
readUpdate(documentParseInfo.fieldsBuffer, (DocumentUpdate) documentOperation);
verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
break;
default:
throw new IllegalStateException("Implementation out of sync with itself. This is a bug.");
}
} catch (JsonReaderException e) {
throw JsonReaderException.addDocId(e, documentParseInfo.documentId);
}
if (documentParseInfo.create.isPresent()) {
if (!(documentOperation instanceof DocumentUpdate)) {
throw new RuntimeException("Could not set create flag on non update operation.");
}
DocumentUpdate update = (DocumentUpdate) documentOperation;
update.setCreateIfNonExistent(documentParseInfo.create.get());
}
return documentOperation;
}
Aggregations