DATAES-908 - Polishing.

This commit is contained in:
Peter-Josef Meisch 2020-08-19 21:30:36 +02:00
parent c82792b34d
commit 26ab5f6db4
5 changed files with 14 additions and 19 deletions

View File

@ -148,9 +148,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
// We should call this because we are not going through a mapper. // We should call this because we are not going through a mapper.
Object queryObject = query.getObject(); Object queryObject = query.getObject();
if (queryObject != null) { if (queryObject != null) {
updateIndexedObject(queryObject, updateIndexedObject(queryObject, IndexedObjectInformation.of(indexResponse.getId(), indexResponse.getSeqNo(),
IndexedObjectInformation.of(indexResponse.getId(), indexResponse.getSeqNo(), indexResponse.getPrimaryTerm(), indexResponse.getVersion()));
indexResponse.getPrimaryTerm(), indexResponse.getVersion()));
} }
maybeCallbackAfterSaveWithQuery(query, index); maybeCallbackAfterSaveWithQuery(query, index);

View File

@ -162,9 +162,8 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
// We should call this because we are not going through a mapper. // We should call this because we are not going through a mapper.
Object queryObject = query.getObject(); Object queryObject = query.getObject();
if (queryObject != null) { if (queryObject != null) {
updateIndexedObject(queryObject, updateIndexedObject(queryObject, IndexedObjectInformation.of(documentId, response.getSeqNo(),
IndexedObjectInformation.of(documentId, response.getSeqNo(), response.getPrimaryTerm(), response.getPrimaryTerm(), response.getVersion()));
response.getVersion()));
} }
maybeCallbackAfterSaveWithQuery(query, index); maybeCallbackAfterSaveWithQuery(query, index);

View File

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.elasticsearch.core; package org.springframework.data.elasticsearch.core;
import org.elasticsearch.action.DocWriteResponse;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2; import reactor.util.function.Tuple2;
@ -27,6 +25,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.bulk.BulkResponse;
@ -75,6 +74,7 @@ import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm; import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
import org.springframework.data.elasticsearch.core.query.UpdateQuery; import org.springframework.data.elasticsearch.core.query.UpdateQuery;
import org.springframework.data.elasticsearch.support.VersionInfo; import org.springframework.data.elasticsearch.support.VersionInfo;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.callback.ReactiveEntityCallbacks; import org.springframework.data.mapping.callback.ReactiveEntityCallbacks;
import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.MappingContext;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -206,9 +206,8 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
.map(it -> { .map(it -> {
T savedEntity = it.getT1(); T savedEntity = it.getT1();
IndexResponse indexResponse = it.getT2(); IndexResponse indexResponse = it.getT2();
return updateIndexedObject(savedEntity, return updateIndexedObject(savedEntity, IndexedObjectInformation.of(indexResponse.getId(),
IndexedObjectInformation.of(indexResponse.getId(), indexResponse.getSeqNo(), indexResponse.getSeqNo(), indexResponse.getPrimaryTerm(), indexResponse.getVersion()));
indexResponse.getPrimaryTerm(), indexResponse.getVersion()));
}).flatMap(saved -> maybeCallAfterSave(saved, index)); }).flatMap(saved -> maybeCallAfterSave(saved, index));
} }
@ -244,9 +243,8 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
BulkItemResponse bulkItemResponse = indexAndResponse.getT2(); BulkItemResponse bulkItemResponse = indexAndResponse.getT2();
DocWriteResponse response = bulkItemResponse.getResponse(); DocWriteResponse response = bulkItemResponse.getResponse();
updateIndexedObject(savedEntity, updateIndexedObject(savedEntity, IndexedObjectInformation.of(response.getId(), response.getSeqNo(),
IndexedObjectInformation.of(response.getId(), response.getSeqNo(), response.getPrimaryTerm(), response.getVersion()));
response.getPrimaryTerm(), response.getVersion()));
return maybeCallAfterSave(savedEntity, index); return maybeCallAfterSave(savedEntity, index);
}); });

View File

@ -3469,10 +3469,10 @@ public abstract class ElasticsearchTemplateTests {
@Test // DATAES-908 @Test // DATAES-908
void shouldFillVersionOnSaveArray() { void shouldFillVersionOnSaveArray() {
VersionedEntity[] array = {new VersionedEntity(), new VersionedEntity()}; VersionedEntity[] array = { new VersionedEntity(), new VersionedEntity() };
Iterator<VersionedEntity> results = operations.save(array).iterator(); Iterator<VersionedEntity> results = operations.save(array).iterator();
VersionedEntity saved1 = results.next(); VersionedEntity saved1 = results.next();
VersionedEntity saved2= results.next(); VersionedEntity saved2 = results.next();
assertThat(saved1.getVersion()).isNotNull(); assertThat(saved1.getVersion()).isNotNull();
assertThat(saved2.getVersion()).isNotNull(); assertThat(saved2.getVersion()).isNotNull();
@ -3490,7 +3490,7 @@ public abstract class ElasticsearchTemplateTests {
@Test // DATAES-908 @Test // DATAES-908
void shouldFillVersionOnBulkIndex() { void shouldFillVersionOnBulkIndex() {
VersionedEntity entity1 = new VersionedEntity(); VersionedEntity entity1 = new VersionedEntity();
VersionedEntity entity2= new VersionedEntity(); VersionedEntity entity2 = new VersionedEntity();
IndexQuery query1 = new IndexQueryBuilder().withObject(entity1).build(); IndexQuery query1 = new IndexQueryBuilder().withObject(entity1).build();
IndexQuery query2 = new IndexQueryBuilder().withObject(entity2).build(); IndexQuery query2 = new IndexQueryBuilder().withObject(entity2).build();
operations.bulkIndex(Arrays.asList(query1, query2), VersionedEntity.class); operations.bulkIndex(Arrays.asList(query1, query2), VersionedEntity.class);

View File

@ -974,8 +974,7 @@ public class ReactiveElasticsearchTemplateTests {
@Test // DATAES-908 @Test // DATAES-908
void shouldFillVersionOnSaveAll() { void shouldFillVersionOnSaveAll() {
VersionedEntity saved = template.saveAll(singletonList(new VersionedEntity()), VersionedEntity.class) VersionedEntity saved = template.saveAll(singletonList(new VersionedEntity()), VersionedEntity.class).blockLast();
.blockLast();
assertThat(saved.getVersion()).isNotNull(); assertThat(saved.getVersion()).isNotNull();
} }