Revert "Support partially update document by entity."

This reverts commit 7e904cdbe752ef00131c0945b91d106e3edb1341.
This commit is contained in:
Peter-Josef Meisch 2022-09-24 22:00:49 +02:00
parent 7e904cdbe7
commit 8bb3474c05
No known key found for this signature in database
GPG Key ID: DE108246970C7708
4 changed files with 3 additions and 76 deletions

View File

@ -8,4 +8,4 @@ In order to run the tests locally with `./mvnw test` you need to have docker run
== Class names of the test classes
Test classes that do depend on the client have either `ERHLC` (when using the deprecated Elasticsearch `RestHighLevelClient`) or `ELC` (the new `ElasticsearchClient`) in their name.
Tset classes that do depend on the client have either `ERHLC` (when using the deprecated Elasticsearch `RestHighLevelClient`) or `ELC` (the new `ElasticsearchClient`) in their name.

View File

@ -48,7 +48,6 @@ import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
import org.springframework.data.elasticsearch.core.routing.DefaultRoutingResolver;
import org.springframework.data.elasticsearch.core.routing.RoutingResolver;
import org.springframework.data.elasticsearch.support.VersionInfo;
@ -75,7 +74,6 @@ import org.springframework.util.Assert;
* @author Subhobrata Dey
* @author Steven Pearce
* @author Anton Naydenov
* @author Haibo Liu
*/
public abstract class AbstractElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
@ -307,7 +305,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
@Override
public String delete(Object entity, IndexCoordinates index) {
String entityId = getEntityId(entity);
Assert.notNull(entityId, "entity must have an id that is notnull");
Assert.notNull(entityId, "entity must have an if that is notnull");
return this.delete(entityId, index);
}
@ -470,25 +468,6 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
return getRequiredPersistentEntity(clazz).getIndexCoordinates();
}
@Override
public <T> UpdateResponse update(T entity) {
return update(this.buildUpdateQueryByEntity(entity), this.getIndexCoordinatesFor(entity.getClass()));
}
protected <T> UpdateQuery buildUpdateQueryByEntity(T entity) {
String id = this.getEntityId(entity);
Assert.notNull(entity, "entity must have an id that is notnull");
UpdateQuery.Builder updateQueryBuilder = UpdateQuery.builder(id)
.withDocument(elasticsearchConverter.mapObject(entity));
String routing = this.getEntityRouting(entity);
if (Objects.nonNull(routing)) {
updateQueryBuilder.withRouting(routing);
}
return updateQueryBuilder.build();
}
protected <T> T updateIndexedObject(T entity, IndexedObjectInformation indexedObjectInformation) {
ElasticsearchPersistentEntity<?> persistentEntity = elasticsearchConverter.getMappingContext()
@ -529,7 +508,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
}
@Nullable
public String getEntityId(Object entity) {
private String getEntityId(Object entity) {
Object id = entityOperations.forEntity(entity, elasticsearchConverter.getConversionService(), routingResolver)
.getId();

View File

@ -37,7 +37,6 @@ import org.springframework.lang.Nullable;
* @author Peter-Josef Meisch
* @author Farid Faoudi
* @author Sijia Liu
* @author Haibo Liu
* @since 4.0
*/
public interface DocumentOperations {
@ -308,15 +307,6 @@ public interface DocumentOperations {
*/
ByQueryResponse delete(Query query, Class<?> clazz, IndexCoordinates index);
/**
* Partially update a document by the given entity.
*
* @param entity the entity to update partially
* @return the update response
* @param <T> the entity type
*/
<T> UpdateResponse update(T entity);
/**
* Partial update of the document.
*

View File

@ -105,7 +105,6 @@ import org.springframework.lang.Nullable;
* @author Farid Faoudi
* @author Peer Mueller
* @author Sijia Liu
* @author Haibo Liu
*/
@SpringIntegrationTest
public abstract class ElasticsearchIntegrationTests implements NewElasticsearchClientDevelopment {
@ -178,20 +177,6 @@ public abstract class ElasticsearchIntegrationTests implements NewElasticsearchC
protected abstract Query getQueryWithRescorer();
@Test
public void shouldThrowDataAccessExceptionIfDocumentDoesNotExistWhileDoingPartialUpdateByEntity() {
// given
String documentId = nextIdAsString();
String messageBeforeUpdate = "some test message";
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message(messageBeforeUpdate)
.version(System.currentTimeMillis()).build();
assertThatThrownBy(() -> operations.update(sampleEntity))
.isInstanceOf(DataAccessException.class);
}
@Test
public void shouldThrowDataAccessExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
@ -1514,33 +1499,6 @@ public abstract class ElasticsearchIntegrationTests implements NewElasticsearchC
assertThat(indexOperations.exists()).isFalse();
}
@Test
public void shouldDoPartialUpdateBySuppliedEntityForExistingDocument() {
// given
String documentId = nextIdAsString();
String messageBeforeUpdate = "some test message";
String messageAfterUpdate = "test message";
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message(messageBeforeUpdate)
.version(System.currentTimeMillis()).build();
IndexQuery indexQuery = getIndexQuery(sampleEntity);
operations.index(indexQuery, IndexCoordinates.of(indexNameProvider.indexName()));
// modify the entity
sampleEntity.setMessage(messageAfterUpdate);
// when
operations.update(sampleEntity);
// then
SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class,
IndexCoordinates.of(indexNameProvider.indexName()));
assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate);
}
@Test
public void shouldDoPartialUpdateForExistingDocument() {