Skip to content

Commit 47a0125

Browse files
dharrigandaschl
authored andcommitted
Some little tidy-ups on the codebase.
-=david=-
1 parent d1779a5 commit 47a0125

File tree

3 files changed

+116
-117
lines changed

3 files changed

+116
-117
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
/**
3434
* Simple {@link PersistenceExceptionTranslator} for Couchbase.
35-
*
35+
* <p/>
3636
* Convert the given runtime exception to an appropriate exception from the {@code org.springframework.dao} hierarchy.
3737
* Return {@literal null} if no translation is appropriate: any other exception may have resulted from user code, and
3838
* should not be translated.
@@ -45,20 +45,21 @@ public class CouchbaseExceptionTranslator implements PersistenceExceptionTransla
4545
* Translate Couchbase specific exceptions to spring exceptions if possible.
4646
*
4747
* @param ex the exception to translate.
48+
*
4849
* @return the translated exception or null.
4950
*/
50-
@Override
51-
public final DataAccessException translateExceptionIfPossible(final RuntimeException ex) {
51+
@Override
52+
public final DataAccessException translateExceptionIfPossible(final RuntimeException ex) {
5253

53-
if (ex instanceof ConnectionException) {
54-
return new DataAccessResourceFailureException(ex.getMessage(), ex);
55-
}
56-
57-
if (ex instanceof ObservedException
58-
|| ex instanceof ObservedTimeoutException
59-
|| ex instanceof ObservedModifiedException) {
60-
return new DataIntegrityViolationException(ex.getMessage(), ex);
61-
}
54+
if (ex instanceof ConnectionException) {
55+
return new DataAccessResourceFailureException(ex.getMessage(), ex);
56+
}
57+
58+
if (ex instanceof ObservedException
59+
|| ex instanceof ObservedTimeoutException
60+
|| ex instanceof ObservedModifiedException) {
61+
return new DataIntegrityViolationException(ex.getMessage(), ex);
62+
}
6263

6364
if (ex instanceof CancellationException) {
6465
throw new OperationCancellationException(ex.getMessage(), ex);
@@ -67,8 +68,9 @@ public final DataAccessException translateExceptionIfPossible(final RuntimeExcep
6768
if (ex instanceof InvalidViewException) {
6869
throw new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
6970
}
70-
71-
return null;
72-
}
71+
72+
// Unable to translate exception, therefore just throw the original!
73+
throw ex;
74+
}
7375

7476
}

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,118 +33,120 @@ public interface CouchbaseOperations {
3333

3434
/**
3535
* Save the given object.
36-
*
36+
* <p/>
3737
* <p>When the document already exists (specified by its unique id), then it will be overriden. Otherwise it will be
3838
* created.</p>
3939
*
4040
* @param objectToSave the object to store in the bucket.
4141
*/
4242
void save(Object objectToSave);
43-
43+
4444
/**
4545
* Save a list of objects.
46-
*
46+
* <p/>
4747
* <p>When one of the documents already exists (specified by its unique id), then it will be overriden. Otherwise it
4848
* will be created.</p>
4949
*
5050
* @param batchToSave the list of objects to store in the bucket.
5151
*/
52-
void save(Collection<? extends Object> batchToSave);
53-
52+
void save(Collection<?> batchToSave);
53+
5454
/**
5555
* Insert the given object.
56-
*
56+
* <p/>
5757
* <p>When the document already exists (specified by its unique id), then it will not be overriden. Use the
5858
* {@link CouchbaseOperations#save} method for this task.</p>
5959
*
6060
* @param objectToSave the object to add to the bucket.
6161
*/
6262
void insert(Object objectToSave);
63-
63+
6464
/**
6565
* Insert a list of objects.
66-
*
66+
* <p/>
6767
* <p>When one of the documents already exists (specified by its unique id), then it will not be overriden. Use the
6868
* {@link CouchbaseOperations#save} method for this.</p>
6969
*
7070
* @param batchToSave the list of objects to add to the bucket.
7171
*/
72-
void insert(Collection<? extends Object> batchToSave);
72+
void insert(Collection<?> batchToSave);
7373

7474
/**
7575
* Update the given object.
76-
*
76+
* <p/>
7777
* <p>When the document does not exist (specified by its unique id) it will not be created. Use the
7878
* {@link CouchbaseOperations#save} method for this.</p>
7979
*
8080
* @param objectToSave the object to add to the bucket.
8181
*/
8282
void update(Object objectToSave);
83-
83+
8484
/**
8585
* Insert a list of objects.
86-
*
86+
* <p/>
8787
* <p>If one of the documents does not exist (specified by its unique id), then it will not be created. Use the
8888
* {@link CouchbaseOperations#save} method for this.</p>
8989
*
9090
* @param batchToSave the list of objects to add to the bucket.
9191
*/
92-
void update(Collection<? extends Object> batchToSave);
93-
92+
void update(Collection<?> batchToSave);
93+
9494
/**
9595
* Find an object by its given Id and map it to the corresponding entity.
9696
*
9797
* @param id the unique ID of the document.
9898
* @param entityClass the entity to map to.
99+
*
99100
* @return returns the found object or null otherwise.
100101
*/
101102
<T> T findById(String id, Class<T> entityClass);
102103

103104
/**
104105
* Query a View for a list of documents of type T.
105-
*
106+
* <p/>
106107
* <p>There is no need to {@link Query#setIncludeDocs(boolean)} explicitely, because it will be set to true all the
107108
* time. It is valid to pass in a empty constructed {@link Query} object.</p>
108-
*
109+
* <p/>
109110
* <p>This method does not work with reduced views, because they by design do not contain references to original
110111
* objects. Use the provided {@link #queryView} method for more flexibility and direct access.</p>
111112
*
112113
* @param design the name of the design document.
113114
* @param view the name of the viewName.
114115
* @param query the Query object to customize the viewName query.
115116
* @param entityClass the entity to map to.
117+
*
116118
* @return the converted collection
117119
*/
118120
<T> List<T> findByView(String design, String view, Query query, Class<T> entityClass);
119121

120122

121123
/**
122124
* Query a View with direct access to the {@link ViewResponse}.
123-
*
124125
* <p>This method is available to ease the working with views by still wrapping exceptions into the Spring
125126
* infrastructure.</p>
126-
*
127127
* <p>It is especially needed if you want to run reduced viewName queries, because they can't be mapped onto entities
128128
* directly.</p>
129129
*
130130
* @param design the name of the designDocument document.
131131
* @param view the name of the viewName.
132132
* @param query the Query object to customize the viewName query.
133-
* @return
133+
*
134+
* @return ViewResponse containing the results of the query.
134135
*/
135136
ViewResponse queryView(String design, String view, Query query);
136137

137138
/**
138139
* Checks if the given document exists.
139140
*
140141
* @param id the unique ID of the document.
142+
*
141143
* @return whether the document could be found or not.
142144
*/
143145
boolean exists(String id);
144146

145147
/**
146148
* Remove the given object from the bucket by id.
147-
*
149+
* <p/>
148150
* If the object is a String, it will be treated as the document key
149151
* directly.
150152
*
@@ -157,22 +159,24 @@ public interface CouchbaseOperations {
157159
*
158160
* @param batchToRemove the list of Objects to remove.
159161
*/
160-
void remove(Collection<? extends Object> batchToRemove);
162+
void remove(Collection<?> batchToRemove);
161163

162164
/**
163165
* Executes a BucketCallback translating any exceptions as necessary.
164-
*
166+
* <p/>
165167
* Allows for returning a result object, that is a domain object or a collection of domain objects.
166168
*
167169
* @param action the action to execute in the callback.
168170
* @param <T> the return type.
169-
* @return
171+
*
172+
* @return the return type.
170173
*/
171174
<T> T execute(BucketCallback<T> action);
172175

173176
/**
174177
* Returns the underlying {@link CouchbaseConverter}.
175-
* @return
178+
*
179+
* @return CouchbaseConverter.
176180
*/
177181
CouchbaseConverter getConverter();
178182

0 commit comments

Comments
 (0)