Adopt immutables test to newly introduced converter infrastructure.
See #669
This commit is contained in:
@@ -15,26 +15,21 @@
|
||||
*/
|
||||
package example.springdata.jdbc.immutables;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
|
||||
import org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory;
|
||||
import org.springframework.data.jdbc.core.convert.Identifier;
|
||||
import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
||||
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
|
||||
import org.springframework.data.jdbc.core.convert.MappingJdbcConverter;
|
||||
import org.springframework.data.jdbc.core.convert.RelationResolver;
|
||||
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
|
||||
import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.relational.core.conversion.RowDocumentAccessor;
|
||||
import org.springframework.data.relational.core.dialect.Dialect;
|
||||
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -78,27 +73,17 @@ class Application {
|
||||
|
||||
var jdbcTypeFactory = new DefaultJdbcTypeFactory(operations.getJdbcOperations());
|
||||
|
||||
return new BasicJdbcConverter(mappingContext, relationResolver, conversions, jdbcTypeFactory,
|
||||
dialect.getIdentifierProcessing()) {
|
||||
return new MappingJdbcConverter(mappingContext, relationResolver, conversions, jdbcTypeFactory) {
|
||||
|
||||
@Override
|
||||
public <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) {
|
||||
@SuppressWarnings("all")
|
||||
protected <S> S readAggregate(ConversionContext context, RowDocumentAccessor documentAccessor,
|
||||
TypeInformation<? extends S> typeHint) {
|
||||
|
||||
// rows will not be mapped to the entity interface, but to its implementation generated by Immutable
|
||||
RelationalPersistentEntity<T> implementationEntity = getImplementationEntity(mappingContext, entity);
|
||||
return super.mapRow(implementationEntity, resultSet, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier,
|
||||
Object key) {
|
||||
|
||||
// rows will not be mapped to the entity interface, but to its implementation generated by Immutable
|
||||
RelationalPersistentEntity<?> implementationEntity = getImplementationEntity(mappingContext,
|
||||
path.getLeafEntity());
|
||||
var propertyPath = new DelegatePersistentPropertyPathExtension(mappingContext,
|
||||
path.getRequiredPersistentPropertyPath(), implementationEntity);
|
||||
return super.mapRow(propertyPath, resultSet, identifier, key);
|
||||
mappingContext.getRequiredPersistentEntity(typeHint));
|
||||
|
||||
return (S) super.readAggregate(context, documentAccessor, implementationEntity.getTypeInformation());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -126,26 +111,4 @@ class Application {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect {@link #getLeafEntity()} to a different entity type.
|
||||
*/
|
||||
static class DelegatePersistentPropertyPathExtension extends PersistentPropertyPathExtension {
|
||||
|
||||
private final RelationalPersistentEntity<?> leafEntity;
|
||||
|
||||
public DelegatePersistentPropertyPathExtension(
|
||||
MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context,
|
||||
PersistentPropertyPath<? extends RelationalPersistentProperty> path, RelationalPersistentEntity<?> leafEntity) {
|
||||
|
||||
super(context, path);
|
||||
|
||||
this.leafEntity = leafEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RelationalPersistentEntity<?> getLeafEntity() {
|
||||
return leafEntity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user