Skip to content

Commit b47fc00

Browse files
committed
DATACOUCH-531 - Initial javadoc polish for GA
1 parent e262a05 commit b47fc00

22 files changed

+315
-166
lines changed

src/main/java/org/springframework/data/couchbase/CouchbaseClientFactory.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,47 @@
2525
import com.couchbase.client.java.Collection;
2626
import com.couchbase.client.java.Scope;
2727

28+
/**
29+
* The {@link CouchbaseClientFactory} is the main way to get access to the managed SDK instance and resources.
30+
* <p>
31+
* Please note that a single factory is always bound to a {@link Bucket}, so if you need to access more than one
32+
* you need to initialize one factory for each.
33+
*/
2834
public interface CouchbaseClientFactory extends Closeable {
2935

36+
/**
37+
* Provides access to the managed SDK {@link Cluster} reference.
38+
*/
3039
Cluster getCluster();
3140

41+
/**
42+
* Provides access to the managed SDK {@link Bucket} reference.
43+
*/
3244
Bucket getBucket();
3345

46+
/**
47+
* Provides access to the managed SDK {@link Scope} reference.
48+
*/
3449
Scope getScope();
3550

36-
PersistenceExceptionTranslator getExceptionTranslator();
37-
51+
/**
52+
* Provides access to a collection (identified by its name) in managed SDK {@link Scope} reference.
53+
*
54+
* @param name the name of the collection. If null is passed in, the default collection is assumed.
55+
*/
3856
Collection getCollection(String name);
3957

58+
/**
59+
* Returns a new {@link CouchbaseClientFactory} set to the scope given as an argument.
60+
*
61+
* @param scopeName the name of the scope to use for all collection access.
62+
* @return a new client factory, bound to the other scope.
63+
*/
64+
CouchbaseClientFactory withScope(String scopeName);
65+
66+
/**
67+
* The exception translator used on the factory.
68+
*/
69+
PersistenceExceptionTranslator getExceptionTranslator();
70+
4071
}

src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import com.couchbase.client.java.Scope;
3232
import com.couchbase.client.java.env.ClusterEnvironment;
3333

34+
/**
35+
* The default implementation of a {@link CouchbaseClientFactory}.
36+
*/
3437
public class SimpleCouchbaseClientFactory implements CouchbaseClientFactory {
3538

3639
private final Supplier<Cluster> cluster;
@@ -69,6 +72,7 @@ private SimpleCouchbaseClientFactory(final Supplier<Cluster> cluster, final Stri
6972
this.exceptionTranslator = new CouchbaseExceptionTranslator();
7073
}
7174

75+
@Override
7276
public CouchbaseClientFactory withScope(final String scopeName) {
7377
return new SimpleCouchbaseClientFactory(cluster, bucket.name(), scopeName);
7478
}

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,59 @@
6565
@Configuration
6666
public abstract class AbstractCouchbaseConfiguration {
6767

68+
/**
69+
* The connection string which allows the SDK to connect to the cluster.
70+
* <p>
71+
* Note that the connection string can take many forms, in its simplest it is just a single hostname
72+
* like "127.0.0.1". Please refer to the couchbase Java SDK documentation for all the different
73+
* possibilities and options.
74+
*/
6875
public abstract String getConnectionString();
6976

77+
/**
78+
* The username of the user accessing Couchbase, configured on the cluster.
79+
*/
7080
public abstract String getUserName();
7181

82+
/**
83+
* The password used or the username to authenticate against the cluster.
84+
*/
7285
public abstract String getPassword();
7386

87+
/**
88+
* The name of the bucket that should be used (for example "travel-sample").
89+
*/
7490
public abstract String getBucketName();
7591

92+
/**
93+
* If a non-default scope should be used, override this method.
94+
*
95+
* @return the custom scope name or null if the default scope should be used (default).
96+
*/
7697
protected String getScopeName() {
7798
return null;
7899
}
79100

101+
/**
102+
* Allows to override the {@link Authenticator} used.
103+
* <p>
104+
* The default implementation uses the {@link PasswordAuthenticator} and takes the username and password from
105+
* {@link #getUserName()} and {@link #getPassword()} respectively.
106+
*
107+
* @return the authenticator to be passed into the SDK.
108+
*/
80109
protected Authenticator authenticator() {
81110
return PasswordAuthenticator.create(getUserName(), getPassword());
82111
}
83112

113+
/**
114+
* The {@link CouchbaseClientFactory} provides access to the lower level SDK resources.
115+
*
116+
* @param couchbaseCluster the cluster reference from the SDK.
117+
* @return the initialized factory.
118+
*/
84119
@Bean
85-
public CouchbaseClientFactory couchbaseClientFactory(Cluster couchbaseCluster) {
120+
public CouchbaseClientFactory couchbaseClientFactory(final Cluster couchbaseCluster) {
86121
return new SimpleCouchbaseClientFactory(couchbaseCluster, getBucketName(), getScopeName());
87122
}
88123

@@ -99,6 +134,11 @@ public ClusterEnvironment couchbaseClusterEnvironment() {
99134
return builder.build();
100135
}
101136

137+
/**
138+
* Can be overridden to customize the configuration of the environment before bootstrap.
139+
*
140+
* @param builder the builder that can be customized.
141+
*/
102142
protected void configureEnvironment(final ClusterEnvironment.Builder builder) {
103143

104144
}

src/main/java/org/springframework/data/couchbase/core/CouchbaseOperations.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@
2424
*/
2525
public interface CouchbaseOperations extends FluentCouchbaseOperations {
2626

27+
/**
28+
* Returns the converter used for this template/operations.
29+
*/
2730
CouchbaseConverter getConverter();
2831

32+
/**
33+
* The name of the bucket used.
34+
*/
2935
String getBucketName();
3036

37+
/**
38+
* The name of the scope used, null if the default scope is used.
39+
*/
3140
String getScopeName();
3241

42+
/**
43+
* Returns the underlying client factory.
44+
*/
3345
CouchbaseClientFactory getCouchbaseClientFactory();
3446

3547
}

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.springframework.context.ApplicationContext;
2121
import org.springframework.context.ApplicationContextAware;
2222
import org.springframework.context.ConfigurableApplicationContext;
23-
import org.springframework.dao.DataAccessException;
24-
import org.springframework.dao.support.PersistenceExceptionTranslator;
2523
import org.springframework.data.couchbase.CouchbaseClientFactory;
2624
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
2725
import org.springframework.data.couchbase.core.index.CouchbasePersistentEntityIndexCreator;
@@ -34,7 +32,7 @@
3432
import com.couchbase.client.java.Collection;
3533

3634
/**
37-
* Implements Couchbase operations findBy, insertBy, upsertBy, replaceBy, removeBy, existsBy
35+
* Implements lower-level couchbase operations on top of the SDK with entity mapping capabilities.
3836
*
3937
* @author Michael Nitschinger
4038
* @author Michael Reiche
@@ -44,7 +42,6 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex
4442

4543
private final CouchbaseClientFactory clientFactory;
4644
private final CouchbaseConverter converter;
47-
private final PersistenceExceptionTranslator exceptionTranslator;
4845
private final CouchbaseTemplateSupport templateSupport;
4946
private final MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext;
5047
private final ReactiveCouchbaseTemplate reactiveCouchbaseTemplate;
@@ -53,7 +50,6 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex
5350
public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter) {
5451
this.clientFactory = clientFactory;
5552
this.converter = converter;
56-
this.exceptionTranslator = clientFactory.getExceptionTranslator();
5753
this.templateSupport = new CouchbaseTemplateSupport(converter);
5854
this.reactiveCouchbaseTemplate = new ReactiveCouchbaseTemplate(clientFactory, converter);
5955

@@ -146,33 +142,18 @@ public CouchbaseConverter getConverter() {
146142
return converter;
147143
}
148144

149-
CouchbaseTemplateSupport support() {
150-
return templateSupport;
151-
}
152-
153145
public ReactiveCouchbaseTemplate reactive() {
154146
return reactiveCouchbaseTemplate;
155147
}
156148

157-
/**
158-
* Tries to convert the given {@link RuntimeException} into a {@link DataAccessException} but returns the original
159-
* exception if the conversation failed. Thus allows safe re-throwing of the return value.
160-
*
161-
* @param ex the exception to translate
162-
*/
163-
RuntimeException potentiallyConvertRuntimeException(RuntimeException ex) {
164-
RuntimeException resolved = exceptionTranslator.translateExceptionIfPossible(ex);
165-
return resolved == null ? ex : resolved;
166-
}
167-
168149
@Override
169-
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
150+
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
170151
prepareIndexCreator(applicationContext);
171152
templateSupport.setApplicationContext(applicationContext);
172153
reactiveCouchbaseTemplate.setApplicationContext(applicationContext);
173154
}
174155

175-
private void prepareIndexCreator(ApplicationContext context) {
156+
private void prepareIndexCreator(final ApplicationContext context) {
176157
String[] indexCreators = context.getBeanNamesForType(CouchbasePersistentEntityIndexCreator.class);
177158

178159
for (String creator : indexCreators) {

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@
4040
import org.springframework.util.Assert;
4141

4242
/**
43-
* encode/decode support for CouchbaseTemplate
43+
* Internal encode/decode support for CouchbaseTemplate.
4444
*
4545
* @author Michael Nitschinger
4646
* @author Michael Reiche
4747
* @since 3.0
4848
*/
49-
public class CouchbaseTemplateSupport implements ApplicationContextAware {
49+
class CouchbaseTemplateSupport implements ApplicationContextAware {
50+
5051
private static final Logger LOG = LoggerFactory.getLogger(CouchbaseTemplateSupport.class);
5152

5253
private final CouchbaseConverter converter;
5354
private final MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext;
54-
// TODO: this should be replaced I think
5555
private final TranslationService translationService;
56-
EntityCallbacks entityCallbacks;
56+
private EntityCallbacks entityCallbacks;
5757
private ApplicationContext applicationContext;
5858

5959
public CouchbaseTemplateSupport(final CouchbaseConverter converter) {

src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperation.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,38 @@
2020

2121
public interface ExecutableExistsByIdOperation {
2222

23+
/**
24+
* Checks if the document exists in the bucket.
25+
*/
2326
ExecutableExistsById existsById();
2427

2528
interface TerminatingExistsById {
2629

30+
/**
31+
* Performs the operation on the ID given.
32+
*
33+
* @param id the ID to perform the operation on.
34+
* @return true if the document exists, false otherwise.
35+
*/
2736
boolean one(String id);
2837

38+
/**
39+
* Performs the operation on the collection of ids.
40+
*
41+
* @param ids the ids to check.
42+
* @return a map consisting of the document IDs as the keys and if they exist as the value.
43+
*/
2944
Map<String, Boolean> all(Collection<String> ids);
3045

3146
}
3247

3348
interface ExistsByIdWithCollection extends TerminatingExistsById {
3449

50+
/**
51+
* Allows to specify a different collection than the default one configured.
52+
*
53+
* @param collection the collection to use in this scope.
54+
*/
3555
TerminatingExistsById inCollection(String collection);
3656
}
3757

src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperation.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@
1919
import java.util.Optional;
2020
import java.util.stream.Stream;
2121

22+
import org.springframework.dao.IncorrectResultSizeDataAccessException;
2223
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
2324
import org.springframework.lang.Nullable;
2425

2526
public interface ExecutableFindByAnalyticsOperation {
2627

28+
/**
29+
* Queries the analytics service.
30+
*
31+
* @param domainType the entity type to use for the results.
32+
*/
2733
<T> ExecutableFindByAnalytics<T> findByAnalytics(Class<T> domainType);
2834

2935
interface TerminatingFindByAnalytics<T> {
36+
3037
/**
3138
* Get exactly zero or one result.
3239
*
3340
* @return {@link Optional#empty()} if no match found.
34-
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
41+
* @throws IncorrectResultSizeDataAccessException if more than one match found.
3542
*/
3643
default Optional<T> one() {
3744
return Optional.ofNullable(oneValue());
@@ -41,7 +48,7 @@ default Optional<T> one() {
4148
* Get exactly zero or one result.
4249
*
4350
* @return {@literal null} if no match found.
44-
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
51+
* @throws IncorrectResultSizeDataAccessException if more than one match found.
4552
*/
4653
@Nullable
4754
T oneValue();
@@ -93,19 +100,12 @@ default Optional<T> first() {
93100

94101
}
95102

96-
/**
97-
* Terminating operations invoking the actual query execution.
98-
*
99-
* @author Christoph Strobl
100-
* @since 2.0
101-
*/
102103
interface FindByAnalyticsWithQuery<T> extends TerminatingFindByAnalytics<T> {
103104

104105
/**
105-
* Set the filter query to be used.
106+
* Set the filter for the analytics query to be used.
106107
*
107108
* @param query must not be {@literal null}.
108-
* @return new instance of {@link TerminatingFindByAnalytics}.
109109
* @throws IllegalArgumentException if query is {@literal null}.
110110
*/
111111
TerminatingFindByAnalytics<T> matching(AnalyticsQuery query);

0 commit comments

Comments
 (0)