Merge branch 'master' of github.com:SpringSource/spring-data-keyvalue
This commit is contained in:
13
pom.xml
13
pom.xml
@@ -25,7 +25,7 @@
|
||||
<url>http://www.SpringSource.org</url>
|
||||
</organization>
|
||||
|
||||
<developers>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>mpollack</id>
|
||||
<name>Mark Pollack</name>
|
||||
@@ -49,6 +49,17 @@
|
||||
</roles>
|
||||
<timezone>+2</timezone>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>jbrisbin</id>
|
||||
<name>Jon Brisbin</name>
|
||||
<email>jon at jbrisbin.com</email>
|
||||
<organization>NPC International</organization>
|
||||
<organizationUrl>http://www.npcinternational.com</organizationUrl>
|
||||
<roles>
|
||||
<role>Developer</role>
|
||||
</roles>
|
||||
<timezone>-6</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@@ -163,6 +164,52 @@ public class RiakTemplate extends AbstractRiakTemplate implements BucketKeyValue
|
||||
return setWithMetaData(bucket, key, value, metaData, null);
|
||||
}
|
||||
|
||||
/*----------------- Put Operations -----------------*/
|
||||
|
||||
/**
|
||||
* Save an object to Riak and let it generate an ID for it.
|
||||
*
|
||||
* @param bucket
|
||||
* @param value
|
||||
* @return The generated ID
|
||||
*/
|
||||
public <B, V> String put(B bucket, V value) {
|
||||
return put(bucket, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an object to Riak and let it generate an ID for it.
|
||||
*
|
||||
* @param bucket
|
||||
* @param value
|
||||
* @param metaData
|
||||
* @return The generated ID
|
||||
*/
|
||||
public <B, V> String put(B bucket, V value, Map<String, String> metaData) {
|
||||
String bucketName = bucket.toString();
|
||||
RestTemplate restTemplate = getRestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("X-Riak-ClientId", RIAK_CLIENT_ID);
|
||||
headers.setContentType(extractMediaType(value));
|
||||
if (null != metaData) {
|
||||
for (Map.Entry<String, String> entry : metaData.entrySet()) {
|
||||
headers.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
HttpEntity<V> entity = new HttpEntity<V>(value, headers);
|
||||
try {
|
||||
URI uri = restTemplate.postForLocation(defaultUri, entity, bucketName, "");
|
||||
String suri = uri.toString();
|
||||
String id = suri.substring(suri.lastIndexOf("/") + 1);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New ID: " + id);
|
||||
}
|
||||
return id;
|
||||
} catch (RestClientException e) {
|
||||
throw new DataStoreOperationException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------- Get Operations -----------------*/
|
||||
|
||||
public <B, K> RiakMetaData getMetaData(B bucket, K key) {
|
||||
|
||||
@@ -40,6 +40,7 @@ class RiakTemplateSpec extends Specification {
|
||||
int run = 1
|
||||
@Shared def riakBin = System.properties["bamboo.RIAK_BIN"] ?: "/usr/sbin/riak"
|
||||
@Shared def p
|
||||
@Shared def id
|
||||
/*
|
||||
def setupSpec() {
|
||||
p = "$riakBin start".execute()
|
||||
@@ -68,6 +69,20 @@ class RiakTemplateSpec extends Specification {
|
||||
|
||||
}
|
||||
|
||||
def "Test generating ID for object"() {
|
||||
|
||||
given:
|
||||
def val = "value"
|
||||
def objIn = [test: val, integer: 12]
|
||||
|
||||
when:
|
||||
id = riak.put("test", objIn, null)
|
||||
|
||||
then:
|
||||
null != id
|
||||
|
||||
}
|
||||
|
||||
def "Test custom object"() {
|
||||
|
||||
given:
|
||||
@@ -261,9 +276,10 @@ class RiakTemplateSpec extends Specification {
|
||||
given:
|
||||
def testKey = new SimpleBucketKeyPair("test", "test")
|
||||
def testKey2 = new SimpleBucketKeyPair(TestObject.name, "test")
|
||||
def testKey3 = new SimpleBucketKeyPair("test", id)
|
||||
|
||||
when:
|
||||
def deleted = riak.deleteKeys(testKey, testKey2)
|
||||
def deleted = riak.deleteKeys(testKey, testKey2, testKey3)
|
||||
|
||||
then:
|
||||
true == deleted
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
|
||||
<para>One of the primary goals of the SDKV project is to make accessing Key/Value stores easier for the developer by taking away the mundane tasks of basic IO, buffering, type conversion, exception handling, and sundry other logistical concerns so the developer can focus on creating great applications. SDKV for Riak works toward this goal by making basic persistence and data access as easy as using a <classname>Map</classname>.</para>
|
||||
|
||||
<section id="riak:template:objects:get">
|
||||
<section id="riak:template:objects:set">
|
||||
<title>Saving data into Riak</title>
|
||||
|
||||
<para>To store data in Riak, use one of the six different <literal>set</literal> methods:
|
||||
@@ -114,9 +114,30 @@ public class Example {
|
||||
</para>
|
||||
|
||||
<para>Additionally, there is a <literal>setWithMetaData</literal> method that takes a <classname>Map</classname> of metadata that will be set as the outgoing HTTP headers. To set <ulink url="https://wiki.basho.com/display/RIAK/REST+API#RESTAPI-Storeaneworexistingobjectwithakey">custom metadata</ulink>, your key should be prefixed with <literal>X-Riak-Meta-</literal> e.g. <literal>X-Riak-Meta-Custom-Header</literal>.</para>
|
||||
|
||||
<section id="riak:template:objects:set:genid">
|
||||
<title>Letting Riak generate the key</title>
|
||||
|
||||
<para>Riak has the ability to generate random IDs for you when storing objects. The <classname>RiakTemplate</classname> exposes this capability via the <literal>put</literal> method. It will return the ID it generated for you as a <classname>String</classname>.
|
||||
<programlisting language="java"><![CDATA[import org.springframework.data.keyvalue.riak.core.RiakTemplate;
|
||||
|
||||
public class Example {
|
||||
|
||||
@Autowired
|
||||
RiakTemplate riak;
|
||||
|
||||
public String setData(String bucket, String data) throws Exception {
|
||||
String id = riak.put(bucket, data); // Returns the generated ID
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="riak:template:objects:set">
|
||||
<section id="riak:template:objects:get">
|
||||
<title>Retrieving data from Riak</title>
|
||||
|
||||
<para>Retrieving data from Riak is just as easy. There are actually 13 different <literal>get</literal> methods on <classname>RiakTemplate</classname> that give the developer a wide range options for accessing and converting your data.</para>
|
||||
|
||||
@@ -3,7 +3,7 @@ SPRING DATA RIAK INTEGRATION CHANGELOG
|
||||
http://www.springsource.org/spring-data
|
||||
|
||||
|
||||
Changes in version 1.0.0.M2 (2010-12-dd)
|
||||
Changes in version 1.0.0.M1 (2010-12-dd)
|
||||
----------------------------------------
|
||||
General
|
||||
* Generified RiakTemplate for exception translation, serialization, and data access
|
||||
|
||||
Reference in New Issue
Block a user