Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Original pull request #1869
  • Loading branch information
schauder committed Aug 30, 2024
1 parent 848ffee commit b006923
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.data.mapping.PropertyReferenceException;
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.query.CriteriaDefinition;
Expand Down Expand Up @@ -66,7 +65,7 @@ public class QueryMapper {
*
* @param converter must not be {@literal null}.
*/
public QueryMapper( JdbcConverter converter) {
public QueryMapper(JdbcConverter converter) {

Assert.notNull(converter, "JdbcConverter must not be null");

Expand All @@ -90,8 +89,7 @@ public List<OrderByField> getMappedSort(Table table, Sort sort, @Nullable Relati
SqlSort.validate(order);

OrderByField simpleOrderByField = createSimpleOrderByField(table, entity, order);
OrderByField orderBy = simpleOrderByField
.withNullHandling(order.getNullHandling());
OrderByField orderBy = simpleOrderByField.withNullHandling(order.getNullHandling());
mappedOrder.add(order.isAscending() ? orderBy.asc() : orderBy.desc());
}

Expand Down Expand Up @@ -285,7 +283,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc
SQLType sqlType;
Comparator comparator = criteria.getComparator();

if (criteria.getValue()instanceof JdbcValue settableValue) {
if (criteria.getValue() instanceof JdbcValue settableValue) {

mappedValue = convertValue(comparator, settableValue.getValue(), propertyField.getTypeHint());
sqlType = getTypeHint(mappedValue, actualType.getType(), settableValue);
Expand Down Expand Up @@ -424,7 +422,8 @@ private Condition mapEmbeddedObjectCondition(CriteriaDefinition criteria, MapSql
@Nullable
private Object convertValue(Comparator comparator, @Nullable Object value, TypeInformation<?> typeHint) {

if ((Comparator.IN.equals(comparator) || Comparator.NOT_IN.equals(comparator)) && value instanceof Collection<?> collection && !collection.isEmpty()) {
if ((Comparator.IN.equals(comparator) || Comparator.NOT_IN.equals(comparator))
&& value instanceof Collection<?> collection && !collection.isEmpty()) {

Collection<Object> mapped = new ArrayList<>(collection.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.relational.core.conversion.IdValueSource;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
Expand All @@ -47,7 +46,7 @@
public class SqlParametersFactory {
private final RelationalMappingContext context;
private final JdbcConverter converter;

/**
* @since 3.1
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -42,14 +41,9 @@
import org.springframework.data.jdbc.testing.IntegrationTest;
import org.springframework.data.jdbc.testing.TestClass;
import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.repository.CrudRepository;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the integration for customizing the namespace with Mybatis.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
*/
package org.springframework.data.relational.core.conversion;

import java.util.function.Function;

import org.springframework.core.convert.ConversionService;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPathAccessor;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.EntityInstantiators;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.projection.EntityProjectionIntrospector;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
Expand Down Expand Up @@ -127,5 +123,4 @@ public interface RelationalConverter {
@Nullable
Object writeValue(@Nullable Object value, TypeInformation<?> type);


}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class BasicRelationalPersistentProperty extends AnnotationBasedPersistent
private final boolean hasExplicitColumnName;
private final @Nullable Expression columnNameExpression;
private final Lazy<Optional<SqlIdentifier>> collectionIdColumnName;
private final @Nullable Expression collectionIdColumnNameExpression;
private final Lazy<SqlIdentifier> collectionKeyColumnName;
private final @Nullable Expression collectionKeyColumnNameExpression;
private final boolean isEmbedded;
Expand Down Expand Up @@ -98,16 +97,13 @@ public BasicRelationalPersistentProperty(Property property, PersistentEntity<?,
collectionIdColumnName = Lazy.of(() -> Optional.of(createSqlIdentifier(mappedCollection.idColumn())));
}

this.collectionIdColumnNameExpression = detectExpression(mappedCollection.idColumn());

collectionKeyColumnName = Lazy.of(
() -> StringUtils.hasText(mappedCollection.keyColumn()) ? createSqlIdentifier(mappedCollection.keyColumn())
: createDerivedSqlIdentifier(namingStrategy.getKeyColumn(this)));

this.collectionKeyColumnNameExpression = detectExpression(mappedCollection.keyColumn());
} else {

this.collectionIdColumnNameExpression = null;
this.collectionKeyColumnNameExpression = null;
}

Expand Down

0 comments on commit b006923

Please sign in to comment.