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
6 Store Operations
Chapter Sections
Chapters

6.1. Add Operations

The add() method adds a value to the database with the specified key, but will fail if the key already exists in the database.

API Callclient.add(key, expiry, value)
Asynchronousyes
Description Add a value with the specified key that does not already exist. Will fail if the key/value pair already exist.
ReturnsFuture<Boolean> ( Asynchronous request value, as Boolean )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Object value Value to be stored

The add() method adds a value to the database using the specified key.

client.add("someKey", 0, someObject);

Unlike Section 6.2, “Set Operations” the operation can fail (and return false) if the specified key already exist.

For example, the first operation in the example below may complete if the key does not already exist, but the second operation will always fail as the first operation will have set the key:

OperationFuture<Boolean> addOp = client.add("someKey",0,"astring");
System.out.printf("Result was %b",addOp.get());
addOp =  client.add("someKey",0,"anotherstring");
System.out.printf("Result was %b",addOp.get());
API Callclient.add(key, expiry, value, transcoder)
Asynchronousyes
Description Add a value with the specified key that does not already exist. Will fail if the key/value pair already exist.
ReturnsFuture<Boolean> ( Asynchronous request value, as Boolean )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Object value Value to be stored
Transcoder<T> transcoder Transcoder class to be used to serialize value

This method is identical to the add() method, but supports the use of a custom transcoder for serialization of the object value. For more information on transcoding, see Section 4.3, “Object Serialization (Transcoding)”.