diff --git a/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCache.java b/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCache.java
index 066f9ba4..cd01d8b6 100644
--- a/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCache.java
+++ b/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCache.java
@@ -22,9 +22,11 @@ import org.springframework.cache.Cache;
import org.springframework.cache.support.SimpleValueWrapper;
/**
- * The CouchbaseCache class implements the Spring Cache interface
- * on top of Couchbase Server and the Couchbase Java SDK.
+ * The {@link CouchbaseCache} class implements the Spring Cache interface on top of Couchbase Server and the Couchbase
+ * Java SDK.
*
+ * @see
+ * Official Spring Cache Reference
* @author Michael Nitschinger
*/
public class CouchbaseCache implements Cache {
@@ -65,7 +67,7 @@ public class CouchbaseCache implements Cache {
* @return the actual CouchbaseClient instance.
*/
public final CouchbaseClient getNativeCache() {
- return this.client;
+ return client;
}
/**
@@ -76,7 +78,7 @@ public class CouchbaseCache implements Cache {
*/
public final ValueWrapper get(final Object key) {
String documentId = key.toString();
- Object result = this.client.get(documentId);
+ Object result = client.get(documentId);
return (result != null ? new SimpleValueWrapper(result) : null);
}
@@ -88,7 +90,7 @@ public class CouchbaseCache implements Cache {
*/
public final void put(final Object key, final Object value) {
String documentId = key.toString();
- this.client.set(documentId, 0, value);
+ client.set(documentId, 0, value);
}
/**
@@ -98,7 +100,7 @@ public class CouchbaseCache implements Cache {
*/
public final void evict(final Object key) {
String documentId = key.toString();
- this.client.delete(documentId);
+ client.delete(documentId);
}
/**
@@ -108,7 +110,7 @@ public class CouchbaseCache implements Cache {
* Also note that "flush" may not be enabled on the bucket.
*/
public final void clear() {
- this.client.flush();
+ client.flush();
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java b/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java
index acb1deb7..33fccde7 100644
--- a/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java
+++ b/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java
@@ -25,11 +25,10 @@ import org.springframework.cache.Cache;
import org.springframework.cache.support.AbstractCacheManager;
/**
- * The CouchbaseCacheManager orchestrates CouchbaseCache instances.
+ * The {@link CouchbaseCacheManager} orchestrates {@link CouchbaseCache} instances.
*
- * Since more than one current CouchbaseClient connection can be used
- * for caching, the CouchbaseCacheManager orchestrates and handles
- * them for the Spring Cache abstraction layer.
+ * Since more than one current {@link CouchbaseClient} connection can be used for caching, the
+ * {@link CouchbaseCacheManager} orchestrates and handles them for the Spring Cache abstraction layer.
*
* @author Michael Nitschinger
*/
@@ -55,7 +54,7 @@ public class CouchbaseCacheManager extends AbstractCacheManager {
* @return the actual CouchbaseClient instances.
*/
public final HashMap getClients() {
- return this.clients;
+ return clients;
}
/**
@@ -67,7 +66,7 @@ public class CouchbaseCacheManager extends AbstractCacheManager {
protected final Collection extends Cache> loadCaches() {
Collection caches = new LinkedHashSet();
- for (Map.Entry cache : this.clients.entrySet()) {
+ for (Map.Entry cache : clients.entrySet()) {
caches.add(new CouchbaseCache(cache.getKey(), cache.getValue()));
}
diff --git a/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java b/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java
index ae04a2fd..76edbc7d 100644
--- a/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java
+++ b/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java
@@ -25,7 +25,7 @@ import org.springframework.context.annotation.ClassPathScanningCandidateComponen
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.data.annotation.Persistent;
-import org.springframework.data.couchbase.core.CouchbaseMappingContext;
+import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.mapping.Document;
@@ -42,12 +42,16 @@ public abstract class AbstractCouchbaseConfiguration {
/**
* Return the {@link CouchbaseClient} instance to connect to.
+ *
+ * @throws Exception on Bean construction failure.
*/
@Bean
public abstract CouchbaseClient couchbaseClient() throws Exception;
/**
* Creates a {@link CouchbaseTemplate}.
+ *
+ * @throws Exception on Bean construction failure.
*/
@Bean
public CouchbaseTemplate couchbaseTemplate() throws Exception {
@@ -55,8 +59,9 @@ public abstract class AbstractCouchbaseConfiguration {
}
/**
- * Creates a {@link MappingCouchbaseConverter} using the configured {@link
- * #couchbaseMappingContext}.
+ * Creates a {@link MappingCouchbaseConverter} using the configured {@link #couchbaseMappingContext}.
+ *
+ * @throws Exception on Bean construction failure.
*/
@Bean
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
@@ -64,8 +69,9 @@ public abstract class AbstractCouchbaseConfiguration {
}
/**
- * Creates a {@link CouchbaseMappingContext} equipped with entity classes
- * scanned from the mapping base package.
+ * Creates a {@link CouchbaseMappingContext} equipped with entity classes scanned from the mapping base package.
+ *
+ * @throws Exception on Bean construction failure.
*/
@Bean
public CouchbaseMappingContext couchbaseMappingContext() throws Exception {
@@ -76,12 +82,14 @@ public abstract class AbstractCouchbaseConfiguration {
/**
* Scans the mapping base package for classes annotated with {@link Document}.
+ *
+ * @throws ClassNotFoundException if intial entity sets could not be loaded.
*/
protected Set> getInitialEntitySet() throws ClassNotFoundException {
String basePackage = getMappingBasePackage();
Set> initialEntitySet = new HashSet>();
- if(StringUtils.hasText(basePackage)) {
+ if (StringUtils.hasText(basePackage)) {
ClassPathScanningCandidateComponentProvider componentProvider =
new ClassPathScanningCandidateComponentProvider(false);
componentProvider.addIncludeFilter(
@@ -100,15 +108,14 @@ public abstract class AbstractCouchbaseConfiguration {
}
/**
- * Return the base package to scan for mapped {@link Document}s. Will return
- * the package name of the configuration class (the concrete class, not this
- * one here) by default. So if you have a {@code com.acme.AppConfig} extending
- * {@link AbstractCouchbaseConfiguration} the base package will be considered
- * {@code com.acme} unless the method is overridden to implement alternate
- * behavior.
+ * Return the base package to scan for mapped {@link Document}s. Will return the package name of the configuration
+ * class (the concrete class, not this one here) by default.
*
- * @return the base package to scan for mapped {@link Document} classes or
- * {@literal null} to not enable scanning for entities.
+ *
So if you have a {@code com.acme.AppConfig} extending {@link AbstractCouchbaseConfiguration} the base package
+ * will be considered {@code com.acme} unless the method is overridden to implement alternate behavior.
+ *
+ * @return the base package to scan for mapped {@link Document} classes or {@literal null} to not enable scanning for
+ * entities.
*/
protected String getMappingBasePackage() {
return getClass().getPackage().getName();
diff --git a/src/main/java/org/springframework/data/couchbase/config/BeanNames.java b/src/main/java/org/springframework/data/couchbase/config/BeanNames.java
index eeb20484..3db93cc6 100644
--- a/src/main/java/org/springframework/data/couchbase/config/BeanNames.java
+++ b/src/main/java/org/springframework/data/couchbase/config/BeanNames.java
@@ -17,12 +17,18 @@
package org.springframework.data.couchbase.config;
/**
+ * Contains default bean names that will be used when no "id" is supplied to the beans.
+ *
* @author Michael Nitschinger
*/
public class BeanNames {
- static final String MAPPING_CONTEXT = "mappingContext";
+ /**
+ * Refers to the "" bean.
+ */
static final String COUCHBASE = "couchbase";
- static final String DB_FACTORY = "couchbaseDbFactory";
- static final String DEFAULT_CONVERTER_BEAN_NAME = "mappingConverter";
+
+ /**
+ * Refers to the "" bean.
+ */
static final String COUCHBASE_TEMPLATE = "couchbaseTemplate";
}
diff --git a/src/main/java/org/springframework/data/couchbase/config/CouchbaseJmxParser.java b/src/main/java/org/springframework/data/couchbase/config/CouchbaseJmxParser.java
index 229d62ff..fa916cdf 100644
--- a/src/main/java/org/springframework/data/couchbase/config/CouchbaseJmxParser.java
+++ b/src/main/java/org/springframework/data/couchbase/config/CouchbaseJmxParser.java
@@ -28,12 +28,22 @@ import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
- * Enables Parsing of "" configurations.
+ * Enables Parsing of the "" configuration bean.
+ *
+ * In order to enable JMX, different JmxComponents need to be registered. The dependency to the original
+ * {@link com.couchbase.client.CouchbaseClient} object is solved by through the "couchbase-ref" attribute.
*
* @author Michael Nitschinger
*/
public class CouchbaseJmxParser implements BeanDefinitionParser {
+ /**
+ * Parse the element and dispatch the registration of the JMX components.
+ *
+ * @param element the XML element which contains the attributes.
+ * @param parserContext encapsulates the parsing state and configuration.
+ * @return null, because no bean instance needs to be returned.
+ */
public BeanDefinition parse(final Element element, final ParserContext parserContext) {
String name = element.getAttribute("couchbase-ref");
if (!StringUtils.hasText(name)) {
@@ -43,7 +53,14 @@ public class CouchbaseJmxParser implements BeanDefinitionParser {
return null;
}
- protected void registerJmxComponents(String refName, Element element, ParserContext parserContext) {
+ /**
+ * Register the JMX components in the context.
+ *
+ * @param refName the reference name to the couchbase client.
+ * @param element the XML element which contains the attributes.
+ * @param parserContext encapsulates the parsing state and configuration.
+ */
+ protected void registerJmxComponents(final String refName, final Element element, final ParserContext parserContext) {
Object eleSource = parserContext.extractSource(element);
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
@@ -53,8 +70,17 @@ public class CouchbaseJmxParser implements BeanDefinitionParser {
parserContext.registerComponent(compositeDef);
}
- protected void createBeanDefEntry(Class> clazz, CompositeComponentDefinition compositeDef,
- String refName, Object eleSource, ParserContext parserContext) {
+ /**
+ * Creates Bean Definitions for JMX components and adds them as a nested component.
+ *
+ * @param clazz the class type to register.
+ * @param compositeDef component that can hold nested components.
+ * @param refName the reference name to the couchbase client.
+ * @param eleSource source element to reference.
+ * @param parserContext encapsulates the parsing state and configuration.
+ */
+ protected void createBeanDefEntry(final Class> clazz, final CompositeComponentDefinition compositeDef,
+ final String refName, final Object eleSource, final ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(clazz);
builder.getRawBeanDefinition().setSource(eleSource);
builder.addConstructorArgReference(refName);
diff --git a/src/main/java/org/springframework/data/couchbase/config/CouchbaseNamespaceHandler.java b/src/main/java/org/springframework/data/couchbase/config/CouchbaseNamespaceHandler.java
index 0b33b6f6..9c260a9c 100644
--- a/src/main/java/org/springframework/data/couchbase/config/CouchbaseNamespaceHandler.java
+++ b/src/main/java/org/springframework/data/couchbase/config/CouchbaseNamespaceHandler.java
@@ -24,11 +24,17 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
/**
* {@link org.springframework.beans.factory.xml.NamespaceHandler} for Couchbase configuration.
*
+ * This handler acts as a container for one or more bean parsers and registers them. During parsing, the elements
+ * get analyzed and the appropriate registered parser is called.
+ *
* @author Michael Nitschinger
*/
public class CouchbaseNamespaceHandler extends NamespaceHandlerSupport {
- public void init() {
+ /**
+ * Register bean definition parsers in the namespace handler.
+ */
+ public final void init() {
RepositoryConfigurationExtension extension = new CouchbaseRepositoryConfigurationExtension();
registerBeanDefinitionParser("repositories", new RepositoryBeanDefinitionParser(extension));
diff --git a/src/main/java/org/springframework/data/couchbase/config/CouchbaseParser.java b/src/main/java/org/springframework/data/couchbase/config/CouchbaseParser.java
index 3718a776..ce11c9a1 100644
--- a/src/main/java/org/springframework/data/couchbase/config/CouchbaseParser.java
+++ b/src/main/java/org/springframework/data/couchbase/config/CouchbaseParser.java
@@ -31,19 +31,32 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
-
/**
- * Parser for "" definitions.
+ * Parser for "" bean definitions.
+ *
+ * The outcome of this bean definition parser will be a constructed {@link CouchbaseClient}.
*
* @author Michael Nitschinger
*/
public class CouchbaseParser extends AbstractSingleBeanDefinitionParser {
+ /**
+ * Defines the bean class that will be constructed.
+ *
+ * @param element the XML element which contains the attributes.
+ * @return the class type to instantiate.
+ */
@Override
protected Class getBeanClass(final Element element) {
return CouchbaseClient.class;
}
+ /**
+ * Parse the bean definition and build up the bean.
+ *
+ * @param element the XML element which contains the attributes.
+ * @param bean the builder which builds the bean.
+ */
@Override
protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
String host = element.getAttribute("host");
@@ -57,12 +70,30 @@ public class CouchbaseParser extends AbstractSingleBeanDefinitionParser {
StringUtils.hasText(password) ? password : CouchbaseFactoryBean.DEFAULT_PASSWORD);
}
+ /**
+ * Resolve the bean ID and assign a default if not set.
+ *
+ * @param element the XML element which contains the attributes.
+ * @param definition the bean definition to work with.
+ * @param parserContext encapsulates the parsing state and configuration.
+ * @return the ID to work with.
+ */
+ @Override
protected String resolveId(final Element element, final AbstractBeanDefinition definition,
final ParserContext parserContext) {
String id = super.resolveId(element, definition, parserContext);
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE;
}
+ /**
+ * Convert a list of hosts into a URI format that can be used by the {@link CouchbaseClient}.
+ *
+ * To make it simple to use, the list of hosts can be passed in as a comma separated list. This list gets parsed
+ * and converted into a URI format that is suitable for the underlying {@link CouchbaseClient} object.
+ *
+ * @param hosts the host list to convert.
+ * @return the converted list with URIs.
+ */
private List convertHosts(final String hosts) {
String[] split = hosts.split(",");
List nodes = new ArrayList();
diff --git a/src/main/java/org/springframework/data/couchbase/config/CouchbaseTemplateParser.java b/src/main/java/org/springframework/data/couchbase/config/CouchbaseTemplateParser.java
index b1e99f81..ee85abaa 100644
--- a/src/main/java/org/springframework/data/couchbase/config/CouchbaseTemplateParser.java
+++ b/src/main/java/org/springframework/data/couchbase/config/CouchbaseTemplateParser.java
@@ -25,21 +25,46 @@ import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
+ * Parser for "" bean definitions.
+ *
+ * The outcome of this bean definition parser will be a constructed {@link CouchbaseTemplate}.
+ *
* @author Michael Nitschinger
*/
public class CouchbaseTemplateParser extends AbstractSingleBeanDefinitionParser {
+ /**
+ * Resolve the bean ID and assign a default if not set.
+ *
+ * @param element the XML element which contains the attributes.
+ * @param definition the bean definition to work with.
+ * @param parserContext encapsulates the parsing state and configuration.
+ * @return the ID to work with.
+ */
+ @Override
protected String resolveId(final Element element, final AbstractBeanDefinition definition,
final ParserContext parserContext) {
String id = super.resolveId(element, definition, parserContext);
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE_TEMPLATE;
}
+ /**
+ * Defines the bean class that will be constructed.
+ *
+ * @param element the XML element which contains the attributes.
+ * @return the class type to instantiate.
+ */
@Override
protected Class getBeanClass(final Element element) {
return CouchbaseTemplate.class;
}
+ /**
+ * Parse the bean definition and build up the bean.
+ *
+ * @param element the XML element which contains the attributes.
+ * @param bean the builder which builds the bean.
+ */
@Override
protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
String converterRef = element.getAttribute("converter-ref");
diff --git a/src/main/java/org/springframework/data/couchbase/core/BucketCallback.java b/src/main/java/org/springframework/data/couchbase/core/BucketCallback.java
index 84e462b5..dfdcd8a3 100644
--- a/src/main/java/org/springframework/data/couchbase/core/BucketCallback.java
+++ b/src/main/java/org/springframework/data/couchbase/core/BucketCallback.java
@@ -20,8 +20,20 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
+ * Defines the callback which will be wrapped and executed on a bucket.
+ *
* @author Michael Nitschinger
*/
public interface BucketCallback {
+
+ /**
+ * The enclosed body will be executed on the connected bucket.
+ *
+ * @return the result of the enclosed execution.
+ * @throws TimeoutException if the enclosed operation timed out.
+ * @throws ExecutionException if the result could not be retrieved because of a thrown exception before.
+ * @throws InterruptedException if the enclosed operation was interrupted.
+ */
T doInBucket() throws TimeoutException, ExecutionException, InterruptedException;
+
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseExceptionTranslator.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseExceptionTranslator.java
index 3c7945ab..e87cc36e 100644
--- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseExceptionTranslator.java
+++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseExceptionTranslator.java
@@ -35,10 +35,9 @@ import java.util.concurrent.CancellationException;
/**
* Simple {@link PersistenceExceptionTranslator} for Couchbase.
*
- * Convert the given runtime exception to an appropriate exception from the
- * {@code org.springframework.dao} hierarchy. Return {@literal null} if no translation
- * is appropriate: any other exception may have resulted from user code, and should not
- * be translated.
+ * Convert the given runtime exception to an appropriate exception from the {@code org.springframework.dao} hierarchy.
+ * Return {@literal null} if no translation is appropriate: any other exception may have resulted from user code, and
+ * should not be translated.
*
* @author Michael Nitschinger
*/
diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseFactoryBean.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseFactoryBean.java
index ae5d33da..abaa706e 100644
--- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseFactoryBean.java
+++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseFactoryBean.java
@@ -34,76 +34,183 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
/**
- * Convenient Factory for configuring Couchbase.
+ * Convenient Factory for configuring a {@link CouchbaseClient}.
+ *
+ * To set the properties correctly on the {@link CouchbaseClient} a {@link CouchbaseConnectionFactoryBuilder} is used.
+ * After all properties are set, the client is constructed and used.
*
* @author Michael Nitschinger
*/
public class CouchbaseFactoryBean implements FactoryBean, InitializingBean,
DisposableBean, PersistenceExceptionTranslator {
+ /**
+ * Defines the default hostname to be used if no other list is supplied.
+ */
public static final String DEFAULT_NODE = "127.0.0.1";
+
+ /**
+ * Defines the default bucket name to be used if no other bucket name is supplied.
+ */
public static final String DEFAULT_BUCKET = "default";
+
+ /**
+ * Defines the password of the default bucket.
+ */
public static final String DEFAULT_PASSWORD = "";
+ /**
+ * Holds the enclosed {@link CouchbaseClient}.
+ */
private CouchbaseClient couchbaseClient;
- private PersistenceExceptionTranslator exceptionTranslator = new CouchbaseExceptionTranslator();
- private String bucket;
- private String password;
- private List nodes;
- private CouchbaseConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder();
+ /**
+ * The exception translator is used to properly map exceptions to spring-type exceptions.
+ */
+ private PersistenceExceptionTranslator exceptionTranslator = new CouchbaseExceptionTranslator();
+
+ /**
+ * Contains the actual bucket name.
+ */
+ private String bucket;
+
+ /**
+ * Contains the actual bucket password.
+ */
+ private String password;
+
+ /**
+ * Contains the list of nodes to connect to.
+ */
+ private List nodes;
+
+ /**
+ * The builder which allows to customize client settings.
+ */
+ private final CouchbaseConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder();
+
+ /**
+ * Set the observe poll interval in miliseconds.
+ *
+ * @param interval the observe poll interval.
+ */
public void setObservePollInterval(final int interval) {
builder.setObsPollInterval(interval);
}
+ /**
+ * Set the maximum number of polls.
+ *
+ * @param max the maximum number of polls.
+ */
public void setObservePollMax(final int max) {
builder.setObsPollMax(max);
}
+ /**
+ * Set the reconnect threshold time in seconds.
+ *
+ * @param time the reconnect threshold time.
+ */
public void setReconnectThresholdTime(final int time) {
builder.setReconnectThresholdTime(time, TimeUnit.SECONDS);
}
+ /**
+ * Set the view timeout in miliseconds.
+ *
+ * @param timeout the view timeout.
+ */
public void setViewTimeout(final int timeout) {
builder.setViewTimeout(timeout);
}
+ /**
+ * Set the failure mode if memcached buckets are used.
+ *
+ * See the proper values of {@link FailureMode} to use.
+ *
+ * @param mode the failure mode.
+ */
public void setFailureMode(final String mode) {
builder.setFailureMode(FailureMode.valueOf(mode));
}
+ /**
+ * Set the operation timeout in miliseconds.
+ *
+ * @param timeout the operation timeout.
+ */
public void setOpTimeout(final int timeout) {
builder.setOpTimeout(timeout);
}
+ /**
+ * Set the operation queue maximum block time in miliseconds.
+ *
+ * @param time the operation queue maximum block time.
+ */
public void setOpQueueMaxBlockTime(final int time) {
builder.setOpQueueMaxBlockTime(time);
}
+ /**
+ * Shutdown the client when the bean is destroyed.
+ *
+ * @throws Exception if shutdown failed.
+ */
@Override
public void destroy() throws Exception {
couchbaseClient.shutdown();
}
+ /**
+ * Return the underlying {@link CouchbaseClient}.
+ *
+ * @return the client object.
+ * @throws Exception if returning the client failed.
+ */
@Override
public CouchbaseClient getObject() throws Exception {
return couchbaseClient;
}
+ /**
+ * Returns the object type of the client.
+ *
+ * @return the {@link CouchbaseClient} class.
+ */
@Override
public Class> getObjectType() {
return CouchbaseClient.class;
}
+ /**
+ * The client should be returned as a singleton.
+ *
+ * @return returns true.
+ */
@Override
public boolean isSingleton() {
return true;
}
+ /**
+ * Set the nodes as an array of URIs.
+ *
+ * @param nodes the nodes to connect to.
+ */
public void setNodes(final URI[] nodes) {
this.nodes = filterNonNullElementsAsList(nodes);
}
+ /**
+ * Convert the array of elements to a list and filter empty or null elements.
+ *
+ * @param elements the elements to convert.
+ * @param the type of the elements.
+ * @return the converted list.
+ */
private List filterNonNullElementsAsList(T[] elements) {
if (elements == null) {
return Collections.emptyList();
@@ -119,6 +226,11 @@ public class CouchbaseFactoryBean implements FactoryBean, Initi
return Collections.unmodifiableList(candidateElements);
}
+ /**
+ * Instantiate the {@link CouchbaseClient}.
+ *
+ * @throws Exception if something goes wrong during instantiation.
+ */
@Override
public void afterPropertiesSet() throws Exception {
nodes = nodes != null ? nodes : Arrays.asList(new URI("http://" + DEFAULT_NODE + ":8091/pools"));
@@ -129,8 +241,15 @@ public class CouchbaseFactoryBean implements FactoryBean, Initi
couchbaseClient = new CouchbaseClient(factory);
}
+ /**
+ * Translate exception if possible.
+ *
+ * @param ex the exception to translate.
+ * @return the translate exception.
+ */
@Override
public DataAccessException translateExceptionIfPossible(final RuntimeException ex) {
return exceptionTranslator.translateExceptionIfPossible(ex);
}
+
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseOperations.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseOperations.java
index a688d5e6..bc2fa217 100644
--- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseOperations.java
+++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseOperations.java
@@ -25,6 +25,8 @@ import com.couchbase.client.protocol.views.ViewResponse;
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
/**
+ * Defines common operations on the Couchbase data source, most commonly implemented by {@link CouchbaseTemplate}.
+ *
* @author Michael Nitschinger
*/
public interface CouchbaseOperations {
@@ -32,13 +34,8 @@ public interface CouchbaseOperations {
/**
* Save the given object.
*
- * When the document already exists (specified by its unique id),
- * then it will be overriden. Otherwise it will be created.
- *
- *
- * The object is converted to a JSON representation using an instance of
- * {@link CouchbaseConverter}.
- *
+ *
When the document already exists (specified by its unique id), then it will be overriden. Otherwise it will be
+ * created.
*
* @param objectToSave the object to store in the bucket.
*/
@@ -47,8 +44,8 @@ public interface CouchbaseOperations {
/**
* Save a list of objects.
*
- * When one of the documents already exists (specified by its unique id),
- * then it will be overriden. Otherwise it will be created.
+ *
When one of the documents already exists (specified by its unique id), then it will be overriden. Otherwise it
+ * will be created.
*
* @param batchToSave the list of objects to store in the bucket.
*/
@@ -57,14 +54,8 @@ public interface CouchbaseOperations {
/**
* Insert the given object.
*
- * When the document already exists (specified by its unique id),
- * then it will not be overriden. Use the {@link CouchbaseOperations#save}
- * method for this.
- *
- *
- * The object is converted to a JSON representation using an instance of
- * {@link CouchbaseConverter}.
- *
+ *
When the document already exists (specified by its unique id), then it will not be overriden. Use the
+ * {@link CouchbaseOperations#save} method for this task.
*
* @param objectToSave the object to add to the bucket.
*/
@@ -73,9 +64,8 @@ public interface CouchbaseOperations {
/**
* Insert a list of objects.
*
- * When one of the documents already exists (specified by its unique id),
- * then it will not be overriden. Use the {@link CouchbaseOperations#save}
- * method for this.
+ *
When one of the documents already exists (specified by its unique id), then it will not be overriden. Use the
+ * {@link CouchbaseOperations#save} method for this.
*
* @param batchToSave the list of objects to add to the bucket.
*/
@@ -84,14 +74,8 @@ public interface CouchbaseOperations {
/**
* Update the given object.
*
- * When the document does not exists (specified by its unique id),
- * then it will not be created. Use the {@link CouchbaseOperations#save}
- * method for this.
- *
- *
- * The object is converted to a JSON representation using an instance of
- * {@link CouchbaseConverter}.
- *
+ *
When the document does not exist (specified by its unique id) it will not be created. Use the
+ * {@link CouchbaseOperations#save} method for this.
*
* @param objectToSave the object to add to the bucket.
*/
@@ -100,9 +84,8 @@ public interface CouchbaseOperations {
/**
* Insert a list of objects.
*
- * When one of the documents does not exists (specified by its unique id),
- * then it will not be created. Use the {@link CouchbaseOperations#save}
- * method for this.
+ *
If one of the documents does not exist (specified by its unique id), then it will not be created. Use the
+ * {@link CouchbaseOperations#save} method for this.
*
* @param batchToSave the list of objects to add to the bucket.
*/
@@ -120,13 +103,11 @@ public interface CouchbaseOperations {
/**
* Query a View for a list of documents of type T.
*
- *
There is no need to {@link Query#setIncludeDocs(boolean)} explicitely,
- * because it will be set to true all the time. It is valid to pass in a
- * empty constructed {@link Query} object.
+ *
There is no need to {@link Query#setIncludeDocs(boolean)} explicitely, because it will be set to true all the
+ * time. It is valid to pass in a empty constructed {@link Query} object.
*
- *
This method does not work with reduced views, because they by design
- * do not contain references to original objects. Use the provided
- * {@link #queryView} method for more flexibility and direct access.
+ *
This method does not work with reduced views, because they by design do not contain references to original
+ * objects. Use the provided {@link #queryView} method for more flexibility and direct access.
*
* @param design the name of the design document.
* @param view the name of the view.
@@ -140,11 +121,11 @@ public interface CouchbaseOperations {
/**
* Query a View with direct access to the {@link ViewResponse}.
*
- *
This method is available to ease the working with views by still wrapping
- * exceptions into the Spring infrastructure.
+ *
This method is available to ease the working with views by still wrapping exceptions into the Spring
+ * infrastructure.
*
- *
It is especially needed if you want to run reduced view queries, because
- * they can't be mapped onto entities directly.
+ *
It is especially needed if you want to run reduced view queries, because they can't be mapped onto entities
+ * directly.
*
* @param design the name of the design document.
* @param view the name of the view.
@@ -181,8 +162,7 @@ public interface CouchbaseOperations {
/**
* Executes a BucketCallback translating any exceptions as necessary.
*
- * Allows for returning a result object, that is a domain object or a
- * collection of domain objects.
+ * Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param action the action to execute in the callback.
* @param the return type.
@@ -191,7 +171,7 @@ public interface CouchbaseOperations {
T execute(BucketCallback action);
/**
- * Returns the underlying {@link CouchbaseConverter}
+ * Returns the underlying {@link CouchbaseConverter}.
* @return
*/
CouchbaseConverter getConverter();
diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
index 59303620..a96a5ff4 100644
--- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
+++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
@@ -31,10 +31,7 @@ import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService;
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
-import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
-import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
-import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
-import org.springframework.data.couchbase.core.mapping.CouchbaseStorable;
+import org.springframework.data.couchbase.core.mapping.*;
import org.springframework.data.mapping.context.MappingContext;
import com.couchbase.client.CouchbaseClient;
diff --git a/src/main/java/org/springframework/data/couchbase/core/OperationCancellationException.java b/src/main/java/org/springframework/data/couchbase/core/OperationCancellationException.java
index e6ec92b3..1eb960ed 100644
--- a/src/main/java/org/springframework/data/couchbase/core/OperationCancellationException.java
+++ b/src/main/java/org/springframework/data/couchbase/core/OperationCancellationException.java
@@ -19,8 +19,7 @@ package org.springframework.data.couchbase.core;
import org.springframework.dao.TransientDataAccessException;
/**
- * Data Access Exception that identifies Operations cancelled while being
- * processed.
+ * Data Access Exception that identifies Operations cancelled while being processed.
*
* @author Michael Nitschinger
*/
diff --git a/src/main/java/org/springframework/data/couchbase/core/OperationInterruptedException.java b/src/main/java/org/springframework/data/couchbase/core/OperationInterruptedException.java
index add1f4b1..ae29899b 100644
--- a/src/main/java/org/springframework/data/couchbase/core/OperationInterruptedException.java
+++ b/src/main/java/org/springframework/data/couchbase/core/OperationInterruptedException.java
@@ -19,8 +19,7 @@ package org.springframework.data.couchbase.core;
import org.springframework.dao.TransientDataAccessException;
/**
- * Data Access Exception that identifies Operations interrupted while being
- * processed.
+ * Data Access Exception that identifies Operations interrupted while being processed.
*
* @author Michael Nitschinger
*/
diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java
index f3f6ccdb..785a91b7 100644
--- a/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java
+++ b/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java
@@ -22,27 +22,50 @@ import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.EntityInstantiators;
/**
+ * An abstract {@link CouchbaseConverter} that provides the basics for the {@link MappingCouchbaseConverter}.
+ *
* @author Michael Nitschinger
*/
-public abstract class AbstractCouchbaseConverter implements CouchbaseConverter,
- InitializingBean {
+public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, InitializingBean {
+ /**
+ * Contains the conversion service.
+ */
protected final GenericConversionService conversionService;
+
+ /**
+ * Contains the entity instantiators.
+ */
protected EntityInstantiators instantiators = new EntityInstantiators();
+
+ /**
+ * Holds the custom conversions.
+ */
protected CustomConversions conversions = new CustomConversions();
- public AbstractCouchbaseConverter(
- GenericConversionService conversionService) {
+ /**
+ * Create a new converter and hand it over the {@link ConversionService}
+ *
+ * @param conversionService the conversion service to use.
+ */
+ public AbstractCouchbaseConverter(final GenericConversionService conversionService) {
this.conversionService = conversionService;
}
+ /**
+ * Return the conversion service.
+ *
+ * @return the conversion service.
+ */
public ConversionService getConversionService() {
return conversionService;
}
+ /**
+ * Do nothing after the properties set on the bean.
+ */
@Override
public void afterPropertiesSet() {
-
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseConverter.java
index cba4dd0c..a8fb6b37 100644
--- a/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseConverter.java
+++ b/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseConverter.java
@@ -23,11 +23,13 @@ import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
/**
+ * Marker interface for the converter, identifying the types to and from that can be converted.
+ *
* @author Michael Nitschinger
*/
-public interface CouchbaseConverter extends
- EntityConverter,
- CouchbasePersistentProperty, Object, CouchbaseDocument>,
+public interface CouchbaseConverter
+ extends EntityConverter,
+ CouchbasePersistentProperty, Object, CouchbaseDocument>,
CouchbaseWriter