@@ -68,9 +68,35 @@ public SimpleReactiveCouchbaseRepository(CouchbaseEntityInformation<T, String> e
68
68
this .operations = operations ;
69
69
}
70
70
71
+ @ Override
72
+ public Flux <T > findAll (Sort sort ) {
73
+ return findAll (new Query ().with (sort ));
74
+ }
75
+
71
76
@ SuppressWarnings ("unchecked" )
72
77
@ Override
73
78
public <S extends T > Mono <S > save (S entity ) {
79
+ return save (entity , getScope (), getCollection ());
80
+ }
81
+
82
+ @ Override
83
+ public <S extends T > Flux <S > saveAll (Iterable <S > entities ) {
84
+ Assert .notNull (entities , "The given Iterable of entities must not be null!" );
85
+ String scope = getScope ();
86
+ String collection = getCollection ();
87
+ return Flux .fromIterable (entities ).flatMap (e -> save (e , scope , collection ));
88
+ }
89
+
90
+ @ Override
91
+ public <S extends T > Flux <S > saveAll (Publisher <S > entityStream ) {
92
+ Assert .notNull (entityStream , "The given Iterable of entities must not be null!" );
93
+ String scope = getScope ();
94
+ String collection = getCollection ();
95
+ return Flux .from (entityStream ).flatMap (e -> save (e , scope , collection ));
96
+ }
97
+
98
+ @ SuppressWarnings ("unchecked" )
99
+ private <S extends T > Mono <S > save (S entity , String scope , String collection ) {
74
100
Assert .notNull (entity , "Entity must not be null!" );
75
101
Mono <S > result ;
76
102
final CouchbasePersistentEntity <?> mapperEntity = operations .getConverter ().getMappingContext ()
@@ -83,97 +109,100 @@ public <S extends T> Mono<S> save(S entity) {
83
109
84
110
if (!versionPresent ) { // the entity doesn't have a version property
85
111
// No version field - no cas
86
- result = (Mono <S >) operations .upsertById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ())
87
- .one (entity );
112
+ result = (Mono <S >) operations .upsertById (getJavaType ()).inScope (scope ).inCollection (collection ).one (entity );
88
113
} else if (existingDocument ) { // there is a version property, and it is non-zero
89
114
// Updating existing document with cas
90
- result = (Mono <S >) operations .replaceById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ())
91
- .one (entity );
115
+ result = (Mono <S >) operations .replaceById (getJavaType ()).inScope (scope ).inCollection (collection ).one (entity );
92
116
} else { // there is a version property, but it's zero or not set.
93
117
// Creating new document
94
- result = (Mono <S >) operations .insertById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ())
95
- .one (entity );
118
+ result = (Mono <S >) operations .insertById (getJavaType ()).inScope (scope ).inCollection (collection ).one (entity );
96
119
}
97
120
return result ;
98
121
}
99
122
100
123
@ Override
101
- public Flux <T > findAll ( Sort sort ) {
102
- return findAll ( new Query (). with ( sort ));
124
+ public Mono <T > findById ( ID id ) {
125
+ return findById ( id , getScope (), getCollection ( ));
103
126
}
104
127
105
128
@ Override
106
- public <S extends T > Flux <S > saveAll (Iterable <S > entities ) {
107
- Assert .notNull (entities , "The given Iterable of entities must not be null!" );
108
- return Flux .fromIterable (entities ).flatMap (e -> save (e ));
129
+ public Mono <T > findById (Publisher <ID > publisher ) {
130
+ Assert .notNull (publisher , "The given Publisher must not be null!" );
131
+ String scope = getScope ();
132
+ String collection = getCollection ();
133
+ return Mono .from (publisher ).flatMap (id -> findById (id , scope , collection ));
109
134
}
110
135
136
+ @ SuppressWarnings ("unchecked" )
111
137
@ Override
112
- public <S extends T > Flux <S > saveAll (Publisher <S > entityStream ) {
113
- Assert .notNull (entityStream , "The given Iterable of entities must not be null!" );
114
- return Flux .from (entityStream ).flatMap (this ::save );
138
+ public Flux <T > findAllById (Iterable <ID > ids ) {
139
+ Assert .notNull (ids , "The given Iterable of ids must not be null!" );
140
+ List <String > convertedIds = Streamable .of (ids ).stream ().map (Objects ::toString ).collect (Collectors .toList ());
141
+ return (Flux <T >) operations .findById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ())
142
+ .all (convertedIds );
115
143
}
116
144
117
145
@ Override
118
- public Mono <T > findById (ID id ) {
119
- return operations .findById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ()).one (id .toString ());
146
+ public Flux <T > findAllById (Publisher <ID > entityStream ) {
147
+ Assert .notNull (entityStream , "The given entityStream must not be null!" );
148
+ String scope = getScope ();
149
+ String collection = getCollection ();
150
+ return Flux .from (entityStream ).flatMap (id -> findById (id , scope , collection ));
120
151
}
121
152
122
- @ Override
123
- public Mono <T > findById (Publisher <ID > publisher ) {
124
- Assert .notNull (publisher , "The given Publisher must not be null!" );
125
- return Mono .from (publisher ).flatMap (this ::findById );
153
+ private Mono <T > findById (ID id , String scope , String collection ) {
154
+ return operations .findById (getJavaType ()).inScope (scope ).inCollection (collection ).one (id .toString ());
126
155
}
127
156
128
157
@ Override
129
158
public Mono <Boolean > existsById (ID id ) {
130
159
Assert .notNull (id , "The given id must not be null!" );
131
- return operations .existsById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ()).one (id .toString ());
160
+ return existsById (id , getScope (), getCollection ());
161
+ }
162
+
163
+ private Mono <Boolean > existsById (ID id , String scope , String collection ) {
164
+ Assert .notNull (id , "The given id must not be null!" );
165
+ return operations .existsById (getJavaType ()).inScope (scope ).inCollection (collection ).one (id .toString ());
132
166
}
133
167
134
168
@ Override
135
169
public Mono <Boolean > existsById (Publisher <ID > publisher ) {
136
170
Assert .notNull (publisher , "The given Publisher must not be null!" );
137
- return Mono .from (publisher ).flatMap (this ::existsById );
171
+ String scope = getScope ();
172
+ String collection = getCollection ();
173
+ return Mono .from (publisher ).flatMap (id -> existsById (id , scope , collection ));
138
174
}
139
175
140
176
@ Override
141
177
public Flux <T > findAll () {
142
178
return findAll (new Query ());
143
179
}
144
180
145
- @ SuppressWarnings ("unchecked" )
146
- @ Override
147
- public Flux <T > findAllById (Iterable <ID > ids ) {
148
- Assert .notNull (ids , "The given Iterable of ids must not be null!" );
149
- List <String > convertedIds = Streamable .of (ids ).stream ().map (Objects ::toString ).collect (Collectors .toList ());
150
- return (Flux <T >) operations .findById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ())
151
- .all (convertedIds );
152
- }
153
-
154
181
@ Override
155
- public Flux <T > findAllById (Publisher <ID > entityStream ) {
156
- Assert .notNull (entityStream , "The given entityStream must not be null!" );
157
- return Flux .from (entityStream ).flatMap (this ::findById );
182
+ public Mono <Void > deleteById (ID id ) {
183
+ return deleteById (id , getScope (), getCollection ());
158
184
}
159
185
160
- @ Override
161
- public Mono <Void > deleteById (ID id ) {
162
- return operations .removeById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ()).one (id .toString ())
163
- .then ();
186
+ private Mono <Void > deleteById (ID id , String scope , String collection ) {
187
+ return operations .removeById (getJavaType ()).inScope (scope ).inCollection (collection ).one (id .toString ()).then ();
164
188
}
165
189
166
190
@ Override
167
191
public Mono <Void > deleteById (Publisher <ID > publisher ) {
168
192
Assert .notNull (publisher , "The given id must not be null!" );
169
- return Mono .from (publisher ).flatMap (this ::deleteById );
193
+ String scope = getScope ();
194
+ String collection = getCollection ();
195
+ return Mono .from (publisher ).flatMap (e -> deleteById (e , scope , collection ));
170
196
}
171
197
172
198
@ Override
173
199
public Mono <Void > delete (T entity ) {
200
+ return delete (entity , getScope (), getCollection ());
201
+ }
202
+
203
+ private Mono <Void > delete (T entity , String scope , String collection ) {
174
204
Assert .notNull (entity , "Entity must not be null!" );
175
- return operations .removeById (getJavaType ()).inScope (getScope ()).inCollection (getCollection ()).one (getId (entity ))
176
- .then ();
205
+ return operations .removeById (getJavaType ()).inScope (scope ).inCollection (collection ).one (getId (entity )).then ();
177
206
}
178
207
179
208
@ Override
@@ -191,13 +220,9 @@ public Mono<Void> deleteAll(Iterable<? extends T> entities) {
191
220
@ Override
192
221
public Mono <Void > deleteAll (Publisher <? extends T > entityStream ) {
193
222
Assert .notNull (entityStream , "The given publisher of entities must not be null!" );
194
- return Flux .from (entityStream ).flatMap (this ::delete ).single ();
195
- }
196
-
197
- @ Override
198
- public Mono <Long > count () {
199
- return operations .findByQuery (getJavaType ()).withConsistency (buildQueryScanConsistency ()).inScope (getScope ())
200
- .inCollection (getCollection ()).count ();
223
+ String scope = getScope ();
224
+ String collection = getCollection ();
225
+ return Flux .from (entityStream ).flatMap (e -> delete (e , scope , collection )).single ();
201
226
}
202
227
203
228
@ Override
@@ -206,6 +231,12 @@ public Mono<Void> deleteAll() {
206
231
.inCollection (getCollection ()).all ().then ();
207
232
}
208
233
234
+ @ Override
235
+ public Mono <Long > count () {
236
+ return operations .findByQuery (getJavaType ()).withConsistency (buildQueryScanConsistency ()).inScope (getScope ())
237
+ .inCollection (getCollection ()).count ();
238
+ }
239
+
209
240
private Flux <T > findAll (Query query ) {
210
241
return operations .findByQuery (getJavaType ()).withConsistency (buildQueryScanConsistency ()).inScope (getScope ())
211
242
.inCollection (getCollection ()).matching (query ).all ();
0 commit comments