Skip to content

Commit 4511387

Browse files
committed
DATACOUCH-21 - Documentation and Formatting improvements
1 parent ab252f8 commit 4511387

40 files changed

+721
-187
lines changed

src/main/java/org/springframework/data/couchbase/cache/CouchbaseCache.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import org.springframework.cache.support.SimpleValueWrapper;
2323

2424
/**
25-
* The CouchbaseCache class implements the Spring Cache interface
26-
* on top of Couchbase Server and the Couchbase Java SDK.
25+
* The {@link CouchbaseCache} class implements the Spring Cache interface on top of Couchbase Server and the Couchbase
26+
* Java SDK.
2727
*
28+
* @see <a href="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/cache.html">
29+
* Official Spring Cache Reference</a>
2830
* @author Michael Nitschinger
2931
*/
3032
public class CouchbaseCache implements Cache {
@@ -65,7 +67,7 @@ public final String getName() {
6567
* @return the actual CouchbaseClient instance.
6668
*/
6769
public final CouchbaseClient getNativeCache() {
68-
return this.client;
70+
return client;
6971
}
7072

7173
/**
@@ -76,7 +78,7 @@ public final CouchbaseClient getNativeCache() {
7678
*/
7779
public final ValueWrapper get(final Object key) {
7880
String documentId = key.toString();
79-
Object result = this.client.get(documentId);
81+
Object result = client.get(documentId);
8082
return (result != null ? new SimpleValueWrapper(result) : null);
8183
}
8284

@@ -88,7 +90,7 @@ public final ValueWrapper get(final Object key) {
8890
*/
8991
public final void put(final Object key, final Object value) {
9092
String documentId = key.toString();
91-
this.client.set(documentId, 0, value);
93+
client.set(documentId, 0, value);
9294
}
9395

9496
/**
@@ -98,7 +100,7 @@ public final void put(final Object key, final Object value) {
98100
*/
99101
public final void evict(final Object key) {
100102
String documentId = key.toString();
101-
this.client.delete(documentId);
103+
client.delete(documentId);
102104
}
103105

104106
/**
@@ -108,7 +110,7 @@ public final void evict(final Object key) {
108110
* Also note that "flush" may not be enabled on the bucket.
109111
*/
110112
public final void clear() {
111-
this.client.flush();
113+
client.flush();
112114
}
113115

114116
}

src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
import org.springframework.cache.support.AbstractCacheManager;
2626

2727
/**
28-
* The CouchbaseCacheManager orchestrates CouchbaseCache instances.
28+
* The {@link CouchbaseCacheManager} orchestrates {@link CouchbaseCache} instances.
2929
*
30-
* Since more than one current CouchbaseClient connection can be used
31-
* for caching, the CouchbaseCacheManager orchestrates and handles
32-
* them for the Spring Cache abstraction layer.
30+
* Since more than one current {@link CouchbaseClient} connection can be used for caching, the
31+
* {@link CouchbaseCacheManager} orchestrates and handles them for the Spring Cache abstraction layer.
3332
*
3433
* @author Michael Nitschinger
3534
*/
@@ -55,7 +54,7 @@ public CouchbaseCacheManager(final HashMap<String, CouchbaseClient> clients) {
5554
* @return the actual CouchbaseClient instances.
5655
*/
5756
public final HashMap<String, CouchbaseClient> getClients() {
58-
return this.clients;
57+
return clients;
5958
}
6059

6160
/**
@@ -67,7 +66,7 @@ public final HashMap<String, CouchbaseClient> getClients() {
6766
protected final Collection<? extends Cache> loadCaches() {
6867
Collection<Cache> caches = new LinkedHashSet<Cache>();
6968

70-
for (Map.Entry<String, CouchbaseClient> cache : this.clients.entrySet()) {
69+
for (Map.Entry<String, CouchbaseClient> cache : clients.entrySet()) {
7170
caches.add(new CouchbaseCache(cache.getKey(), cache.getValue()));
7271
}
7372

src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.springframework.context.annotation.Configuration;
2626
import org.springframework.core.type.filter.AnnotationTypeFilter;
2727
import org.springframework.data.annotation.Persistent;
28-
import org.springframework.data.couchbase.core.CouchbaseMappingContext;
28+
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
2929
import org.springframework.data.couchbase.core.CouchbaseTemplate;
3030
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
3131
import org.springframework.data.couchbase.core.mapping.Document;
@@ -42,30 +42,36 @@ public abstract class AbstractCouchbaseConfiguration {
4242

4343
/**
4444
* Return the {@link CouchbaseClient} instance to connect to.
45+
*
46+
* @throws Exception on Bean construction failure.
4547
*/
4648
@Bean
4749
public abstract CouchbaseClient couchbaseClient() throws Exception;
4850

4951
/**
5052
* Creates a {@link CouchbaseTemplate}.
53+
*
54+
* @throws Exception on Bean construction failure.
5155
*/
5256
@Bean
5357
public CouchbaseTemplate couchbaseTemplate() throws Exception {
5458
return new CouchbaseTemplate(couchbaseClient(), mappingCouchbaseConverter());
5559
}
5660

5761
/**
58-
* Creates a {@link MappingCouchbaseConverter} using the configured {@link
59-
* #couchbaseMappingContext}.
62+
* Creates a {@link MappingCouchbaseConverter} using the configured {@link #couchbaseMappingContext}.
63+
*
64+
* @throws Exception on Bean construction failure.
6065
*/
6166
@Bean
6267
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
6368
return new MappingCouchbaseConverter(couchbaseMappingContext());
6469
}
6570

6671
/**
67-
* Creates a {@link CouchbaseMappingContext} equipped with entity classes
68-
* scanned from the mapping base package.
72+
* Creates a {@link CouchbaseMappingContext} equipped with entity classes scanned from the mapping base package.
73+
*
74+
* @throws Exception on Bean construction failure.
6975
*/
7076
@Bean
7177
public CouchbaseMappingContext couchbaseMappingContext() throws Exception {
@@ -76,12 +82,14 @@ public CouchbaseMappingContext couchbaseMappingContext() throws Exception {
7682

7783
/**
7884
* Scans the mapping base package for classes annotated with {@link Document}.
85+
*
86+
* @throws ClassNotFoundException if intial entity sets could not be loaded.
7987
*/
8088
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
8189
String basePackage = getMappingBasePackage();
8290
Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();
8391

84-
if(StringUtils.hasText(basePackage)) {
92+
if (StringUtils.hasText(basePackage)) {
8593
ClassPathScanningCandidateComponentProvider componentProvider =
8694
new ClassPathScanningCandidateComponentProvider(false);
8795
componentProvider.addIncludeFilter(
@@ -100,15 +108,14 @@ protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
100108
}
101109

102110
/**
103-
* Return the base package to scan for mapped {@link Document}s. Will return
104-
* the package name of the configuration class (the concrete class, not this
105-
* one here) by default. So if you have a {@code com.acme.AppConfig} extending
106-
* {@link AbstractCouchbaseConfiguration} the base package will be considered
107-
* {@code com.acme} unless the method is overridden to implement alternate
108-
* behavior.
111+
* Return the base package to scan for mapped {@link Document}s. Will return the package name of the configuration
112+
* class (the concrete class, not this one here) by default.
113+
*
114+
* <p>So if you have a {@code com.acme.AppConfig} extending {@link AbstractCouchbaseConfiguration} the base package
115+
* will be considered {@code com.acme} unless the method is overridden to implement alternate behavior.</p>
109116
*
110-
* @return the base package to scan for mapped {@link Document} classes or
111-
* {@literal null} to not enable scanning for entities.
117+
* @return the base package to scan for mapped {@link Document} classes or {@literal null} to not enable scanning for
118+
* entities.
112119
*/
113120
protected String getMappingBasePackage() {
114121
return getClass().getPackage().getName();

src/main/java/org/springframework/data/couchbase/config/BeanNames.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@
1717
package org.springframework.data.couchbase.config;
1818

1919
/**
20+
* Contains default bean names that will be used when no "id" is supplied to the beans.
21+
*
2022
* @author Michael Nitschinger
2123
*/
2224
public class BeanNames {
23-
static final String MAPPING_CONTEXT = "mappingContext";
25+
/**
26+
* Refers to the "<couchbase:couchbase />" bean.
27+
*/
2428
static final String COUCHBASE = "couchbase";
25-
static final String DB_FACTORY = "couchbaseDbFactory";
26-
static final String DEFAULT_CONVERTER_BEAN_NAME = "mappingConverter";
29+
30+
/**
31+
* Refers to the "<couchbase:template />" bean.
32+
*/
2733
static final String COUCHBASE_TEMPLATE = "couchbaseTemplate";
2834
}

src/main/java/org/springframework/data/couchbase/config/CouchbaseJmxParser.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@
2828
import org.w3c.dom.Element;
2929

3030
/**
31-
* Enables Parsing of "<couchbase:jmx />" configurations.
31+
* Enables Parsing of the "<couchbase:jmx />" configuration bean.
32+
*
33+
* In order to enable JMX, different JmxComponents need to be registered. The dependency to the original
34+
* {@link com.couchbase.client.CouchbaseClient} object is solved by through the "couchbase-ref" attribute.
3235
*
3336
* @author Michael Nitschinger
3437
*/
3538
public class CouchbaseJmxParser implements BeanDefinitionParser {
3639

40+
/**
41+
* Parse the element and dispatch the registration of the JMX components.
42+
*
43+
* @param element the XML element which contains the attributes.
44+
* @param parserContext encapsulates the parsing state and configuration.
45+
* @return null, because no bean instance needs to be returned.
46+
*/
3747
public BeanDefinition parse(final Element element, final ParserContext parserContext) {
3848
String name = element.getAttribute("couchbase-ref");
3949
if (!StringUtils.hasText(name)) {
@@ -43,7 +53,14 @@ public BeanDefinition parse(final Element element, final ParserContext parserCon
4353
return null;
4454
}
4555

46-
protected void registerJmxComponents(String refName, Element element, ParserContext parserContext) {
56+
/**
57+
* Register the JMX components in the context.
58+
*
59+
* @param refName the reference name to the couchbase client.
60+
* @param element the XML element which contains the attributes.
61+
* @param parserContext encapsulates the parsing state and configuration.
62+
*/
63+
protected void registerJmxComponents(final String refName, final Element element, final ParserContext parserContext) {
4764
Object eleSource = parserContext.extractSource(element);
4865
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
4966

@@ -53,8 +70,17 @@ protected void registerJmxComponents(String refName, Element element, ParserCont
5370
parserContext.registerComponent(compositeDef);
5471
}
5572

56-
protected void createBeanDefEntry(Class<?> clazz, CompositeComponentDefinition compositeDef,
57-
String refName, Object eleSource, ParserContext parserContext) {
73+
/**
74+
* Creates Bean Definitions for JMX components and adds them as a nested component.
75+
*
76+
* @param clazz the class type to register.
77+
* @param compositeDef component that can hold nested components.
78+
* @param refName the reference name to the couchbase client.
79+
* @param eleSource source element to reference.
80+
* @param parserContext encapsulates the parsing state and configuration.
81+
*/
82+
protected void createBeanDefEntry(final Class<?> clazz, final CompositeComponentDefinition compositeDef,
83+
final String refName, final Object eleSource, final ParserContext parserContext) {
5884
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(clazz);
5985
builder.getRawBeanDefinition().setSource(eleSource);
6086
builder.addConstructorArgReference(refName);

src/main/java/org/springframework/data/couchbase/config/CouchbaseNamespaceHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
/**
2525
* {@link org.springframework.beans.factory.xml.NamespaceHandler} for Couchbase configuration.
2626
*
27+
* This handler acts as a container for one or more bean parsers and registers them. During parsing, the elements
28+
* get analyzed and the appropriate registered parser is called.
29+
*
2730
* @author Michael Nitschinger
2831
*/
2932
public class CouchbaseNamespaceHandler extends NamespaceHandlerSupport {
3033

31-
public void init() {
34+
/**
35+
* Register bean definition parsers in the namespace handler.
36+
*/
37+
public final void init() {
3238
RepositoryConfigurationExtension extension = new CouchbaseRepositoryConfigurationExtension();
3339

3440
registerBeanDefinitionParser("repositories", new RepositoryBeanDefinitionParser(extension));

src/main/java/org/springframework/data/couchbase/config/CouchbaseParser.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,32 @@
3131
import java.util.ArrayList;
3232
import java.util.List;
3333

34-
3534
/**
36-
* Parser for "<couchbase:couchbase />" definitions.
35+
* Parser for "<couchbase:couchbase />" bean definitions.
36+
*
37+
* The outcome of this bean definition parser will be a constructed {@link CouchbaseClient}.
3738
*
3839
* @author Michael Nitschinger
3940
*/
4041
public class CouchbaseParser extends AbstractSingleBeanDefinitionParser {
4142

43+
/**
44+
* Defines the bean class that will be constructed.
45+
*
46+
* @param element the XML element which contains the attributes.
47+
* @return the class type to instantiate.
48+
*/
4249
@Override
4350
protected Class getBeanClass(final Element element) {
4451
return CouchbaseClient.class;
4552
}
4653

54+
/**
55+
* Parse the bean definition and build up the bean.
56+
*
57+
* @param element the XML element which contains the attributes.
58+
* @param bean the builder which builds the bean.
59+
*/
4760
@Override
4861
protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
4962
String host = element.getAttribute("host");
@@ -57,12 +70,30 @@ protected void doParse(final Element element, final BeanDefinitionBuilder bean)
5770
StringUtils.hasText(password) ? password : CouchbaseFactoryBean.DEFAULT_PASSWORD);
5871
}
5972

73+
/**
74+
* Resolve the bean ID and assign a default if not set.
75+
*
76+
* @param element the XML element which contains the attributes.
77+
* @param definition the bean definition to work with.
78+
* @param parserContext encapsulates the parsing state and configuration.
79+
* @return the ID to work with.
80+
*/
81+
@Override
6082
protected String resolveId(final Element element, final AbstractBeanDefinition definition,
6183
final ParserContext parserContext) {
6284
String id = super.resolveId(element, definition, parserContext);
6385
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE;
6486
}
6587

88+
/**
89+
* Convert a list of hosts into a URI format that can be used by the {@link CouchbaseClient}.
90+
*
91+
* To make it simple to use, the list of hosts can be passed in as a comma separated list. This list gets parsed
92+
* and converted into a URI format that is suitable for the underlying {@link CouchbaseClient} object.
93+
*
94+
* @param hosts the host list to convert.
95+
* @return the converted list with URIs.
96+
*/
6697
private List<URI> convertHosts(final String hosts) {
6798
String[] split = hosts.split(",");
6899
List<URI> nodes = new ArrayList<URI>();

src/main/java/org/springframework/data/couchbase/config/CouchbaseTemplateParser.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,46 @@
2525
import org.w3c.dom.Element;
2626

2727
/**
28+
* Parser for "<couchbase:template />" bean definitions.
29+
*
30+
* The outcome of this bean definition parser will be a constructed {@link CouchbaseTemplate}.
31+
*
2832
* @author Michael Nitschinger
2933
*/
3034
public class CouchbaseTemplateParser extends AbstractSingleBeanDefinitionParser {
3135

36+
/**
37+
* Resolve the bean ID and assign a default if not set.
38+
*
39+
* @param element the XML element which contains the attributes.
40+
* @param definition the bean definition to work with.
41+
* @param parserContext encapsulates the parsing state and configuration.
42+
* @return the ID to work with.
43+
*/
44+
@Override
3245
protected String resolveId(final Element element, final AbstractBeanDefinition definition,
3346
final ParserContext parserContext) {
3447
String id = super.resolveId(element, definition, parserContext);
3548
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE_TEMPLATE;
3649
}
3750

51+
/**
52+
* Defines the bean class that will be constructed.
53+
*
54+
* @param element the XML element which contains the attributes.
55+
* @return the class type to instantiate.
56+
*/
3857
@Override
3958
protected Class getBeanClass(final Element element) {
4059
return CouchbaseTemplate.class;
4160
}
4261

62+
/**
63+
* Parse the bean definition and build up the bean.
64+
*
65+
* @param element the XML element which contains the attributes.
66+
* @param bean the builder which builds the bean.
67+
*/
4368
@Override
4469
protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
4570
String converterRef = element.getAttribute("converter-ref");

0 commit comments

Comments
 (0)