Spring Data Key-Value

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

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.RiakKeyValueTemplate
All Implemented Interfaces:
BeanClassLoaderAware, InitializingBean, KeyValueStoreOperations, MapReduceOperations

public class RiakKeyValueTemplate
extends AbstractRiakTemplate
implements KeyValueStoreOperations, MapReduceOperations, InitializingBean

An implementation of KeyValueStoreOperations 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([bucket: "mybucket", key: "mykey"], obj)
 ...
 def name = riak.get([bucket: "mybucket", key: "mykey"]).name
 println "Hello $name!"
 
You're key object should be one of:

Author:
J. Brisbin

Field Summary
protected  RiakTemplate riak
           
 
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
RiakKeyValueTemplate()
          Take all the defaults.
RiakKeyValueTemplate(ClientHttpRequestFactory requestFactory)
          Use the specified ClientHttpRequestFactory.
RiakKeyValueTemplate(String defaultUri, String mapReduceUri)
          Use the specified defaultUri and mapReduceUri.
 
Method Summary
 void afterPropertiesSet()
           
<K> boolean
containsKey(K key)
          Does the store contain this key?
 RiakMapReduceJob createMapReduceJob()
           
<K> boolean
deleteKeys(K... keys)
          Delete one or more keys from the store.
 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.
<K,V> V
get(K key)
          Get a value at the specified key, trying to infer the type from either the bucket in which the value was stored, or (by default) as a java.util.Map.
<K,V> V
getAndSet(K key, V value)
          Get the old value at the specified key and replace it with the given value.
<K> byte[]
getAndSetAsBytes(K key, byte[] value)
          Get the old value at the specified key as a byte array and replace it with the given bytes.
<K,V,T> T
getAndSetAsType(K key, V value, Class<T> requiredType)
          Get the old value at the specified key and replace it with the given value, converting it to an instance of the given type.
<K> byte[]
getAsBytes(K key)
          Get the value at the specified key as a byte array.
<K> RiakValue<byte[]>
getAsBytesWithMetaData(K key)
           
<K,T> T
getAsType(K key, Class<T> requiredType)
          Get the value at the specified key and convert it into an instance of the specified type.
<B> Map<String,Object>
getBucketSchema(B bucket)
          Get the properties of the specified bucket.
<B> Map<String,Object>
getBucketSchema(B bucket, boolean listKeys)
          Get the properties of the bucket and specify whether or not to list the keys in that bucket.
<K> RiakMetaData
getMetaData(K key)
           
<K,V> List<V>
getValues(K... keys)
          Variation on KeyValueStoreOperations.getValues(java.util.List) that uses varargs instead of a java.util.List.
<K,V> List<V>
getValues(List<K> keys)
          Get all the values at the specified keys.
<T,K> List<T>
getValuesAsType(Class<T> requiredType, K... keys)
          A variation on KeyValueStoreOperations.getValuesAsType(java.util.List, Class) that takes uses varargs instead of a java.util.List.
<K,T> List<T>
getValuesAsType(List<K> keys, Class<T> requiredType)
          Get all the values at the specified keys, converting the values into instances of the specified type.
<K,T> RiakValue<T>
getWithMetaData(K key, Class<T> requiredType)
           
<K1,K2> RiakKeyValueTemplate
link(K1 destination, K2 source, String tag)
          Use Riak's native Link mechanism to link two entries together.
<T,K> T
linkWalk(K source, 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).
<K,V> KeyValueStoreOperations
set(K key, V value)
          Set a value at a specified key.
<K,V> KeyValueStoreOperations
set(K key, V value, QosParameters qosParams)
          Variation on set() that allows the user to specify QosParameters.
<K> KeyValueStoreOperations
setAsBytes(K key, byte[] value)
          Set a value as a byte array at a specified key.
<K> KeyValueStoreOperations
setAsBytes(K key, byte[] value, QosParameters qosParams)
           
<K,V> KeyValueStoreOperations
setIfKeyNonExistent(K key, V value)
          Set the value at the given key only if that key doesn't already exist.
<K> KeyValueStoreOperations
setIfKeyNonExistentAsBytes(K key, byte[] value)
          Set the value at the given key as a byte array only if that key doesn't already exist.
<K,V> KeyValueStoreOperations
setMultiple(Map<K,V> keysAndValues)
          Convenience method to set multiple values as Key/Value pairs.
<K> KeyValueStoreOperations
setMultipleAsBytes(Map<K,byte[]> keysAndValues)
          Convenience method to set multiple values as Key/byte[] pairs.
<K> KeyValueStoreOperations
setMultipleAsBytesIfKeysNonExistent(Map<K,byte[]> keysAndValues)
          Variation on setting multiple values as byte arrays only if the key doesn't already exist.
<K,V> KeyValueStoreOperations
setMultipleIfKeysNonExistent(Map<K,V> keysAndValues)
          Variation on setting multiple values only if the key doesn't already exist.
<K,V> KeyValueStoreOperations
setWithMetaData(K key, V value, Map<String,String> metaData)
           
<K,V> KeyValueStoreOperations
setWithMetaData(K key, V value, Map<String,String> metaData, QosParameters qosParams)
          Variation on setWithMetaData() that allows the user to pass QosParameters.
<T> Future<List<T>>
submit(MapReduceJob job)
          Submit the job to run asynchronously.
<B> KeyValueStoreOperations
updateBucketSchema(B bucket, Map<String,Object> props)
           
 
Methods inherited from class org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
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
 

Field Detail

riak

protected RiakTemplate riak
Constructor Detail

RiakKeyValueTemplate

public RiakKeyValueTemplate()
Take all the defaults.


RiakKeyValueTemplate

public RiakKeyValueTemplate(ClientHttpRequestFactory requestFactory)
Use the specified ClientHttpRequestFactory.

Parameters:
requestFactory -

RiakKeyValueTemplate

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

Parameters:
defaultUri -
mapReduceUri -
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractRiakTemplate
Throws:
Exception

set

public <K,V> KeyValueStoreOperations set(K key,
                                         V value)
Description copied from interface: KeyValueStoreOperations
Set a value at a specified key.

Specified by:
set in interface KeyValueStoreOperations
Returns:
This template interface

set

public <K,V> KeyValueStoreOperations set(K key,
                                         V value,
                                         QosParameters qosParams)
Description copied from interface: KeyValueStoreOperations
Variation on set() that allows the user to specify QosParameters.

Specified by:
set in interface KeyValueStoreOperations
Returns:

setAsBytes

public <K> KeyValueStoreOperations setAsBytes(K key,
                                              byte[] value)
Description copied from interface: KeyValueStoreOperations
Set a value as a byte array at a specified key.

Specified by:
setAsBytes in interface KeyValueStoreOperations
Returns:
This template interface

setAsBytes

public <K> KeyValueStoreOperations setAsBytes(K key,
                                              byte[] value,
                                              QosParameters qosParams)
Specified by:
setAsBytes in interface KeyValueStoreOperations

setWithMetaData

public <K,V> KeyValueStoreOperations setWithMetaData(K key,
                                                     V value,
                                                     Map<String,String> metaData,
                                                     QosParameters qosParams)
Description copied from interface: KeyValueStoreOperations
Variation on setWithMetaData() that allows the user to pass QosParameters.

Specified by:
setWithMetaData in interface KeyValueStoreOperations
Returns:

setWithMetaData

public <K,V> KeyValueStoreOperations setWithMetaData(K key,
                                                     V value,
                                                     Map<String,String> metaData)
Specified by:
setWithMetaData in interface KeyValueStoreOperations

getMetaData

public <K> RiakMetaData getMetaData(K key)

getWithMetaData

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

get

public <K,V> V get(K key)
Description copied from interface: KeyValueStoreOperations
Get a value at the specified key, trying to infer the type from either the bucket in which the value was stored, or (by default) as a java.util.Map.

Specified by:
get in interface KeyValueStoreOperations
Returns:
The converted value, or null if not found.

getAsBytes

public <K> byte[] getAsBytes(K key)
Description copied from interface: KeyValueStoreOperations
Get the value at the specified key as a byte array.

Specified by:
getAsBytes in interface KeyValueStoreOperations
Returns:
The byte array of data, or null if not found.

getAsBytesWithMetaData

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

getAsType

public <K,T> T getAsType(K key,
                         Class<T> requiredType)
Description copied from interface: KeyValueStoreOperations
Get the value at the specified key and convert it into an instance of the specified type.

Specified by:
getAsType in interface KeyValueStoreOperations
Returns:
The converted value, or null if not found.

getAndSet

public <K,V> V getAndSet(K key,
                         V value)
Description copied from interface: KeyValueStoreOperations
Get the old value at the specified key and replace it with the given value.

Specified by:
getAndSet in interface KeyValueStoreOperations
Returns:
The old value (before it was overwritten).

getAndSetAsBytes

public <K> byte[] getAndSetAsBytes(K key,
                                   byte[] value)
Description copied from interface: KeyValueStoreOperations
Get the old value at the specified key as a byte array and replace it with the given bytes.

Specified by:
getAndSetAsBytes in interface KeyValueStoreOperations
Returns:
The old byte array (before it was overwritten).

getAndSetAsType

public <K,V,T> T getAndSetAsType(K key,
                                 V value,
                                 Class<T> requiredType)
Description copied from interface: KeyValueStoreOperations
Get the old value at the specified key and replace it with the given value, converting it to an instance of the given type.

Specified by:
getAndSetAsType in interface KeyValueStoreOperations
requiredType - The type to convert the value to.
Returns:
The old value (before it was overwritten).

getValues

public <K,V> List<V> getValues(List<K> keys)
Description copied from interface: KeyValueStoreOperations
Get all the values at the specified keys.

Specified by:
getValues in interface KeyValueStoreOperations
Returns:
A list of the values retrieved or an empty list if none were found.

getValues

public <K,V> List<V> getValues(K... keys)
Description copied from interface: KeyValueStoreOperations
Variation on KeyValueStoreOperations.getValues(java.util.List) that uses varargs instead of a java.util.List.

Specified by:
getValues in interface KeyValueStoreOperations
Returns:
A list of the values retrieved or an empty list if none were found.

getValuesAsType

public <K,T> List<T> getValuesAsType(List<K> keys,
                                     Class<T> requiredType)
Description copied from interface: KeyValueStoreOperations
Get all the values at the specified keys, converting the values into instances of the specified type.

Specified by:
getValuesAsType in interface KeyValueStoreOperations
Returns:
A list of the values retrieved or an empty list if none were found.

getValuesAsType

public <T,K> List<T> getValuesAsType(Class<T> requiredType,
                                     K... keys)
Description copied from interface: KeyValueStoreOperations
A variation on KeyValueStoreOperations.getValuesAsType(java.util.List, Class) that takes uses varargs instead of a java.util.List.

Specified by:
getValuesAsType in interface KeyValueStoreOperations
Returns:
A list of the values retrieved or an empty list if none were found.

setIfKeyNonExistent

public <K,V> KeyValueStoreOperations setIfKeyNonExistent(K key,
                                                         V value)
Description copied from interface: KeyValueStoreOperations
Set the value at the given key only if that key doesn't already exist.

Specified by:
setIfKeyNonExistent in interface KeyValueStoreOperations
Returns:
This template interface

setIfKeyNonExistentAsBytes

public <K> KeyValueStoreOperations setIfKeyNonExistentAsBytes(K key,
                                                              byte[] value)
Description copied from interface: KeyValueStoreOperations
Set the value at the given key as a byte array only if that key doesn't already exist.

Specified by:
setIfKeyNonExistentAsBytes in interface KeyValueStoreOperations
Returns:
This template interface

setMultiple

public <K,V> KeyValueStoreOperations setMultiple(Map<K,V> keysAndValues)
Description copied from interface: KeyValueStoreOperations
Convenience method to set multiple values as Key/Value pairs.

Specified by:
setMultiple in interface KeyValueStoreOperations
Returns:
This template interface

setMultipleAsBytes

public <K> KeyValueStoreOperations setMultipleAsBytes(Map<K,byte[]> keysAndValues)
Description copied from interface: KeyValueStoreOperations
Convenience method to set multiple values as Key/byte[] pairs.

Specified by:
setMultipleAsBytes in interface KeyValueStoreOperations
Returns:
This template interface

setMultipleIfKeysNonExistent

public <K,V> KeyValueStoreOperations setMultipleIfKeysNonExistent(Map<K,V> keysAndValues)
Description copied from interface: KeyValueStoreOperations
Variation on setting multiple values only if the key doesn't already exist.

Specified by:
setMultipleIfKeysNonExistent in interface KeyValueStoreOperations
Returns:
This template interface

setMultipleAsBytesIfKeysNonExistent

public <K> KeyValueStoreOperations setMultipleAsBytesIfKeysNonExistent(Map<K,byte[]> keysAndValues)
Description copied from interface: KeyValueStoreOperations
Variation on setting multiple values as byte arrays only if the key doesn't already exist.

Specified by:
setMultipleAsBytesIfKeysNonExistent in interface KeyValueStoreOperations
Returns:

containsKey

public <K> boolean containsKey(K key)
Description copied from interface: KeyValueStoreOperations
Does the store contain this key?

Specified by:
containsKey in interface KeyValueStoreOperations
Returns:
true if the key exists, false otherwise.

deleteKeys

public <K> boolean deleteKeys(K... keys)
Description copied from interface: KeyValueStoreOperations
Delete one or more keys from the store.

Specified by:
deleteKeys in interface KeyValueStoreOperations
Returns:
true if all keys were successfully deleted, false otherwise.

createMapReduceJob

public RiakMapReduceJob createMapReduceJob()

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 <K1,K2> RiakKeyValueTemplate link(K1 destination,
                                         K2 source,
                                         String tag)
Use Riak's native Link mechanism to link two entries together.

Parameters:
destination - Key to the child object
source - Key to the parent object
tag - The tag for this relationship
Returns:
This template interface

linkWalk

public <T,K> T linkWalk(K source,
                        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:
source -
tag -
Returns:

getBucketSchema

public <B> Map<String,Object> getBucketSchema(B bucket)
Description copied from interface: KeyValueStoreOperations
Get the properties of the specified bucket.

Specified by:
getBucketSchema in interface KeyValueStoreOperations
Returns:
The bucket properties, without a list of keys in that bucket.

getBucketSchema

public <B> Map<String,Object> getBucketSchema(B bucket,
                                              boolean listKeys)
Description copied from interface: KeyValueStoreOperations
Get the properties of the bucket and specify whether or not to list the keys in that bucket.

Specified by:
getBucketSchema in interface KeyValueStoreOperations
Returns:
The bucket properties, with or without a list of keys in that bucket.

updateBucketSchema

public <B> KeyValueStoreOperations updateBucketSchema(B bucket,
                                                      Map<String,Object> props)
Specified by:
updateBucketSchema in interface KeyValueStoreOperations

Spring Data Key-Value

Copyright © 2010-2011 SpringSource. All Rights Reserved.