Search in sources :

Example 91 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class StringTestCase method serializeAndDeserialize.

private Document serializeAndDeserialize(Document doc, DocumentTypeManager manager) {
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(doc);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buffer);
    return new Document(deserializer);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document)

Example 92 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class LocalSyncSession method update.

@Override
public boolean update(DocumentUpdate update) {
    Document document = access.documents.get(update.getId());
    if (document == null) {
        return false;
    }
    update.applyTo(document);
    return true;
}
Also used : Document(com.yahoo.document.Document)

Example 93 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class MessageBusAsyncSession method toSuccess.

@SuppressWarnings("deprecation")
private static Response toSuccess(Reply reply, long reqId) {
    switch(reply.getType()) {
        case DocumentProtocol.REPLY_GETDOCUMENT:
            GetDocumentReply docReply = ((GetDocumentReply) reply);
            Document getDoc = docReply.getDocument();
            if (getDoc != null) {
                getDoc.setLastModified(docReply.getLastModified());
            }
            return new DocumentResponse(reqId, getDoc);
        case DocumentProtocol.REPLY_REMOVEDOCUMENT:
            return new RemoveResponse(reqId, ((RemoveDocumentReply) reply).wasFound());
        case DocumentProtocol.REPLY_UPDATEDOCUMENT:
            return new UpdateResponse(reqId, ((UpdateDocumentReply) reply).wasFound());
        case DocumentProtocol.REPLY_PUTDOCUMENT:
            break;
        default:
            return new Response(reqId);
    }
    Message msg = reply.getMessage();
    switch(msg.getType()) {
        case DocumentProtocol.MESSAGE_PUTDOCUMENT:
            return new DocumentResponse(reqId, ((PutDocumentMessage) msg).getDocumentPut().getDocument());
        case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
            return new DocumentIdResponse(reqId, ((RemoveDocumentMessage) msg).getDocumentId());
        case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
            return new DocumentUpdateResponse(reqId, ((UpdateDocumentMessage) msg).getDocumentUpdate());
        default:
            return new Response(reqId);
    }
}
Also used : Document(com.yahoo.document.Document)

Example 94 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class MessageBusSyncSession method get.

@Override
public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority pri, Duration timeout) {
    GetDocumentMessage msg = new GetDocumentMessage(id, fieldSet);
    msg.setPriority(pri);
    Reply reply = syncSend(msg, timeout != null ? timeout : defaultTimeout);
    if (reply.hasErrors()) {
        throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply));
    }
    if (reply.getType() != DocumentProtocol.REPLY_GETDOCUMENT) {
        throw new DocumentAccessException("Received unknown response: " + reply);
    }
    GetDocumentReply docReply = ((GetDocumentReply) reply);
    Document doc = docReply.getDocument();
    if (doc != null) {
        doc.setLastModified(docReply.getLastModified());
    }
    return doc;
}
Also used : GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Reply(com.yahoo.messagebus.Reply) RemoveDocumentReply(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply) UpdateDocumentReply(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 95 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class XmlDocumentWriterTestCase method requireThatPredicateFieldValuesAreSerializedAsString.

@Test
public void requireThatPredicateFieldValuesAreSerializedAsString() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_predicate", DataType.PREDICATE);
    docType.addField(field);
    Document doc = new Document(docType, "doc:scheme:");
    PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class);
    doc.setFieldValue("my_predicate", predicate);
    new XmlDocumentWriter().write(doc);
    Mockito.verify(predicate, Mockito.times(1)).printXml(Mockito.any(XmlStream.class));
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Aggregations

Document (com.yahoo.document.Document)109 Test (org.junit.Test)63 DocumentType (com.yahoo.document.DocumentType)41 DocumentPut (com.yahoo.document.DocumentPut)40 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 InputStream (java.io.InputStream)18 DocumentId (com.yahoo.document.DocumentId)16 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)13 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)13 HashMap (java.util.HashMap)13 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)12 FieldValue (com.yahoo.document.datatypes.FieldValue)12 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)12 DocumentOperation (com.yahoo.document.DocumentOperation)10 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Array (com.yahoo.document.datatypes.Array)8