Polishing.
Tweak method names. Rebase onto main. Convert issue references to GH- from hash prefixed ones. Remove final keyword from variable and parameter declarations. Original pull request: #999. See #987
This commit is contained in:
@@ -19,7 +19,6 @@ import java.sql.Array;
|
||||
import java.sql.JDBCType;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -28,7 +27,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
@@ -228,12 +226,10 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
|
||||
TypeDescriptor sourceDescriptor = TypeDescriptor.valueOf(value.getClass());
|
||||
TypeDescriptor targetDescriptor = createTypeDescriptor(type);
|
||||
|
||||
return getConversionService().convert(value, sourceDescriptor,
|
||||
targetDescriptor);
|
||||
return getConversionService().convert(value, sourceDescriptor, targetDescriptor);
|
||||
}
|
||||
|
||||
if ( !getConversions().hasCustomReadTarget(value.getClass(), type.getType()) &&
|
||||
value instanceof Array) {
|
||||
if (value instanceof Array) {
|
||||
try {
|
||||
return readValue(((Array) value).getArray(), type);
|
||||
} catch (SQLException | ConverterNotFoundException e) {
|
||||
@@ -244,17 +240,6 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
|
||||
return super.readValue(value, type);
|
||||
}
|
||||
|
||||
private static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) {
|
||||
|
||||
List<TypeInformation<?>> typeArguments = type.getTypeArguments();
|
||||
Class<?>[] generics = new Class[typeArguments.size()];
|
||||
for (int i = 0; i < typeArguments.size(); i++) {
|
||||
generics[i] = typeArguments.get(i).getType();
|
||||
}
|
||||
|
||||
return new TypeDescriptor(ResolvableType.forClassWithGenerics(type.getType(), generics), type.getType(), null);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.relational.core.conversion.RelationalConverter#writeValue(java.lang.Object, org.springframework.data.util.TypeInformation)
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.springframework.util.ClassUtils;
|
||||
* conversion.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Jens Schauder
|
||||
* @since 2.0
|
||||
*/
|
||||
class QueryMapper {
|
||||
@@ -299,7 +300,7 @@ class QueryMapper {
|
||||
&& (criteria.getValue() == null || !criteria.getValue().getClass().isArray())) {
|
||||
|
||||
RelationalPersistentProperty property = ((MetadataBackedField) propertyField).property;
|
||||
JdbcValue jdbcValue = convertSpecial(property, criteria.getValue());
|
||||
JdbcValue jdbcValue = convertToJdbcValue(property, criteria.getValue());
|
||||
mappedValue = jdbcValue.getValue();
|
||||
sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType().getVendorTypeNumber()
|
||||
: propertyField.getSqlType();
|
||||
@@ -315,14 +316,14 @@ class QueryMapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts values while taking special value types like arrays, {@link Iterable}, or {@link Pair}.
|
||||
*
|
||||
* Converts values while taking specific value types like arrays, {@link Iterable}, or {@link Pair}.
|
||||
*
|
||||
* @param property the property to which the value relates. It determines the type to convert to. Must not be
|
||||
* {@literal null}.
|
||||
* @param value the value to be converted.
|
||||
* @return a non null {@link JdbcValue} holding the converted value and the appropriate JDBC type information.
|
||||
*/
|
||||
private JdbcValue convertSpecial(RelationalPersistentProperty property, @Nullable Object value) {
|
||||
private JdbcValue convertToJdbcValue(RelationalPersistentProperty property, @Nullable Object value) {
|
||||
|
||||
if (value == null) {
|
||||
return JdbcValue.of(null, JDBCType.NULL);
|
||||
@@ -330,8 +331,8 @@ class QueryMapper {
|
||||
|
||||
if (value instanceof Pair) {
|
||||
|
||||
final JdbcValue first = convertSimple(property, ((Pair<?, ?>) value).getFirst());
|
||||
final JdbcValue second = convertSimple(property, ((Pair<?, ?>) value).getSecond());
|
||||
JdbcValue first = getWriteValue(property, ((Pair<?, ?>) value).getFirst());
|
||||
JdbcValue second = getWriteValue(property, ((Pair<?, ?>) value).getSecond());
|
||||
return JdbcValue.of(Pair.of(first.getValue(), second.getValue()), first.getJdbcType());
|
||||
}
|
||||
|
||||
@@ -342,7 +343,7 @@ class QueryMapper {
|
||||
|
||||
for (Object o : (Iterable<?>) value) {
|
||||
|
||||
final JdbcValue jdbcValue = convertSimple(property, o);
|
||||
JdbcValue jdbcValue = getWriteValue(property, o);
|
||||
if (jdbcType == null) {
|
||||
jdbcType = jdbcValue.getJdbcType();
|
||||
}
|
||||
@@ -355,13 +356,13 @@ class QueryMapper {
|
||||
|
||||
if (value.getClass().isArray()) {
|
||||
|
||||
final Object[] valueAsArray = (Object[]) value;
|
||||
final Object[] mappedValueArray = new Object[valueAsArray.length];
|
||||
Object[] valueAsArray = (Object[]) value;
|
||||
Object[] mappedValueArray = new Object[valueAsArray.length];
|
||||
JDBCType jdbcType = null;
|
||||
|
||||
for (int i = 0; i < valueAsArray.length; i++) {
|
||||
|
||||
final JdbcValue jdbcValue = convertSimple(property, valueAsArray[i]);
|
||||
JdbcValue jdbcValue = getWriteValue(property, valueAsArray[i]);
|
||||
if (jdbcType == null) {
|
||||
jdbcType = jdbcValue.getJdbcType();
|
||||
}
|
||||
@@ -372,7 +373,7 @@ class QueryMapper {
|
||||
return JdbcValue.of(mappedValueArray, jdbcType);
|
||||
}
|
||||
|
||||
return convertSimple(property, value);
|
||||
return getWriteValue(property, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,7 +384,7 @@ class QueryMapper {
|
||||
* @param value the value to be converted.
|
||||
* @return a non null {@link JdbcValue} holding the converted value and the appropriate JDBC type information.
|
||||
*/
|
||||
private JdbcValue convertSimple(RelationalPersistentProperty property, Object value) {
|
||||
private JdbcValue getWriteValue(RelationalPersistentProperty property, Object value) {
|
||||
|
||||
return converter.writeJdbcValue( //
|
||||
value, //
|
||||
|
||||
@@ -32,12 +32,12 @@ import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -515,7 +515,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
assertThat(result).extracting(e -> e.idProp).containsExactly(entity.idProp);
|
||||
}
|
||||
|
||||
@Test // #987
|
||||
@Test // GH-987
|
||||
void queryBySimpleReference() {
|
||||
|
||||
final DummyEntity one = repository.save(createDummyEntity());
|
||||
@@ -528,7 +528,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
assertThat(result).extracting(e -> e.idProp).containsExactly(two.idProp);
|
||||
}
|
||||
|
||||
@Test // #987
|
||||
@Test // GH-987
|
||||
void queryByAggregateReference() {
|
||||
|
||||
final DummyEntity one = repository.save(createDummyEntity());
|
||||
|
||||
@@ -78,12 +78,12 @@ public class PartTreeJdbcQueryUnitTests {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> createQuery(queryMethod));
|
||||
}
|
||||
|
||||
@Test // #922
|
||||
@Test // GH-922
|
||||
public void createQueryByAggregateReference() throws Exception {
|
||||
|
||||
JdbcQueryMethod queryMethod = getQueryMethod("findAllByHobbyReference", Hobby.class);
|
||||
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
|
||||
final Hobby hobby = new Hobby();
|
||||
Hobby hobby = new Hobby();
|
||||
hobby.name = "twentythree";
|
||||
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] {hobby}), returnedType);
|
||||
|
||||
@@ -110,12 +110,12 @@ public class PartTreeJdbcQueryUnitTests {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> createQuery(queryMethod));
|
||||
}
|
||||
|
||||
@Test // #922
|
||||
@Test // GH-922
|
||||
public void createQueryForQueryByAggregateReference() throws Exception {
|
||||
|
||||
JdbcQueryMethod queryMethod = getQueryMethod("findViaReferenceByHobbyReference", AggregateReference.class);
|
||||
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
|
||||
final AggregateReference<Object, String> hobby = AggregateReference.to("twentythree");
|
||||
AggregateReference<Object, String> hobby = AggregateReference.to("twentythree");
|
||||
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] {hobby}), returnedType);
|
||||
|
||||
assertSoftly(softly -> {
|
||||
@@ -127,12 +127,12 @@ public class PartTreeJdbcQueryUnitTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // #922
|
||||
@Test // GH-922
|
||||
public void createQueryForQueryByAggregateReferenceId() throws Exception {
|
||||
|
||||
JdbcQueryMethod queryMethod = getQueryMethod("findViaIdByHobbyReference", String.class);
|
||||
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
|
||||
final String hobby = "twentythree";
|
||||
String hobby = "twentythree";
|
||||
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] {hobby}), returnedType);
|
||||
|
||||
assertSoftly(softly -> {
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
package org.springframework.data.relational.core.conversion;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.convert.CustomConversions;
|
||||
@@ -160,7 +163,7 @@ public class BasicRelationalConverter implements RelationalConverter {
|
||||
if (getConversions().hasCustomReadTarget(value.getClass(), type.getType())) {
|
||||
|
||||
TypeDescriptor sourceDescriptor = TypeDescriptor.valueOf(value.getClass());
|
||||
TypeDescriptor targetDescriptor = typeInformationToTypeDescriptor(type);
|
||||
TypeDescriptor targetDescriptor = createTypeDescriptor(type);
|
||||
|
||||
return getConversionService().convert(value, sourceDescriptor, targetDescriptor);
|
||||
}
|
||||
@@ -250,11 +253,15 @@ public class BasicRelationalConverter implements RelationalConverter {
|
||||
return conversionService.convert(value, target);
|
||||
}
|
||||
|
||||
protected static TypeDescriptor typeInformationToTypeDescriptor(TypeInformation<?> type) {
|
||||
protected static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) {
|
||||
|
||||
Class<?>[] generics = type.getTypeArguments().stream().map(TypeInformation::getType).toArray(Class[]::new);
|
||||
List<TypeInformation<?>> typeArguments = type.getTypeArguments();
|
||||
Class<?>[] generics = new Class[typeArguments.size()];
|
||||
for (int i = 0; i < typeArguments.size(); i++) {
|
||||
generics[i] = typeArguments.get(i).getType();
|
||||
}
|
||||
|
||||
return new TypeDescriptor(ResolvableType.forClassWithGenerics(type.getType(), generics), null, null);
|
||||
return new TypeDescriptor(ResolvableType.forClassWithGenerics(type.getType(), generics), type.getType(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user