Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.1
Community Wiki and Resources
Download Client Library
JavaDoc
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
Java Client Library
SDK Forum
Wiki: Java Client Library
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
8 Update Operations
Chapter Sections
Chapters

8.1. Append Methods

The append() methods allow you to add information to an existing key/value pair in the database. You can use this to add information to a string or other data after the existing data.

The append() methods append raw serialized data on to the end of the existing data in the key. If you have previously stored a serialized object into Couchbase and then use append, the content of the serialized object will not be extended. For example, adding an Array of integers into the database, and then using append() to add another integer will result in the key referring to a serialized version of the array, immediately followed by a serialized version of the integer. It will not contain an updated array with the new integer appended to it. De-serialization of objects that have had data appended may result in data corruption.

API Callclient.append(casunique, key, value)
Asynchronousno
Description Append a value to an existing key
ReturnsObject ( Binary object )
Arguments 
long casunique Unique value used to verify a key/value combination
String key Document ID used to identify the value
Object value Value to be stored

The append() appends information to the end of an existing key/value pair. The append() function requires a CAS value. For more information on CAS values, see Section 7.4, “CAS get Methods”.

For example, to append a string to an existing key:

CASValue<Object> casv = client.gets("samplekey");
client.append(casv.getCas(),"samplekey", "appendedstring");

You can check if the append operation succeeded by using the return OperationFuture value:

OperationFuture<Boolean> appendOp =
    client.append(casv.getCas(),"notsamplekey", "appendedstring");

try {
    if (appendOp.get().booleanValue()) {
        System.out.printf("Append succeeded\n");
    }
    else {
        System.out.printf("Append failed\n");
    }
}
catch (Exception e) {
...
}
API Callclient.append(casunique, key, value, transcoder)
Asynchronousno
Description Append a value to an existing key
ReturnsObject ( Binary object )
Arguments 
long casunique Unique value used to verify a key/value combination
String key Document ID used to identify the value
Object value Value to be stored
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form of the append() method supports the use of custom transcoder.