public class DocumentUpdate extends DocumentOperation implements 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("doc:test:http://music.yahoo.com/")); FieldUpdate update = FieldUpdate.createAssign(musicType.getField("artist"), "lillbabs"); docUpdate.addFieldUpdate(update);
FieldUpdate
,
ValueUpdate
Modifier and Type | Field and Description |
---|---|
static int |
CLASSID |
Constructor and Description |
---|
DocumentUpdate(DocumentType docType,
DocumentId docId)
Creates a DocumentUpdate.
|
DocumentUpdate(DocumentType docType,
String docId)
Creates a DocumentUpdate.
|
DocumentUpdate(DocumentUpdateReader reader)
Creates a new document update using a reader
|
Modifier and Type | Method and 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 given
FieldUpdate to this DocumentUpdate. |
void |
addFieldUpdateNoCheck(FieldUpdate fieldUpdate) |
DocumentUpdate |
applyTo(Document doc)
Applies this document update.
|
void |
clearFieldUpdates()
Removes all field updates from the list for field updates.
|
boolean |
equals(Object o) |
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 updates
|
List<FieldPathUpdate> |
getFieldPathUpdates()
Get an unmodifiable list of all field path updates this document update specifies.
|
FieldUpdate |
getFieldUpdate(Field field)
Returns the update for a field
|
FieldUpdate |
getFieldUpdate(int index)
Get the field update at the specified index in the list of field updates.
|
FieldUpdate |
getFieldUpdate(String fieldName)
Returns the update for a field name
|
List<FieldUpdate> |
getFieldUpdates()
Get an unmodifiable list of all field updates that this document update specifies.
|
DocumentId |
getId() |
Optional<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.
|
Iterator<FieldPathUpdate> |
iterator() |
DocumentUpdate |
prune(Document doc)
Prune away any field update that will not modify any field in the document.
|
FieldUpdate |
removeFieldUpdate(int index)
Removes the field update at the specified position in the list of field updates.
|
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.
|
FieldUpdate |
setFieldUpdate(int index,
FieldUpdate upd)
Replaces the field update at the specified index in the list of field updates.
|
void |
setFieldUpdates(List<FieldUpdate> fieldUpdates)
Assigns the field updates of this document update.
|
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.
|
String |
toString() |
getCondition, setCondition
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final int CLASSID
public DocumentUpdate(DocumentType docType, DocumentId docId)
docId
- the ID of the updatedocType
- the document type that this update is valid forpublic DocumentUpdate(DocumentUpdateReader reader)
public DocumentUpdate(DocumentType docType, String docId)
docId
- the ID of the updatedocType
- the document type that this update is valid forpublic DocumentId getId()
getId
in class DocumentOperation
public void setId(DocumentId id)
public DocumentUpdate applyTo(Document doc)
doc
- the document to apply the update toIllegalArgumentException
- if the document does not have the same document type as this updatepublic DocumentUpdate prune(Document doc)
doc
- document to check againstIllegalArgumentException
- if the document does not have the same document type as this updatepublic List<FieldUpdate> getFieldUpdates()
public List<FieldPathUpdate> getFieldPathUpdates()
public DocumentType getDocumentType()
public void setDocumentType(DocumentType type)
public FieldUpdate getFieldUpdate(int index)
index
- the index of the FieldUpdate to returnIndexOutOfBoundsException
- if index is out of rangepublic FieldUpdate setFieldUpdate(int index, FieldUpdate upd)
index
- index of the FieldUpdate to replaceupd
- the FieldUpdate to be stored at the specified positionIndexOutOfBoundsException
- if index is out of rangepublic FieldUpdate getFieldUpdate(Field field)
field
- the field to return the update ofpublic void clearFieldUpdates()
public FieldUpdate getFieldUpdate(String fieldName)
fieldName
- the field name to return the update ofpublic void setFieldUpdates(List<FieldUpdate> fieldUpdates)
fieldUpdates
- the new list of updates of thisNullPointerException
- if the argument passed is nullpublic int size()
public DocumentUpdate addFieldUpdate(FieldUpdate update)
FieldUpdate
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.update
- The FieldUpdate to add to this DocumentUpdate.IllegalArgumentException
- If the DocumentType
of this DocumentUpdate does not have a corresponding
field.public DocumentUpdate addFieldPathUpdate(FieldPathUpdate fieldPathUpdate)
public void addFieldUpdateNoCheck(FieldUpdate fieldUpdate)
public void addAll(DocumentUpdate update)
update
- The update whose content to add to this.IllegalArgumentException
- If the DocumentId
or DocumentType
of the given DocumentUpdate
does not match the content of this.public FieldUpdate removeFieldUpdate(int index)
index
- the index of the FieldUpdate to removeIndexOutOfBoundsException
- if index is out of rangepublic DocumentType getType()
public final void serialize(com.yahoo.io.GrowableByteBuffer buf)
public void serialize(DocumentUpdateWriter data)
public Iterator<FieldPathUpdate> iterator()
iterator
in interface Iterable<FieldPathUpdate>
public boolean isEmpty()
public void setCreateIfNonExistent(boolean value)
value
- Whether the document it updates should be created.public boolean getCreateIfNonExistent()
Copyright © 2018. All rights reserved.