43
43
import org .springframework .data .elasticsearch .core .event .ReactiveAfterSaveCallback ;
44
44
import org .springframework .data .elasticsearch .core .event .ReactiveBeforeConvertCallback ;
45
45
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentEntity ;
46
- import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentProperty ;
47
46
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
48
47
import org .springframework .data .elasticsearch .core .mapping .SimpleElasticsearchMappingContext ;
49
48
import org .springframework .data .elasticsearch .core .query .ByQueryResponse ;
55
54
import org .springframework .data .elasticsearch .core .script .Script ;
56
55
import org .springframework .data .elasticsearch .core .suggest .response .Suggest ;
57
56
import org .springframework .data .elasticsearch .support .VersionInfo ;
58
- import org .springframework .data .mapping .PersistentPropertyAccessor ;
59
57
import org .springframework .data .mapping .callback .ReactiveEntityCallbacks ;
60
58
import org .springframework .lang .NonNull ;
61
59
import org .springframework .lang .Nullable ;
@@ -320,51 +318,6 @@ protected IndexQuery getIndexQuery(Object value) {
320
318
return query ;
321
319
}
322
320
323
- protected <T > T updateIndexedObject (T entity , IndexedObjectInformation indexedObjectInformation ) {
324
-
325
- ElasticsearchPersistentEntity <?> persistentEntity = converter .getMappingContext ()
326
- .getPersistentEntity (entity .getClass ());
327
-
328
- if (persistentEntity != null ) {
329
- // noinspection DuplicatedCode
330
- PersistentPropertyAccessor <Object > propertyAccessor = persistentEntity .getPropertyAccessor (entity );
331
- ElasticsearchPersistentProperty idProperty = persistentEntity .getIdProperty ();
332
-
333
- // Only deal with text because ES generated Ids are strings!
334
- if (indexedObjectInformation .id () != null && idProperty != null && idProperty .isReadable ()
335
- && idProperty .getType ().isAssignableFrom (String .class )) {
336
- propertyAccessor .setProperty (idProperty , indexedObjectInformation .id ());
337
- }
338
-
339
- if (indexedObjectInformation .seqNo () != null && indexedObjectInformation .primaryTerm () != null
340
- && persistentEntity .hasSeqNoPrimaryTermProperty ()) {
341
- ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity .getSeqNoPrimaryTermProperty ();
342
- // noinspection ConstantConditions
343
- propertyAccessor .setProperty (seqNoPrimaryTermProperty ,
344
- new SeqNoPrimaryTerm (indexedObjectInformation .seqNo (), indexedObjectInformation .primaryTerm ()));
345
- }
346
-
347
- if (indexedObjectInformation .version () != null && persistentEntity .hasVersionProperty ()) {
348
- ElasticsearchPersistentProperty versionProperty = persistentEntity .getVersionProperty ();
349
- // noinspection ConstantConditions
350
- propertyAccessor .setProperty (versionProperty , indexedObjectInformation .version ());
351
- }
352
-
353
- var indexedIndexNameProperty = persistentEntity .getIndexedIndexNameProperty ();
354
- if (indexedIndexNameProperty != null ) {
355
- propertyAccessor .setProperty (indexedIndexNameProperty , indexedObjectInformation .index ());
356
- }
357
-
358
- // noinspection unchecked
359
- return (T ) propertyAccessor .getBean ();
360
- } else {
361
- EntityOperations .AdaptableEntity <T > adaptableEntity = entityOperations .forEntity (entity ,
362
- converter .getConversionService (), routingResolver );
363
- adaptableEntity .populateIdIfNecessary (indexedObjectInformation .id ());
364
- }
365
- return entity ;
366
- }
367
-
368
321
@ Override
369
322
public <T > Flux <MultiGetItem <T >> multiGet (Query query , Class <T > clazz ) {
370
323
return multiGet (query , clazz , getIndexCoordinatesFor (clazz ));
@@ -391,12 +344,16 @@ public <T> Mono<T> save(T entity, IndexCoordinates index) {
391
344
.map (it -> {
392
345
T savedEntity = it .getT1 ();
393
346
IndexResponseMetaData indexResponseMetaData = it .getT2 ();
394
- return updateIndexedObject (savedEntity , new IndexedObjectInformation (
395
- indexResponseMetaData .id (),
396
- indexResponseMetaData .index (),
397
- indexResponseMetaData .seqNo (),
398
- indexResponseMetaData .primaryTerm (),
399
- indexResponseMetaData .version ()));
347
+ return entityOperations .updateIndexedObject (
348
+ savedEntity ,
349
+ new IndexedObjectInformation (
350
+ indexResponseMetaData .id (),
351
+ indexResponseMetaData .index (),
352
+ indexResponseMetaData .seqNo (),
353
+ indexResponseMetaData .primaryTerm (),
354
+ indexResponseMetaData .version ()),
355
+ converter ,
356
+ routingResolver );
400
357
}).flatMap (saved -> maybeCallbackAfterSave (saved , index ));
401
358
}
402
359
@@ -652,7 +609,11 @@ public Mono<T> toEntity(@Nullable Document document) {
652
609
documentAfterLoad .hasSeqNo () ? documentAfterLoad .getSeqNo () : null ,
653
610
documentAfterLoad .hasPrimaryTerm () ? documentAfterLoad .getPrimaryTerm () : null ,
654
611
documentAfterLoad .hasVersion () ? documentAfterLoad .getVersion () : null );
655
- entity = updateIndexedObject (entity , indexedObjectInformation );
612
+ entity = entityOperations .updateIndexedObject (
613
+ entity ,
614
+ indexedObjectInformation ,
615
+ converter ,
616
+ routingResolver );
656
617
657
618
return maybeCallbackAfterConvert (entity , documentAfterLoad , index );
658
619
});
0 commit comments