Package com.yahoo.document
Class DocumentUpdate
java.lang.Object
com.yahoo.document.DocumentOperation
com.yahoo.document.DocumentUpdate
- All Implemented Interfaces:
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 multiple value 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:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDocumentUpdate
(DocumentType docType, DocumentId docId) Creates a DocumentUpdate.DocumentUpdate
(DocumentType docType, 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
Modifier and TypeMethodDescriptionvoid
addAll
(DocumentUpdate update) Adds all the field- and field path updates of the given document update to this.addFieldPathUpdate
(FieldPathUpdate fieldPathUpdate) Adds a field path update to perform on the document.addFieldUpdate
(FieldUpdate update) Adds the givenFieldUpdate
to this DocumentUpdate.void
addFieldUpdates
(Collection<FieldUpdate> fieldUpdates) Applies this document update.void
Removes all field updates from the list for field updates.boolean
Get an unmodifiable collection of all field path updates that this document update specifies.Get an unmodifiable collection of all field updates that this document update specifies.boolean
Gets whether this update should create the document it updates if that document does not exist.Returns the type of the document this updatesgetFieldUpdate
(Field field) Returns the update for a fieldgetFieldUpdate
(String fieldName) Returns the update for a field namegetId()
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.iterator()
Prune away any field update that will not modify any field in the document.removeFieldUpdate
(Field field) removeFieldUpdate
(String fieldName) void
final 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
(Collection<FieldUpdate> fieldUpdates) Assigns the field updates of this document update.void
setFieldUpdates
(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.toString()
Methods inherited from class com.yahoo.document.DocumentOperation
getCondition, setCondition
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
CLASSID
public static final int CLASSID- See Also:
-
-
Constructor Details
-
DocumentUpdate
Creates a DocumentUpdate.- Parameters:
docId
- the ID of the updatedocType
- the document type that this update is valid for
-
DocumentUpdate
Creates a new document update using a reader -
DocumentUpdate
Creates a new document update which is a copy of the argument. -
DocumentUpdate
Creates a DocumentUpdate.- Parameters:
docId
- the ID of the updatedocType
- the document type that this update is valid for
-
-
Method Details
-
getId
- Specified by:
getId
in classDocumentOperation
-
setId
Sets the document id of the document to update. Use only while deserializing - changing the document id after creation has undefined behaviour. -
applyTo
Applies this document update.- Parameters:
doc
- the document to apply the update to- Returns:
- a reference to itself
- Throws:
IllegalArgumentException
- if the document does not have the same document type as this update
-
prune
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:
IllegalArgumentException
- if the document does not have the same document type as this update
-
fieldUpdates
Get an unmodifiable collection of all field updates that this document update specifies.- Returns:
- a collection of all FieldUpdates in this DocumentUpdate
-
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
Returns the type of the document this updates- Returns:
- The documentype of the document
-
setDocumentType
Sets the document type. Use only while deserializing - changing the document type after creation has undefined behaviour. -
getFieldUpdate
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
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
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:
NullPointerException
- if the argument passed is null
-
setFieldUpdates
The same as setFieldUpdates(Collection<FieldUpdate>) -
addFieldUpdates
-
size
public int size()Get the number of field updates in this document update.- Returns:
- the size of the List of FieldUpdates
-
addFieldUpdate
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:
IllegalArgumentException
- If theDocumentType
of this DocumentUpdate does not have a corresponding field.
-
addFieldPathUpdate
Adds a field path update to perform on the document.- Returns:
- a reference to itself.
-
addAll
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:
IllegalArgumentException
- If theDocumentId
orDocumentType
of the given DocumentUpdate does not match the content of this.
-
removeFieldUpdate
-
removeFieldUpdate
-
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
-
equals
-
hashCode
public int hashCode() -
toString
-
iterator
- Specified by:
iterator
in interfaceIterable<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
-