From 9cb0e8325c72c6baa4d65705cce719e5122ca61a Mon Sep 17 00:00:00 2001 From: "J. Brisbin" Date: Fri, 26 Nov 2010 09:52:59 -0600 Subject: [PATCH 1/4] Added link walking and setting bucket properties --- spring-data-keyvalue-parent/pom.xml | 6 + .../pom.xml | 4 + .../DataStoreConnectionFailureException.java | 2 +- .../riak/DataStoreOperationException.java | 2 +- .../riak/convert/KeyValueStoreMetaData.java | 2 +- .../riak/core/AbstractAsyncOperation.java | 2 +- .../data}/riak/core/BucketKeyPair.java | 2 +- .../data}/riak/core/BucketKeyResolver.java | 4 +- .../riak/core/KeyValueStoreMetaData.java | 2 +- .../riak/core/KeyValueStoreOperations.java | 71 ++++----- .../data}/riak/core/KeyValueStoreValue.java | 2 +- .../data}/riak/core/RiakMetaData.java | 4 +- .../data}/riak/core/RiakTemplate.java | 137 +++++++++++++++--- .../data}/riak/core/RiakValue.java | 2 +- .../data}/riak/core/SimpleBucketKeyPair.java | 2 +- .../riak/core/SimpleBucketKeyResolver.java | 2 +- .../mapreduce/ErlangMapReduceOperation.java | 4 +- .../JavascriptMapReduceOperation.java | 8 +- .../data}/riak/mapreduce/MapReduceJob.java | 2 +- .../riak/mapreduce/MapReduceOperation.java | 2 +- .../riak/mapreduce/MapReduceOperations.java | 4 +- .../data}/riak/mapreduce/MapReducePhase.java | 2 +- .../riak/mapreduce/RiakMapReduceJob.java | 8 +- .../riak/mapreduce/RiakMapReducePhase.java | 4 +- .../resources/META-INF/spring/app-context.xml | 0 .../data}/riak/core/RiakTemplateSpec.groovy | 32 +++- .../data}/riak/core/TestObject.java | 2 +- .../src/test/resources/log4j.properties | 2 +- .../data}/RiakTemplateTests.xml | 2 +- .../template.mf | 0 spring-datastore-riak/.classpath | 10 -- spring-datastore-riak/.project | 23 --- .../.settings/org.eclipse.jdt.core.prefs | 6 - .../.settings/org.maven.ide.eclipse.prefs | 9 -- 34 files changed, 215 insertions(+), 151 deletions(-) rename {spring-datastore-riak => spring-data-riak}/pom.xml (97%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/DataStoreConnectionFailureException.java (95%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/DataStoreOperationException.java (95%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/convert/KeyValueStoreMetaData.java (95%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/AbstractAsyncOperation.java (96%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/BucketKeyPair.java (88%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/BucketKeyResolver.java (80%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/KeyValueStoreMetaData.java (90%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/KeyValueStoreOperations.java (82%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/KeyValueStoreValue.java (88%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/RiakMetaData.java (82%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/RiakTemplate.java (82%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/RiakValue.java (90%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/SimpleBucketKeyPair.java (94%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/core/SimpleBucketKeyResolver.java (97%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/ErlangMapReduceOperation.java (86%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/JavascriptMapReduceOperation.java (78%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/MapReduceJob.java (96%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/MapReduceOperation.java (94%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/MapReduceOperations.java (91%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/MapReducePhase.java (95%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/RiakMapReduceJob.java (94%) rename {spring-datastore-riak/src/main/java/org/springframework/datastore => spring-data-riak/src/main/java/org/springframework/data}/riak/mapreduce/RiakMapReducePhase.java (92%) rename {spring-datastore-riak => spring-data-riak}/src/main/resources/META-INF/spring/app-context.xml (100%) rename {spring-datastore-riak/src/test/groovy/org/springframework/datastore => spring-data-riak/src/test/groovy/org/springframework/data}/riak/core/RiakTemplateSpec.groovy (85%) rename {spring-datastore-riak/src/test/groovy/org/springframework/datastore => spring-data-riak/src/test/groovy/org/springframework/data}/riak/core/TestObject.java (95%) rename {spring-datastore-riak => spring-data-riak}/src/test/resources/log4j.properties (90%) rename {spring-datastore-riak/src/test/resources/org/springframework/datastore => spring-data-riak/src/test/resources/org/springframework/data}/RiakTemplateTests.xml (80%) rename {spring-datastore-riak => spring-data-riak}/template.mf (100%) delete mode 100644 spring-datastore-riak/.classpath delete mode 100644 spring-datastore-riak/.project delete mode 100644 spring-datastore-riak/.settings/org.eclipse.jdt.core.prefs delete mode 100644 spring-datastore-riak/.settings/org.maven.ide.eclipse.prefs 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.mockito mockito-all diff --git a/spring-datastore-riak/pom.xml b/spring-data-riak/pom.xml similarity index 97% rename from spring-datastore-riak/pom.xml rename to spring-data-riak/pom.xml index cca5ba595..96261dc0c 100644 --- a/spring-datastore-riak/pom.xml +++ b/spring-data-riak/pom.xml @@ -92,6 +92,10 @@ jsr250-api true + + javax.mail + mail + org.mockito 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 82% 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..dc7988800 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: *


- * <bean id="riak" class="org.springframework.datastore.riak.core.RiakTemplate"
+ * <bean id="riak" class="org.springframework.data.riak.core.RiakTemplate"
  *     p:defaultUri="http://localhost:8098/riak/{bucket}/{key}"
  *     p:mapReduceUri="http://localhost:8098/mapred"/>
  * 
@@ -82,11 +83,11 @@ import java.util.regex.Pattern; * * You're key object should be one of:
  • A String encoding the bucket and key * together, separated by a colon. e.g. "mybucket:mykey"
  • An implementation of - * BucketKeyPair (like {@link org.springframework.datastore.riak.core.SimpleBucketKeyPair})
  • + * BucketKeyPair (like {@link org.springframework.data.riak.core.SimpleBucketKeyPair}) *
  • A Map with both a "bucket" and a "key" specified.
  • 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. */ @@ -614,7 +615,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 +625,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 +639,82 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe new ResponseExtractor() { public Object extractData(ClientHttpResponse response) throws IOException { - response.getHeaders(); - return null; //To change body of implemented methods use File | Settings | File Templates. + String contentType = ((List) response.getHeaders().get("Content-Type")).get(0) + .toString(); + if (contentType.startsWith("multipart/mixed")) { + List results = new LinkedList(); + ByteArrayDataSource ds = new ByteArrayDataSource(response.getBody(), + "multipart/mixed"); + try { + MimeMultipart mp = new MimeMultipart(ds); + int msgCnt = mp.getCount(); + for (int i = 0; i < msgCnt; i++) { + BodyPart bp = mp.getBodyPart(i); + if (bp.getContentType().startsWith("multipart/mixed")) { + MimeMultipart part = (MimeMultipart) bp.getContent(); + int partCnt = part.getCount(); + for (int j = 0; j < partCnt; j++) { + final BodyPart partBody = part.getBodyPart(j); + String partType = partBody.getContentType(); + String link = partBody.getHeader("Link")[0]; + String[] links = StringUtils.delimitedListToStringArray(link, ","); + String bucketName = null; + for (String s : links) { + if (s.contains("rel=\"up\"")) { + String[] linkParts = StringUtils.delimitedListToStringArray(s, ";"); + int start = linkParts[0].lastIndexOf("/"); + bucketName = linkParts[0].substring(start + 1, + linkParts[0].length() - 1); + break; + } + } + Class clazz = Map.class; + if (null != bucketName) { + try { + clazz = Class.forName(bucketName); + } catch (ClassNotFoundException e) { + } + } + + // Can convert message? + for (HttpMessageConverter converter : restTemplate.getMessageConverters()) { + if (converter.canRead(clazz, MediaType.parseMediaType(partType))) { + HttpInputMessage msg = new HttpInputMessage() { + public InputStream getBody() throws IOException { + try { + return partBody.getInputStream(); + } catch (MessagingException e) { + log.error(e.getMessage(), e); + } + return null; + } + + public HttpHeaders getHeaders() { + return new HttpHeaders(); + } + }; + results.add(converter.read(clazz, msg)); + break; + } + } + + log.debug(String.format("results=%s", results)); + } + } + } + } catch (MessagingException e) { + log.error(e.getMessage(), e); + } + + return results; + } + return null; } }, bkpSource.getBucket(), bkpSource.getKey(), tag); - return null; + return returnObj; } /*----------------- Bucket Operations -----------------*/ @@ -666,6 +737,24 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe } } + public KeyValueStoreOperations updateBucketSchema(B bucket, Map props) { + Map bucketProps = new LinkedHashMap(); + bucketProps.put("props", props); + RestTemplate restTemplate = getRestTemplate(); + String bucketName; + if (bucket instanceof String) { + bucketName = bucket.toString(); + } else { + BucketKeyPair bkp = resolveBucketKeyPair(bucket, null); + bucketName = bkp.getBucket().toString(); + } + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity(bucketProps, headers); + restTemplate.put(defaultUri, entity, bucketName, ""); + return this; + } + public void afterPropertiesSet() throws Exception { Assert.notNull(conversionService, "Must specify a valid ConversionService."); diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakValue.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakValue.java similarity index 90% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakValue.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakValue.java index bb35d9cfc..1b91c0957 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakValue.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakValue.java @@ -1,4 +1,4 @@ -package org.springframework.datastore.riak.core; +package org.springframework.data.riak.core; /** * @author J. Brisbin diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/SimpleBucketKeyPair.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/SimpleBucketKeyPair.java similarity index 94% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/SimpleBucketKeyPair.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/SimpleBucketKeyPair.java index beb287517..56e087f03 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/SimpleBucketKeyPair.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/SimpleBucketKeyPair.java @@ -1,4 +1,4 @@ -package org.springframework.datastore.riak.core; +package org.springframework.data.riak.core; /** * @author J. Brisbin diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/SimpleBucketKeyResolver.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/SimpleBucketKeyResolver.java similarity index 97% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/SimpleBucketKeyResolver.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/core/SimpleBucketKeyResolver.java index 61667619f..86e147b63 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/SimpleBucketKeyResolver.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/SimpleBucketKeyResolver.java @@ -1,4 +1,4 @@ -package org.springframework.datastore.riak.core; +package org.springframework.data.riak.core; import org.codehaus.groovy.runtime.GStringImpl; import org.springframework.util.ClassUtils; diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/ErlangMapReduceOperation.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/ErlangMapReduceOperation.java similarity index 86% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/ErlangMapReduceOperation.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/ErlangMapReduceOperation.java index 3d50e8d9f..0d804ab71 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/ErlangMapReduceOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/ErlangMapReduceOperation.java @@ -1,10 +1,10 @@ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; import java.util.LinkedHashMap; import java.util.Map; /** - * An implementation of {@link org.springframework.datastore.riak.mapreduce.MapReduceOperation} + * An implementation of {@link org.springframework.data.riak.mapreduce.MapReduceOperation} * to represent an Erlang M/R function, which must be already defined inside the * Riak server. * diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/JavascriptMapReduceOperation.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/JavascriptMapReduceOperation.java similarity index 78% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/JavascriptMapReduceOperation.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/JavascriptMapReduceOperation.java index 3c95cc849..8a31925b4 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/JavascriptMapReduceOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/JavascriptMapReduceOperation.java @@ -1,9 +1,9 @@ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; -import org.springframework.datastore.riak.core.BucketKeyPair; +import org.springframework.data.riak.core.BucketKeyPair; /** - * An implementation of {@link org.springframework.datastore.riak.mapreduce.MapReduceOperation} + * An implementation of {@link org.springframework.data.riak.mapreduce.MapReduceOperation} * to describe a Javascript language M/R function. * * @author J. Brisbin @@ -39,7 +39,7 @@ public class JavascriptMapReduceOperation implements MapReduceOperation { } /** - * Set the {@link org.springframework.datastore.riak.core.BucketKeyPair} to + * Set the {@link org.springframework.data.riak.core.BucketKeyPair} to * point to for the Javascript to use in this M/R function. * * @param bucketKeyPair diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceJob.java similarity index 96% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceJob.java index 3275425a5..694a88033 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; import java.util.List; import java.util.concurrent.Callable; diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperation.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceOperation.java similarity index 94% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperation.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceOperation.java index 0e3e6fb54..a00b106dd 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceOperation.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; /** * A generic interface to a Map/Reduce operation. diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceOperations.java similarity index 91% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceOperations.java index 3e04565a0..8ab1a67c3 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReduceOperations.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; import java.util.List; import java.util.concurrent.Future; @@ -27,7 +27,7 @@ import java.util.concurrent.Future; public interface MapReduceOperations { /** - * Execute a {@link org.springframework.datastore.riak.mapreduce.MapReduceJob} + * Execute a {@link org.springframework.data.riak.mapreduce.MapReduceJob} * synchronously. * * @param job diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReducePhase.java similarity index 95% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReducePhase.java index 92b7c98f5..09b0b180b 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/MapReducePhase.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; /** * A generic interface to the phases of Map/Reduce jobs. diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/RiakMapReduceJob.java similarity index 94% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/RiakMapReduceJob.java index 28692bd9a..d0a06f04e 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/RiakMapReduceJob.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.datastore.riak.core.BucketKeyPair; -import org.springframework.datastore.riak.core.RiakTemplate; +import org.springframework.data.riak.core.BucketKeyPair; +import org.springframework.data.riak.core.RiakTemplate; import java.io.IOException; import java.io.StringWriter; @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; /** - * An implementation of {@link org.springframework.datastore.riak.mapreduce.MapReduceJob} + * An implementation of {@link org.springframework.data.riak.mapreduce.MapReduceJob} * for the Riak data store. * * @author J. Brisbin diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/RiakMapReducePhase.java similarity index 92% rename from spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java rename to spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/RiakMapReducePhase.java index 6f74836f5..38386fb6f 100644 --- a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/mapreduce/RiakMapReducePhase.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package org.springframework.datastore.riak.mapreduce; +package org.springframework.data.riak.mapreduce; /** - * An implementation of {@link org.springframework.datastore.riak.mapreduce.MapReducePhase} + * An implementation of {@link org.springframework.data.riak.mapreduce.MapReducePhase} * for the Riak data store. * * @author J. Brisbin diff --git a/spring-datastore-riak/src/main/resources/META-INF/spring/app-context.xml b/spring-data-riak/src/main/resources/META-INF/spring/app-context.xml similarity index 100% rename from spring-datastore-riak/src/main/resources/META-INF/spring/app-context.xml rename to spring-data-riak/src/main/resources/META-INF/spring/app-context.xml diff --git a/spring-datastore-riak/src/test/groovy/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy similarity index 85% rename from spring-datastore-riak/src/test/groovy/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy rename to spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy index 764d1f4b4..4fcd71c5f 100644 --- a/spring-datastore-riak/src/test/groovy/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy +++ b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy @@ -13,20 +13,20 @@ * 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 org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext -import org.springframework.datastore.riak.mapreduce.JavascriptMapReduceOperation -import org.springframework.datastore.riak.mapreduce.MapReduceJob -import org.springframework.datastore.riak.mapreduce.RiakMapReducePhase +import org.springframework.data.riak.mapreduce.JavascriptMapReduceOperation +import org.springframework.data.riak.mapreduce.MapReduceJob +import org.springframework.data.riak.mapreduce.RiakMapReducePhase import org.springframework.test.context.ContextConfiguration import spock.lang.Specification /** * @author J. Brisbin */ -@ContextConfiguration(locations = "/org/springframework/datastore/RiakTemplateTests.xml") +@ContextConfiguration(locations = "/org/springframework/data/RiakTemplateTests.xml") class RiakTemplateSpec extends Specification { @Autowired @@ -74,6 +74,16 @@ class RiakTemplateSpec extends Specification { } + def "Test updating bucket schema"() { + + when: + def schema = riak.updateBucketSchema("test", [n_val: 2]).getBucketSchema("test") + + then: + 2 == schema.props.n_val + + } + def "Test get with metadata"() { when: @@ -108,6 +118,18 @@ class RiakTemplateSpec extends Specification { } + def "Test link walking"() { + + when: + def val = riak.linkWalk("test:test", "test") + + then: + null != val + 1 == val.size() + val.get(0) instanceof TestObject + + } + def "Test multiple get"() { when: diff --git a/spring-datastore-riak/src/test/groovy/org/springframework/datastore/riak/core/TestObject.java b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java similarity index 95% rename from spring-datastore-riak/src/test/groovy/org/springframework/datastore/riak/core/TestObject.java rename to spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java index d435ae1f3..fb37ae547 100644 --- a/spring-datastore-riak/src/test/groovy/org/springframework/datastore/riak/core/TestObject.java +++ b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.datastore.riak.core; +package org.springframework.data.riak.core; /** * @author J. Brisbin diff --git a/spring-datastore-riak/src/test/resources/log4j.properties b/spring-data-riak/src/test/resources/log4j.properties similarity index 90% rename from spring-datastore-riak/src/test/resources/log4j.properties rename to spring-data-riak/src/test/resources/log4j.properties index 1868ac530..002fb5bcf 100644 --- a/spring-datastore-riak/src/test/resources/log4j.properties +++ b/spring-data-riak/src/test/resources/log4j.properties @@ -7,7 +7,7 @@ log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.category.org.apache.activemq=ERROR log4j.category.org.springframework.batch=DEBUG log4j.category.org.springframework.transaction=INFO -log4j.category.org.springframework.datastore=DEBUG +log4j.category.org.springframework.data=DEBUG log4j.category.org.hibernate.SQL=DEBUG # for debugging datasource initialization diff --git a/spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml b/spring-data-riak/src/test/resources/org/springframework/data/RiakTemplateTests.xml similarity index 80% rename from spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml rename to spring-data-riak/src/test/resources/org/springframework/data/RiakTemplateTests.xml index 840d44434..51394025e 100644 --- a/spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml +++ b/spring-data-riak/src/test/resources/org/springframework/data/RiakTemplateTests.xml @@ -5,6 +5,6 @@ - + diff --git a/spring-datastore-riak/template.mf b/spring-data-riak/template.mf similarity index 100% rename from spring-datastore-riak/template.mf rename to spring-data-riak/template.mf diff --git a/spring-datastore-riak/.classpath b/spring-datastore-riak/.classpath deleted file mode 100644 index 96f09f11f..000000000 --- a/spring-datastore-riak/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/spring-datastore-riak/.project b/spring-datastore-riak/.project deleted file mode 100644 index 45b6dcb1e..000000000 --- a/spring-datastore-riak/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - spring-datastore-riak - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.maven.ide.eclipse.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.maven.ide.eclipse.maven2Nature - - diff --git a/spring-datastore-riak/.settings/org.eclipse.jdt.core.prefs b/spring-datastore-riak/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index f9a36c4a2..000000000 --- a/spring-datastore-riak/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,6 +0,0 @@ -#Tue Nov 02 11:10:32 EDT 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/spring-datastore-riak/.settings/org.maven.ide.eclipse.prefs b/spring-datastore-riak/.settings/org.maven.ide.eclipse.prefs deleted file mode 100644 index 79fd8836b..000000000 --- a/spring-datastore-riak/.settings/org.maven.ide.eclipse.prefs +++ /dev/null @@ -1,9 +0,0 @@ -#Tue Nov 02 11:10:23 EDT 2010 -activeProfiles= -eclipse.preferences.version=1 -fullBuildGoals=process-test-resources -includeModules=false -resolveWorkspaceProjects=true -resourceFilterGoals=process-resources resources\:testResources -skipCompilerPlugin=true -version=1 From e0ad5baa1ed25bb79f719751012140bc60cbaa32 Mon Sep 17 00:00:00 2001 From: "J. Brisbin" Date: Fri, 26 Nov 2010 10:16:26 -0600 Subject: [PATCH 2/4] Fixing build so tests run groovyc/spec tests all pass --- spring-data-riak/pom.xml | 39 ++++++++++++++++++ .../data/riak/core/TestObject.java | 41 +++++++++++++++++++ spring-data-riak/template.mf | 2 + 3 files changed, 82 insertions(+) create mode 100644 spring-data-riak/src/test/java/org/springframework/data/riak/core/TestObject.java diff --git a/spring-data-riak/pom.xml b/spring-data-riak/pom.xml index 96261dc0c..120963fd0 100644 --- a/spring-data-riak/pom.xml +++ b/spring-data-riak/pom.xml @@ -130,6 +130,45 @@ org.spockframework spock-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-data-riak/src/test/java/org/springframework/data/riak/core/TestObject.java b/spring-data-riak/src/test/java/org/springframework/data/riak/core/TestObject.java new file mode 100644 index 000000000..fb37ae547 --- /dev/null +++ b/spring-data-riak/src/test/java/org/springframework/data/riak/core/TestObject.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.riak.core; + +/** + * @author J. Brisbin + */ +public class TestObject { + String test = "value"; + Integer integer = 12; + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + + public Integer getInteger() { + return integer; + } + + public void setInteger(Integer integer) { + this.integer = integer; + } +} diff --git a/spring-data-riak/template.mf b/spring-data-riak/template.mf index 5d4d14cf3..aba21f9d8 100644 --- a/spring-data-riak/template.mf +++ b/spring-data-riak/template.mf @@ -24,3 +24,5 @@ Import-Template: org.codehaus.jackson.*;version="[1.5.6, 1.5.6)", org.codehaus.jackson.map.*;version="[1.5.6, 1.5.6)", org.codehaus.groovy.runtime.*;version="[1.7.5, 2.0.0)", + javax.activation.*;version="[1.1, 2.0)", + javax.mail.*;version="[1.4.0, 2.0.0)", \ No newline at end of file From 78f41c1729d6f13204a86857d9b6b5ead5b1c152 Mon Sep 17 00:00:00 2001 From: "J. Brisbin" Date: Fri, 26 Nov 2010 10:46:33 -0600 Subject: [PATCH 3/4] Added the ability to return discreet objects from M/R queries as well as Lists --- .../data/riak/core/RiakTemplate.java | 20 +++++++-- .../data/riak/core/RiakTemplateSpec.groovy | 26 +++++++++++- .../data/riak/core/TestObject.java | 41 ------------------- 3 files changed, 41 insertions(+), 46 deletions(-) delete mode 100644 spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java diff --git a/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java index dc7988800..ef1cbcda7 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java +++ b/spring-data-riak/src/main/java/org/springframework/data/riak/core/RiakTemplate.java @@ -548,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; } diff --git a/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy index 4fcd71c5f..749c8022d 100644 --- a/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy +++ b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/RiakTemplateSpec.groovy @@ -178,7 +178,7 @@ class RiakTemplateSpec extends Specification { } - def "Test Map/Reduce"() { + def "Test Map/Reduce returning Integer"() { given: MapReduceJob job = riak.createMapReduceJob() @@ -193,7 +193,29 @@ class RiakTemplateSpec extends Specification { addPhase(reducePhase) when: - def result = riak.execute(job, List) + def result = riak.execute(job, Integer) + + then: + 1 == result + + } + + def "Test Map/Reduce returning List"() { + + given: + MapReduceJob job = riak.createMapReduceJob() + def mapJs = new JavascriptMapReduceOperation("function(v){ return [1]; }") + def mapPhase = new RiakMapReducePhase("map", "javascript", mapJs) + + def reduceJs = new JavascriptMapReduceOperation("function(v){ return [v.length]; }") + def reducePhase = new RiakMapReducePhase("reduce", "javascript", reduceJs) + + job.addInputs(["test"]). + addPhase(mapPhase). + addPhase(reducePhase) + + when: + def result = riak.execute(job) then: 1 == result.size() diff --git a/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java b/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java deleted file mode 100644 index fb37ae547..000000000 --- a/spring-data-riak/src/test/groovy/org/springframework/data/riak/core/TestObject.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2010 by J. Brisbin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.riak.core; - -/** - * @author J. Brisbin - */ -public class TestObject { - String test = "value"; - Integer integer = 12; - - public String getTest() { - return test; - } - - public void setTest(String test) { - this.test = test; - } - - public Integer getInteger() { - return integer; - } - - public void setInteger(Integer integer) { - this.integer = integer; - } -} From ba7ecd1d1de336893f6a42f16415c5fd5ae1a26c Mon Sep 17 00:00:00 2001 From: "J. Brisbin" Date: Fri, 26 Nov 2010 13:31:47 -0600 Subject: [PATCH 4/4] Changed module name from datastore to data in root pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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-parent spring-data-keyvalue-core spring-data-redis - spring-datastore-riak + spring-data-riak