Package com.yahoo.document
Class Document
java.lang.Object
com.yahoo.vespa.objects.Selectable
com.yahoo.vespa.objects.Identifiable
- All Implemented Interfaces:
Cloneable
,Comparable<FieldValue>
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 Summary
-
Constructor Summary
ConstructorDescriptionCreates a document that is a shallow copy of another.Document
(DocumentType docType, DocumentId id) Create a document with the given document type and identifier.Document
(DocumentType docType, String id) Create a document with the given document type and identifier.Document
(DocumentReader reader) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Assign this non-fieldvalue value to this field value.void
clear()
clone()
int
compareTo
(FieldValue fieldValue) static Document
createDocument
(DocumentReader buffer) void
deserialize
(Field field, FieldReader reader) Read a field value from the specified readervoid
deserialize
(DocumentReader reader) protected void
doSetFieldValue
(Field field, FieldValue value) boolean
Returns true if the argument is a document which has the same set of valuesfinal int
This is an approximation of serialized size.Returns the named field object, or null if that field does not exist.int
getFieldValue
(Field field) Returns the value of the given field.getId()
Returns the last modified time of this Document, when stored in persistent storage.int
int
hashCode()
iterator()
void
onSerialize
(com.yahoo.vespa.objects.Serializer data) void
Deprecated.removeFieldValue
(Field field) Removes and returns a field value.void
serialize
(Field field, FieldWriter writer) Write out field value to the specified writervoid
serialize
(DocumentWriter writer) void
serialize
(OutputStream out) void
setDataType
(DataType type) void
setId
(DocumentId id) void
setLastModified
(Long lastModified) Sets the last modified time of this Document.toJson()
Get JSON representation of the document root and its children contained in a JSON objecttoString()
toXml()
Deprecated.Deprecated.Methods inherited from class com.yahoo.document.datatypes.StructuredFieldValue
getFieldValue, isGenerated, iterateNested, removeFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue
Methods inherited from class com.yahoo.document.datatypes.FieldValue
create, deserialize, getRecursiveValue, getRecursiveValue, getWrappedValue, onDeserialize, serialize
Methods inherited from class com.yahoo.vespa.objects.Identifiable
create, createFromId, deserialize, deserializeOptional, deserializeWithId, equals, getClassId, getRawUtf8Bytes, getUtf8, onGetClassId, putUtf8, registerClass, serialize, serializeOptional, serializeWithId, visitMembers
Methods inherited from class com.yahoo.vespa.objects.Selectable
select, select, selectMembers
-
Field Details
-
classId
public static final int classId -
SERIALIZED_VERSION
public static final short SERIALIZED_VERSION- See Also:
-
-
Constructor Details
-
Document
Create a document with the given document type and identifier.- Parameters:
docType
- DocumentType to use for creationid
- The id for this document
-
Document
Create a document with the given document type and identifier.- Parameters:
docType
- DocumentType to use for creationid
- The id for this document
-
Document
Creates a document that is a shallow copy of another.- Parameters:
doc
- The document to copy.
-
Document
- Parameters:
reader
- The deserializer to use for creating this document
-
-
Method Details
-
getId
-
setId
-
assign
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 classFieldValue
-
clone
- Overrides:
clone
in classFieldValue
-
setDataType
- Overrides:
setDataType
in classCompositeFieldValue
-
getSerializedSize
- 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
- Throws:
SerializationException
-
createDocument
-
getField
Description copied from class:StructuredFieldValue
Returns the named field object, or null if that field does not exist.- Specified by:
getField
in classStructuredFieldValue
- Parameters:
fieldName
- The name of the field to return.- Returns:
- The corresponding field, or null.
-
getFieldValue
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 classStructuredFieldValue
- Parameters:
field
- The field whose value to return.- Returns:
- The value of the field, or null.
-
doSetFieldValue
- Specified by:
doSetFieldValue
in classStructuredFieldValue
-
removeFieldValue
Description copied from class:StructuredFieldValue
Removes and returns a field value.- Specified by:
removeFieldValue
in classStructuredFieldValue
- 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 classStructuredFieldValue
-
iterator
- Specified by:
iterator
in classStructuredFieldValue
-
toString
- Overrides:
toString
in classcom.yahoo.vespa.objects.Identifiable
-
toXML
Deprecated. -
toXml
Deprecated.Get XML representation of the document root and its children, contained within a <document></document> tag.- Overrides:
toXml
in classFieldValue
- Returns:
- XML representation of document
-
printXml
Deprecated.- Specified by:
printXml
in classFieldValue
-
toJson
Get JSON representation of the document root and its children contained in a JSON object- Returns:
- JSON representation of document
-
equals
Returns true if the argument is a document which has the same set of values- Overrides:
equals
in classCompositeFieldValue
-
hashCode
public int hashCode()- Overrides:
hashCode
in classCompositeFieldValue
-
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
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
- Overrides:
onSerialize
in classFieldValue
- Throws:
SerializationException
-
getDataType
- Overrides:
getDataType
in classStructuredFieldValue
-
getFieldCount
public int getFieldCount()- Specified by:
getFieldCount
in classStructuredFieldValue
-
serialize
-
deserialize
-
serialize
Description copied from class:FieldValue
Write out field value to the specified writer- Specified by:
serialize
in classFieldValue
-
deserialize
Description copied from class:FieldValue
Read a field value from the specified reader- Specified by:
deserialize
in classFieldValue
-
compareTo
- Specified by:
compareTo
in interfaceComparable<FieldValue>
- Overrides:
compareTo
in classFieldValue
-