21
21
import java .util .Optional ;
22
22
import java .util .Set ;
23
23
24
+ import org .jspecify .annotations .Nullable ;
24
25
import org .springframework .context .ApplicationEventPublisher ;
25
26
import org .springframework .context .ApplicationEventPublisherAware ;
26
27
import org .springframework .dao .DataAccessException ;
34
35
import org .springframework .data .keyvalue .core .mapping .context .KeyValueMappingContext ;
35
36
import org .springframework .data .keyvalue .core .query .KeyValueQuery ;
36
37
import org .springframework .data .mapping .context .MappingContext ;
37
- import org .springframework .lang .Nullable ;
38
38
import org .springframework .util .Assert ;
39
39
import org .springframework .util .ClassUtils ;
40
40
import org .springframework .util .CollectionUtils ;
@@ -143,7 +143,7 @@ public <T> T insert(T objectToInsert) {
143
143
KeyValuePersistentEntity <?, ?> entity = getKeyValuePersistentEntity (objectToInsert );
144
144
145
145
GeneratingIdAccessor generatingIdAccessor = new GeneratingIdAccessor (entity .getPropertyAccessor (objectToInsert ),
146
- entity .getIdProperty (), identifierGenerator );
146
+ entity .getRequiredIdProperty (), identifierGenerator );
147
147
Object id = generatingIdAccessor .getOrGenerateIdentifier ();
148
148
149
149
return insert (id , objectToInsert );
@@ -213,7 +213,8 @@ public <T> Iterable<T> findAll(Class<T> type) {
213
213
214
214
return executeRequired (adapter -> {
215
215
216
- Iterable <?> values = adapter .getAllOf (resolveKeySpace (type ), type );
216
+ String keyspace = resolveKeySpace (type );
217
+ Iterable <?> values = adapter .getAllOf (keyspace , type );
217
218
218
219
ArrayList <T > filtered = new ArrayList <>();
219
220
for (Object candidate : values ) {
@@ -258,7 +259,6 @@ public void delete(Class<?> type) {
258
259
Assert .notNull (type , "Type to delete must not be null" );
259
260
260
261
String keyspace = resolveKeySpace (type );
261
-
262
262
potentiallyPublishEvent (KeyValueEvent .beforeDropKeySpace (keyspace , type ));
263
263
264
264
execute ((KeyValueCallback <Void >) adapter -> {
@@ -272,16 +272,16 @@ public void delete(Class<?> type) {
272
272
273
273
@ SuppressWarnings ("unchecked" )
274
274
@ Override
275
- public <T > T delete (T objectToDelete ) {
275
+ public <T > @ Nullable T delete (T objectToDelete ) {
276
276
277
277
Class <T > type = (Class <T >) ClassUtils .getUserClass (objectToDelete );
278
278
KeyValuePersistentEntity <?, ?> entity = getKeyValuePersistentEntity (objectToDelete );
279
279
280
- return delete (entity .getIdentifierAccessor (objectToDelete ).getIdentifier (), type );
280
+ return delete (entity .getIdentifierAccessor (objectToDelete ).getRequiredIdentifier (), type );
281
281
}
282
282
283
283
@ Override
284
- public <T > T delete (Object id , Class <T > type ) {
284
+ public <T > @ Nullable T delete (Object id , Class <T > type ) {
285
285
286
286
Assert .notNull (id , "Id for object to be deleted must not be null" );
287
287
Assert .notNull (type , "Type to delete must not be null" );
@@ -301,12 +301,12 @@ public <T> T delete(Object id, Class<T> type) {
301
301
public long count (Class <?> type ) {
302
302
303
303
Assert .notNull (type , "Type for count must not be null" );
304
- return adapter .count (resolveKeySpace (type ));
304
+ String keyspace = resolveKeySpace (type );
305
+ return adapter .count (keyspace );
305
306
}
306
307
307
- @ Nullable
308
308
@ Override
309
- public <T > T execute (KeyValueCallback <T > action ) {
309
+ public <T > @ Nullable T execute (KeyValueCallback <T > action ) {
310
310
311
311
Assert .notNull (action , "KeyValueCallback must not be null" );
312
312
@@ -401,8 +401,12 @@ public void destroy() throws Exception {
401
401
return this .mappingContext .getRequiredPersistentEntity (ClassUtils .getUserClass (objectToInsert ));
402
402
}
403
403
404
- private String resolveKeySpace (Class <?> type ) {
405
- return this .mappingContext .getRequiredPersistentEntity (type ).getKeySpace ();
404
+
405
+ private String resolveKeySpace (Class <?> type ) {
406
+
407
+ String keyspace = this .mappingContext .getRequiredPersistentEntity (type ).getKeySpace ();
408
+ Assert .notNull (keyspace , "Keyspace must not be null" );
409
+ return keyspace ;
406
410
}
407
411
408
412
private RuntimeException resolveExceptionIfPossible (RuntimeException e ) {
0 commit comments