Search:

Search all manuals
Search this manual
Manual
Membase Client Library: Java
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
4 Membase Client Library: Java — Retrieve Operations
Chapter Sections
Chapters

4.5. Bulk get Methods

The bulk getBulk() methods allow you to get one or more items from the database in a single request. Using the bulk methods is more efficient than multiple single requests as the operation can be conducted in a single network call.

API Callclient.getBulk(keycollection)
Asynchronousno
Description Get one or more key values
ReturnsMap<String,Object> ( Map of Strings/Objects )
Arguments 
Collection<String> keycollection One or more keys used to reference a value

The first format accepts a String Collection as the request argument which is used to specify the list of keys that you want to retrieve. The return type is Map between the keys and object values.

For example:

Map<String,Object> keyvalues = membase.getBulk(keylist);

System.out.printf("A is %s\n",keyvalues.get("keyA"));
System.out.printf("B is %s\n",keyvalues.get("keyB"));
System.out.printf("C is %s\n",keyvalues.get("keyC"));

Note

The returned map will only contain entries for keys that exist from the original request. For example, if you request the values for three keys, but only one exists, the resultant map will contain only that one key/value pair.

API Callclient.getBulk(keycollection, transcoder)
Asynchronousno
Description Get one or more key values
ReturnsMap<String,T> ( Map of Strings/Transcoded objects )
Arguments 
Collection<String> keycollection One or more keys used to reference a value
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form of the getBulk() method supports the same Collection argument, but also supports the use of a custom transcoder on the returned values.

Note

The specified transcoder will be used for every value requested from the database.

API Callclient.getBulk(keyn)
Asynchronousno
Description Get one or more key values
ReturnsMap<String,Object> ( Map of Strings/Objects )
Arguments 
String... keyn One or more keys used to reference a value

The third form of the getBulk() method supports a variable list of arguments with each interpreted as the key to be retrieved from the database.

For example, the equivalent of the Collection method operation using this method would be:

Map<String,Object> keyvalues = membase.getBulk("keyA","keyB","keyC");

System.out.printf("A is %s\n",keyvalues.get("keyA"));
System.out.printf("B is %s\n",keyvalues.get("keyB"));
System.out.printf("C is %s\n",keyvalues.get("keyC"));

The return Map will only contain entries for keys that exist. Non-existent keys will be silently ignored.

API Callclient.getBulk(transcoder, keyn)
Asynchronousno
Description Get one or more key values
ReturnsMap<String,T> ( Map of Strings/Transcoded objects )
Arguments 
Transcoder<T> transcoder Transcoder class to be used to serialize value
String... keyn One or more keys used to reference a value

The fourth form of the getBulk() method uses the variable list of arguments but supports a custom transcoder.

Warning

Note that unlike other formats of the methods used for supporting custom transcoders, the transcoder specification is at the start of the argument list, not the end.

API Callclient.asyncGetBulk(keycollection)
Asynchronousyes
Description Get one or more key values
ReturnsBulkFuture<Map<String,Object>> ( Map of Strings/Objects )
Arguments 
Collection<String> keycollection One or more keys used to reference a value

The asynchronous getBulk() method supports a Collection of keys to be retrieved, returning a BulkFuture object (part of the spymemcached package) with the returned map of key/value information. As with other asynchronous methods, the benefit is that you do not need to actively wait for the response.

The BulkFuture object operates slightly different in context to the standard Future object. Whereas the Future object gets a returned single value, the BulkFuture object will return an object containing as many keys as have been returned. For very large queries requesting large numbers of keys this means that multiple requests may be required to obtain every key from the original list.

For example, the code below will obtain as many keys as possible from the supplied Collection.

BulkFuture<Map<String,Object>> keyvalues = membase.asyncGetBulk(keylist);

Map<String,Object> keymap = keyvalues.getSome(5,TimeUnit.SECONDS);

System.out.printf("A is %s\n",keymap.get("keyA"));
System.out.printf("B is %s\n",keymap.get("keyB"));
System.out.printf("C is %s\n",keymap.get("keyC"));
API Callclient.asyncGetBulk(keycollection, transcoder)
Asynchronousyes
Description Get one or more key values
ReturnsBulkFuture<Map<String,T>> ( Map of Strings/Transcoded objects )
Arguments 
Collection<String> keycollection One or more keys used to reference a value
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form of the asynchronous getBulk() method supports the custom transcoder for the returned values.

API Callclient.asyncGetBulk(keyn)
Asynchronousyes
Description Get one or more key values
ReturnsBulkFuture<Map<String,Object>> ( Map of Strings/Objects )
Arguments 
String... keyn One or more keys used to reference a value

The third form is identical to the multi-argument key request method (see collection based asyncBulkGet()), except that the operation occurs asynchronously.

API Callclient.asyncGetBulk(transcoder, keyn)
Asynchronousyes
Description Get one or more key values
ReturnsBulkFuture<Map<String,T>> ( Map of Strings/Transcoded objects )
Arguments 
Transcoder<T> transcoder Transcoder class to be used to serialize value
String... keyn One or more keys used to reference a value

The final form of the asyncGetBulk() method supports a customer transcoder with the variable list of keys supplied as arguments.