22
22
import java .util .Map ;
23
23
import java .util .Objects ;
24
24
import java .util .Optional ;
25
+ import java .util .Set ;
25
26
import java .util .stream .Collectors ;
26
27
import java .util .stream .StreamSupport ;
27
28
28
- import org .apache .geode .cache .Cache ;
29
29
import org .apache .geode .cache .CacheTransactionManager ;
30
30
import org .apache .geode .cache .DataPolicy ;
31
+ import org .apache .geode .cache .GemFireCache ;
31
32
import org .apache .geode .cache .Region ;
32
33
import org .apache .geode .cache .query .SelectResults ;
33
34
41
42
import org .springframework .data .gemfire .repository .query .QueryString ;
42
43
import org .springframework .data .gemfire .repository .query .support .PagingUtils ;
43
44
import org .springframework .data .gemfire .util .CollectionUtils ;
45
+ import org .springframework .data .gemfire .util .RegionUtils ;
44
46
import org .springframework .data .gemfire .util .SpringUtils ;
45
47
import org .springframework .data .repository .CrudRepository ;
46
48
import org .springframework .data .repository .PagingAndSortingRepository ;
@@ -140,6 +142,9 @@ public SimpleGemfireRepository(@NonNull GemfireTemplate template,
140
142
return this .template ;
141
143
}
142
144
145
+ /**
146
+ * @inheritDoc
147
+ */
143
148
@ Override
144
149
public <U extends T > U save (@ NonNull U entity ) {
145
150
@@ -155,6 +160,9 @@ public <U extends T> U save(@NonNull U entity) {
155
160
return entity ;
156
161
}
157
162
163
+ /**
164
+ * @inheritDoc
165
+ */
158
166
@ Override
159
167
public T save (@ NonNull Wrapper <T , ID > wrapper ) {
160
168
@@ -170,6 +178,9 @@ public T save(@NonNull Wrapper<T, ID> wrapper) {
170
178
return entity ;
171
179
}
172
180
181
+ /**
182
+ * @inheritDoc
183
+ */
173
184
@ Override
174
185
public <U extends T > Iterable <U > saveAll (@ NonNull Iterable <U > entities ) {
175
186
@@ -223,6 +234,9 @@ public boolean existsById(ID id) {
223
234
return findById (id ).isPresent ();
224
235
}
225
236
237
+ /**
238
+ * @inheritDoc
239
+ */
226
240
@ Override
227
241
public @ NonNull Iterable <T > findAll () {
228
242
@@ -234,6 +248,9 @@ public boolean existsById(ID id) {
234
248
return toList (selectResults );
235
249
}
236
250
251
+ /**
252
+ * @inheritDoc
253
+ */
237
254
@ Override
238
255
public Page <T > findAll (@ NonNull Pageable pageable ) {
239
256
@@ -244,6 +261,9 @@ public Page<T> findAll(@NonNull Pageable pageable) {
244
261
return toPage (results , pageable );
245
262
}
246
263
264
+ /**
265
+ * @inheritDoc
266
+ */
247
267
@ Override
248
268
public @ NonNull Iterable <T > findAll (@ NonNull Sort sort ) {
249
269
@@ -256,6 +276,9 @@ public Page<T> findAll(@NonNull Pageable pageable) {
256
276
return toList (selectResults );
257
277
}
258
278
279
+ /**
280
+ * @inheritDoc
281
+ */
259
282
@ Override
260
283
public @ NonNull Iterable <T > findAllById (@ NonNull Iterable <ID > ids ) {
261
284
@@ -274,6 +297,9 @@ public Page<T> findAll(@NonNull Pageable pageable) {
274
297
return values ;
275
298
}
276
299
300
+ /**
301
+ * @inheritDoc
302
+ */
277
303
@ Override
278
304
public Optional <T > findById (@ NonNull ID id ) {
279
305
@@ -284,11 +310,17 @@ public Optional<T> findById(@NonNull ID id) {
284
310
return Optional .ofNullable (value );
285
311
}
286
312
313
+ /**
314
+ * @inheritDoc
315
+ */
287
316
@ Override
288
317
public void delete (@ NonNull T entity ) {
289
318
deleteById (getEntityInformation ().getRequiredId (entity ));
290
319
}
291
320
321
+ /**
322
+ * @inheritDoc
323
+ */
292
324
@ Override
293
325
public void deleteAll () {
294
326
@@ -305,39 +337,53 @@ public void deleteAll() {
305
337
});
306
338
}
307
339
340
+ /**
341
+ * @inheritDoc
342
+ */
308
343
@ Override
309
344
public void deleteAll (@ NonNull Iterable <? extends T > entities ) {
310
345
CollectionUtils .nullSafeIterable (entities ).forEach (this ::delete );
311
346
}
312
347
348
+ /**
349
+ * @inheritDoc
350
+ */
313
351
@ Override
314
352
public void deleteById (@ NonNull ID id ) {
315
353
getTemplate ().remove (id );
316
354
}
317
355
318
- boolean isPartitioned (Region <?, ?> region ) {
356
+ boolean isPartitioned (@ Nullable Region <?, ?> region ) {
319
357
320
358
return region != null
321
359
&& region .getAttributes () != null
322
360
&& isPartitioned (region .getAttributes ().getDataPolicy ());
323
361
}
324
362
325
- boolean isPartitioned (DataPolicy dataPolicy ) {
363
+ boolean isPartitioned (@ Nullable DataPolicy dataPolicy ) {
326
364
return dataPolicy != null && dataPolicy .withPartitioning ();
327
365
}
328
366
329
- boolean isTransactionPresent (Region <?, ?> region ) {
367
+ boolean isTransactionPresent (@ Nullable Region <?, ?> region ) {
330
368
331
- return region .getRegionService () instanceof Cache
332
- && isTransactionPresent (((Cache ) region .getRegionService ()).getCacheTransactionManager ());
369
+ return region != null
370
+ && region .getRegionService () instanceof GemFireCache
371
+ && isTransactionPresent (((GemFireCache ) region .getRegionService ()).getCacheTransactionManager ());
333
372
}
334
373
335
- boolean isTransactionPresent (CacheTransactionManager cacheTransactionManager ) {
374
+ boolean isTransactionPresent (@ Nullable CacheTransactionManager cacheTransactionManager ) {
336
375
return cacheTransactionManager != null && cacheTransactionManager .exists ();
337
376
}
338
377
339
- <K > void doRegionClear (Region <K , ?> region ) {
340
- region .removeAll (region .keySet ());
378
+ <K > void doRegionClear (@ NonNull Region <K , ?> region ) {
379
+ region .removeAll (resolveRegionKeys (region ));
380
+ }
381
+
382
+ @ NonNull <K > Set <K > resolveRegionKeys (@ NonNull Region <K , ?> region ) {
383
+
384
+ return RegionUtils .isClient (region ) ? region .keySetOnServer ()
385
+ : RegionUtils .isServer (region ) ? region .keySet ()
386
+ : Collections .emptySet ();
341
387
}
342
388
343
389
@ NonNull List <T > toList (@ Nullable Iterable <T > iterable ) {
0 commit comments