Spring Data Key-Value

org.springframework.data.keyvalue.riak.core
Class RiakTemplate

java.lang.Object
  extended by org.springframework.web.client.support.RestGatewaySupport
      extended by org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
          extended by org.springframework.data.keyvalue.riak.core.RiakTemplate
All Implemented Interfaces:
BeanClassLoaderAware, InitializingBean, BucketKeyValueStoreOperations, MapReduceOperations

public class RiakTemplate
extends AbstractRiakTemplate
implements BucketKeyValueStoreOperations, MapReduceOperations

An implementation of BucketKeyValueStoreOperations and MapReduceOperations for the Riak data store.

To use the RiakTemplate, create a singleton in your Spring application-context.xml:


 <bean id="riak" class="org.springframework.data.keyvalue.riak.core.RiakTemplate"
     p:defaultUri="http://localhost:8098/riak/{bucket}/{key}"
     p:mapReduceUri="http://localhost:8098/mapred"/>
 
To store and retrieve objects in Riak, use the setXXX and getXXX methods (example in Groovy):

 def obj = new TestObject(name: "My Name", age: 40)
 riak.set("mybucket", "mykey", obj)
 ...
 def name = riak.get("mybucket", "mykey").name
 println "Hello $name!"
 

Author:
J. Brisbin <[email protected]>

Field Summary
 
Fields inherited from class org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
bucketKeyResolvers, cache, classLoader, conversionService, defaultQosParameters, defaultType, defaultUri, groovyPresent, httpDate, log, mapReduceUri, prefix, RIAK_CLIENT_ID, RIAK_META_CLASSNAME, RIAK_VCLOCK, useCache, workerPool
 
Fields inherited from class org.springframework.web.client.support.RestGatewaySupport
logger
 
Constructor Summary
RiakTemplate()
          Take all the defaults.
RiakTemplate(ClientHttpRequestFactory requestFactory)
          Use the specified ClientHttpRequestFactory.
RiakTemplate(String defaultUri, String mapReduceUri)
          Use the specified defaultUri and mapReduceUri.
 
Method Summary
<B,K> boolean
containsKey(B bucket, K key)
          Variant of KeyValueStoreOperations.containsKey(Object) that takes a discreet bucket and key pair.
<B,K> boolean
delete(B bucket, K key)
          Delete a specific entry from this data store.
<K> boolean
deleteKeys(K... keys)
           
 Object execute(MapReduceJob job)
          Execute a MapReduceJob synchronously.
<T> T
execute(MapReduceJob job, Class<T> targetType)
          Execute a MapReduceJob synchronously, converting the result into the given type.
<B,K,T> T
get(B bucket, K key)
          Variant of KeyValueStoreOperations.get(Object) that takes a discreet bucket and key pair.
<B,K,V> V
getAndSet(B bucket, K key, V value)
          Variant of KeyValueStoreOperations.getAndSet(Object, Object) that takes a discreet bucket and key pair.
<B,K> byte[]
getAndSetAsBytes(B bucket, K key, byte[] value)
          Variant of KeyValueStoreOperations.getAndSetAsBytes(Object, byte[]) that takes a discreet bucket and key pair.
<B,K,V,T> T
getAndSetAsType(B bucket, K key, V value, Class<T> requiredType)
          Variant of KeyValueStoreOperations.getAndSetAsType(Object, Object, Class) that takes a discreet bucket and key pair.
<B,K> byte[]
getAsBytes(B bucket, K key)
          Variant of KeyValueStoreOperations.getAsBytes(Object) that takes a discreet bucket and key pair.
<B,K> RiakValue<byte[]>
getAsBytesWithMetaData(B bucket, K key)
           
<B,K,T> T
getAsType(B bucket, K key, Class<T> requiredType)
          Variant of KeyValueStoreOperations.getAsType(Object, Class) that takes a discreet bucket and key pair.
<B> Map<String,Object>
getBucketSchema(B bucket)
           
<B> Map<String,Object>
getBucketSchema(B bucket, boolean listKeys)
           
<B,K> RiakMetaData
getMetaData(B bucket, K key)
           
<K,V> List<V>
getValues(K... keys)
           
<K,V> List<V>
getValues(List<K> keys)
           
<T,K> List<T>
getValuesAsType(Class<T> requiredType, K... keys)
           
<K,T> List<T>
getValuesAsType(List<K> keys, Class<T> requiredType)
           
<B,K,T> RiakValue<T>
getWithMetaData(B bucket, K key, Class<T> requiredType)
           
<B1,K1,B2,K2>
RiakTemplate
link(B1 destBucket, K1 destKey, B2 sourceBucket, K2 sourceKey, String tag)
          Use Riak's native Link mechanism to link two entries together.
<B,T,K> T
linkWalk(B bucket, K key, String tag)
          Use Riak's link walking mechanism to retrieve a multipart message that will be decoded like they were individual objects (e.g. using the built-in HttpMessageConverters of RestTemplate).
<B,T,K> T
linkWalkAsType(B bucket, K key, String tag, Class<T> requiredType)
          Use Riak's link walking mechanism to retrieve a multipart message that will be decoded like they were individual objects (e.g. using the built-in HttpMessageConverters of RestTemplate) and return the result as a list of objects of one of: The type specified by requiredType If that's null, try using the bucket name in which the object was stored If all else fails, use a Map
<B,V> String
put(B bucket, V value)
          Save an object to Riak and let it generate an ID for it.
<B,V> String
put(B bucket, V value, Map<String,String> metaData)
          Save an object to Riak and let it generate an ID for it.
<B,K,V> BucketKeyValueStoreOperations
set(B bucket, K key, V value)
          Variant of KeyValueStoreOperations.set(Object, Object) that takes a discreet bucket and key pair.
<B,K,V> BucketKeyValueStoreOperations
set(B bucket, K key, V value, QosParameters qosParams)
          Variant of KeyValueStoreOperations.set(Object, Object, QosParameters) that takes a discreet bucket and key pair.
<B,K> BucketKeyValueStoreOperations
setAsBytes(B bucket, K key, byte[] value)
          Variant of KeyValueStoreOperations.setAsBytes(Object, byte[]) that takes a discreet bucket and key pair.
<B,K> BucketKeyValueStoreOperations
setAsBytes(B bucket, K key, byte[] value, QosParameters qosParams)
          Variant of KeyValueStoreOperations.setAsBytes(Object, byte[], QosParameters) that takes a discreet bucket and key pair.
<B,K,V> BucketKeyValueStoreOperations
setIfKeyNonExistent(B bucket, K key, V value)
          Variant of KeyValueStoreOperations.setIfKeyNonExistent(Object, Object) that takes a discreet bucket and key pair.
<B,K> BucketKeyValueStoreOperations
setIfKeyNonExistentAsBytes(B bucket, K key, byte[] value)
          Variant of KeyValueStoreOperations.setIfKeyNonExistentAsBytes(Object, byte[]) that takes a discreet bucket and key pair.
<B,K,V> BucketKeyValueStoreOperations
setWithMetaData(B bucket, K key, V value, Map<String,String> metaData)
          Variant of KeyValueStoreOperations.setWithMetaData(Object, Object, java.util.Map) that takes a discreet bucket and key pair.
<B,K,V> BucketKeyValueStoreOperations
setWithMetaData(B bucket, K key, V value, Map<String,String> metaData, QosParameters qosParams)
          Variant of KeyValueStoreOperations.setWithMetaData(Object, Object, java.util.Map, QosParameters) that takes a discreet bucket and key pair.
<T> Future<List<T>>
submit(MapReduceJob job)
          Submit the job to run asynchronously.
<B> BucketKeyValueStoreOperations
updateBucketSchema(B bucket, Map<String,Object> props)
           
 
Methods inherited from class org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
afterPropertiesSet, checkCache, defaultHeaders, extractMediaType, extractMetaData, extractQosParameters, extractValue, getConversionService, getDefaultQosParameters, getDefaultType, getDefaultUri, getHost, getIgnoreNotFound, getMapReduceUri, getPort, getPrefix, getType, getType, getWorkerPool, isUseCache, resolveBucketKeyPair, setBeanClassLoader, setConversionService, setDefaultQosParameters, setDefaultType, setDefaultUri, setIgnoreNotFound, setMapReduceUri, setUseCache, setWorkerPool
 
Methods inherited from class org.springframework.web.client.support.RestGatewaySupport
getRestTemplate, setRestTemplate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RiakTemplate

public RiakTemplate()
Take all the defaults.


RiakTemplate

public RiakTemplate(ClientHttpRequestFactory requestFactory)
Use the specified ClientHttpRequestFactory.

Parameters:
requestFactory -

RiakTemplate

public RiakTemplate(String defaultUri,
                    String mapReduceUri)
Use the specified defaultUri and mapReduceUri.

Parameters:
defaultUri -
mapReduceUri -
Method Detail

set

public <B,K,V> BucketKeyValueStoreOperations set(B bucket,
                                                 K key,
                                                 V value)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.set(Object, Object) that takes a discreet bucket and key pair.

Specified by:
set in interface BucketKeyValueStoreOperations
Returns:

set

public <B,K,V> BucketKeyValueStoreOperations set(B bucket,
                                                 K key,
                                                 V value,
                                                 QosParameters qosParams)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.set(Object, Object, QosParameters) that takes a discreet bucket and key pair.

Specified by:
set in interface BucketKeyValueStoreOperations
Returns:

setAsBytes

public <B,K> BucketKeyValueStoreOperations setAsBytes(B bucket,
                                                      K key,
                                                      byte[] value)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.setAsBytes(Object, byte[]) that takes a discreet bucket and key pair.

Specified by:
setAsBytes in interface BucketKeyValueStoreOperations
Returns:

setAsBytes

public <B,K> BucketKeyValueStoreOperations setAsBytes(B bucket,
                                                      K key,
                                                      byte[] value,
                                                      QosParameters qosParams)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.setAsBytes(Object, byte[], QosParameters) that takes a discreet bucket and key pair.

Specified by:
setAsBytes in interface BucketKeyValueStoreOperations
Returns:

setWithMetaData

public <B,K,V> BucketKeyValueStoreOperations setWithMetaData(B bucket,
                                                             K key,
                                                             V value,
                                                             Map<String,String> metaData,
                                                             QosParameters qosParams)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.setWithMetaData(Object, Object, java.util.Map, QosParameters) that takes a discreet bucket and key pair.

Specified by:
setWithMetaData in interface BucketKeyValueStoreOperations
Returns:

setWithMetaData

public <B,K,V> BucketKeyValueStoreOperations setWithMetaData(B bucket,
                                                             K key,
                                                             V value,
                                                             Map<String,String> metaData)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.setWithMetaData(Object, Object, java.util.Map) that takes a discreet bucket and key pair.

Specified by:
setWithMetaData in interface BucketKeyValueStoreOperations
Returns:

put

public <B,V> String put(B bucket,
                        V value)
Save an object to Riak and let it generate an ID for it.

Parameters:
bucket -
value -
Returns:
The generated ID

put

public <B,V> String put(B bucket,
                        V value,
                        Map<String,String> metaData)
Save an object to Riak and let it generate an ID for it.

Parameters:
bucket -
value -
metaData -
Returns:
The generated ID

getMetaData

public <B,K> RiakMetaData getMetaData(B bucket,
                                      K key)

getWithMetaData

public <B,K,T> RiakValue<T> getWithMetaData(B bucket,
                                            K key,
                                            Class<T> requiredType)

get

public <B,K,T> T get(B bucket,
                     K key)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.get(Object) that takes a discreet bucket and key pair.

Specified by:
get in interface BucketKeyValueStoreOperations
Returns:

getAsBytes

public <B,K> byte[] getAsBytes(B bucket,
                               K key)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.getAsBytes(Object) that takes a discreet bucket and key pair.

Specified by:
getAsBytes in interface BucketKeyValueStoreOperations
Returns:

getAsBytesWithMetaData

public <B,K> RiakValue<byte[]> getAsBytesWithMetaData(B bucket,
                                                      K key)

getAsType

public <B,K,T> T getAsType(B bucket,
                           K key,
                           Class<T> requiredType)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.getAsType(Object, Class) that takes a discreet bucket and key pair.

Specified by:
getAsType in interface BucketKeyValueStoreOperations
Returns:

getAndSet

public <B,K,V> V getAndSet(B bucket,
                           K key,
                           V value)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.getAndSet(Object, Object) that takes a discreet bucket and key pair.

Specified by:
getAndSet in interface BucketKeyValueStoreOperations
Returns:

getAndSetAsBytes

public <B,K> byte[] getAndSetAsBytes(B bucket,
                                     K key,
                                     byte[] value)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.getAndSetAsBytes(Object, byte[]) that takes a discreet bucket and key pair.

Specified by:
getAndSetAsBytes in interface BucketKeyValueStoreOperations
Returns:

getAndSetAsType

public <B,K,V,T> T getAndSetAsType(B bucket,
                                   K key,
                                   V value,
                                   Class<T> requiredType)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.getAndSetAsType(Object, Object, Class) that takes a discreet bucket and key pair.

Specified by:
getAndSetAsType in interface BucketKeyValueStoreOperations
Returns:

getValues

public <K,V> List<V> getValues(List<K> keys)

getValues

public <K,V> List<V> getValues(K... keys)

getValuesAsType

public <K,T> List<T> getValuesAsType(List<K> keys,
                                     Class<T> requiredType)

getValuesAsType

public <T,K> List<T> getValuesAsType(Class<T> requiredType,
                                     K... keys)

setIfKeyNonExistent

public <B,K,V> BucketKeyValueStoreOperations setIfKeyNonExistent(B bucket,
                                                                 K key,
                                                                 V value)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.setIfKeyNonExistent(Object, Object) that takes a discreet bucket and key pair.

Specified by:
setIfKeyNonExistent in interface BucketKeyValueStoreOperations
Returns:

setIfKeyNonExistentAsBytes

public <B,K> BucketKeyValueStoreOperations setIfKeyNonExistentAsBytes(B bucket,
                                                                      K key,
                                                                      byte[] value)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.setIfKeyNonExistentAsBytes(Object, byte[]) that takes a discreet bucket and key pair.

Specified by:
setIfKeyNonExistentAsBytes in interface BucketKeyValueStoreOperations
Returns:

containsKey

public <B,K> boolean containsKey(B bucket,
                                 K key)
Description copied from interface: BucketKeyValueStoreOperations
Variant of KeyValueStoreOperations.containsKey(Object) that takes a discreet bucket and key pair.

Specified by:
containsKey in interface BucketKeyValueStoreOperations
Returns:

delete

public <B,K> boolean delete(B bucket,
                            K key)
Description copied from interface: BucketKeyValueStoreOperations
Delete a specific entry from this data store.

Specified by:
delete in interface BucketKeyValueStoreOperations
Returns:

deleteKeys

public <K> boolean deleteKeys(K... keys)

execute

public Object execute(MapReduceJob job)
Description copied from interface: MapReduceOperations
Execute a MapReduceJob synchronously.

Specified by:
execute in interface MapReduceOperations
Returns:

execute

public <T> T execute(MapReduceJob job,
                     Class<T> targetType)
Description copied from interface: MapReduceOperations
Execute a MapReduceJob synchronously, converting the result into the given type.

Specified by:
execute in interface MapReduceOperations
Returns:
The converted value.

submit

public <T> Future<List<T>> submit(MapReduceJob job)
Description copied from interface: MapReduceOperations
Submit the job to run asynchronously.

Specified by:
submit in interface MapReduceOperations
Returns:
The Future representing the submitted job.

link

public <B1,K1,B2,K2> RiakTemplate link(B1 destBucket,
                                       K1 destKey,
                                       B2 sourceBucket,
                                       K2 sourceKey,
                                       String tag)
Use Riak's native Link mechanism to link two entries together.

Parameters:
destBucket - Bucket of child entry
destKey - Key of child entry
sourceBucket - Bucket of parent entry
sourceKey - Key of parent entry
tag - Tag for this relationship
Returns:

linkWalk

public <B,T,K> T linkWalk(B bucket,
                          K key,
                          String tag)
Use Riak's link walking mechanism to retrieve a multipart message that will be decoded like they were individual objects (e.g. using the built-in HttpMessageConverters of RestTemplate).

Parameters:
bucket -
key -
tag -
Returns:

linkWalkAsType

public <B,T,K> T linkWalkAsType(B bucket,
                                K key,
                                String tag,
                                Class<T> requiredType)
Use Riak's link walking mechanism to retrieve a multipart message that will be decoded like they were individual objects (e.g. using the built-in HttpMessageConverters of RestTemplate) and return the result as a list of objects of one of:
  1. The type specified by requiredType
  2. If that's null, try using the bucket name in which the object was stored
  3. If all else fails, use a Map

Parameters:
bucket -
key -
tag -
requiredType -
Returns:

getBucketSchema

public <B> Map<String,Object> getBucketSchema(B bucket)

getBucketSchema

public <B> Map<String,Object> getBucketSchema(B bucket,
                                              boolean listKeys)

updateBucketSchema

public <B> BucketKeyValueStoreOperations updateBucketSchema(B bucket,
                                                            Map<String,Object> props)

Spring Data Key-Value

Copyright © 2010-2011 SpringSource. All Rights Reserved.