16
16
17
17
package org .springframework .data .couchbase .repository .support ;
18
18
19
- import static org .springframework .data .couchbase .repository .support .Util .*;
20
-
21
19
import reactor .core .publisher .Flux ;
22
20
import reactor .core .publisher .Mono ;
23
21
26
24
import java .util .stream .Collectors ;
27
25
28
26
import org .reactivestreams .Publisher ;
29
-
30
27
import org .springframework .data .couchbase .core .CouchbaseOperations ;
31
28
import org .springframework .data .couchbase .core .ReactiveCouchbaseOperations ;
32
29
import org .springframework .data .couchbase .core .query .Query ;
33
30
import org .springframework .data .couchbase .repository .ReactiveCouchbaseRepository ;
34
31
import org .springframework .data .couchbase .repository .query .CouchbaseEntityInformation ;
32
+ import static org .springframework .data .couchbase .repository .support .Util .hasNonZeroVersionProperty ;
35
33
import org .springframework .data .domain .Sort ;
36
34
import org .springframework .data .util .Streamable ;
37
35
import org .springframework .util .Assert ;
@@ -69,8 +67,8 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
69
67
* @param entityInformation the Metadata for the entity.
70
68
* @param operations the reference to the reactive template used.
71
69
*/
72
- public SimpleReactiveCouchbaseRepository (CouchbaseEntityInformation <T , String > entityInformation ,
73
- ReactiveCouchbaseOperations operations ) {
70
+ public SimpleReactiveCouchbaseRepository (final CouchbaseEntityInformation <T , String > entityInformation ,
71
+ final ReactiveCouchbaseOperations operations ) {
74
72
Assert .notNull (operations , "ReactiveCouchbaseOperations must not be null!" );
75
73
Assert .notNull (entityInformation , "CouchbaseEntityInformation must not be null!" );
76
74
@@ -80,7 +78,7 @@ public SimpleReactiveCouchbaseRepository(CouchbaseEntityInformation<T, String> e
80
78
81
79
@ SuppressWarnings ("unchecked" )
82
80
@ Override
83
- public <S extends T > Mono <S > save (S entity ) {
81
+ public <S extends T > Mono <S > save (final S entity ) {
84
82
Assert .notNull (entity , "Entity must not be null!" );
85
83
// if entity has non-null version property, then replace()
86
84
if (hasNonZeroVersionProperty (entity , operations .getConverter ())) {
@@ -91,102 +89,115 @@ public <S extends T> Mono<S> save(S entity) {
91
89
}
92
90
93
91
@ Override
94
- public Flux <T > findAll (Sort sort ) {
92
+ public Flux <T > findAll (final Sort sort ) {
95
93
return findAll (new Query ().with (sort ));
96
94
}
97
95
96
+ @ SuppressWarnings ("unchecked" )
98
97
@ Override
99
- public <S extends T > Flux <S > saveAll (Iterable <S > entities ) {
98
+ public <S extends T > Flux <S > saveAll (final Iterable <S > entities ) {
100
99
Assert .notNull (entities , "The given Iterable of entities must not be null!" );
101
100
return Flux .fromIterable (entities ).flatMap (this ::save );
102
101
}
103
102
103
+ @ SuppressWarnings ("unchecked" )
104
104
@ Override
105
- public <S extends T > Flux <S > saveAll (Publisher <S > entityStream ) {
105
+ public <S extends T > Flux <S > saveAll (final Publisher <S > entityStream ) {
106
106
Assert .notNull (entityStream , "The given Iterable of entities must not be null!" );
107
107
return Flux .from (entityStream ).flatMap (this ::save );
108
108
}
109
109
110
+ @ SuppressWarnings ("unchecked" )
110
111
@ Override
111
- public Mono <T > findById (ID id ) {
112
+ public Mono <T > findById (final ID id ) {
112
113
return operations .findById (entityInformation .getJavaType ()).one (id .toString ());
113
114
}
114
115
116
+ @ SuppressWarnings ("unchecked" )
115
117
@ Override
116
- public Mono <T > findById (Publisher <ID > publisher ) {
118
+ public Mono <T > findById (final Publisher <ID > publisher ) {
117
119
Assert .notNull (publisher , "The given Publisher must not be null!" );
118
120
return Mono .from (publisher ).flatMap (this ::findById );
119
121
}
120
122
123
+ @ SuppressWarnings ("unchecked" )
121
124
@ Override
122
- public Mono <Boolean > existsById (ID id ) {
125
+ public Mono <Boolean > existsById (final ID id ) {
123
126
Assert .notNull (id , "The given id must not be null!" );
124
127
return operations .existsById ().one (id .toString ());
125
128
}
126
129
130
+ @ SuppressWarnings ("unchecked" )
127
131
@ Override
128
- public Mono <Boolean > existsById (Publisher <ID > publisher ) {
132
+ public Mono <Boolean > existsById (final Publisher <ID > publisher ) {
129
133
Assert .notNull (publisher , "The given Publisher must not be null!" );
130
134
return Mono .from (publisher ).flatMap (this ::existsById );
131
135
}
132
136
137
+ @ SuppressWarnings ("unchecked" )
133
138
@ Override
134
139
public Flux <T > findAll () {
135
140
return findAll (new Query ());
136
141
}
137
142
138
143
@ SuppressWarnings ("unchecked" )
139
144
@ Override
140
- public Flux <T > findAllById (Iterable <ID > ids ) {
145
+ public Flux <T > findAllById (final Iterable <ID > ids ) {
141
146
Assert .notNull (ids , "The given Iterable of ids must not be null!" );
142
147
List <String > convertedIds = Streamable .of (ids ).stream ().map (Objects ::toString ).collect (Collectors .toList ());
143
148
return (Flux <T >) operations .findById (entityInformation .getJavaType ()).all (convertedIds );
144
149
}
145
150
151
+ @ SuppressWarnings ("unchecked" )
146
152
@ Override
147
- public Flux <T > findAllById (Publisher <ID > entityStream ) {
153
+ public Flux <T > findAllById (final Publisher <ID > entityStream ) {
148
154
Assert .notNull (entityStream , "The given entityStream must not be null!" );
149
155
return Flux .from (entityStream ).flatMap (this ::findById );
150
156
}
151
157
158
+ @ SuppressWarnings ("unchecked" )
152
159
@ Override
153
- public Mono <Void > deleteById (ID id ) {
160
+ public Mono <Void > deleteById (final ID id ) {
154
161
return operations .removeById ().one (id .toString ()).then ();
155
162
}
156
163
157
164
@ Override
158
- public Mono <Void > deleteById (Publisher <ID > publisher ) {
165
+ public Mono <Void > deleteById (final Publisher <ID > publisher ) {
159
166
Assert .notNull (publisher , "The given id must not be null!" );
160
167
return Mono .from (publisher ).flatMap (this ::deleteById );
161
168
}
162
169
170
+ @ SuppressWarnings ("unchecked" )
163
171
@ Override
164
- public Mono <Void > delete (T entity ) {
172
+ public Mono <Void > delete (final T entity ) {
165
173
Assert .notNull (entity , "Entity must not be null!" );
166
174
return operations .removeById ().one (entityInformation .getId (entity )).then ();
167
175
}
168
176
177
+ @ SuppressWarnings ("unchecked" )
169
178
@ Override
170
- public Mono <Void > deleteAllById (Iterable <? extends ID > ids ) {
171
- return operations .removeById ().all (Streamable .of (ids ).map (Object ::toString ).toList ()).then ();
172
- }
173
-
174
- @ Override
175
- public Mono <Void > deleteAll (Iterable <? extends T > entities ) {
179
+ public Mono <Void > deleteAll (final Iterable <? extends T > entities ) {
176
180
return operations .removeById ().all (Streamable .of (entities ).map (entityInformation ::getId ).toList ()).then ();
177
181
}
178
182
179
183
@ Override
180
- public Mono <Void > deleteAll (Publisher <? extends T > entityStream ) {
184
+ public Mono <Void > deleteAll (final Publisher <? extends T > entityStream ) {
181
185
Assert .notNull (entityStream , "The given publisher of entities must not be null!" );
182
186
return Flux .from (entityStream ).flatMap (this ::delete ).single ();
183
187
}
184
188
189
+ @ Override
190
+ public Mono <Void > deleteAllById (final Iterable <? extends ID > ids ) {
191
+ return operations .removeById ().all (Streamable .of (ids ).map (Object ::toString ).toList ()).then ();
192
+ }
193
+
194
+ @ SuppressWarnings ("unchecked" )
185
195
@ Override
186
196
public Mono <Long > count () {
187
197
return operations .findByQuery (entityInformation .getJavaType ()).consistentWith (buildQueryScanConsistency ()).count ();
188
198
}
189
199
200
+ @ SuppressWarnings ("unchecked" )
190
201
@ Override
191
202
public Mono <Void > deleteAll () {
192
203
return operations .removeByQuery (entityInformation .getJavaType ()).all ().then ();
@@ -201,7 +212,7 @@ protected CouchbaseEntityInformation<T, String> getEntityInformation() {
201
212
return entityInformation ;
202
213
}
203
214
204
- private Flux <T > findAll (Query query ) {
215
+ private Flux <T > findAll (final Query query ) {
205
216
return operations .findByQuery (entityInformation .getJavaType ()).consistentWith (buildQueryScanConsistency ())
206
217
.matching (query ).all ();
207
218
}
@@ -219,7 +230,7 @@ private QueryScanConsistency buildQueryScanConsistency() {
219
230
*
220
231
* @param crudMethodMetadata the injected repository metadata.
221
232
*/
222
- void setRepositoryMethodMetadata (CrudMethodMetadata crudMethodMetadata ) {
233
+ void setRepositoryMethodMetadata (final CrudMethodMetadata crudMethodMetadata ) {
223
234
this .crudMethodMetadata = crudMethodMetadata ;
224
235
}
225
236
0 commit comments