Class AbstractDocument<T>
- java.lang.Object
-
- com.couchbase.client.java.document.AbstractDocument<T>
-
- All Implemented Interfaces:
Document<T>
- Direct Known Subclasses:
BinaryDocument,ByteArrayDocument,JsonArrayDocument,JsonBooleanDocument,JsonDocument,JsonDoubleDocument,JsonLongDocument,JsonStringDocument,LegacyDocument,RawJsonDocument,SerializableDocument,StringDocument
public abstract class AbstractDocument<T> extends Object implements Document<T>
Common parent implementation of aDocument. It is recommended that allDocumentimplementations extend from this class so that parameter checks are consistently applied. It also ensures that equals and hashcode are applied on the contents and therefore comparisons work as expected.- Since:
- 2.0.0
- Author:
- Michael Nitschinger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDocument()Constructor needed for possible subclass serialization.protectedAbstractDocument(String id, int expiry, T content, long cas)protectedAbstractDocument(String id, int expiry, T content, long cas, MutationToken mutationToken)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcas()The last-known CAS value for theDocument(0 if not set).Tcontent()The content of theDocument.booleanequals(Object o)intexpiry()The optional expiration time for theDocument(0 if not set).inthashCode()Stringid()The per-bucket unique ID of theDocument.MutationTokenmutationToken()The optional, opaque mutation token set after a successful mutation and if enabled on the environment.protected voidreadFromSerializedStream(ObjectInputStream stream)Helper method to create the document from an object input stream, used for serialization purposes.StringtoString()protected voidwriteToSerializedStream(ObjectOutputStream stream)Helper method to write the current document state to the output stream for serialization purposes.
-
-
-
Constructor Detail
-
AbstractDocument
protected AbstractDocument()
Constructor needed for possible subclass serialization.
-
AbstractDocument
protected AbstractDocument(String id, int expiry, T content, long cas, MutationToken mutationToken)
-
-
Method Detail
-
id
public String id()
Description copied from interface:DocumentThe per-bucket unique ID of theDocument.
-
cas
public long cas()
Description copied from interface:DocumentThe last-known CAS value for theDocument(0 if not set).
-
expiry
public int expiry()
Description copied from interface:DocumentThe optional expiration time for theDocument(0 if not set).
-
mutationToken
public MutationToken mutationToken()
Description copied from interface:DocumentThe optional, opaque mutation token set after a successful mutation and if enabled on the environment. Note that the mutation token is always null, unless they are explicitly enabled on the environment, the server version is supported (>= 4.0.0) and the mutation operation succeeded. If set, it can be used for enhanced durability requirements, as well as optimized consistency for N1QL queries.- Specified by:
mutationTokenin interfaceDocument<T>- Returns:
- the mutation token if set, otherwise null.
-
writeToSerializedStream
protected void writeToSerializedStream(ObjectOutputStream stream) throws IOException
Helper method to write the current document state to the output stream for serialization purposes.- Parameters:
stream- the stream to write to.- Throws:
IOException
-
readFromSerializedStream
protected void readFromSerializedStream(ObjectInputStream stream) throws IOException, ClassNotFoundException
Helper method to create the document from an object input stream, used for serialization purposes.- Parameters:
stream- the stream to read from.- Throws:
IOExceptionClassNotFoundException
-
-