@@ -362,6 +362,76 @@ public List<IndexedObjectInformation> bulkOperation(List<?> queries, BulkOptions
362
362
public abstract List <IndexedObjectInformation > doBulkOperation (List <?> queries , BulkOptions bulkOptions ,
363
363
IndexCoordinates index );
364
364
365
+ @ Override
366
+ public <T > UpdateResponse update (T entity ) {
367
+
368
+ Assert .notNull (entity , "entity must not be null" );
369
+
370
+ return update (entity , getIndexCoordinatesFor (entity .getClass ()));
371
+ }
372
+
373
+ @ Override
374
+ public <T > UpdateResponse update (T entity , IndexCoordinates index ) {
375
+
376
+ Assert .notNull (entity , "entity must not be null" );
377
+ Assert .notNull (index , "index must not be null" );
378
+
379
+ return update (buildUpdateQueryByEntity (entity ), index );
380
+ }
381
+
382
+ protected <T > UpdateQuery buildUpdateQueryByEntity (T entity ) {
383
+
384
+ Assert .notNull (entity , "entity must not be null" );
385
+
386
+ String id = getEntityId (entity );
387
+ Assert .notNull (id , "entity must have an id that is notnull" );
388
+
389
+ UpdateQuery .Builder updateQueryBuilder = UpdateQuery .builder (id )
390
+ .withDocument (elasticsearchConverter .mapObject (entity ));
391
+
392
+ String routing = getEntityRouting (entity );
393
+ if (StringUtils .hasText (routing )) {
394
+ updateQueryBuilder .withRouting (routing );
395
+ }
396
+
397
+ return updateQueryBuilder .build ();
398
+ }
399
+
400
+ protected <T > T updateIndexedObject (T entity , IndexedObjectInformation indexedObjectInformation ) {
401
+
402
+ ElasticsearchPersistentEntity <?> persistentEntity = elasticsearchConverter .getMappingContext ()
403
+ .getPersistentEntity (entity .getClass ());
404
+
405
+ if (persistentEntity != null ) {
406
+ PersistentPropertyAccessor <Object > propertyAccessor = persistentEntity .getPropertyAccessor (entity );
407
+ ElasticsearchPersistentProperty idProperty = persistentEntity .getIdProperty ();
408
+
409
+ // Only deal with text because ES generated Ids are strings!
410
+ if (indexedObjectInformation .getId () != null && idProperty != null && idProperty .isWritable ()
411
+ && idProperty .getType ().isAssignableFrom (String .class )) {
412
+ propertyAccessor .setProperty (idProperty , indexedObjectInformation .getId ());
413
+ }
414
+
415
+ if (indexedObjectInformation .getSeqNo () != null && indexedObjectInformation .getPrimaryTerm () != null
416
+ && persistentEntity .hasSeqNoPrimaryTermProperty ()) {
417
+ ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity .getSeqNoPrimaryTermProperty ();
418
+ // noinspection ConstantConditions
419
+ propertyAccessor .setProperty (seqNoPrimaryTermProperty ,
420
+ new SeqNoPrimaryTerm (indexedObjectInformation .getSeqNo (), indexedObjectInformation .getPrimaryTerm ()));
421
+ }
422
+
423
+ if (indexedObjectInformation .getVersion () != null && persistentEntity .hasVersionProperty ()) {
424
+ ElasticsearchPersistentProperty versionProperty = persistentEntity .getVersionProperty ();
425
+ // noinspection ConstantConditions
426
+ propertyAccessor .setProperty (versionProperty , indexedObjectInformation .getVersion ());
427
+ }
428
+
429
+ // noinspection unchecked
430
+ return (T ) propertyAccessor .getBean ();
431
+ }
432
+ return entity ;
433
+ }
434
+
365
435
// endregion
366
436
367
437
// region SearchOperations
@@ -463,64 +533,6 @@ public IndexCoordinates getIndexCoordinatesFor(Class<?> clazz) {
463
533
return getRequiredPersistentEntity (clazz ).getIndexCoordinates ();
464
534
}
465
535
466
- @ Override
467
- public <T > UpdateResponse update (T entity ) {
468
- return update (buildUpdateQueryByEntity (entity ), getIndexCoordinatesFor (entity .getClass ()));
469
- }
470
-
471
- protected <T > UpdateQuery buildUpdateQueryByEntity (T entity ) {
472
-
473
- Assert .notNull (entity , "entity must not be null" );
474
-
475
- String id = getEntityId (entity );
476
- Assert .notNull (id , "entity must have an id that is notnull" );
477
-
478
- UpdateQuery .Builder updateQueryBuilder = UpdateQuery .builder (id )
479
- .withDocument (elasticsearchConverter .mapObject (entity ));
480
-
481
- String routing = getEntityRouting (entity );
482
- if (StringUtils .hasText (routing )) {
483
- updateQueryBuilder .withRouting (routing );
484
- }
485
-
486
- return updateQueryBuilder .build ();
487
- }
488
-
489
- protected <T > T updateIndexedObject (T entity , IndexedObjectInformation indexedObjectInformation ) {
490
-
491
- ElasticsearchPersistentEntity <?> persistentEntity = elasticsearchConverter .getMappingContext ()
492
- .getPersistentEntity (entity .getClass ());
493
-
494
- if (persistentEntity != null ) {
495
- PersistentPropertyAccessor <Object > propertyAccessor = persistentEntity .getPropertyAccessor (entity );
496
- ElasticsearchPersistentProperty idProperty = persistentEntity .getIdProperty ();
497
-
498
- // Only deal with text because ES generated Ids are strings!
499
- if (indexedObjectInformation .getId () != null && idProperty != null && idProperty .isWritable ()
500
- && idProperty .getType ().isAssignableFrom (String .class )) {
501
- propertyAccessor .setProperty (idProperty , indexedObjectInformation .getId ());
502
- }
503
-
504
- if (indexedObjectInformation .getSeqNo () != null && indexedObjectInformation .getPrimaryTerm () != null
505
- && persistentEntity .hasSeqNoPrimaryTermProperty ()) {
506
- ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity .getSeqNoPrimaryTermProperty ();
507
- // noinspection ConstantConditions
508
- propertyAccessor .setProperty (seqNoPrimaryTermProperty ,
509
- new SeqNoPrimaryTerm (indexedObjectInformation .getSeqNo (), indexedObjectInformation .getPrimaryTerm ()));
510
- }
511
-
512
- if (indexedObjectInformation .getVersion () != null && persistentEntity .hasVersionProperty ()) {
513
- ElasticsearchPersistentProperty versionProperty = persistentEntity .getVersionProperty ();
514
- // noinspection ConstantConditions
515
- propertyAccessor .setProperty (versionProperty , indexedObjectInformation .getVersion ());
516
- }
517
-
518
- // noinspection unchecked
519
- return (T ) propertyAccessor .getBean ();
520
- }
521
- return entity ;
522
- }
523
-
524
536
ElasticsearchPersistentEntity <?> getRequiredPersistentEntity (Class <?> clazz ) {
525
537
return elasticsearchConverter .getMappingContext ().getRequiredPersistentEntity (clazz );
526
538
}
0 commit comments