public class CouchbaseDocument extends Object implements CouchbaseStorable
CouchbaseDocument is an abstract representation of a document stored inside Couchbase Server.
It acts like a TreeMap, but only allows those types to be written that are supported by the underlying
storage format, which is currently JSON. Note that JSON conversion is not happening here, but performed at a
different stage based on the payload stored in the CouchbaseDocument.
In addition to the actual content, meta data is also stored. This especially refers to the document ID and its expiration time. Note that this information is not mandatory, since documents can be nested and therefore only the topmost document most likely has an ID.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_EXPIRATION_TIME
Defnes the default expiration time for the document.
|
| Constructor and Description |
|---|
CouchbaseDocument()
Creates a completely empty
CouchbaseDocument. |
CouchbaseDocument(Object id)
Creates a empty
CouchbaseDocument, and set the ID immediately. |
CouchbaseDocument(Object id,
int expiration)
Creates a empty
CouchbaseDocument with ID and expiration time. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(String key)
Returns true if it contains a payload for the specified key.
|
boolean |
containsValue(Object value)
Returns true if it contains the given value.
|
TreeMap<String,Object> |
export()
Returns the current payload, including all recursive elements.
|
Object |
get(String key)
Potentially get a value from the payload with the given key.
|
Map<String,Object> |
getContent()
Returns the underlying payload.
|
int |
getExpiration()
Returns the expiration time of the document.
|
Object |
getId()
Returns the ID of the document.
|
CouchbaseDocument |
put(String key,
Object value)
Store a value with the given key for later retreival.
|
CouchbaseDocument |
setContent(com.couchbase.client.java.json.JsonObject payload)
Allows to set the full payload as a json object for convenience.
|
CouchbaseDocument |
setContent(Map<String,Object> content)
Allows to set the full payload as a map.
|
CouchbaseDocument |
setExpiration(int expiration)
Set the expiration time of the document.
|
CouchbaseDocument |
setId(Object id)
Sets the unique ID of the document per bucket.
|
int |
size()
Returns the size of the attributes in this document (not nested).
|
int |
size(boolean recursive)
Retruns the size of the attributes in this and recursive documents.
|
String |
toString()
A string representation of expiration, id and payload.
|
public static final int DEFAULT_EXPIRATION_TIME
public CouchbaseDocument()
CouchbaseDocument.public CouchbaseDocument(Object id)
CouchbaseDocument, and set the ID immediately.id - the document ID.public CouchbaseDocument(Object id, int expiration)
CouchbaseDocument with ID and expiration time.id - the document ID.expiration - the expiration time of the document.public final CouchbaseDocument put(String key, Object value)
key - the key of the attribute.value - the actual content to be stored.CouchbaseDocument for chaining.public final Object get(String key)
key - the key of the attribute.public final TreeMap<String,Object> export()
It either returns the raw results or makes sure that the recusrive elements are also exported properly.
public final boolean containsKey(String key)
key - the key of the attribute.public final boolean containsValue(Object value)
value - the value to check for.public final int size()
public final int size(boolean recursive)
recursive - wheter nested attributes should be taken into account.public Map<String,Object> getContent()
Note that unlike export(), the nested objects are not converted, so the "raw" map is returned.
public CouchbaseDocument setContent(Map<String,Object> content)
content - the payload to setpublic CouchbaseDocument setContent(com.couchbase.client.java.json.JsonObject payload)
payload - the payload to setpublic int getExpiration()
If the expiration time is 0, then the document will be persisted until deleted manually ("forever").
public CouchbaseDocument setExpiration(int expiration)
If the expiration time is 0, then the document will be persisted until deleted manually ("forever").
Expiration should be expressed as seconds if <= 30 days (30 x 24 x 60 x 60 seconds), or as an expiry date (UTC, UNIX time ie. seconds form the Epoch) if > 30 days.
expiration - CouchbaseDocument for chaining.public Object getId()
public CouchbaseDocument setId(Object id)
id - the ID of the document.CouchbaseDocument for chaining.Copyright © 2011–2023 Pivotal Software, Inc.. All rights reserved.