Internal refactoring stringRepresentation/convertId.

Original Pull Request #2312
Closes #2228
This commit is contained in:
Peter-Josef Meisch 2022-09-27 20:23:33 +02:00 committed by GitHub
parent 8a1d8deb67
commit 05c6444b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -531,11 +531,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
Object id = entityOperations.forEntity(entity, elasticsearchConverter.getConversionService(), routingResolver) Object id = entityOperations.forEntity(entity, elasticsearchConverter.getConversionService(), routingResolver)
.getId(); .getId();
if (id != null) { return convertId(id);
return stringIdRepresentation(id);
}
return null;
} }
@Nullable @Nullable

View File

@ -80,13 +80,28 @@ public interface ElasticsearchOperations extends DocumentOperations, SearchOpera
* gets the String representation for an id. * gets the String representation for an id.
* *
* @param id * @param id
* @return * @return String representation
* @since 4.0 * @since 4.0
* @deprecated since 5.0, use {@link ElasticsearchOperations#convertId(Object)}.
*/ */
@Deprecated
@Nullable @Nullable
default String stringIdRepresentation(@Nullable Object id) { default String stringIdRepresentation(@Nullable Object id) {
return Objects.toString(id, null); return Objects.toString(id, null);
} }
/**
* Converts an idValue to a String representation. The default implementation calls
* {@link ElasticsearchConverter#convertId(Object)}
*
* @param idValue the value to convert
* @return the converted value or {@literal null} if idValue is null
* @since 5.0
*/
@Nullable
default String convertId(@Nullable Object idValue) {
return idValue != null ? getElasticsearchConverter().convertId(idValue) : null;
}
// endregion // endregion
// region routing // region routing

View File

@ -313,7 +313,7 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
} }
protected @Nullable String stringIdRepresentation(@Nullable ID id) { protected @Nullable String stringIdRepresentation(@Nullable ID id) {
return operations.stringIdRepresentation(id); return operations.convertId(id);
} }
private IndexCoordinates getIndexCoordinates() { private IndexCoordinates getIndexCoordinates() {