diff --git a/pom.xml b/pom.xml
index 3e6019fb5..78ccfb3dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
spring-data-keyvalue-parentspring-data-keyvalue-corespring-data-redis
- spring-datastore-riak
+ spring-data-riak
diff --git a/spring-data-keyvalue-parent/pom.xml b/spring-data-keyvalue-parent/pom.xml
index 0245bc3ac..6d4495752 100644
--- a/spring-data-keyvalue-parent/pom.xml
+++ b/spring-data-keyvalue-parent/pom.xml
@@ -255,6 +255,12 @@
true
+
+ javax.mail
+ mail
+ 1.4.2
+
+
org.mockitomockito-all
diff --git a/spring-datastore-riak/pom.xml b/spring-data-riak/pom.xml
similarity index 73%
rename from spring-datastore-riak/pom.xml
rename to spring-data-riak/pom.xml
index cca5ba595..120963fd0 100644
--- a/spring-datastore-riak/pom.xml
+++ b/spring-data-riak/pom.xml
@@ -92,6 +92,10 @@
jsr250-apitrue
+
+ javax.mail
+ mail
+ org.mockito
@@ -126,6 +130,45 @@
org.spockframeworkspock-maven
+
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+
+ test-compile
+
+ run
+
+
+
+
+
+ org.codehaus.groovy
+ groovy-all
+ 1.7.5
+
+
+ asm
+ asm
+ 3.2
+
+
+ antlr
+ antlr
+ 2.7.7
+
+
+
+
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java b/spring-data-riak/src/main/java/org/springframework/data/riak/DataStoreConnectionFailureException.java
similarity index 95%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/DataStoreConnectionFailureException.java
index 119050472..b439eab97 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/DataStoreConnectionFailureException.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.datastore.riak;
+package org.springframework.data.riak;
import org.springframework.dao.DataAccessResourceFailureException;
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java b/spring-data-riak/src/main/java/org/springframework/data/riak/DataStoreOperationException.java
similarity index 95%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/DataStoreOperationException.java
index 892593a7b..ce25450a1 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/DataStoreOperationException.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.datastore.riak;
+package org.springframework.data.riak;
import org.springframework.dao.DataAccessException;
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java b/spring-data-riak/src/main/java/org/springframework/data/riak/convert/KeyValueStoreMetaData.java
similarity index 95%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/convert/KeyValueStoreMetaData.java
index ea9cb8810..331f1cccb 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/convert/KeyValueStoreMetaData.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.datastore.riak.convert;
+package org.springframework.data.riak.convert;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/AbstractAsyncOperation.java
similarity index 96%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/AbstractAsyncOperation.java
index c78f0f76d..5e395c467 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/AbstractAsyncOperation.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/BucketKeyPair.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/BucketKeyPair.java
similarity index 88%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/BucketKeyPair.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/BucketKeyPair.java
index 615ed6a03..b32cca31c 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/BucketKeyPair.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/BucketKeyPair.java
@@ -1,4 +1,4 @@
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
/**
* A generic interface for representing composite keys in data stores that use a
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/BucketKeyResolver.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/BucketKeyResolver.java
similarity index 80%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/BucketKeyResolver.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/BucketKeyResolver.java
index 5425f1ec3..6a1c157e0 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/BucketKeyResolver.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/BucketKeyResolver.java
@@ -1,8 +1,8 @@
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
/**
* A generic interface to a resolver to turn a single object into a {@link
- * org.springframework.datastore.riak.core.BucketKeyPair}.
+ * org.springframework.data.riak.core.BucketKeyPair}.
*
* @author J. Brisbin
*/
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreMetaData.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreMetaData.java
similarity index 90%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreMetaData.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreMetaData.java
index dc5ddbf21..267b73a7f 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreMetaData.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreMetaData.java
@@ -1,4 +1,4 @@
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
import org.springframework.http.MediaType;
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreOperations.java
similarity index 82%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreOperations.java
index 8ccb10283..b746b700e 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreOperations.java
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
import java.util.List;
import java.util.Map;
/**
- * Generic abstraction for Key/Value stores. Contains most operations that
- * generic K/V stores might expose.
+ * Generic abstraction for Key/Value stores. Contains most operations that generic K/V stores
+ * might expose.
*/
public interface KeyValueStoreOperations {
@@ -47,9 +47,8 @@ public interface KeyValueStoreOperations {
// Get operations
/**
- * 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.
+ * 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.
*
* @param key
* @return The converted value, or null if not found.
@@ -65,8 +64,7 @@ public interface KeyValueStoreOperations {
byte[] getAsBytes(K key);
/**
- * Get the value at the specified key and convert it into an instance of the
- * specified type.
+ * Get the value at the specified key and convert it into an instance of the specified type.
*
* @param key
* @param requiredType
@@ -77,8 +75,7 @@ public interface KeyValueStoreOperations {
// Get and Set operations
/**
- * Get the old value at the specified key and replace it with the given
- * value.
+ * Get the old value at the specified key and replace it with the given value.
*
* @param key
* @param value
@@ -87,8 +84,8 @@ public interface KeyValueStoreOperations {
V getAndSet(K key, V value);
/**
- * Get the old value at the specified key as a byte array and replace it with
- * the given bytes.
+ * Get the old value at the specified key as a byte array and replace it with the given
+ * bytes.
*
* @param key
* @param value
@@ -97,8 +94,8 @@ public interface KeyValueStoreOperations {
byte[] getAndSetAsBytes(K key, byte[] value);
/**
- * Get the old value at the specified key and replace it with the given value,
- * converting it to an instance of the given type.
+ * Get the old value at the specified key and replace it with the given value, converting it
+ * to an instance of the given type.
*
* @param key
* @param value
@@ -113,40 +110,36 @@ public interface KeyValueStoreOperations {
* Get all the values at the specified keys.
*
* @param keys
- * @return A list of the values retrieved or an empty list if none were
- * found.
+ * @return A list of the values retrieved or an empty list if none were found.
*/
List getValues(List keys);
/**
- * Variation on {@link KeyValueStoreOperations#getValues(java.util.List)} that
- * uses varargs instead of a java.util.List.
+ * Variation on {@link KeyValueStoreOperations#getValues(java.util.List)} that uses varargs
+ * instead of a java.util.List.
*
* @param keys
- * @return A list of the values retrieved or an empty list if none were
- * found.
+ * @return A list of the values retrieved or an empty list if none were found.
*/
List getValues(K... keys);
/**
- * Get all the values at the specified keys, converting the values into
- * instances of the specified type.
+ * Get all the values at the specified keys, converting the values into instances of the
+ * specified type.
*
* @param keys
* @param requiredType
- * @return A list of the values retrieved or an empty list if none were
- * found.
+ * @return A list of the values retrieved or an empty list if none were found.
*/
List getValuesAsType(List keys, Class requiredType);
/**
- * A variation on {@link KeyValueStoreOperations#getValuesAsType(java.util.List,
- * Class)} that takes uses varargs instead of a java.util.List.
+ * A variation on {@link KeyValueStoreOperations#getValuesAsType(java.util.List, Class)} that
+ * takes uses varargs instead of a java.util.List.
*
* @param requiredType
* @param keys
- * @return A list of the values retrieved or an empty list if none were
- * found.
+ * @return A list of the values retrieved or an empty list if none were found.
*/
List getValuesAsType(Class requiredType, K... keys);
@@ -162,8 +155,7 @@ public interface KeyValueStoreOperations {
KeyValueStoreOperations setIfKeyNonExistent(K key, V value);
/**
- * Set the value at the given key as a byte array only if that key doesn't
- * already exist.
+ * Set the value at the given key as a byte array only if that key doesn't already exist.
*
* @param key
* @param value
@@ -192,8 +184,7 @@ public interface KeyValueStoreOperations {
// Multiple key-value set if non-existent
/**
- * Variation on setting multiple values only if the key doesn't already
- * exist.
+ * Variation on setting multiple values only if the key doesn't already exist.
*
* @param keysAndValues
* @return This template interface
@@ -201,8 +192,7 @@ public interface KeyValueStoreOperations {
KeyValueStoreOperations setMultipleIfKeysNonExistent(Map keysAndValues);
/**
- * Variation on setting multiple values as byte arryas only if the key doesn't
- * already exist.
+ * Variation on setting multiple values as byte arrays only if the key doesn't already exist.
*
* @param keysAndValues
* @param
@@ -222,8 +212,8 @@ public interface KeyValueStoreOperations {
* Delete one or more keys from the store.
*
* @param keys
- * @return true if all keys were successfully deleted,
- * false otherwise.
+ * @return true if all keys were successfully deleted, false
+ * otherwise.
*/
boolean deleteKeys(K... keys);
@@ -235,14 +225,15 @@ public interface KeyValueStoreOperations {
*/
Map getBucketSchema(B bucket);
+ KeyValueStoreOperations updateBucketSchema(B bucket, Map props);
+
/**
- * Get the properties of the bucket and specify whether or not to list the
- * keys in that bucket.
+ * Get the properties of the bucket and specify whether or not to list the keys in that
+ * bucket.
*
* @param bucket
* @param listKeys
- * @return The bucket properties, with or without a list of keys in that
- * bucket.
+ * @return The bucket properties, with or without a list of keys in that bucket.
*/
Map getBucketSchema(B bucket, boolean listKeys);
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreValue.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreValue.java
similarity index 88%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreValue.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreValue.java
index f0924c0c8..5b593d9fc 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreValue.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/KeyValueStoreValue.java
@@ -1,4 +1,4 @@
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
/**
* A generic interface for dealing with values and their store metadata.
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakMetaData.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakMetaData.java
similarity index 82%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakMetaData.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakMetaData.java
index f74efc6d4..062940b95 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakMetaData.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakMetaData.java
@@ -1,11 +1,11 @@
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
import org.springframework.http.MediaType;
import java.util.Map;
/**
- * An implementation of {@link org.springframework.datastore.riak.core.KeyValueStoreMetaData}
+ * An implementation of {@link org.springframework.data.riak.core.KeyValueStoreMetaData}
* for Riak.
*
* @author J. Brisbin
diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java
similarity index 80%
rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java
rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java
index fdce5eec7..ef1cbcda7 100644
--- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java
+++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.datastore.riak.core;
+package org.springframework.data.riak.core;
import org.codehaus.groovy.runtime.GStringImpl;
import org.codehaus.jackson.map.ObjectMapper;
@@ -26,11 +26,11 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.ConversionServiceFactory;
import org.springframework.dao.DataAccessResourceFailureException;
-import org.springframework.datastore.riak.DataStoreOperationException;
-import org.springframework.datastore.riak.convert.KeyValueStoreMetaData;
-import org.springframework.datastore.riak.mapreduce.MapReduceJob;
-import org.springframework.datastore.riak.mapreduce.MapReduceOperations;
-import org.springframework.datastore.riak.mapreduce.RiakMapReduceJob;
+import org.springframework.data.riak.DataStoreOperationException;
+import org.springframework.data.riak.convert.KeyValueStoreMetaData;
+import org.springframework.data.riak.mapreduce.MapReduceJob;
+import org.springframework.data.riak.mapreduce.MapReduceOperations;
+import org.springframework.data.riak.mapreduce.RiakMapReduceJob;
import org.springframework.http.*;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
@@ -39,9 +39,14 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
+import org.springframework.util.StringUtils;
import org.springframework.web.client.*;
import org.springframework.web.client.support.RestGatewaySupport;
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.util.ByteArrayDataSource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -49,10 +54,7 @@ import java.io.StringWriter;
import java.lang.annotation.Annotation;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -61,13 +63,12 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * An implementation of {@link org.springframework.datastore.riak.core.KeyValueStoreOperations}
- * and {@link org.springframework.datastore.riak.mapreduce.MapReduceOperations} for the Riak
- * data store.
+ * An implementation of {@link org.springframework.data.riak.core.KeyValueStoreOperations} and
+ * {@link org.springframework.data.riak.mapreduce.MapReduceOperations} for the Riak data store.
*
* To use the RiakTemplate, create a singleton in your Spring application-context.xml:
*
A
* String of only the key name, but specifying a bucket by using the {@link
- * org.springframework.datastore.riak.convert.KeyValueStoreMetaData} annotation on the object
- * you're storing.
+ * org.springframework.data.riak.convert.KeyValueStoreMetaData} annotation on the object you're
+ * storing.
*
* @author J. Brisbin
*/
@@ -96,7 +97,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe
/**
* Client ID used by Riak to correlate updates.
*/
- private static final String RIAK_CLIENT_ID = "org.springframework.datastore.riak.core.RiakTemplate/1.0";
+ private static final String RIAK_CLIENT_ID = "org.springframework.data.riak.core.RiakTemplate/1.0";
/**
* Regex used to extract host, port, and prefix from the given URI.
*/
@@ -547,11 +548,25 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe
public T execute(MapReduceJob job, Class targetType) {
RestTemplate restTemplate = getRestTemplate();
- ResponseEntity resp = restTemplate.postForEntity(mapReduceUri,
+ ResponseEntity resp = restTemplate.postForEntity(mapReduceUri,
job.toJson(),
- targetType);
+ List.class);
if (resp.hasBody()) {
- return resp.getBody();
+ if (!targetType.isAssignableFrom(List.class)) {
+ List> results = (List>) resp.getBody();
+ if (results.size() == 1) {
+ Object obj = results.get(0);
+ if (obj.getClass() != targetType) {
+ ConversionService conv = getConversionService();
+ if (conv.canConvert(obj.getClass(), targetType)) {
+ return conv.convert(obj, targetType);
+ }
+ } else {
+ return (T) obj;
+ }
+ }
+ }
+ return (T) resp.getBody();
}
return null;
}
@@ -614,7 +629,9 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe
}
/**
- * Incomplete implementation of Link Walking.
+ * 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).
*
* @param source
* @param tag
@@ -622,10 +639,10 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe
*/
public T linkWalk(K source, String tag) {
BucketKeyPair bkpSource = resolveBucketKeyPair(source, null);
- RestTemplate restTemplate = getRestTemplate();
+ final RestTemplate restTemplate = getRestTemplate();
final List types = new ArrayList();
types.add(MediaType.ALL);
- restTemplate.execute(defaultUri + "/_,{tag},_",
+ T returnObj = (T) restTemplate.execute(defaultUri + "/_,{tag},_",
HttpMethod.GET,
new RequestCallback() {
public void doWithRequest(ClientHttpRequest request) throws
@@ -636,14 +653,82 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe
new ResponseExtractor