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