Skip to content

Commit 6430790

Browse files
committed
Adopt immutables test to newly introduced converter infrastructure.
See #669
1 parent 20b779e commit 6430790

File tree

1 file changed

+10
-47
lines changed
  • jdbc/immutables/src/main/java/example/springdata/jdbc/immutables

1 file changed

+10
-47
lines changed

jdbc/immutables/src/main/java/example/springdata/jdbc/immutables/Application.java

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,21 @@
1515
*/
1616
package example.springdata.jdbc.immutables;
1717

18-
import java.sql.ResultSet;
19-
2018
import org.springframework.boot.autoconfigure.SpringBootApplication;
2119
import org.springframework.context.annotation.Configuration;
2220
import org.springframework.context.annotation.Lazy;
2321
import org.springframework.core.io.ResourceLoader;
24-
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
2522
import org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory;
26-
import org.springframework.data.jdbc.core.convert.Identifier;
2723
import org.springframework.data.jdbc.core.convert.JdbcConverter;
2824
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
25+
import org.springframework.data.jdbc.core.convert.MappingJdbcConverter;
2926
import org.springframework.data.jdbc.core.convert.RelationResolver;
3027
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
3128
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
32-
import org.springframework.data.mapping.PersistentPropertyPath;
33-
import org.springframework.data.mapping.context.MappingContext;
29+
import org.springframework.data.relational.core.conversion.RowDocumentAccessor;
3430
import org.springframework.data.relational.core.dialect.Dialect;
35-
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
3631
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
37-
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
32+
import org.springframework.data.util.TypeInformation;
3833
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
3934
import org.springframework.util.ClassUtils;
4035

@@ -78,27 +73,17 @@ public JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, NamedParam
7873

7974
var jdbcTypeFactory = new DefaultJdbcTypeFactory(operations.getJdbcOperations());
8075

81-
return new BasicJdbcConverter(mappingContext, relationResolver, conversions, jdbcTypeFactory,
82-
dialect.getIdentifierProcessing()) {
83-
84-
@Override
85-
public <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) {
86-
87-
// rows will not be mapped to the entity interface, but to its implementation generated by Immutable
88-
RelationalPersistentEntity<T> implementationEntity = getImplementationEntity(mappingContext, entity);
89-
return super.mapRow(implementationEntity, resultSet, key);
90-
}
76+
return new MappingJdbcConverter(mappingContext, relationResolver, conversions, jdbcTypeFactory) {
9177

9278
@Override
93-
public <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier,
94-
Object key) {
79+
@SuppressWarnings("all")
80+
protected <S> S readAggregate(ConversionContext context, RowDocumentAccessor documentAccessor,
81+
TypeInformation<? extends S> typeHint) {
9582

96-
// rows will not be mapped to the entity interface, but to its implementation generated by Immutable
9783
RelationalPersistentEntity<?> implementationEntity = getImplementationEntity(mappingContext,
98-
path.getLeafEntity());
99-
var propertyPath = new DelegatePersistentPropertyPathExtension(mappingContext,
100-
path.getRequiredPersistentPropertyPath(), implementationEntity);
101-
return super.mapRow(propertyPath, resultSet, identifier, key);
84+
mappingContext.getRequiredPersistentEntity(typeHint));
85+
86+
return (S) super.readAggregate(context, documentAccessor, implementationEntity.getTypeInformation());
10287
}
10388
};
10489
}
@@ -126,26 +111,4 @@ private <T> RelationalPersistentEntity<T> getImplementationEntity(JdbcMappingCon
126111
}
127112
}
128113

129-
/**
130-
* Redirect {@link #getLeafEntity()} to a different entity type.
131-
*/
132-
static class DelegatePersistentPropertyPathExtension extends PersistentPropertyPathExtension {
133-
134-
private final RelationalPersistentEntity<?> leafEntity;
135-
136-
public DelegatePersistentPropertyPathExtension(
137-
MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context,
138-
PersistentPropertyPath<? extends RelationalPersistentProperty> path, RelationalPersistentEntity<?> leafEntity) {
139-
140-
super(context, path);
141-
142-
this.leafEntity = leafEntity;
143-
}
144-
145-
@Override
146-
public RelationalPersistentEntity<?> getLeafEntity() {
147-
return leafEntity;
148-
}
149-
}
150-
151114
}

0 commit comments

Comments
 (0)