Class Document

java.lang.Object
com.yahoo.vespa.objects.Selectable
All Implemented Interfaces:
Cloneable, Comparable<FieldValue>

public class Document extends StructuredFieldValue
A document is an identifiable set of value bindings of a document type. A document represents an instance of some entity of interest in an application, like an article, a web document, a product, etc. Deprecation: Try to use document set and get methods only with FieldValue types, not with primitive types. Support for direct access to primitive types will be removed soon.
Author:
bratseth, Einar M R Rosenvinge
  • Field Details

    • classId

      public static final int classId
    • SERIALIZED_VERSION

      public static final short SERIALIZED_VERSION
      See Also:
  • Constructor Details

    • Document

      public Document(DocumentType docType, String id)
      Create a document with the given document type and identifier.
      Parameters:
      docType - DocumentType to use for creation
      id - The id for this document
    • Document

      public Document(DocumentType docType, DocumentId id)
      Create a document with the given document type and identifier.
      Parameters:
      docType - DocumentType to use for creation
      id - The id for this document
    • Document

      public Document(Document doc)
      Creates a document that is a shallow copy of another.
      Parameters:
      doc - The document to copy.
    • Document

      public Document(DocumentReader reader)
      Parameters:
      reader - The deserializer to use for creating this document
  • Method Details

    • getId

      public DocumentId getId()
    • setId

      public void setId(DocumentId id)
    • assign

      public void assign(Object o)
      Description copied from class: FieldValue
      Assign this non-fieldvalue value to this field value. This is used to be able to assign ints to Integer field values and List to Array field values and such.

      Override to accept the specific types that should be legal.

      Specified by:
      assign in class FieldValue
    • clone

      public Document clone()
      Overrides:
      clone in class FieldValue
    • setDataType

      public void setDataType(DataType type)
      Overrides:
      setDataType in class CompositeFieldValue
    • getSerializedSize

      public int getSerializedSize() throws SerializationException
      Throws:
      SerializationException
    • getApproxSize

      public final int getApproxSize()
      This is an approximation of serialized size. We just set it to 4096 as a definition of a medium document.
      Returns:
      Approximate size of document (4096)
    • serialize

      public void serialize(OutputStream out) throws SerializationException
      Throws:
      SerializationException
    • createDocument

      public static Document createDocument(DocumentReader buffer)
    • getField

      public Field getField(String fieldName)
      Description copied from class: StructuredFieldValue
      Returns the named field object, or null if that field does not exist.
      Specified by:
      getField in class StructuredFieldValue
      Parameters:
      fieldName - The name of the field to return.
      Returns:
      The corresponding field, or null.
    • getFieldValue

      public FieldValue getFieldValue(Field field)
      Description copied from class: StructuredFieldValue
      Returns the value of the given field. If the field does not exist, this method returns null.
      Specified by:
      getFieldValue in class StructuredFieldValue
      Parameters:
      field - The field whose value to return.
      Returns:
      The value of the field, or null.
    • doSetFieldValue

      protected void doSetFieldValue(Field field, FieldValue value)
      Specified by:
      doSetFieldValue in class StructuredFieldValue
    • removeFieldValue

      public FieldValue removeFieldValue(Field field)
      Description copied from class: StructuredFieldValue
      Removes and returns a field value.
      Specified by:
      removeFieldValue in class StructuredFieldValue
      Parameters:
      field - The field whose value to remove.
      Returns:
      The previous value of the field, or null.
    • clear

      public void clear()
      Specified by:
      clear in class StructuredFieldValue
    • iterator

      public Iterator<Map.Entry<Field,FieldValue>> iterator()
      Specified by:
      iterator in class StructuredFieldValue
    • toString

      public String toString()
      Overrides:
      toString in class com.yahoo.vespa.objects.Identifiable
    • toXML

      @Deprecated public String toXML(String indent)
      Deprecated.
    • toXml

      @Deprecated public String toXml()
      Deprecated.
      Get XML representation of the document root and its children, contained within a <document></document> tag.
      Overrides:
      toXml in class FieldValue
      Returns:
      XML representation of document
    • printXml

      @Deprecated public void printXml(XmlStream xml)
      Deprecated.
      Specified by:
      printXml in class FieldValue
    • toJson

      public String toJson()
      Get JSON representation of the document root and its children contained in a JSON object
      Returns:
      JSON representation of document
    • equals

      public boolean equals(Object o)
      Returns true if the argument is a document which has the same set of values
      Overrides:
      equals in class CompositeFieldValue
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class CompositeFieldValue
    • getLastModified

      public Long getLastModified()
      Returns the last modified time of this Document, when stored in persistent storage. This is typically set by the library that retrieves the Document from persistent storage. This variable doesn't really belong in document. It is used when retrieving docblocks of documents to be able to see when documents was last modified in VDS, without having to add modified times separate in the API. NOTE: This is a transient field, and will not be serialized with a Document (will be null after deserialization).
      Returns:
      the last modified time of this Document (in milliseconds), or null if unset
    • setLastModified

      public void setLastModified(Long lastModified)
      Sets the last modified time of this Document. This is typically set by the library that retrieves the Document from persistent storage, and should not be set by arbitrary clients. NOTE: This is a transient field, and will not be serialized with a Document (will be null after deserialization).
      Parameters:
      lastModified - the last modified time of this Document (in milliseconds)
    • onSerialize

      public void onSerialize(com.yahoo.vespa.objects.Serializer data) throws SerializationException
      Overrides:
      onSerialize in class FieldValue
      Throws:
      SerializationException
    • getDataType

      public DocumentType getDataType()
      Overrides:
      getDataType in class StructuredFieldValue
    • getFieldCount

      public int getFieldCount()
      Specified by:
      getFieldCount in class StructuredFieldValue
    • serialize

      public void serialize(DocumentWriter writer)
    • deserialize

      public void deserialize(DocumentReader reader)
    • serialize

      public void serialize(Field field, FieldWriter writer)
      Description copied from class: FieldValue
      Write out field value to the specified writer
      Specified by:
      serialize in class FieldValue
    • deserialize

      public void deserialize(Field field, FieldReader reader)
      Description copied from class: FieldValue
      Read a field value from the specified reader
      Specified by:
      deserialize in class FieldValue
    • compareTo

      public int compareTo(FieldValue fieldValue)
      Specified by:
      compareTo in interface Comparable<FieldValue>
      Overrides:
      compareTo in class FieldValue