Browse Source

#2 - Adapt code to API changes.

pull/1188/head
Oliver Gierke 8 years ago committed by Mark Paluch
parent
commit
853b3fb449
  1. 26
      src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java
  2. 35
      src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java
  3. 18
      src/main/java/org/springframework/data/r2dbc/function/convert/MappingR2dbcConverter.java
  4. 6
      src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryExecution.java
  5. 14
      src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethod.java
  6. 12
      src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactory.java
  7. 6
      src/main/java/org/springframework/data/relational/repository/query/DtoInstantiatingConverter.java
  8. 6
      src/main/java/org/springframework/data/relational/repository/query/RelationalEntityMetadata.java
  9. 12
      src/main/java/org/springframework/data/relational/repository/query/SimpleRelationalEntityMetadata.java
  10. 28
      src/main/java/org/springframework/data/relational/repository/support/MappingRelationalEntityInformation.java
  11. 2
      src/test/java/org/springframework/data/r2dbc/function/DatabaseClientIntegrationTests.java
  12. 6
      src/test/java/org/springframework/data/r2dbc/repository/R2dbcRepositoryIntegrationTests.java
  13. 6
      src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java
  14. 7
      src/test/java/org/springframework/data/r2dbc/repository/query/StringBasedR2dbcQueryUnitTests.java
  15. 6
      src/test/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryUnitTests.java
  16. 13
      src/test/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepositoryIntegrationTests.java

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

@ -27,11 +27,11 @@ import java.util.stream.Collectors; @@ -27,11 +27,11 @@ import java.util.stream.Collectors;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.r2dbc.function.convert.EntityRowMapper;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.util.Pair;
import org.springframework.data.util.StreamUtils;
import org.springframework.util.ClassUtils;
@ -41,14 +41,14 @@ import org.springframework.util.ClassUtils; @@ -41,14 +41,14 @@ import org.springframework.util.ClassUtils;
*/
public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStrategy {
private final JdbcMappingContext mappingContext;
private final RelationalMappingContext mappingContext;
private final EntityInstantiators instantiators;
public DefaultReactiveDataAccessStrategy() {
this(new JdbcMappingContext(), new EntityInstantiators());
this(new RelationalMappingContext(), new EntityInstantiators());
}
public DefaultReactiveDataAccessStrategy(JdbcMappingContext mappingContext, EntityInstantiators instantiators) {
public DefaultReactiveDataAccessStrategy(RelationalMappingContext mappingContext, EntityInstantiators instantiators) {
this.mappingContext = mappingContext;
this.instantiators = instantiators;
}
@ -56,14 +56,14 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra @@ -56,14 +56,14 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
@Override
public List<String> getAllFields(Class<?> typeToRead) {
JdbcPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(typeToRead);
RelationalPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(typeToRead);
if (persistentEntity == null) {
return Collections.singletonList("*");
}
return StreamUtils.createStreamFromIterator(persistentEntity.iterator()) //
.map(JdbcPersistentProperty::getColumnName) //
.map(RelationalPersistentProperty::getColumnName) //
.collect(Collectors.toList());
}
@ -72,12 +72,12 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra @@ -72,12 +72,12 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
Class<?> userClass = ClassUtils.getUserClass(object);
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(object);
List<Pair<String, Object>> values = new ArrayList<>();
for (JdbcPersistentProperty property : entity) {
for (RelationalPersistentProperty property : entity) {
Object value = propertyAccessor.getProperty(property);
@ -94,7 +94,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra @@ -94,7 +94,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
@Override
public Sort getMappedSort(Class<?> typeToRead, Sort sort) {
JdbcPersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToRead);
RelationalPersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToRead);
if (entity == null) {
return sort;
}
@ -103,7 +103,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra @@ -103,7 +103,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
for (Order order : sort) {
JdbcPersistentProperty persistentProperty = entity.getPersistentProperty(order.getProperty());
RelationalPersistentProperty persistentProperty = entity.getPersistentProperty(order.getProperty());
if (persistentProperty == null) {
mappedOrder.add(order);
} else {
@ -117,7 +117,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra @@ -117,7 +117,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
@Override
public <T> BiFunction<Row, RowMetadata, T> getRowMapper(Class<T> typeToRead) {
return new EntityRowMapper<T>((JdbcPersistentEntity) mappingContext.getRequiredPersistentEntity(typeToRead),
return new EntityRowMapper<T>((RelationalPersistentEntity) mappingContext.getRequiredPersistentEntity(typeToRead),
instantiators, mappingContext);
}

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

@ -25,9 +25,6 @@ import java.util.function.BiFunction; @@ -25,9 +25,6 @@ import java.util.function.BiFunction;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
@ -35,6 +32,9 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter; @@ -35,6 +32,9 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.util.ClassUtils;
/**
@ -45,13 +45,13 @@ import org.springframework.util.ClassUtils; @@ -45,13 +45,13 @@ import org.springframework.util.ClassUtils;
*/
public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
private final JdbcPersistentEntity<T> entity;
private final RelationalPersistentEntity<T> entity;
private final EntityInstantiators entityInstantiators;
private final ConversionService conversions;
private final MappingContext<JdbcPersistentEntity<?>, JdbcPersistentProperty> context;
private final MappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> context;
public EntityRowMapper(JdbcPersistentEntity<T> entity, EntityInstantiators entityInstantiators,
JdbcMappingContext context) {
public EntityRowMapper(RelationalPersistentEntity<T> entity, EntityInstantiators entityInstantiators,
RelationalMappingContext context) {
this.entity = entity;
this.entityInstantiators = entityInstantiators;
@ -67,7 +67,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -67,7 +67,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(entity.getPropertyAccessor(result),
conversions);
for (JdbcPersistentProperty property : entity) {
for (RelationalPersistentProperty property : entity) {
if (entity.isConstructorArgument(property)) {
continue;
@ -90,11 +90,12 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -90,11 +90,12 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
* Read a single value or a complete Entity from the {@link ResultSet} passed as an argument.
*
* @param row the {@link Row} to extract the value from. Must not be {@literal null}.
* @param property the {@link JdbcPersistentProperty} for which the value is intended. Must not be {@literal null}.
* @param property the {@link RelationalPersistentProperty} for which the value is intended. Must not be
* {@literal null}.
* @param prefix to be used for all column names accessed by this method. Must not be {@literal null}.
* @return the value read from the {@link ResultSet}. May be {@literal null}.
*/
private Object readFrom(Row row, JdbcPersistentProperty property, String prefix) {
private Object readFrom(Row row, RelationalPersistentProperty property, String prefix) {
try {
@ -109,7 +110,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -109,7 +110,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
}
}
private static Class<?> getType(JdbcPersistentProperty property) {
private static Class<?> getType(RelationalPersistentProperty property) {
return ClassUtils.resolvePrimitiveIfNecessary(property.getActualType());
}
@ -118,7 +119,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -118,7 +119,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
String prefix = property.getName() + "_";
@SuppressWarnings("unchecked")
JdbcPersistentEntity<S> entity = (JdbcPersistentEntity<S>) context
RelationalPersistentEntity<S> entity = (RelationalPersistentEntity<S>) context
.getRequiredPersistentEntity(property.getActualType());
if (readFrom(row, entity.getRequiredIdProperty(), prefix) == null) {
@ -130,7 +131,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -130,7 +131,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(instance);
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(accessor, conversions);
for (JdbcPersistentProperty p : entity) {
for (RelationalPersistentProperty p : entity) {
if (!entity.isConstructorArgument(property)) {
propertyAccessor.setProperty(p, readFrom(row, p, prefix));
}
@ -139,17 +140,17 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -139,17 +140,17 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
return instance;
}
private <S> S createInstance(Row row, String prefix, JdbcPersistentEntity<S> entity) {
private <S> S createInstance(Row row, String prefix, RelationalPersistentEntity<S> entity) {
return entityInstantiators.getInstantiatorFor(entity).createInstance(entity,
new RowParameterValueProvider(row, entity, conversions, prefix));
}
@RequiredArgsConstructor
private static class RowParameterValueProvider implements ParameterValueProvider<JdbcPersistentProperty> {
private static class RowParameterValueProvider implements ParameterValueProvider<RelationalPersistentProperty> {
private final @NonNull Row resultSet;
private final @NonNull JdbcPersistentEntity<?> entity;
private final @NonNull RelationalPersistentEntity<?> entity;
private final @NonNull ConversionService conversionService;
private final @NonNull String prefix;
@ -158,7 +159,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> { @@ -158,7 +159,7 @@ public class EntityRowMapper<T> implements BiFunction<Row, RowMetadata, T> {
* @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter)
*/
@Override
public <T> T getParameterValue(Parameter<T, JdbcPersistentProperty> parameter) {
public <T> T getParameterValue(Parameter<T, RelationalPersistentProperty> parameter) {
String column = prefix + entity.getRequiredPersistentProperty(parameter.getName()).getColumnName();

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

@ -23,10 +23,10 @@ import java.util.Map; @@ -23,10 +23,10 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@ -37,10 +37,10 @@ import org.springframework.util.ClassUtils; @@ -37,10 +37,10 @@ import org.springframework.util.ClassUtils;
*/
public class MappingR2dbcConverter {
private final MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
public MappingR2dbcConverter(
MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext) {
MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext) {
this.mappingContext = mappingContext;
}
@ -56,13 +56,13 @@ public class MappingR2dbcConverter { @@ -56,13 +56,13 @@ public class MappingR2dbcConverter {
Assert.notNull(object, "Entity object must not be null!");
Class<?> userClass = ClassUtils.getUserClass(object);
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
Map<String, Optional<Object>> update = new LinkedHashMap<>();
PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(object);
for (JdbcPersistentProperty property : entity) {
for (RelationalPersistentProperty property : entity) {
update.put(property.getColumnName(), Optional.ofNullable(propertyAccessor.getProperty(property)));
}
@ -82,12 +82,12 @@ public class MappingR2dbcConverter { @@ -82,12 +82,12 @@ public class MappingR2dbcConverter {
Assert.notNull(object, "Entity object must not be null!");
Class<?> userClass = ClassUtils.getUserClass(object);
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(userClass);
return (row, metadata) -> {
PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(object);
JdbcPersistentProperty idProperty = entity.getRequiredIdProperty();
RelationalPersistentProperty idProperty = entity.getRequiredIdProperty();
if (propertyAccessor.getProperty(idProperty) == null) {
@ -99,7 +99,7 @@ public class MappingR2dbcConverter { @@ -99,7 +99,7 @@ public class MappingR2dbcConverter {
};
}
public MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> getMappingContext() {
public MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> getMappingContext() {
return mappingContext;
}
}

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

@ -20,10 +20,10 @@ import lombok.RequiredArgsConstructor; @@ -20,10 +20,10 @@ import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.r2dbc.function.FetchSpec;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.repository.query.DtoInstantiatingConverter;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ReturnedType;
@ -64,7 +64,7 @@ interface R2dbcQueryExecution { @@ -64,7 +64,7 @@ interface R2dbcQueryExecution {
final class ResultProcessingConverter implements Converter<Object, Object> {
private final @NonNull ResultProcessor processor;
private final @NonNull MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
private final @NonNull MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
private final @NonNull EntityInstantiators instantiators;
/* (non-Javadoc)

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

@ -26,11 +26,11 @@ import org.springframework.data.domain.Page; @@ -26,11 +26,11 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.repository.query.RelationalEntityMetadata;
import org.springframework.data.relational.repository.query.RelationalParameters;
import org.springframework.data.relational.repository.query.SimpleRelationalEntityMetadata;
@ -56,7 +56,7 @@ public class R2dbcQueryMethod extends QueryMethod { @@ -56,7 +56,7 @@ public class R2dbcQueryMethod extends QueryMethod {
private static final ClassTypeInformation<Slice> SLICE_TYPE = ClassTypeInformation.from(Slice.class);
private final Method method;
private final MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
private final Optional<Query> query;
private @Nullable RelationalEntityMetadata<?> metadata;
@ -70,7 +70,7 @@ public class R2dbcQueryMethod extends QueryMethod { @@ -70,7 +70,7 @@ public class R2dbcQueryMethod extends QueryMethod {
* @param mappingContext must not be {@literal null}.
*/
public R2dbcQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory projectionFactory,
MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext) {
MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext) {
super(method, metadata, projectionFactory);
@ -162,11 +162,11 @@ public class R2dbcQueryMethod extends QueryMethod { @@ -162,11 +162,11 @@ public class R2dbcQueryMethod extends QueryMethod {
} else {
JdbcPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
JdbcPersistentEntity<?> managedEntity = mappingContext.getRequiredPersistentEntity(domainClass);
RelationalPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
RelationalPersistentEntity<?> managedEntity = mappingContext.getRequiredPersistentEntity(domainClass);
returnedEntity = returnedEntity == null || returnedEntity.getType().isInterface() ? managedEntity
: returnedEntity;
JdbcPersistentEntity<?> tableEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity
RelationalPersistentEntity<?> tableEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity
: managedEntity;
this.metadata = new SimpleRelationalEntityMetadata<>((Class<Object>) returnedEntity.getType(), tableEntity);

12
src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactory.java

@ -21,8 +21,6 @@ import lombok.RequiredArgsConstructor; @@ -21,8 +21,6 @@ import lombok.RequiredArgsConstructor;
import java.lang.reflect.Method;
import java.util.Optional;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.r2dbc.function.DatabaseClient;
@ -30,6 +28,8 @@ import org.springframework.data.r2dbc.function.convert.MappingR2dbcConverter; @@ -30,6 +28,8 @@ import org.springframework.data.r2dbc.function.convert.MappingR2dbcConverter;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.data.r2dbc.repository.query.R2dbcQueryMethod;
import org.springframework.data.r2dbc.repository.query.StringBasedR2dbcQuery;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
import org.springframework.data.repository.core.NamedQueries;
@ -54,7 +54,7 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport { @@ -54,7 +54,7 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
private final DatabaseClient databaseClient;
private final MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext;
private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
private final MappingR2dbcConverter converter;
/**
@ -64,7 +64,7 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport { @@ -64,7 +64,7 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
* @param mappingContext must not be {@literal null}.
*/
public R2dbcRepositoryFactory(DatabaseClient databaseClient,
MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> mappingContext) {
MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext) {
Assert.notNull(databaseClient, "DatabaseClient must not be null!");
Assert.notNull(mappingContext, "MappingContext must not be null!");
@ -118,9 +118,9 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport { @@ -118,9 +118,9 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
private <T, ID> RelationalEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
@Nullable RepositoryInformation information) {
JdbcPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
return new MappingRelationalEntityInformation<>((JdbcPersistentEntity<T>) entity);
return new MappingRelationalEntityInformation<>((RelationalPersistentEntity<T>) entity);
}
/**

6
src/main/java/org/springframework/data/relational/repository/query/DtoInstantiatingConverter.java

@ -18,8 +18,6 @@ package org.springframework.data.relational.repository.query; @@ -18,8 +18,6 @@ package org.springframework.data.relational.repository.query;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.EntityInstantiator;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentProperty;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
@ -28,6 +26,8 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter; @@ -28,6 +26,8 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.util.Assert;
/**
@ -49,7 +49,7 @@ public class DtoInstantiatingConverter implements Converter<Object, Object> { @@ -49,7 +49,7 @@ public class DtoInstantiatingConverter implements Converter<Object, Object> {
* @param instantiators must not be {@literal null}.
*/
public DtoInstantiatingConverter(Class<?> dtoType,
MappingContext<? extends JdbcPersistentEntity<?>, JdbcPersistentProperty> context,
MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> context,
EntityInstantiators instantiator) {
Assert.notNull(dtoType, "DTO type must not be null!");

6
src/main/java/org/springframework/data/relational/repository/query/RelationalEntityMetadata.java

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
*/
package org.springframework.data.relational.repository.query;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.repository.core.EntityMetadata;
/**
@ -33,9 +33,9 @@ public interface RelationalEntityMetadata<T> extends EntityMetadata<T> { @@ -33,9 +33,9 @@ public interface RelationalEntityMetadata<T> extends EntityMetadata<T> {
String getTableName();
/**
* Returns the {@link JdbcPersistentEntity} that supposed to determine the table to be queried.
* Returns the {@link RelationalPersistentEntity} that supposed to determine the table to be queried.
*
* @return
*/
JdbcPersistentEntity<?> getTableEntity();
RelationalPersistentEntity<?> getTableEntity();
}

12
src/main/java/org/springframework/data/relational/repository/query/SimpleRelationalEntityMetadata.java

@ -17,7 +17,7 @@ package org.springframework.data.relational.repository.query; @@ -17,7 +17,7 @@ package org.springframework.data.relational.repository.query;
import lombok.Getter;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.util.Assert;
/**
@ -28,16 +28,16 @@ import org.springframework.util.Assert; @@ -28,16 +28,16 @@ import org.springframework.util.Assert;
public class SimpleRelationalEntityMetadata<T> implements RelationalEntityMetadata<T> {
private final Class<T> type;
private final @Getter JdbcPersistentEntity<?> tableEntity;
private final @Getter RelationalPersistentEntity<?> tableEntity;
/**
* Creates a new {@link SimpleRelationalEntityMetadata} using the given type and {@link JdbcPersistentEntity} to use
* for table lookups.
* Creates a new {@link SimpleRelationalEntityMetadata} using the given type and {@link RelationalPersistentEntity} to
* use for table lookups.
*
* @param type must not be {@literal null}.
* @param tableEntity must not be {@literal null}.
*/
public SimpleRelationalEntityMetadata(Class<T> type, JdbcPersistentEntity<?> tableEntity) {
public SimpleRelationalEntityMetadata(Class<T> type, RelationalPersistentEntity<?> tableEntity) {
Assert.notNull(type, "Type must not be null!");
Assert.notNull(tableEntity, "Table entity must not be null!");
@ -54,7 +54,7 @@ public class SimpleRelationalEntityMetadata<T> implements RelationalEntityMetada @@ -54,7 +54,7 @@ public class SimpleRelationalEntityMetadata<T> implements RelationalEntityMetada
}
/* (non-Javadoc)
* @see org.springframework.data.jdbc.repository.query.JdbcEntityMetadata#getTableName()
* @see org.springframework.data.jdbc.repository.query.RelationalEntityMetadata#getTableName()
*/
public String getTableName() {
return tableEntity.getTableName();

28
src/main/java/org/springframework/data/relational/repository/support/MappingRelationalEntityInformation.java

@ -15,13 +15,13 @@ @@ -15,13 +15,13 @@
*/
package org.springframework.data.relational.repository.support;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
import org.springframework.data.repository.core.support.PersistentEntityInformation;
import org.springframework.lang.Nullable;
/**
* {@link RelationalEntityInformation} implementation using a {@link JdbcPersistentEntity} instance to lookup the
* {@link RelationalEntityInformation} implementation using a {@link RelationalPersistentEntity} instance to lookup the
* necessary information. Can be configured with a custom table name.
* <p>
* Entity types that do not declare an explicit Id type fall back to {@link Long} as Id type.
@ -31,51 +31,51 @@ import org.springframework.lang.Nullable; @@ -31,51 +31,51 @@ import org.springframework.lang.Nullable;
public class MappingRelationalEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements RelationalEntityInformation<T, ID> {
private final JdbcPersistentEntity<T> entityMetadata;
private final RelationalPersistentEntity<T> entityMetadata;
private final @Nullable String customTableName;
private final Class<ID> fallbackIdType;
/**
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link JdbcPersistentEntity}.
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link RelationalPersistentEntity}.
*
* @param entity must not be {@literal null}.
*/
public MappingRelationalEntityInformation(JdbcPersistentEntity<T> entity) {
public MappingRelationalEntityInformation(RelationalPersistentEntity<T> entity) {
this(entity, null, null);
}
/**
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link JdbcPersistentEntity} and fallback
* identifier type.
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link RelationalPersistentEntity} and
* fallback identifier type.
*
* @param entity must not be {@literal null}.
* @param fallbackIdType can be {@literal null}.
*/
public MappingRelationalEntityInformation(JdbcPersistentEntity<T> entity, @Nullable Class<ID> fallbackIdType) {
public MappingRelationalEntityInformation(RelationalPersistentEntity<T> entity, @Nullable Class<ID> fallbackIdType) {
this(entity, null, fallbackIdType);
}
/**
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link JdbcPersistentEntity} and custom
* table name.
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link RelationalPersistentEntity} and
* custom table name.
*
* @param entity must not be {@literal null}.
* @param customTableName can be {@literal null}.
*/
public MappingRelationalEntityInformation(JdbcPersistentEntity<T> entity, String customTableName) {
public MappingRelationalEntityInformation(RelationalPersistentEntity<T> entity, String customTableName) {
this(entity, customTableName, null);
}
/**
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link JdbcPersistentEntity}, collection
* name and identifier type.
* Creates a new {@link MappingRelationalEntityInformation} for the given {@link RelationalPersistentEntity},
* collection name and identifier type.
*
* @param entity must not be {@literal null}.
* @param customTableName can be {@literal null}.
* @param idType can be {@literal null}.
*/
@SuppressWarnings("unchecked")
private MappingRelationalEntityInformation(JdbcPersistentEntity<T> entity, @Nullable String customTableName,
private MappingRelationalEntityInformation(RelationalPersistentEntity<T> entity, @Nullable String customTableName,
@Nullable Class<ID> idType) {
super(entity);

2
src/test/java/org/springframework/data/r2dbc/function/DatabaseClientIntegrationTests.java

@ -28,8 +28,8 @@ import org.junit.Test; @@ -28,8 +28,8 @@ import org.junit.Test;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.mapping.Table;
import org.springframework.data.jdbc.testing.R2dbcIntegrationTestSupport;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.jdbc.core.JdbcTemplate;
/**

6
src/test/java/org/springframework/data/r2dbc/repository/R2dbcRepositoryIntegrationTests.java

@ -32,13 +32,13 @@ import org.junit.Before; @@ -32,13 +32,13 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.Table;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.jdbc.testing.R2dbcIntegrationTestSupport;
import org.springframework.data.r2dbc.function.DatabaseClient;
import org.springframework.data.r2dbc.function.DefaultReactiveDataAccessStrategy;
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.jdbc.core.JdbcTemplate;
@ -49,7 +49,7 @@ import org.springframework.jdbc.core.JdbcTemplate; @@ -49,7 +49,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
*/
public class R2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
private static JdbcMappingContext mappingContext = new JdbcMappingContext();
private static RelationalMappingContext mappingContext = new RelationalMappingContext();
private ConnectionFactory connectionFactory;
private DatabaseClient databaseClient;

6
src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java

@ -28,9 +28,9 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; @@ -28,9 +28,9 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.repository.query.RelationalEntityMetadata;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
@ -42,11 +42,11 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat @@ -42,11 +42,11 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
*/
public class R2dbcQueryMethodUnitTests {
JdbcMappingContext context;
RelationalMappingContext context;
@Before
public void setUp() {
context = new JdbcMappingContext();
this.context = new RelationalMappingContext();
}
@Test

7
src/test/java/org/springframework/data/r2dbc/repository/query/StringBasedR2dbcQueryUnitTests.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.data.r2dbc.repository.query;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
@ -25,13 +26,13 @@ import org.junit.Test; @@ -25,13 +26,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.r2dbc.function.DatabaseClient;
import org.springframework.data.r2dbc.function.DatabaseClient.GenericExecuteSpec;
import org.springframework.data.r2dbc.function.convert.MappingR2dbcConverter;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
@ -52,7 +53,7 @@ public class StringBasedR2dbcQueryUnitTests { @@ -52,7 +53,7 @@ public class StringBasedR2dbcQueryUnitTests {
@Mock private DatabaseClient databaseClient;
@Mock private GenericExecuteSpec bindSpec;
private JdbcMappingContext mappingContext;
private RelationalMappingContext mappingContext;
private MappingR2dbcConverter converter;
private ProjectionFactory factory;
private RepositoryMetadata metadata;
@ -61,7 +62,7 @@ public class StringBasedR2dbcQueryUnitTests { @@ -61,7 +62,7 @@ public class StringBasedR2dbcQueryUnitTests {
@SuppressWarnings("unchecked")
public void setUp() {
this.mappingContext = new JdbcMappingContext();
this.mappingContext = new RelationalMappingContext();
this.converter = new MappingR2dbcConverter(this.mappingContext);
this.metadata = AbstractRepositoryMetadata.getMetadata(SampleRepository.class);
this.factory = new SpelAwareProxyProjectionFactory();

6
src/test/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryUnitTests.java

@ -23,9 +23,9 @@ import org.junit.Test; @@ -23,9 +23,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.r2dbc.function.DatabaseClient;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
import org.springframework.data.repository.Repository;
@ -40,7 +40,7 @@ public class R2dbcRepositoryFactoryUnitTests { @@ -40,7 +40,7 @@ public class R2dbcRepositoryFactoryUnitTests {
@Mock DatabaseClient databaseClient;
@Mock @SuppressWarnings("rawtypes") MappingContext mappingContext;
@Mock @SuppressWarnings("rawtypes") JdbcPersistentEntity entity;
@Mock @SuppressWarnings("rawtypes") RelationalPersistentEntity entity;
@Before
@SuppressWarnings("unchecked")
@ -50,7 +50,7 @@ public class R2dbcRepositoryFactoryUnitTests { @@ -50,7 +50,7 @@ public class R2dbcRepositoryFactoryUnitTests {
@Test
@SuppressWarnings("unchecked")
public void usesMappingJdbcEntityInformationIfMappingContextSet() {
public void usesMappingRelationalEntityInformationIfMappingContextSet() {
R2dbcRepositoryFactory factory = new R2dbcRepositoryFactory(databaseClient, mappingContext);
RelationalEntityInformation<Person, Long> entityInformation = factory.getEntityInformation(Person.class);

13
src/test/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepositoryIntegrationTests.java

@ -34,13 +34,13 @@ import org.junit.Before; @@ -34,13 +34,13 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.JdbcPersistentEntity;
import org.springframework.data.jdbc.core.mapping.Table;
import org.springframework.data.jdbc.testing.R2dbcIntegrationTestSupport;
import org.springframework.data.r2dbc.function.DatabaseClient;
import org.springframework.data.r2dbc.function.DefaultReactiveDataAccessStrategy;
import org.springframework.data.r2dbc.function.convert.MappingR2dbcConverter;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
import org.springframework.jdbc.core.JdbcTemplate;
@ -52,7 +52,7 @@ import org.springframework.jdbc.core.JdbcTemplate; @@ -52,7 +52,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
*/
public class SimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
private static JdbcMappingContext mappingContext = new JdbcMappingContext();
private static RelationalMappingContext mappingContext = new RelationalMappingContext();
private ConnectionFactory connectionFactory;
private DatabaseClient databaseClient;
@ -69,7 +69,7 @@ public class SimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestS @@ -69,7 +69,7 @@ public class SimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestS
.dataAccessStrategy(new DefaultReactiveDataAccessStrategy(mappingContext, new EntityInstantiators())).build();
RelationalEntityInformation<LegoSet, Integer> entityInformation = new MappingRelationalEntityInformation<>(
(JdbcPersistentEntity<LegoSet>) mappingContext.getRequiredPersistentEntity(LegoSet.class));
(RelationalPersistentEntity<LegoSet>) mappingContext.getRequiredPersistentEntity(LegoSet.class));
this.repository = new SimpleR2dbcRepository<>(entityInformation, databaseClient,
new MappingR2dbcConverter(mappingContext));
@ -93,8 +93,7 @@ public class SimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestS @@ -93,8 +93,7 @@ public class SimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestS
.consumeNextWith(actual -> {
assertThat(actual.getId()).isNotNull();
})
.verifyComplete();
}).verifyComplete();
Map<String, Object> map = jdbc.queryForMap("SELECT * FROM repo_legoset");
assertThat(map).containsEntry("name", "SCHAUFELRADBAGGER").containsEntry("manual", 12).containsKey("id");

Loading…
Cancel
Save