1616
1717package org .springframework .data .couchbase .repository .support ;
1818
19+ import static org .springframework .data .couchbase .repository .support .Util .*;
20+
1921import reactor .core .publisher .Flux ;
2022import reactor .core .publisher .Mono ;
2123
2426import java .util .stream .Collectors ;
2527
2628import org .reactivestreams .Publisher ;
29+
2730import org .springframework .data .couchbase .core .CouchbaseOperations ;
2831import org .springframework .data .couchbase .core .ReactiveCouchbaseOperations ;
2932import org .springframework .data .couchbase .core .query .Query ;
3033import org .springframework .data .couchbase .repository .ReactiveCouchbaseRepository ;
3134import org .springframework .data .couchbase .repository .query .CouchbaseEntityInformation ;
32- import static org .springframework .data .couchbase .repository .support .Util .hasNonZeroVersionProperty ;
3335import org .springframework .data .domain .Sort ;
3436import org .springframework .data .util .Streamable ;
3537import 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