Search in sources :

Example 36 with FieldUpdate

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

the class VespaDocumentSerializerHead method write.

@Override
public void write(DocumentUpdate update) {
    update.getId().serialize(this);
    update.getDocumentType().serialize(this);
    putInt(null, update.getFieldUpdates().size());
    for (FieldUpdate up : update.getFieldUpdates()) {
        up.serialize(this);
    }
    DocumentUpdateFlags flags = new DocumentUpdateFlags();
    flags.setCreateIfNonExistent(update.getCreateIfNonExistent());
    putInt(null, flags.injectInto(update.getFieldPathUpdates().size()));
    for (FieldPathUpdate up : update.getFieldPathUpdates()) {
        up.serialize(this);
    }
}
Also used : FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate)

Example 37 with FieldUpdate

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

the class SimpleAdapterFactoryTestCase method requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField.

@Test
public void requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField() {
    DocumentType docType = new DocumentType("my_type");
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:foo:1");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    FieldUpdate fieldUpdate = FieldUpdate.create(field);
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(1));
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(2));
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(4));
    docUpdate.addFieldUpdate(fieldUpdate);
    SimpleAdapterFactory factory = new SimpleAdapterFactory();
    List<UpdateAdapter> adapters = factory.newUpdateAdapterList(docUpdate);
    assertEquals(4, adapters.size());
    UpdateAdapter adapter = adapters.get(0);
    assertNotNull(adapter);
    assertEquals(new IntegerFieldValue(1), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(1));
    assertEquals(new IntegerFieldValue(2), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(2));
    assertEquals(new IntegerFieldValue(4), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(3));
    // always add an adapter for complete updates
    assertNull(adapter.getInputValue("my_int"));
}
Also used : Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Aggregations

FieldUpdate (com.yahoo.document.update.FieldUpdate)37 Test (org.junit.Test)17 DocumentUpdate (com.yahoo.document.DocumentUpdate)16 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)15 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)14 ValueUpdate (com.yahoo.document.update.ValueUpdate)12 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)8 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 HashMap (java.util.HashMap)5 DocumentId (com.yahoo.document.DocumentId)4 DocumentType (com.yahoo.document.DocumentType)4 FieldPathUpdate (com.yahoo.document.fieldpathupdate.FieldPathUpdate)4 ArrayList (java.util.ArrayList)4 Field (com.yahoo.document.Field)3 Array (com.yahoo.document.datatypes.Array)3 Struct (com.yahoo.document.datatypes.Struct)3 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)3