Search:

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

8.2. Prepend Methods

The prepend() methods insert information before the existing data for a given key. Note that as with the append() method, the information will be inserted before the existing binary data stored in the key, which means that serialization of complex objects may lead to corruption when using prepend().

API Callclient.prepend(casunique, key, value)
Asynchronousyes
Description Prepend a value to an existing key
ReturnsFuture<Boolean> ( Asynchronous request value, as Boolean )
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 prepend() inserts information before the existing data stored in the key/value pair. The prepend() function requires a CAS value. For more information on CAS values, see Section 7.4, “CAS get Methods”.

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

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

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

OperationFuture<Boolean> prependOp =
    client.prepend(casv.getCas(),"notsamplekey", "prependedstring");

try {
    if (prependOp.get().booleanValue()) {
        System.out.printf("Prepend succeeded\n");
    }
    else {
        System.out.printf("Prepend failed\n");
    }
}
catch (Exception e) {
...
}
API Callclient.prepend(casunique, key, value, transcoder)
Asynchronousyes
Description Prepend a value to an existing key
ReturnsFuture<Boolean> ( Asynchronous request value, as Boolean )
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 secondary form of the prepend() method supports the use of a custom transcoder for updating the key/value pair.