Package com.yahoo.document
Class DocumentUpdate
- java.lang.Object
-
- com.yahoo.document.DocumentOperation
-
- com.yahoo.document.DocumentUpdate
-
- All Implemented Interfaces:
java.lang.Iterable<FieldPathUpdate>
public class DocumentUpdate extends DocumentOperation implements java.lang.Iterable<FieldPathUpdate>
Specifies one or more field updates to a document.
A document update contains a list of
field updates
for fields to be updated by this update. Each field update is applied atomically, but the entire document update is not. A document update can only contain one field update per field. To make multiple updates to the same field in the same document update, add multiplevalue updates
to the same field update.To update a document and set a string field to a new value:
DocumentType musicType = DocumentTypeManager.getInstance().getDocumentType("music", 0); DocumentUpdate docUpdate = new DocumentUpdate(musicType, new DocumentId("id:test:music::http://music.yahoo.com/")); FieldUpdate update = FieldUpdate.createAssign(musicType.getField("artist"), "lillbabs"); docUpdate.addFieldUpdate(update);
- Author:
- Einar M R Rosenvinge
- See Also:
FieldUpdate
,ValueUpdate
-
-
Field Summary
Fields Modifier and Type Field Description static int
CLASSID
-
Constructor Summary
Constructors Constructor Description DocumentUpdate(DocumentType docType, DocumentId docId)
Creates a DocumentUpdate.DocumentUpdate(DocumentType docType, java.lang.String docId)
Creates a DocumentUpdate.DocumentUpdate(DocumentUpdate update)
Creates a new document update which is a copy of the argument.DocumentUpdate(DocumentUpdateReader reader)
Creates a new document update using a reader
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(DocumentUpdate update)
Adds all the field- and field path updates of the given document update to this.DocumentUpdate
addFieldPathUpdate(FieldPathUpdate fieldPathUpdate)
Adds a field path update to perform on the document.DocumentUpdate
addFieldUpdate(FieldUpdate update)
Adds the givenFieldUpdate
to this DocumentUpdate.void
addFieldUpdates(java.util.Collection<FieldUpdate> fieldUpdates)
DocumentUpdate
applyTo(Document doc)
Applies this document update.void
clearFieldUpdates()
Removes all field updates from the list for field updates.boolean
equals(java.lang.Object o)
java.util.Collection<FieldPathUpdate>
fieldPathUpdates()
Get an unmodifiable collection of all field path updates that this document update specifies.java.util.Collection<FieldUpdate>
fieldUpdates()
Get an unmodifiable collection of all field updates that this document update specifies.boolean
getCreateIfNonExistent()
Gets whether this update should create the document it updates if that document does not exist.DocumentType
getDocumentType()
Returns the type of the document this updatesFieldUpdate
getFieldUpdate(Field field)
Returns the update for a fieldFieldUpdate
getFieldUpdate(java.lang.String fieldName)
Returns the update for a field nameDocumentId
getId()
java.util.Optional<java.lang.Boolean>
getOptionalCreateIfNonExistent()
DocumentType
getType()
Returns the document type of this document update.int
hashCode()
boolean
isEmpty()
Returns whether or not this field update contains any field- or field path updates.java.util.Iterator<FieldPathUpdate>
iterator()
DocumentUpdate
prune(Document doc)
Prune away any field update that will not modify any field in the document.FieldUpdate
removeFieldUpdate(Field field)
FieldUpdate
removeFieldUpdate(java.lang.String fieldName)
void
serialize(DocumentUpdateWriter data)
void
serialize(com.yahoo.io.GrowableByteBuffer buf)
void
setCreateIfNonExistent(boolean value)
Sets whether this update should create the document it updates if that document does not exist.void
setDocumentType(DocumentType type)
Sets the document type.void
setFieldUpdates(java.util.Collection<FieldUpdate> fieldUpdates)
Assigns the field updates of this document update.void
setFieldUpdates(java.util.List<FieldUpdate> fieldUpdates)
The same as setFieldUpdates(Collection<FieldUpdate>)void
setId(DocumentId id)
Sets the document id of the document to update.int
size()
Get the number of field updates in this document update.java.lang.String
toString()
-
Methods inherited from class com.yahoo.document.DocumentOperation
getCondition, setCondition
-
-
-
-
Field Detail
-
CLASSID
public static final int CLASSID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DocumentUpdate
public DocumentUpdate(DocumentType docType, DocumentId docId)
Creates a DocumentUpdate.- Parameters:
docId
- the ID of the updatedocType
- the document type that this update is valid for
-
DocumentUpdate
public DocumentUpdate(DocumentUpdateReader reader)
Creates a new document update using a reader
-
DocumentUpdate
public DocumentUpdate(DocumentUpdate update)
Creates a new document update which is a copy of the argument.
-
DocumentUpdate
public DocumentUpdate(DocumentType docType, java.lang.String docId)
Creates a DocumentUpdate.- Parameters:
docId
- the ID of the updatedocType
- the document type that this update is valid for
-
-
Method Detail
-
getId
public DocumentId getId()
- Specified by:
getId
in classDocumentOperation
-
setId
public void setId(DocumentId id)
Sets the document id of the document to update. Use only while deserializing - changing the document id after creation has undefined behaviour.
-
applyTo
public DocumentUpdate applyTo(Document doc)
Applies this document update.- Parameters:
doc
- the document to apply the update to- Returns:
- a reference to itself
- Throws:
java.lang.IllegalArgumentException
- if the document does not have the same document type as this update
-
prune
public DocumentUpdate prune(Document doc)
Prune away any field update that will not modify any field in the document.- Parameters:
doc
- document to check against- Returns:
- a reference to itself
- Throws:
java.lang.IllegalArgumentException
- if the document does not have the same document type as this update
-
fieldUpdates
public java.util.Collection<FieldUpdate> fieldUpdates()
Get an unmodifiable collection of all field updates that this document update specifies.- Returns:
- a collection of all FieldUpdates in this DocumentUpdate
-
fieldPathUpdates
public java.util.Collection<FieldPathUpdate> fieldPathUpdates()
Get an unmodifiable collection of all field path updates that this document update specifies.- Returns:
- a collection of all FieldPathUpdates in this DocumentUpdate
-
getDocumentType
public DocumentType getDocumentType()
Returns the type of the document this updates- Returns:
- The documentype of the document
-
setDocumentType
public void setDocumentType(DocumentType type)
Sets the document type. Use only while deserializing - changing the document type after creation has undefined behaviour.
-
getFieldUpdate
public FieldUpdate getFieldUpdate(Field field)
Returns the update for a field- Parameters:
field
- the field to return the update of- Returns:
- the update for the field, or null if that field has no update in this
-
clearFieldUpdates
public void clearFieldUpdates()
Removes all field updates from the list for field updates.
-
getFieldUpdate
public FieldUpdate getFieldUpdate(java.lang.String fieldName)
Returns the update for a field name- Parameters:
fieldName
- the field name to return the update of- Returns:
- the update for the field, or null if that field has no update in this
-
setFieldUpdates
public void setFieldUpdates(java.util.Collection<FieldUpdate> fieldUpdates)
Assigns the field updates of this document update. Also note that no assumptions can be made on the order of item after this call. They might have been joined if for the same field or reordered.- Parameters:
fieldUpdates
- the new list of updates of this- Throws:
java.lang.NullPointerException
- if the argument passed is null
-
setFieldUpdates
public void setFieldUpdates(java.util.List<FieldUpdate> fieldUpdates)
The same as setFieldUpdates(Collection<FieldUpdate>)
-
addFieldUpdates
public void addFieldUpdates(java.util.Collection<FieldUpdate> fieldUpdates)
-
size
public int size()
Get the number of field updates in this document update.- Returns:
- the size of the List of FieldUpdates
-
addFieldUpdate
public DocumentUpdate addFieldUpdate(FieldUpdate update)
Adds the givenFieldUpdate
to this DocumentUpdate. If this DocumentUpdate already contains a FieldUpdate for the named field, the content of the given FieldUpdate is added to the existing one.- Parameters:
update
- The FieldUpdate to add to this DocumentUpdate.- Returns:
- This, to allow chaining.
- Throws:
java.lang.IllegalArgumentException
- If theDocumentType
of this DocumentUpdate does not have a corresponding field.
-
addFieldPathUpdate
public DocumentUpdate addFieldPathUpdate(FieldPathUpdate fieldPathUpdate)
Adds a field path update to perform on the document.- Returns:
- a reference to itself.
-
addAll
public void addAll(DocumentUpdate update)
Adds all the field- and field path updates of the given document update to this. If the given update refers to a different document or document type than this, this method throws an exception.- Parameters:
update
- The update whose content to add to this.- Throws:
java.lang.IllegalArgumentException
- If theDocumentId
orDocumentType
of the given DocumentUpdate does not match the content of this.
-
removeFieldUpdate
public FieldUpdate removeFieldUpdate(Field field)
-
removeFieldUpdate
public FieldUpdate removeFieldUpdate(java.lang.String fieldName)
-
getType
public DocumentType getType()
Returns the document type of this document update.- Returns:
- the document type of this document update
-
serialize
public final void serialize(com.yahoo.io.GrowableByteBuffer buf)
-
serialize
public void serialize(DocumentUpdateWriter data)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
iterator
public java.util.Iterator<FieldPathUpdate> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<FieldPathUpdate>
-
isEmpty
public boolean isEmpty()
Returns whether or not this field update contains any field- or field path updates.- Returns:
- True if this update is empty.
-
setCreateIfNonExistent
public void setCreateIfNonExistent(boolean value)
Sets whether this update should create the document it updates if that document does not exist. In this case an empty document is created before the update is applied.- Parameters:
value
- Whether the document it updates should be created.
-
getCreateIfNonExistent
public boolean getCreateIfNonExistent()
Gets whether this update should create the document it updates if that document does not exist.- Returns:
- whether the document it updates should be created.
-
getOptionalCreateIfNonExistent
public java.util.Optional<java.lang.Boolean> getOptionalCreateIfNonExistent()
-
-