Spring Data Couchbase

org.springframework.data.couchbase.core.mapping
Class CouchbaseDocument

java.lang.Object
  extended by org.springframework.data.couchbase.core.mapping.CouchbaseDocument
All Implemented Interfaces:
CouchbaseStorable

public class CouchbaseDocument
extends Object
implements CouchbaseStorable

A CouchbaseDocument is an abstract representation of a document stored inside Couchbase Server.

It acts like a HashMap, 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.

Author:
Michael Nitschinger

Field Summary
static int DEFAULT_EXPIRATION_TIME
          Defnes the default expiration time for the document.
 
Constructor Summary
CouchbaseDocument()
          Creates a completely empty CouchbaseDocument.
CouchbaseDocument(String id)
          Creates a empty CouchbaseDocument, and set the ID immediately.
CouchbaseDocument(String id, int expiration)
          Creates a empty CouchbaseDocument with ID and expiration time.
 
Method Summary
 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.
 HashMap<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.
 int getExpiration()
          Returns the expiration time of the document.
 String getId()
          Returns the ID of the document.
 HashMap<String,Object> getPayload()
          Returns the underlying payload.
 CouchbaseDocument put(String key, Object value)
          Store a value with the given key for later retreival.
 CouchbaseDocument setExpiration(int expiration)
          Set the expiration time of the document.
 CouchbaseDocument setId(String 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRATION_TIME

public static final int DEFAULT_EXPIRATION_TIME
Defnes the default expiration time for the document.

See Also:
Constant Field Values
Constructor Detail

CouchbaseDocument

public CouchbaseDocument()
Creates a completely empty CouchbaseDocument.


CouchbaseDocument

public CouchbaseDocument(String id)
Creates a empty CouchbaseDocument, and set the ID immediately.

Parameters:
id - the document ID.

CouchbaseDocument

public CouchbaseDocument(String id,
                         int expiration)
Creates a empty CouchbaseDocument with ID and expiration time.

Parameters:
id - the document ID.
expiration - the expiration time of the document.
Method Detail

put

public final CouchbaseDocument put(String key,
                                   Object value)
Store a value with the given key for later retreival.

Parameters:
key - the key of the attribute.
value - the actual content to be stored.
Returns:
the CouchbaseDocument for chaining.

get

public final Object get(String key)
Potentially get a value from the payload with the given key.

Parameters:
key - the key of the attribute.
Returns:
the value to which the specified key is mapped, or null if does not contain a mapping for the key.

export

public final HashMap<String,Object> export()
Returns the current payload, including all recursive elements. It either returns the raw results or makes sure that the recusrive elements are also exported properly.

Returns:

containsKey

public final boolean containsKey(String key)
Returns true if it contains a payload for the specified key.

Parameters:
key - the key of the attribute.
Returns:
true if it contains a payload for the specified key.

containsValue

public final boolean containsValue(Object value)
Returns true if it contains the given value.

Parameters:
value - the value to check for.
Returns:
true if it contains the specified value.

size

public final int size()
Returns the size of the attributes in this document (not nested).

Returns:
the size of the attributes in this document (not nested).

size

public final int size(boolean recursive)
Retruns the size of the attributes in this and recursive documents.

Parameters:
recursive - wheter nested attributes should be taken into account.
Returns:
the size of the attributes in this and recursive documents.

getPayload

public HashMap<String,Object> getPayload()
Returns the underlying payload.

Note that unlike export(), the nested objects are not converted, so the "raw" map is returned.

Returns:
the underlying payload.

getExpiration

public int getExpiration()
Returns the expiration time of the document. If the expiration time is 0, then the document will be persisted until deleted manually ("forever").

Returns:
the expiration time of the document.

setExpiration

public CouchbaseDocument setExpiration(int expiration)
Set the expiration time of the document. If the expiration time is 0, then the document will be persisted until deleted manually ("forever").

Parameters:
expiration -
Returns:
the CouchbaseDocument for chaining.

getId

public String getId()
Returns the ID of the document.

Returns:
the ID of the document.

setId

public CouchbaseDocument setId(String id)
Sets the unique ID of the document per bucket.

Parameters:
id - the ID of the document.
Returns:
the CouchbaseDocument for chaining.

toString

public String toString()
A string representation of expiration, id and payload.

Overrides:
toString in class Object
Returns:
the string representation of the object.

Spring Data Couchbase

Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.