public class DocumentRevision extends java.lang.Object implements java.lang.Comparable<DocumentRevision>
A single revision of a document within a datastore.
Documents within the datastore are in fact trees of document revisions, with one document marked as the current winner at any point. Branches in the tree are caused when a document is edited in more than one place before being replicated between datastores. The consuming application is responsible for finding active branches (also called conflicts), and marking the leaf nodes of all branches but one deleted (thereby resolving the conflict).
A DocumentRevision
contains all the information for a single document
revision, including its ID and revision ID, along with the document's
content for this revision as a DocumentBody
object. Clients will
typically set only the revision content rather than the metadata
explicitly.
Constructor and Description |
---|
DocumentRevision() |
DocumentRevision(java.lang.String id) |
DocumentRevision(java.lang.String id,
java.lang.String revision) |
Modifier and Type | Method and Description |
---|---|
byte[] |
asBytes()
Returns the JSON body of the document revision as a
byte
array. |
java.util.Map<java.lang.String,java.lang.Object> |
asMap()
Returns the JSON body of the document revision as a
Map
object. |
int |
compareTo(DocumentRevision o) |
boolean |
equals(java.lang.Object o) |
java.util.Map<java.lang.String,Attachment> |
getAttachments()
top level key: _attachments
|
DocumentBody |
getBody()
the rest of the document
|
int |
getGeneration() |
java.lang.String |
getId() |
java.lang.String |
getRevision() |
long |
getSequence()
Returns the sequence number of this revision.
|
int |
hashCode() |
void |
initialiseSequence(long sequence) |
boolean |
isCurrent() |
boolean |
isDeleted() |
boolean |
isFullRevision()
Returns true if this revision is a full revision.
|
void |
setAttachments(java.util.Map<java.lang.String,Attachment> attachments) |
void |
setBody(DocumentBody body) |
void |
setDeleted(boolean deleted) |
void |
setRevision(java.lang.String revision) |
DocumentRevision |
toFullRevision()
Returns a "Full" document revision.
|
java.lang.String |
toString() |
public DocumentRevision()
public DocumentRevision(java.lang.String id)
public DocumentRevision(java.lang.String id, java.lang.String revision)
public java.lang.String getId()
public java.lang.String getRevision()
public DocumentBody getBody()
public void setBody(DocumentBody body)
public java.util.Map<java.lang.String,Attachment> getAttachments()
public void setAttachments(java.util.Map<java.lang.String,Attachment> attachments)
public boolean isDeleted()
true
if this revision is marked deleted.public boolean isFullRevision()
true
if this revision is a full revision.public DocumentRevision toFullRevision() throws DocumentNotFoundException
IndexManager.find(Map, long, long, List, List)
using the
fields
option to limit the fields returned, a revision will be missing data so it
cannot be regarded as a full revision. If the document is a full revision, this method will
only attempt to load the full revision from the datastore if isFullRevision()
returns false.DocumentNotFoundException
- Thrown if the full document cannot be loaded from the
datastore.public void setRevision(java.lang.String revision)
public boolean isCurrent()
true
if this revision is the current winner for the
document.public java.util.Map<java.lang.String,java.lang.Object> asMap()
Returns the JSON body of the document revision as a Map
object.
This Map includes reserved fields such as _id
and
_rev
. Changing the byte array may affect the DocumentRevision
,
as only a shallow copy is returned.
Map
object.public byte[] asBytes()
Returns the JSON body of the document revision as a byte
array.
This byte array includes reserved fields such as _id
and
_rev
. Changing the byte array does not affect the document
revisions contents.
byte
array.public void setDeleted(boolean deleted)
public long getSequence()
Returns the sequence number of this revision.
The sequence number is unique across the database, it is updated for every modification to the datastore.
public void initialiseSequence(long sequence)
public java.lang.String toString()
toString
in class java.lang.Object
public int getGeneration()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int compareTo(DocumentRevision o)
compareTo
in interface java.lang.Comparable<DocumentRevision>