diff --git a/pom.xml b/pom.xml
index 0f5f7cf1d..8308bf52f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
http://www.SpringSource.org
-
+
mpollack
Mark Pollack
@@ -49,6 +49,17 @@
+2
+
+ jbrisbin
+ Jon Brisbin
+ jon at jbrisbin.com
+ NPC International
+ http://www.npcinternational.com
+
+ Developer
+
+ -6
+
diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java
index a3abe7ba0..f928239bd 100644
--- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java
@@ -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 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 String put(B bucket, V value, Map 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 entry : metaData.entrySet()) {
+ headers.set(entry.getKey(), entry.getValue());
+ }
+ }
+ HttpEntity entity = new HttpEntity(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 RiakMetaData getMetaData(B bucket, K key) {
diff --git a/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy b/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy
index a911e64ac..f92885321 100644
--- a/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy
+++ b/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy
@@ -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
diff --git a/src/docbkx/reference/riak.xml b/src/docbkx/reference/riak.xml
index 15edc0c1e..4d1d6dfe9 100644
--- a/src/docbkx/reference/riak.xml
+++ b/src/docbkx/reference/riak.xml
@@ -89,7 +89,7 @@
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 Map.
-
+
Saving data into Riak
To store data in Riak, use one of the six different set methods:
@@ -114,9 +114,30 @@ public class Example {
Additionally, there is a setWithMetaData method that takes a Map of metadata that will be set as the outgoing HTTP headers. To set custom metadata, your key should be prefixed with X-Riak-Meta- e.g. X-Riak-Meta-Custom-Header.
+
+
+ Letting Riak generate the key
+
+ Riak has the ability to generate random IDs for you when storing objects. The RiakTemplate exposes this capability via the put method. It will return the ID it generated for you as a String.
+
+
+
-
+
Retrieving data from Riak
Retrieving data from Riak is just as easy. There are actually 13 different get methods on RiakTemplate that give the developer a wide range options for accessing and converting your data.
diff --git a/src/main/resources/changelog-riak.txt b/src/main/resources/changelog-riak.txt
index 5a1ad7a97..8c1c19464 100644
--- a/src/main/resources/changelog-riak.txt
+++ b/src/main/resources/changelog-riak.txt
@@ -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