Skip to content

Commit 853b3fb

Browse files
odrotbohmmp911de
authored andcommitted
#2 - Adapt code to API changes.
1 parent bea9501 commit 853b3fb

16 files changed

+102
-101
lines changed

src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import org.springframework.data.convert.EntityInstantiators;
2828
import org.springframework.data.domain.Sort;
2929
import org.springframework.data.domain.Sort.Order;
30-
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
31-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
32-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
3330
import org.springframework.data.mapping.PersistentPropertyAccessor;
3431
import org.springframework.data.r2dbc.function.convert.EntityRowMapper;
32+
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
33+
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
34+
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3535
import org.springframework.data.util.Pair;
3636
import org.springframework.data.util.StreamUtils;
3737
import org.springframework.util.ClassUtils;
@@ -41,29 +41,29 @@
4141
*/
4242
public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStrategy {
4343

44-
private final JdbcMappingContext mappingContext;
44+
private final RelationalMappingContext mappingContext;
4545
private final EntityInstantiators instantiators;
4646

4747
public DefaultReactiveDataAccessStrategy() {
48-
this(new JdbcMappingContext(), new EntityInstantiators());
48+
this(new RelationalMappingContext(), new EntityInstantiators());
4949
}
5050

51-
public DefaultReactiveDataAccessStrategy(JdbcMappingContext mappingContext, EntityInstantiators instantiators) {
51+
public DefaultReactiveDataAccessStrategy(RelationalMappingContext mappingContext, EntityInstantiators instantiators) {
5252
this.mappingContext = mappingContext;
5353
this.instantiators = instantiators;
5454
}
5555

5656
@Override
5757
public List<String> getAllFields(Class<?> typeToRead) {
5858

59-
JdbcPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(typeToRead);
59+
RelationalPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(typeToRead);
6060

6161
if (persistentEntity == null) {
6262
return Collections.singletonList("*");
6363
}
6464

6565
return StreamUtils.createStreamFromIterator(persistentEntity.iterator()) //
66-
.map(JdbcPersistentProperty::getColumnName) //
66+
.map(RelationalPersistentProperty::getColumnName) //
6767
.collect(Collectors.toList());
6868
}
6969

@@ -72,12 +72,12 @@ public List<Pair<String, Object>> getInsert(Object object) {
7272

7373
Class<?> userClass = ClassUtils.getUserClass(object);
7474

75-
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
75+
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
7676
PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(object);
7777

7878
List<Pair<String, Object>> values = new ArrayList<>();
7979

80-
for (JdbcPersistentProperty property : entity) {
80+
for (RelationalPersistentProperty property : entity) {
8181

8282
Object value = propertyAccessor.getProperty(property);
8383

@@ -94,7 +94,7 @@ public List<Pair<String, Object>> getInsert(Object object) {
9494
@Override
9595
public Sort getMappedSort(Class<?> typeToRead, Sort sort) {
9696

97-
JdbcPersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToRead);
97+
RelationalPersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToRead);
9898
if (entity == null) {
9999
return sort;
100100
}
@@ -103,7 +103,7 @@ public Sort getMappedSort(Class<?> typeToRead, Sort sort) {
103103

104104
for (Order order : sort) {
105105

106-
JdbcPersistentProperty persistentProperty = entity.getPersistentProperty(order.getProperty());
106+
RelationalPersistentProperty persistentProperty = entity.getPersistentProperty(order.getProperty());
107107
if (persistentProperty == null) {
108108
mappedOrder.add(order);
109109
} else {
@@ -117,7 +117,7 @@ public Sort getMappedSort(Class<?> typeToRead, Sort sort) {
117117

118118
@Override
119119
public <T> BiFunction<Row, RowMetadata, T> getRowMapper(Class<T> typeToRead) {
120-
return new EntityRowMapper<T>((JdbcPersistentEntity) mappingContext.getRequiredPersistentEntity(typeToRead),
120+
return new EntityRowMapper<T>((RelationalPersistentEntity) mappingContext.getRequiredPersistentEntity(typeToRead),
121121
instantiators, mappingContext);
122122
}
123123

src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525

2626
import org.springframework.core.convert.ConversionService;
2727
import org.springframework.data.convert.EntityInstantiators;
28-
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
29-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
30-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
3128
import org.springframework.data.mapping.MappingException;
3229
import org.springframework.data.mapping.PersistentProperty;
3330
import org.springframework.data.mapping.PersistentPropertyAccessor;
3431
import org.springframework.data.mapping.PreferredConstructor.Parameter;
3532
import org.springframework.data.mapping.context.MappingContext;
3633
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
3734
import org.springframework.data.mapping.model.ParameterValueProvider;
35+
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
36+
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
37+
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3838
import org.springframework.util.ClassUtils;
3939

4040
/**
@@ -45,13 +45,13 @@
4545
*/
4646
public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
4747

48-
private final JdbcPersistentEntity<T> entity;
48+
private final RelationalPersistentEntity<T> entity;
4949
private final EntityInstantiators entityInstantiators;
5050
private final ConversionService conversions;
51-
private final MappingContext<JdbcPersistentEntity<?>, JdbcPersistentProperty> context;
51+
private final MappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> context;
5252

53-
public EntityRowMapper(JdbcPersistentEntity<T> entity, EntityInstantiators entityInstantiators,
54-
JdbcMappingContext context) {
53+
public EntityRowMapper(RelationalPersistentEntity<T> entity, EntityInstantiators entityInstantiators,
54+
RelationalMappingContext context) {
5555

5656
this.entity = entity;
5757
this.entityInstantiators = entityInstantiators;
@@ -67,7 +67,7 @@ public T apply(Row row, RowMetadata metadata) {
6767
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(entity.getPropertyAccessor(result),
6868
conversions);
6969

70-
for (JdbcPersistentProperty property : entity) {
70+
for (RelationalPersistentProperty property : entity) {
7171

7272
if (entity.isConstructorArgument(property)) {
7373
continue;
@@ -90,11 +90,12 @@ public T apply(Row row, RowMetadata metadata) {
9090
* Read a single value or a complete Entity from the {@link ResultSet} passed as an argument.
9191
*
9292
* @param row the {@link Row} to extract the value from. Must not be {@literal null}.
93-
* @param property the {@link JdbcPersistentProperty} for which the value is intended. Must not be {@literal null}.
93+
* @param property the {@link RelationalPersistentProperty} for which the value is intended. Must not be
94+
* {@literal null}.
9495
* @param prefix to be used for all column names accessed by this method. Must not be {@literal null}.
9596
* @return the value read from the {@link ResultSet}. May be {@literal null}.
9697
*/
97-
private Object readFrom(Row row, JdbcPersistentProperty property, String prefix) {
98+
private Object readFrom(Row row, RelationalPersistentProperty property, String prefix) {
9899

99100
try {
100101

@@ -109,7 +110,7 @@ private Object readFrom(Row row, JdbcPersistentProperty property, String prefix)
109110
}
110111
}
111112

112-
private static Class<?> getType(JdbcPersistentProperty property) {
113+
private static Class<?> getType(RelationalPersistentProperty property) {
113114
return ClassUtils.resolvePrimitiveIfNecessary(property.getActualType());
114115
}
115116

@@ -118,7 +119,7 @@ private <S> S readEntityFrom(Row row, PersistentProperty<?> property) {
118119
String prefix = property.getName() + "_";
119120

120121
@SuppressWarnings("unchecked")
121-
JdbcPersistentEntity<S> entity = (JdbcPersistentEntity<S>) context
122+
RelationalPersistentEntity<S> entity = (RelationalPersistentEntity<S>) context
122123
.getRequiredPersistentEntity(property.getActualType());
123124

124125
if (readFrom(row, entity.getRequiredIdProperty(), prefix) == null) {
@@ -130,7 +131,7 @@ private <S> S readEntityFrom(Row row, PersistentProperty<?> property) {
130131
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(instance);
131132
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(accessor, conversions);
132133

133-
for (JdbcPersistentProperty p : entity) {
134+
for (RelationalPersistentProperty p : entity) {
134135
if (!entity.isConstructorArgument(property)) {
135136
propertyAccessor.setProperty(p, readFrom(row, p, prefix));
136137
}
@@ -139,17 +140,17 @@ private <S> S readEntityFrom(Row row, PersistentProperty<?> property) {
139140
return instance;
140141
}
141142

142-
private <S> S createInstance(Row row, String prefix, JdbcPersistentEntity<S> entity) {
143+
private <S> S createInstance(Row row, String prefix, RelationalPersistentEntity<S> entity) {
143144

144145
return entityInstantiators.getInstantiatorFor(entity).createInstance(entity,
145146
new RowParameterValueProvider(row, entity, conversions, prefix));
146147
}
147148

148149
@RequiredArgsConstructor
149-
private static class RowParameterValueProvider implements ParameterValueProvider<JdbcPersistentProperty> {
150+
private static class RowParameterValueProvider implements ParameterValueProvider<RelationalPersistentProperty> {
150151

151152
private final @NonNull Row resultSet;
152-
private final @NonNull JdbcPersistentEntity<?> entity;
153+
private final @NonNull RelationalPersistentEntity<?> entity;
153154
private final @NonNull ConversionService conversionService;
154155
private final @NonNull String prefix;
155156

@@ -158,7 +159,7 @@ private static class RowParameterValueProvider implements ParameterValueProvider
158159
* @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter)
159160
*/
160161
@Override
161-
public <T> T getParameterValue(Parameter<T, JdbcPersistentProperty> parameter) {
162+
public <T> T getParameterValue(Parameter<T, RelationalPersistentProperty> parameter) {
162163

163164
String column = prefix + entity.getRequiredPersistentProperty(parameter.getName()).getColumnName();
164165

src/main/java/org/springframework/data/r2dbc/function/convert/MappingR2dbcConverter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import java.util.Optional;
2424
import java.util.function.BiFunction;
2525

26-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
27-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
2826
import org.springframework.data.mapping.PersistentPropertyAccessor;
2927
import org.springframework.data.mapping.context.MappingContext;
28+
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
29+
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3030
import org.springframework.util.Assert;
3131
import org.springframework.util.ClassUtils;
3232

@@ -37,10 +37,10 @@
3737
*/
3838
public class MappingR2dbcConverter {
3939

40-
private final MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
40+
private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
4141

4242
public MappingR2dbcConverter(
43-
MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext) {
43+
MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext) {
4444
this.mappingContext = mappingContext;
4545
}
4646

@@ -56,13 +56,13 @@ public Map<String, Optional<Object>> getFieldsToUpdate(Object object) {
5656
Assert.notNull(object, "Entity object must not be null!");
5757

5858
Class<?> userClass = ClassUtils.getUserClass(object);
59-
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
59+
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
6060

6161
Map<String, Optional<Object>> update = new LinkedHashMap<>();
6262

6363
PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(object);
6464

65-
for (JdbcPersistentProperty property : entity) {
65+
for (RelationalPersistentProperty property : entity) {
6666
update.put(property.getColumnName(), Optional.ofNullable(propertyAccessor.getProperty(property)));
6767
}
6868

@@ -82,12 +82,12 @@ public <T> BiFunction<Row, RowMetadata, T> populateIdIfNecessary(T object) {
8282
Assert.notNull(object, "Entity object must not be null!");
8383

8484
Class<?> userClass = ClassUtils.getUserClass(object);
85-
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
85+
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
8686

8787
return (row, metadata) -> {
8888

8989
PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(object);
90-
JdbcPersistentProperty idProperty = entity.getRequiredIdProperty();
90+
RelationalPersistentProperty idProperty = entity.getRequiredIdProperty();
9191

9292
if (propertyAccessor.getProperty(idProperty) == null) {
9393

@@ -99,7 +99,7 @@ public <T> BiFunction<Row, RowMetadata, T> populateIdIfNecessary(T object) {
9999
};
100100
}
101101

102-
public MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> getMappingContext() {
102+
public MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> getMappingContext() {
103103
return mappingContext;
104104
}
105105
}

src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryExecution.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import org.springframework.core.convert.converter.Converter;
2222
import org.springframework.data.convert.EntityInstantiators;
23-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
24-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
2523
import org.springframework.data.mapping.context.MappingContext;
2624
import org.springframework.data.r2dbc.function.FetchSpec;
25+
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
26+
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
2727
import org.springframework.data.relational.repository.query.DtoInstantiatingConverter;
2828
import org.springframework.data.repository.query.ResultProcessor;
2929
import org.springframework.data.repository.query.ReturnedType;
@@ -64,7 +64,7 @@ public Object execute(FetchSpec<?> query, Class<?> type, String tableName) {
6464
final class ResultProcessingConverter implements Converter<Object, Object> {
6565

6666
private final @NonNull ResultProcessor processor;
67-
private final @NonNull MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
67+
private final @NonNull MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
6868
private final @NonNull EntityInstantiators instantiators;
6969

7070
/* (non-Javadoc)

src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethod.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import org.springframework.data.domain.Pageable;
2727
import org.springframework.data.domain.Slice;
2828
import org.springframework.data.domain.Sort;
29-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
30-
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
3129
import org.springframework.data.jdbc.repository.query.Query;
3230
import org.springframework.data.mapping.context.MappingContext;
3331
import org.springframework.data.projection.ProjectionFactory;
32+
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
33+
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3434
import org.springframework.data.relational.repository.query.RelationalEntityMetadata;
3535
import org.springframework.data.relational.repository.query.RelationalParameters;
3636
import org.springframework.data.relational.repository.query.SimpleRelationalEntityMetadata;
@@ -56,7 +56,7 @@ public class R2dbcQueryMethod extends QueryMethod {
5656
private static final ClassTypeInformation<Slice> SLICE_TYPE = ClassTypeInformation.from(Slice.class);
5757

5858
private final Method method;
59-
private final MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
59+
private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
6060
private final Optional<Query> query;
6161

6262
private @Nullable RelationalEntityMetadata<?> metadata;
@@ -70,7 +70,7 @@ public class R2dbcQueryMethod extends QueryMethod {
7070
* @param mappingContext must not be {@literal null}.
7171
*/
7272
public R2dbcQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory projectionFactory,
73-
MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext) {
73+
MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext) {
7474

7575
super(method, metadata, projectionFactory);
7676

@@ -162,11 +162,11 @@ public RelationalEntityMetadata<?> getEntityInformation() {
162162

163163
} else {
164164

165-
JdbcPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
166-
JdbcPersistentEntity<?> managedEntity = mappingContext.getRequiredPersistentEntity(domainClass);
165+
RelationalPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
166+
RelationalPersistentEntity<?> managedEntity = mappingContext.getRequiredPersistentEntity(domainClass);
167167
returnedEntity = returnedEntity == null || returnedEntity.getType().isInterface() ? managedEntity
168168
: returnedEntity;
169-
JdbcPersistentEntity<?> tableEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity
169+
RelationalPersistentEntity<?> tableEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity
170170
: managedEntity;
171171

172172
this.metadata = new SimpleRelationalEntityMetadata<>((Class<Object>) returnedEntity.getType(), tableEntity);

0 commit comments

Comments
 (0)