Skip to content

Commit eee83f7

Browse files
mp911demikereiche
authored andcommitted
DATACOUCH-650 - Polishing.
Reorder methods. Remove superfluous final keyword. Reformat pom. Fix dependency to Spring Data Commons. Original pull request: #279.
1 parent f8b7749 commit eee83f7

File tree

3 files changed

+54
-62
lines changed

3 files changed

+54
-62
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<properties>
2121
<couchbase>3.0.10</couchbase>
2222
<couchbase.osgi>3.0.10</couchbase.osgi>
23-
<springdata.commons>2.4.0-DATACMNS-800-SNAPSHOT</springdata.commons>
23+
<springdata.commons>2.5.0-SNAPSHOT</springdata.commons>
2424
<java-module-name>spring.data.couchbase</java-module-name>
2525
</properties>
2626

@@ -41,10 +41,12 @@
4141
<groupId>org.springframework</groupId>
4242
<artifactId>spring-context-support</artifactId>
4343
</dependency>
44+
4445
<dependency>
4546
<groupId>org.springframework</groupId>
4647
<artifactId>spring-web</artifactId>
4748
</dependency>
49+
4850
<dependency>
4951
<groupId>org.springframework</groupId>
5052
<artifactId>spring-tx</artifactId>
@@ -174,12 +176,14 @@
174176
<version>${kotlin}</version>
175177
<optional>true</optional>
176178
</dependency>
179+
177180
<dependency>
178181
<groupId>org.jetbrains.kotlin</groupId>
179182
<artifactId>kotlin-reflect</artifactId>
180183
<version>${kotlin}</version>
181184
<optional>true</optional>
182185
</dependency>
186+
183187
<dependency>
184188
<groupId>org.jetbrains.kotlin</groupId>
185189
<artifactId>kotlin-test</artifactId>

src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.data.couchbase.repository.support;
1818

19+
import static org.springframework.data.couchbase.repository.support.Util.*;
20+
1921
import java.util.Collection;
2022
import java.util.List;
2123
import java.util.Objects;
@@ -26,7 +28,6 @@
2628
import org.springframework.data.couchbase.core.query.Query;
2729
import org.springframework.data.couchbase.repository.CouchbaseRepository;
2830
import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation;
29-
import static org.springframework.data.couchbase.repository.support.Util.hasNonZeroVersionProperty;
3031
import org.springframework.data.domain.Page;
3132
import org.springframework.data.domain.PageImpl;
3233
import org.springframework.data.domain.Pageable;
@@ -64,8 +65,8 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
6465
* @param entityInformation the Metadata for the entity.
6566
* @param couchbaseOperations the reference to the template used.
6667
*/
67-
public SimpleCouchbaseRepository(final CouchbaseEntityInformation<T, String> entityInformation,
68-
final CouchbaseOperations couchbaseOperations) {
68+
public SimpleCouchbaseRepository(CouchbaseEntityInformation<T, String> entityInformation,
69+
CouchbaseOperations couchbaseOperations) {
6970
Assert.notNull(entityInformation, "CouchbaseEntityInformation must not be null!");
7071
Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null!");
7172

@@ -75,7 +76,7 @@ public SimpleCouchbaseRepository(final CouchbaseEntityInformation<T, String> ent
7576

7677
@Override
7778
@SuppressWarnings("unchecked")
78-
public <S extends T> S save(final S entity) {
79+
public <S extends T> S save(S entity) {
7980
Assert.notNull(entity, "Entity must not be null!");
8081
// if entity has non-null, non-zero version property, then replace()
8182
if (hasNonZeroVersionProperty(entity, couchbaseOperations.getConverter())) {
@@ -86,57 +87,55 @@ public <S extends T> S save(final S entity) {
8687
}
8788

8889
@Override
89-
@SuppressWarnings("unchecked")
90-
public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
90+
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
9191
Assert.notNull(entities, "The given Iterable of entities must not be null!");
9292
return Streamable.of(entities).stream().map((e) -> save(e)).collect(StreamUtils.toUnmodifiableList());
9393
}
9494

9595
@Override
96-
public Optional<T> findById(final ID id) {
96+
public Optional<T> findById(ID id) {
9797
Assert.notNull(id, "The given id must not be null!");
9898
return Optional.ofNullable(couchbaseOperations.findById(entityInformation.getJavaType()).one(id.toString()));
9999
}
100100

101101
@Override
102-
@SuppressWarnings("unchecked")
103-
public List<T> findAllById(final Iterable<ID> ids) {
102+
public List<T> findAllById(Iterable<ID> ids) {
104103
Assert.notNull(ids, "The given Iterable of ids must not be null!");
105104
List<String> convertedIds = Streamable.of(ids).stream().map(Objects::toString).collect(Collectors.toList());
106105
Collection<? extends T> all = couchbaseOperations.findById(entityInformation.getJavaType()).all(convertedIds);
107106
return Streamable.of(all).stream().collect(StreamUtils.toUnmodifiableList());
108107
}
109108

110109
@Override
111-
public boolean existsById(final ID id) {
110+
public boolean existsById(ID id) {
112111
Assert.notNull(id, "The given id must not be null!");
113112
return couchbaseOperations.existsById().one(id.toString());
114113
}
115114

116115
@Override
117-
public void deleteById(final ID id) {
116+
public void deleteById(ID id) {
118117
Assert.notNull(id, "The given id must not be null!");
119118
couchbaseOperations.removeById().one(id.toString());
120119
}
121120

122121
@Override
123-
public void delete(final T entity) {
122+
public void delete(T entity) {
124123
Assert.notNull(entity, "Entity must not be null!");
125124
couchbaseOperations.removeById().one(entityInformation.getId(entity));
126125
}
127126

128-
@Override
129-
public void deleteAll(final Iterable<? extends T> entities) {
130-
Assert.notNull(entities, "The given Iterable of entities must not be null!");
131-
couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList());
132-
}
133-
134127
@Override
135128
public void deleteAllById(Iterable<? extends ID> ids) {
136129
Assert.notNull(ids, "The given Iterable of ids must not be null!");
137130
couchbaseOperations.removeById().all(Streamable.of(ids).map(Objects::toString).toList());
138131
}
139132

133+
@Override
134+
public void deleteAll(Iterable<? extends T> entities) {
135+
Assert.notNull(entities, "The given Iterable of entities must not be null!");
136+
couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList());
137+
}
138+
140139
@Override
141140
public long count() {
142141
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
@@ -155,17 +154,17 @@ public List<T> findAll() {
155154
}
156155

157156
@Override
158-
public List<T> findAll(final Sort sort) {
157+
public List<T> findAll(Sort sort) {
159158
return findAll(new Query().with(sort));
160159
}
161160

162161
@Override
163-
public List<T> findAll(final QueryScanConsistency queryScanConsistency) {
162+
public List<T> findAll(QueryScanConsistency queryScanConsistency) {
164163
return findAll(new Query().scanConsistency(queryScanConsistency));
165164
}
166165

167166
@Override
168-
public Page<T> findAll(final Pageable pageable) {
167+
public Page<T> findAll(Pageable pageable) {
169168
List<T> results = findAll(new Query().with(pageable));
170169
return new PageImpl<>(results, pageable, count());
171170
}
@@ -185,7 +184,7 @@ protected CouchbaseEntityInformation<T, String> getEntityInformation() {
185184
* @param query the originating query.
186185
* @return the list of found entities, already executed.
187186
*/
188-
private List<T> findAll(final Query query) {
187+
private List<T> findAll(Query query) {
189188
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
190189
.matching(query).all();
191190
}
@@ -203,7 +202,7 @@ private QueryScanConsistency buildQueryScanConsistency() {
203202
*
204203
* @param crudMethodMetadata the injected repository metadata.
205204
*/
206-
void setRepositoryMethodMetadata(final CrudMethodMetadata crudMethodMetadata) {
205+
void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata) {
207206
this.crudMethodMetadata = crudMethodMetadata;
208207
}
209208

src/main/java/org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.data.couchbase.repository.support;
1818

19+
import static org.springframework.data.couchbase.repository.support.Util.*;
20+
1921
import reactor.core.publisher.Flux;
2022
import reactor.core.publisher.Mono;
2123

@@ -24,12 +26,12 @@
2426
import java.util.stream.Collectors;
2527

2628
import org.reactivestreams.Publisher;
29+
2730
import org.springframework.data.couchbase.core.CouchbaseOperations;
2831
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
2932
import org.springframework.data.couchbase.core.query.Query;
3033
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository;
3134
import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation;
32-
import static org.springframework.data.couchbase.repository.support.Util.hasNonZeroVersionProperty;
3335
import org.springframework.data.domain.Sort;
3436
import org.springframework.data.util.Streamable;
3537
import org.springframework.util.Assert;
@@ -67,8 +69,8 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
6769
* @param entityInformation the Metadata for the entity.
6870
* @param operations the reference to the reactive template used.
6971
*/
70-
public SimpleReactiveCouchbaseRepository(final CouchbaseEntityInformation<T, String> entityInformation,
71-
final ReactiveCouchbaseOperations operations) {
72+
public SimpleReactiveCouchbaseRepository(CouchbaseEntityInformation<T, String> entityInformation,
73+
ReactiveCouchbaseOperations operations) {
7274
Assert.notNull(operations, "ReactiveCouchbaseOperations must not be null!");
7375
Assert.notNull(entityInformation, "CouchbaseEntityInformation must not be null!");
7476

@@ -78,7 +80,7 @@ public SimpleReactiveCouchbaseRepository(final CouchbaseEntityInformation<T, Str
7880

7981
@SuppressWarnings("unchecked")
8082
@Override
81-
public <S extends T> Mono<S> save(final S entity) {
83+
public <S extends T> Mono<S> save(S entity) {
8284
Assert.notNull(entity, "Entity must not be null!");
8385
// if entity has non-null version property, then replace()
8486
if (hasNonZeroVersionProperty(entity, operations.getConverter())) {
@@ -89,115 +91,102 @@ public <S extends T> Mono<S> save(final S entity) {
8991
}
9092

9193
@Override
92-
public Flux<T> findAll(final Sort sort) {
94+
public Flux<T> findAll(Sort sort) {
9395
return findAll(new Query().with(sort));
9496
}
9597

96-
@SuppressWarnings("unchecked")
9798
@Override
98-
public <S extends T> Flux<S> saveAll(final Iterable<S> entities) {
99+
public <S extends T> Flux<S> saveAll(Iterable<S> entities) {
99100
Assert.notNull(entities, "The given Iterable of entities must not be null!");
100101
return Flux.fromIterable(entities).flatMap(this::save);
101102
}
102103

103-
@SuppressWarnings("unchecked")
104104
@Override
105-
public <S extends T> Flux<S> saveAll(final Publisher<S> entityStream) {
105+
public <S extends T> Flux<S> saveAll(Publisher<S> entityStream) {
106106
Assert.notNull(entityStream, "The given Iterable of entities must not be null!");
107107
return Flux.from(entityStream).flatMap(this::save);
108108
}
109109

110-
@SuppressWarnings("unchecked")
111110
@Override
112-
public Mono<T> findById(final ID id) {
111+
public Mono<T> findById(ID id) {
113112
return operations.findById(entityInformation.getJavaType()).one(id.toString());
114113
}
115114

116-
@SuppressWarnings("unchecked")
117115
@Override
118-
public Mono<T> findById(final Publisher<ID> publisher) {
116+
public Mono<T> findById(Publisher<ID> publisher) {
119117
Assert.notNull(publisher, "The given Publisher must not be null!");
120118
return Mono.from(publisher).flatMap(this::findById);
121119
}
122120

123-
@SuppressWarnings("unchecked")
124121
@Override
125-
public Mono<Boolean> existsById(final ID id) {
122+
public Mono<Boolean> existsById(ID id) {
126123
Assert.notNull(id, "The given id must not be null!");
127124
return operations.existsById().one(id.toString());
128125
}
129126

130-
@SuppressWarnings("unchecked")
131127
@Override
132-
public Mono<Boolean> existsById(final Publisher<ID> publisher) {
128+
public Mono<Boolean> existsById(Publisher<ID> publisher) {
133129
Assert.notNull(publisher, "The given Publisher must not be null!");
134130
return Mono.from(publisher).flatMap(this::existsById);
135131
}
136132

137-
@SuppressWarnings("unchecked")
138133
@Override
139134
public Flux<T> findAll() {
140135
return findAll(new Query());
141136
}
142137

143138
@SuppressWarnings("unchecked")
144139
@Override
145-
public Flux<T> findAllById(final Iterable<ID> ids) {
140+
public Flux<T> findAllById(Iterable<ID> ids) {
146141
Assert.notNull(ids, "The given Iterable of ids must not be null!");
147142
List<String> convertedIds = Streamable.of(ids).stream().map(Objects::toString).collect(Collectors.toList());
148143
return (Flux<T>) operations.findById(entityInformation.getJavaType()).all(convertedIds);
149144
}
150145

151-
@SuppressWarnings("unchecked")
152146
@Override
153-
public Flux<T> findAllById(final Publisher<ID> entityStream) {
147+
public Flux<T> findAllById(Publisher<ID> entityStream) {
154148
Assert.notNull(entityStream, "The given entityStream must not be null!");
155149
return Flux.from(entityStream).flatMap(this::findById);
156150
}
157151

158-
@SuppressWarnings("unchecked")
159152
@Override
160-
public Mono<Void> deleteById(final ID id) {
153+
public Mono<Void> deleteById(ID id) {
161154
return operations.removeById().one(id.toString()).then();
162155
}
163156

164157
@Override
165-
public Mono<Void> deleteById(final Publisher<ID> publisher) {
158+
public Mono<Void> deleteById(Publisher<ID> publisher) {
166159
Assert.notNull(publisher, "The given id must not be null!");
167160
return Mono.from(publisher).flatMap(this::deleteById);
168161
}
169162

170-
@SuppressWarnings("unchecked")
171163
@Override
172-
public Mono<Void> delete(final T entity) {
164+
public Mono<Void> delete(T entity) {
173165
Assert.notNull(entity, "Entity must not be null!");
174166
return operations.removeById().one(entityInformation.getId(entity)).then();
175167
}
176168

177-
@SuppressWarnings("unchecked")
178169
@Override
179-
public Mono<Void> deleteAll(final Iterable<? extends T> entities) {
180-
return operations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList()).then();
170+
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
171+
return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then();
181172
}
182173

183174
@Override
184-
public Mono<Void> deleteAll(final Publisher<? extends T> entityStream) {
185-
Assert.notNull(entityStream, "The given publisher of entities must not be null!");
186-
return Flux.from(entityStream).flatMap(this::delete).single();
175+
public Mono<Void> deleteAll(Iterable<? extends T> entities) {
176+
return operations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList()).then();
187177
}
188178

189179
@Override
190-
public Mono<Void> deleteAllById(final Iterable<? extends ID> ids) {
191-
return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then();
180+
public Mono<Void> deleteAll(Publisher<? extends T> entityStream) {
181+
Assert.notNull(entityStream, "The given publisher of entities must not be null!");
182+
return Flux.from(entityStream).flatMap(this::delete).single();
192183
}
193184

194-
@SuppressWarnings("unchecked")
195185
@Override
196186
public Mono<Long> count() {
197187
return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()).count();
198188
}
199189

200-
@SuppressWarnings("unchecked")
201190
@Override
202191
public Mono<Void> deleteAll() {
203192
return operations.removeByQuery(entityInformation.getJavaType()).all().then();
@@ -212,7 +201,7 @@ protected CouchbaseEntityInformation<T, String> getEntityInformation() {
212201
return entityInformation;
213202
}
214203

215-
private Flux<T> findAll(final Query query) {
204+
private Flux<T> findAll(Query query) {
216205
return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
217206
.matching(query).all();
218207
}
@@ -230,7 +219,7 @@ private QueryScanConsistency buildQueryScanConsistency() {
230219
*
231220
* @param crudMethodMetadata the injected repository metadata.
232221
*/
233-
void setRepositoryMethodMetadata(final CrudMethodMetadata crudMethodMetadata) {
222+
void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata) {
234223
this.crudMethodMetadata = crudMethodMetadata;
235224
}
236225

0 commit comments

Comments
 (0)