diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreConnectionFailureException.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreConnectionFailureException.java index f6f6a6089..b9c56ad5c 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreConnectionFailureException.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreConnectionFailureException.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreOperationException.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreOperationException.java index 0d4ddc44e..9dfe893a2 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreOperationException.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/DataStoreOperationException.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/convert/KeyValueStoreMetaData.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/convert/KeyValueStoreMetaData.java index 54a4f163d..40f8d66f5 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/convert/KeyValueStoreMetaData.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/convert/KeyValueStoreMetaData.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/AbstractAsyncOperation.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/AbstractAsyncOperation.java index 15ab148d7..d2a699eeb 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/AbstractAsyncOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/AbstractAsyncOperation.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyPair.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyPair.java index 762a5a907..4fe4be165 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyPair.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyPair.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyResolver.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyResolver.java index 4ddafb8ea..722b5f575 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyResolver.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/BucketKeyResolver.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreMetaData.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreMetaData.java index b07e206f5..e193fe41f 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreMetaData.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreMetaData.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; import org.springframework.http.MediaType; diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreOperations.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreOperations.java index 845d93281..b618bcda6 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreOperations.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreOperations.java @@ -1,15 +1,17 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, - * WIVHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * 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. */ diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreValue.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreValue.java index 3df06128a..51d29c877 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreValue.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/KeyValueStoreValue.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/QosParameters.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/QosParameters.java index 86e9f6159..e65f6f32c 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/QosParameters.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/QosParameters.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakMetaData.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakMetaData.java index c3f1b110a..69d3a6cd2 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakMetaData.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakMetaData.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; import org.springframework.http.MediaType; diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakQosParameters.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakQosParameters.java index fdf3a0e06..a0f4a0ebe 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakQosParameters.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakQosParameters.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java index 72645f3ff..65fb75c42 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakTemplate.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, @@ -47,7 +49,10 @@ import javax.mail.BodyPart; import javax.mail.MessagingException; import javax.mail.internet.MimeMultipart; import javax.mail.util.ByteArrayDataSource; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; import java.lang.annotation.Annotation; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -60,8 +65,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * An implementation of {@link org.springframework.data.keyvalue.riak.core.KeyValueStoreOperations} and - * {@link org.springframework.data.keyvalue.riak.mapreduce.MapReduceOperations} for the Riak data store. + * An implementation of {@link org.springframework.data.keyvalue.riak.core.KeyValueStoreOperations} + * and {@link org.springframework.data.keyvalue.riak.mapreduce.MapReduceOperations} for the Riak + * data store. *

* To use the RiakTemplate, create a singleton in your Spring application-context.xml: *


@@ -83,8 +89,8 @@ import java.util.regex.Pattern;
  * BucketKeyPair (like {@link org.springframework.data.keyvalue.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.data.keyvalue.riak.convert.KeyValueStoreMetaData} annotation on the object you're - * storing.
  • + * org.springframework.data.keyvalue.riak.convert.KeyValueStoreMetaData} annotation on the + * object you're storing. * * @author J. Brisbin */ @@ -225,6 +231,11 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe this.useCache = useCache; } + /** + * Extract the prefix from the URI for use in creating links. + * + * @return + */ public String getPrefix() { Matcher m = prefix.matcher(defaultUri); if (m.matches()) { @@ -250,8 +261,10 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe public KeyValueStoreOperations setAsBytes(K key, byte[] value, QosParameters qosParams) { Assert.notNull(key, "Can't store an object with a NULL key."); BucketKeyPair bucketKeyPair = resolveBucketKeyPair(key, value); + // If I don't give a bucket name, since I don't have an object type, use 'bytes' String bucketName = (null != bucketKeyPair.getBucket() ? bucketKeyPair.getBucket() .toString() : "bytes"); + // Get a key name that may or may not include the QOS parameters. String keyName = (null != qosParams ? bucketKeyPair.getKey() .toString() + extractQosParameters(qosParams) : bucketKeyPair.getKey().toString()); RestTemplate restTemplate = getRestTemplate(); @@ -259,17 +272,22 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe headers.set("X-Riak-ClientId", RIAK_CLIENT_ID); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); HttpEntity entity = new HttpEntity(value, headers); - restTemplate.put(defaultUri, entity, bucketName, keyName); - if (log.isDebugEnabled()) { - log.debug(String.format("PUT byte[]: bucket=%s, key=%s", - bucketKeyPair.getBucket(), - bucketKeyPair.getKey())); + try { + restTemplate.put(defaultUri, entity, bucketName, keyName); + if (log.isDebugEnabled()) { + log.debug(String.format("PUT byte[]: bucket=%s, key=%s", + bucketKeyPair.getBucket(), + bucketKeyPair.getKey())); + } + } catch (RestClientException e) { + throw new DataStoreOperationException(e.getMessage(), e); } return this; } public KeyValueStoreOperations setWithMetaData(K key, V value, Map metaData, QosParameters qosParams) { BucketKeyPair bucketKeyPair = resolveBucketKeyPair(key, value); + // Get a key name that may or may not include the QOS parameters. String keyName = (null != qosParams ? bucketKeyPair.getKey() .toString() + extractQosParameters(qosParams) : bucketKeyPair.getKey().toString()); RestTemplate restTemplate = getRestTemplate(); @@ -282,15 +300,19 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe } } HttpEntity entity = new HttpEntity(value, headers); - restTemplate.put(defaultUri, - entity, - bucketKeyPair.getBucket(), - keyName); - if (log.isDebugEnabled()) { - log.debug(String.format("PUT object: bucket=%s, key=%s, value=%s", + try { + restTemplate.put(defaultUri, + entity, bucketKeyPair.getBucket(), - bucketKeyPair.getKey(), - value)); + keyName); + if (log.isDebugEnabled()) { + log.debug(String.format("PUT object: bucket=%s, key=%s, value=%s", + bucketKeyPair.getBucket(), + bucketKeyPair.getKey(), + value)); + } + } catch (RestClientException e) { + throw new DataStoreOperationException(e.getMessage(), e); } return this; } @@ -303,6 +325,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe public RiakValue getWithMetaData(K key, Class requiredType) { BucketKeyPair bucketKeyPair = resolveBucketKeyPair(key, null); + // If no bucket name is given, infer it from the type name. String bucketName = (null != bucketKeyPair.getBucket() ? bucketKeyPair.getBucket() .toString() : requiredType.getName()); RestTemplate restTemplate = getRestTemplate(); @@ -330,8 +353,10 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe if (e.getStatusCode() != HttpStatus.NOT_FOUND) { throw new DataStoreOperationException(e.getMessage(), e); } + } catch (RestClientException rce) { + // IGNORE } catch (EOFException eof) { - // IGNORE this one + // IGNORE } catch (IOException e) { log.error(e.getMessage(), e); } @@ -342,8 +367,10 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe BucketKeyPair bucketKeyPair = resolveBucketKeyPair(key, null); Class targetClass; try { + // Since no type is specified, first try using the bucket name as the target class... targetClass = Class.forName(bucketKeyPair.getBucket().toString()); } catch (Throwable ignored) { + // ...if that doesn't work, just use a Map, which we know will work. targetClass = Map.class; } RiakValue obj = getWithMetaData(bucketKeyPair, targetClass); @@ -404,6 +431,8 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe if (e.getStatusCode() != HttpStatus.NOT_FOUND) { throw new DataStoreOperationException(e.getMessage(), e); } + } catch (RestClientException e) { + throw new DataStoreOperationException(e.getMessage(), e); } return null; } @@ -573,10 +602,13 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe List.class); if (resp.hasBody()) { if (!targetType.isAssignableFrom(List.class)) { + // M/R jobs always return a List. Try to turn the List into something else. List results = (List) resp.getBody(); if (results.size() == 1) { + // A List of size 1 get's returned as the object at list[0]. Object obj = results.get(0); if (obj.getClass() != targetType) { + // I can't just return it as-is, I have to convert it first. ConversionService conv = getConversionService(); if (conv.canConvert(obj.getClass(), targetType)) { return conv.convert(obj, targetType); @@ -592,6 +624,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe } public Future> submit(MapReduceJob job) { + // Run this job asynchronously. return queue.submit(job); } @@ -610,6 +643,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe BucketKeyPair bkpTo = resolveBucketKeyPair(destination, null); RestTemplate restTemplate = getRestTemplate(); + // Skip all conversion on the data since all we care about is the Link header. RiakValue fromObj = getAsBytesWithMetaData(source); if (null == fromObj) { throw new DataStoreOperationException( @@ -619,29 +653,23 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe headers.setContentType(fromObj.getMetaData().getContentType()); Object linksObj = fromObj.getMetaData().getProperties().get("Link"); List links = new ArrayList(); + // First add all existing links... if (linksObj instanceof List) { links.addAll((List) linksObj); } else if (linksObj instanceof String) { links.add(linksObj.toString()); } + // ...then add the link we're creating... links.add(String.format("<%s/%s/%s>; riaktag=\"%s\"", getPrefix(), bkpTo.getBucket(), bkpTo.getKey(), tag)); - StringWriter sw = new StringWriter(); - boolean needsComma = false; - for (String link : links) { - if (!sw.toString().contains(link)) { - if (needsComma) { - sw.write(", "); - } else { - needsComma = true; - } - sw.write(link); - } - } - headers.set("Link", sw.toString()); + String linkHeader = StringUtils.collectionToCommaDelimitedString(links); + headers.set("Link", linkHeader); + // Make sure to store the data back, otherwise it gets lost! + // Basho at some point will likely add the ability to updated metadata separate + // from the content. Until then, we have to transfer the body back-and-forth. HttpEntity entity = new HttpEntity(fromObj.get(), headers); restTemplate.put(defaultUri, entity, bkpFrom.getBucket(), bkpFrom.getKey()); @@ -667,6 +695,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe new RequestCallback() { public void doWithRequest(ClientHttpRequest request) throws IOException { + // Make sure I can accept a multipart/mixed response. request.getHeaders().setAccept(types); } }, @@ -680,6 +709,9 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe ByteArrayDataSource ds = new ByteArrayDataSource(response.getBody(), "multipart/mixed"); try { + // All this mess is for extracting multipart data from our response. + // I'm using the javax.mail stuff because it's the best multipart library + // that's in Maven and it's a common dependency anyway. MimeMultipart mp = new MimeMultipart(ds); int msgCnt = mp.getCount(); for (int i = 0; i < msgCnt; i++) { @@ -798,17 +830,17 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe } List> converters = getRestTemplate().getMessageConverters(); + ObjectMapper mapper = new ObjectMapper(); + CustomSerializerFactory fac = new CustomSerializerFactory(); if (groovyPresent) { // Native conversion for Groovy GString objects - ObjectMapper mapper = new ObjectMapper(); - CustomSerializerFactory fac = new CustomSerializerFactory(); fac.addSpecificMapping(GStringImpl.class, ToStringSerializer.instance); - mapper.setSerializerFactory(fac); - for (HttpMessageConverter converter : converters) { - if (converter instanceof MappingJacksonHttpMessageConverter) { - ((MappingJacksonHttpMessageConverter) converter).setObjectMapper( - mapper); - } + } + mapper.setSerializerFactory(fac); + for (HttpMessageConverter converter : converters) { + if (converter instanceof MappingJacksonHttpMessageConverter) { + ((MappingJacksonHttpMessageConverter) converter).setObjectMapper( + mapper); } } } @@ -827,6 +859,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe if (null != resolver) { bucketKeyPair = resolver.resolve(key); if (null == bucketKeyPair.getBucket() && null != val) { + // No bucket specified, check for an annotation that specified bucket name. Annotation meta = (val instanceof Class ? (Class) val : val.getClass()).getAnnotation( KeyValueStoreMetaData.class); if (null != meta) { @@ -850,6 +883,7 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe KeyValueStoreMetaData meta = value.getClass() .getAnnotation(KeyValueStoreMetaData.class); if (null != meta) { + // Use the media type specified on the annotation. mediaType = MediaType.parseMediaType(meta.mediaType()); } } @@ -923,6 +957,13 @@ public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOpe } } + /** + * Get a string that represents the QOS parameters, taken either from the specified object or + * from the template defaults. + * + * @param qosParams + * @return + */ protected String extractQosParameters(QosParameters qosParams) { List params = new LinkedList(); if (null != qosParams.getReadThreshold()) { diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakValue.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakValue.java index 16d2e3d3c..4ea033da7 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakValue.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/RiakValue.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyPair.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyPair.java index a694848da..d60a8b854 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyPair.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyPair.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; /** diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyResolver.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyResolver.java index da01c6bae..118a7c890 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyResolver.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/core/SimpleBucketKeyResolver.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.core; import org.codehaus.groovy.runtime.GStringImpl; diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/ErlangMapReduceOperation.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/ErlangMapReduceOperation.java index db1f815c8..072bad831 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/ErlangMapReduceOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/ErlangMapReduceOperation.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.mapreduce; import java.util.LinkedHashMap; diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/JavascriptMapReduceOperation.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/JavascriptMapReduceOperation.java index b15bb483d..b941e4a80 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/JavascriptMapReduceOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/JavascriptMapReduceOperation.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). + * + * 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.keyvalue.riak.mapreduce; import org.springframework.data.keyvalue.riak.core.BucketKeyPair; diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceJob.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceJob.java index 5d0ae10d9..9acaaa9dc 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceJob.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceJob.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperation.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperation.java index 46845acc7..feacc40f4 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperation.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperation.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperations.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperations.java index 1aa6a9c1d..12b32e02b 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperations.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReduceOperations.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReducePhase.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReducePhase.java index 6c62bd0ed..a7afe522c 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReducePhase.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/MapReducePhase.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReduceJob.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReduceJob.java index f4a37b9e0..0fa3c2d38 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReduceJob.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReduceJob.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReducePhase.java b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReducePhase.java index 1e8638592..9f330ca0e 100644 --- a/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReducePhase.java +++ b/spring-data-riak/src/main/java/org/springframework/data/keyvalue/riak/mapreduce/RiakMapReducePhase.java @@ -1,11 +1,13 @@ /* * Copyright (c) 2010 by J. Brisbin + * Portions (c) 2010 by NPC International, Inc. or the + * original author(s). * * 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 + * 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, diff --git a/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy b/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy index 903887bd4..64a95932c 100644 --- a/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy +++ b/spring-data-riak/src/test/groovy/org/springframework/data/keyvalue/riak/core/RiakTemplateSpec.groovy @@ -15,12 +15,14 @@ */ package org.springframework.data.keyvalue.riak.core +import org.junit.runner.RunWith import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.data.keyvalue.riak.mapreduce.JavascriptMapReduceOperation import org.springframework.data.keyvalue.riak.mapreduce.MapReduceJob import org.springframework.data.keyvalue.riak.mapreduce.RiakMapReducePhase import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner import spock.lang.Specification /** diff --git a/src/ant/upload-dist.xml b/src/ant/upload-dist.xml index 142bece01..5395f4d02 100644 --- a/src/ant/upload-dist.xml +++ b/src/ant/upload-dist.xml @@ -6,15 +6,15 @@ - the classpath is set up for you ant -f src/ant/upload-dist.xml \ - -Ddist.id=spring-datastore-keyvalue \ + -Ddist.id=spring-data-keyvalue \ -Ddist.name='Spring Datastore Key-Value' \ -Ddist.key=DATADOC \ -Ddist.releaseType=milestone \ -Ddist.accessKey= \ -Ddist.secretKey= \ -Ddist.bucketName=dist.springframework.org \ - -Ddist.fileName=spring-datastore-keyvalue-1.0.0.M1.zip \ - -Ddist.filePath=../../spring-datastore-keyvalue-1.0.0.M1.zip \ + -Ddist.fileName=spring-data-keyvalue-1.0.0.M1.zip \ + -Ddist.filePath=../../spring-data-keyvalue-1.0.0.M1.zip \ -Ddist.version=1.0.0.M1 \ upload-dist -->