Class Document

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.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 Detail

      • classId

        public static final int classId
    • Constructor Detail

      • Document

        public Document​(DocumentType docType,
                        java.lang.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 Detail

      • getHeader

        @Deprecated
        public Struct getHeader()
        Deprecated.
        do not use: Use getField(), getFieldValue() or iterator() instead
      • getBody

        @Deprecated
        public Struct getBody()
        Deprecated.
        do not use: Use getField(), getFieldValue() or iterator() instead
      • assign

        public void assign​(java.lang.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
      • 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)
      • getField

        public Field getField​(java.lang.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.
      • toString

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

        public java.lang.String toXML​(java.lang.String indent)
      • toXml

        public java.lang.String toXml()
        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
      • toJson

        public java.lang.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​(java.lang.Object o)
        Returns true if the argument is a document which has the same set of values
        Overrides:
        equals in class CompositeFieldValue
      • getLastModified

        public java.lang.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​(java.lang.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)