Merge branch 'master' of github.com:SpringSource/spring-data-keyvalue

This commit is contained in:
Costin Leau
2010-11-26 21:37:46 +02:00
35 changed files with 298 additions and 157 deletions

View File

@@ -12,7 +12,7 @@
<module>spring-data-keyvalue-parent</module>
<module>spring-data-keyvalue-core</module>
<module>spring-data-redis</module>
<module>spring-datastore-riak</module>
<module>spring-data-riak</module>
</modules>
<build>

View File

@@ -255,6 +255,12 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>

View File

@@ -92,6 +92,10 @@
<artifactId>jsr250-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -126,6 +130,45 @@
<groupId>org.spockframework</groupId>
<artifactId>spock-maven</artifactId>
</plugin>
<!-- For running Groovy/Spock tests -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"/>
<groovyc srcdir="src/test/groovy"
destdir="${project.build.testOutputDirectory}"
listfiles="yes"
classpathref="maven.test.classpath"/>
</tasks>
</configuration>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.datastore.riak;
package org.springframework.data.riak;
import org.springframework.dao.DataAccessResourceFailureException;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.datastore.riak;
package org.springframework.data.riak;
import org.springframework.dao.DataAccessException;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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 <jon@jbrisbin.com>
*/

View File

@@ -1,4 +1,4 @@
package org.springframework.datastore.riak.core;
package org.springframework.data.riak.core;
import org.springframework.http.MediaType;

View File

@@ -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
* <code>java.util.Map</code>.
* 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 <code>java.util.Map</code>.
*
* @param key
* @return The converted value, or <code>null</code> if not found.
@@ -65,8 +64,7 @@ public interface KeyValueStoreOperations {
<K> 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 {
<K, V> 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 {
<K> 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.
*/
<K, V> List<V> getValues(List<K> keys);
/**
* Variation on {@link KeyValueStoreOperations#getValues(java.util.List)} that
* uses varargs instead of a <code>java.util.List</code>.
* Variation on {@link KeyValueStoreOperations#getValues(java.util.List)} that uses varargs
* instead of a <code>java.util.List</code>.
*
* @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.
*/
<K, V> List<V> 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.
*/
<K, T> List<T> getValuesAsType(List<K> keys, Class<T> requiredType);
/**
* A variation on {@link KeyValueStoreOperations#getValuesAsType(java.util.List,
* Class)} that takes uses varargs instead of a <code>java.util.List</code>.
* A variation on {@link KeyValueStoreOperations#getValuesAsType(java.util.List, Class)} that
* takes uses varargs instead of a <code>java.util.List</code>.
*
* @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.
*/
<T, K> List<T> getValuesAsType(Class<T> requiredType, K... keys);
@@ -162,8 +155,7 @@ public interface KeyValueStoreOperations {
<K, V> 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 {
<K, V> KeyValueStoreOperations setMultipleIfKeysNonExistent(Map<K, V> 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 <K>
@@ -222,8 +212,8 @@ public interface KeyValueStoreOperations {
* Delete one or more keys from the store.
*
* @param keys
* @return <code>true</code> if all keys were successfully deleted,
* <code>false</code> otherwise.
* @return <code>true</code> if all keys were successfully deleted, <code>false</code>
* otherwise.
*/
<K> boolean deleteKeys(K... keys);
@@ -235,14 +225,15 @@ public interface KeyValueStoreOperations {
*/
<B> Map<String, Object> getBucketSchema(B bucket);
<B> KeyValueStoreOperations updateBucketSchema(B bucket, Map<String, Object> 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.
*/
<B> Map<String, Object> getBucketSchema(B bucket, boolean listKeys);

View File

@@ -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.

View File

@@ -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 <jon@jbrisbin.com>

View File

@@ -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.
* <p/>
* To use the RiakTemplate, create a singleton in your Spring application-context.xml:
* <pre><code>
* &lt;bean id="riak" class="org.springframework.datastore.riak.core.RiakTemplate"
* &lt;bean id="riak" class="org.springframework.data.riak.core.RiakTemplate"
* p:defaultUri="http://localhost:8098/riak/{bucket}/{key}"
* p:mapReduceUri="http://localhost:8098/mapred"/>
* </code></pre>
@@ -82,11 +83,11 @@ import java.util.regex.Pattern;
* </code></pre>
* You're key object should be one of: <ul><li>A <code>String</code> encoding the bucket and key
* together, separated by a colon. e.g. "mybucket:mykey"</li> <li>An implementation of
* BucketKeyPair (like {@link org.springframework.datastore.riak.core.SimpleBucketKeyPair})</li>
* BucketKeyPair (like {@link org.springframework.data.riak.core.SimpleBucketKeyPair})</li>
* <li>A <code>Map</code> with both a "bucket" and a "key" specified.</li> <li>A
* <code>String</code> 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.</li></ul>
* org.springframework.data.riak.convert.KeyValueStoreMetaData} annotation on the object you're
* storing.</li></ul>
*
* @author J. Brisbin <jon@jbrisbin.com>
*/
@@ -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> T execute(MapReduceJob job, Class<T> targetType) {
RestTemplate restTemplate = getRestTemplate();
ResponseEntity<T> resp = restTemplate.postForEntity(mapReduceUri,
ResponseEntity<List> 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, K> T linkWalk(K source, String tag) {
BucketKeyPair bkpSource = resolveBucketKeyPair(source, null);
RestTemplate restTemplate = getRestTemplate();
final RestTemplate restTemplate = getRestTemplate();
final List<MediaType> types = new ArrayList<MediaType>();
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<Object>() {
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<Object> results = new LinkedList<Object>();
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 +751,24 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe
}
}
public <B> KeyValueStoreOperations updateBucketSchema(B bucket, Map<String, Object> props) {
Map<Object, Object> bucketProps = new LinkedHashMap<Object, Object>();
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.");

View File

@@ -1,4 +1,4 @@
package org.springframework.datastore.riak.core;
package org.springframework.data.riak.core;
/**
* @author J. Brisbin <jon@jbrisbin.com>

View File

@@ -1,4 +1,4 @@
package org.springframework.datastore.riak.core;
package org.springframework.data.riak.core;
/**
* @author J. Brisbin <jon@jbrisbin.com>

View File

@@ -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;

View File

@@ -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.
*

View File

@@ -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 <jon@jbrisbin.com>
@@ -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

View File

@@ -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;

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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 <jon@jbrisbin.com>

View File

@@ -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 <jon@jbrisbin.com>

View File

@@ -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 <jon@jbrisbin.com>
*/
@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:
@@ -156,7 +178,7 @@ class RiakTemplateSpec extends Specification {
}
def "Test Map/Reduce"() {
def "Test Map/Reduce returning Integer"() {
given:
MapReduceJob job = riak.createMapReduceJob()
@@ -171,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()

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.datastore.riak.core;
package org.springframework.data.riak.core;
/**
* @author J. Brisbin <jon@jbrisbin.com>

View File

@@ -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

View File

@@ -5,6 +5,6 @@
<import resource="classpath:/META-INF/spring/app-context.xml"/>
<bean id="riakTemplate" class="org.springframework.datastore.riak.core.RiakTemplate"/>
<bean id="riakTemplate" class="org.springframework.data.riak.core.RiakTemplate"/>
</beans>

View File

@@ -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)",

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>spring-datastore-riak</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -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

View File

@@ -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