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