Browse Source

DATAJDBC-544 - Removes all Lombok from production code.

pull/223/head
Jens Schauder 6 years ago
parent
commit
4ee9eb8df5
No known key found for this signature in database
GPG Key ID: 996B1389BA0721C3
  1. 9
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/ArrayUtil.java
  2. 52
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java
  3. 15
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MapEntityRowMapper.java
  4. 71
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java
  5. 15
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGeneratorSource.java
  6. 37
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java
  7. 58
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryCreator.java
  8. 25
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java
  9. 9
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/support/JdbcUtil.java
  10. 86
      spring-data-relational/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java
  11. 18
      spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java
  12. 40
      spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/PathNode.java
  13. 19
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/AbstractDialect.java
  14. 3
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/AnsiDialect.java
  15. 3
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/H2Dialect.java
  16. 10
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java
  17. 16
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/RenderContextFactory.java
  18. 19
      spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java
  19. 8
      spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java
  20. 12
      spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/event/RelationalAuditingCallback.java
  21. 15
      spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/NamingStrategies.java
  22. 21
      spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/SimpleRenderContext.java
  23. 8
      spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/SimpleRelationalEntityMetadata.java

9
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/ArrayUtil.java

@ -15,16 +15,17 @@
*/ */
package org.springframework.data.jdbc.core.convert; package org.springframework.data.jdbc.core.convert;
import lombok.experimental.UtilityClass;
/** /**
* A collection of utility methods for dealing with arrays. * A collection of utility methods for dealing with arrays.
* *
* @author Jens Schauder * @author Jens Schauder
* @since 1.1 * @since 1.1
*/ */
@UtilityClass final class ArrayUtil {
class ArrayUtil {
private ArrayUtil() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
/** /**
* Converts an {@code Byte[]} into a {@code byte[]}. * Converts an {@code Byte[]} into a {@code byte[]}.

52
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java

@ -15,21 +15,57 @@
*/ */
package org.springframework.data.jdbc.core.convert; package org.springframework.data.jdbc.core.convert;
import lombok.Value;
import java.sql.JDBCType; import java.sql.JDBCType;
import java.util.Objects;
import org.springframework.lang.Nullable;
/** /**
* Wraps a value with the JDBCType that should be used to pass it as a bind parameter to a * Wraps a value with the JDBCType that should be used to pass it as a bind parameter to a
* {@link java.sql.PreparedStatement}. Register a converter from any type to {@link JdbcValue} in order to control * {@link java.sql.PreparedStatement}. Register a converter from any type to {@link JdbcValue} in order to control the
* the value and the {@link JDBCType} as which a value should get passed to the JDBC driver. * value and the {@link JDBCType} as which a value should get passed to the JDBC driver.
* *
* @author Jens Schauder * @author Jens Schauder
* @since 1.1 * @since 1.1
*/ */
@Value(staticConstructor = "of") public final class JdbcValue {
public class JdbcValue {
private final Object value;
private final JDBCType jdbcType;
private JdbcValue(@Nullable Object value, @Nullable JDBCType jdbcType) {
this.value = value;
this.jdbcType = jdbcType;
}
public static JdbcValue of(@Nullable Object value, @Nullable JDBCType jdbcType) {
return new JdbcValue(value, jdbcType);
}
@Nullable
public Object getValue() {
return this.value;
}
@Nullable
public JDBCType getJdbcType() {
return this.jdbcType;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
JdbcValue jdbcValue = (JdbcValue) o;
return Objects.equals(value, jdbcValue.value) && jdbcType == jdbcValue.jdbcType;
}
Object value; @Override
JDBCType jdbcType; public int hashCode() {
return Objects.hash(value, jdbcType);
}
} }

15
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MapEntityRowMapper.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.jdbc.core.convert; package org.springframework.data.jdbc.core.convert;
import lombok.RequiredArgsConstructor;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -26,7 +24,6 @@ import org.springframework.data.relational.core.mapping.PersistentPropertyPathEx
import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.NonNull;
/** /**
* A {@link RowMapper} that maps a row to a {@link Map.Entry} so an {@link Iterable} of those can be converted to a * A {@link RowMapper} that maps a row to a {@link Map.Entry} so an {@link Iterable} of those can be converted to a
@ -35,7 +32,6 @@ import org.springframework.lang.NonNull;
* *
* @author Jens Schauder * @author Jens Schauder
*/ */
@RequiredArgsConstructor
class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> { class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
private final PersistentPropertyPathExtension path; private final PersistentPropertyPathExtension path;
@ -44,7 +40,16 @@ class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
private final SqlIdentifier keyColumn; private final SqlIdentifier keyColumn;
private final IdentifierProcessing identifierProcessing; private final IdentifierProcessing identifierProcessing;
@NonNull MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier,
SqlIdentifier keyColumn, IdentifierProcessing identifierProcessing) {
this.path = path;
this.converter = converter;
this.identifier = identifier;
this.keyColumn = keyColumn;
this.identifierProcessing = identifierProcessing;
}
@Override @Override
public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException { public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException {

71
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java

@ -15,13 +15,6 @@
*/ */
package org.springframework.data.jdbc.core.convert; package org.springframework.data.jdbc.core.convert;
import lombok.Value;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository; import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
@ -41,6 +34,11 @@ import org.springframework.data.util.Lazy;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/** /**
* Generates SQL statements to be used by {@link SimpleJdbcRepository} * Generates SQL statements to be used by {@link SimpleJdbcRepository}
* *
@ -722,11 +720,60 @@ class SqlGenerator {
/** /**
* Value object representing a {@code JOIN} association. * Value object representing a {@code JOIN} association.
*/ */
@Value static final class Join {
static class Join {
Table joinTable; private final Table joinTable;
Column joinColumn; private final Column joinColumn;
Column parentId; private final Column parentId;
Join(Table joinTable, Column joinColumn, Column parentId) {
Assert.notNull( joinTable,"JoinTable must not be null.");
Assert.notNull( joinColumn,"JoinColumn must not be null.");
Assert.notNull( parentId,"ParentId must not be null.");
this.joinTable = joinTable;
this.joinColumn = joinColumn;
this.parentId = parentId;
}
Table getJoinTable() {
return this.joinTable;
}
Column getJoinColumn() {
return this.joinColumn;
}
Column getParentId() {
return this.parentId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Join join = (Join) o;
return joinTable.equals(join.joinTable) &&
joinColumn.equals(join.joinColumn) &&
parentId.equals(join.parentId);
}
@Override
public int hashCode() {
return Objects.hash(joinTable, joinColumn, parentId);
}
@Override
public String toString() {
return "Join{" +
"joinTable=" + joinTable +
", joinColumn=" + joinColumn +
", parentId=" + parentId +
'}';
}
} }
/** /**

15
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGeneratorSource.java

@ -15,12 +15,11 @@
*/ */
package org.springframework.data.jdbc.core.convert; package org.springframework.data.jdbc.core.convert;
import lombok.RequiredArgsConstructor;
import java.util.Map; import java.util.Map;
import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ConcurrentReferenceHashMap;
/** /**
@ -31,7 +30,6 @@ import org.springframework.util.ConcurrentReferenceHashMap;
* @author Mark Paluch * @author Mark Paluch
* @author Milan Milanov * @author Milan Milanov
*/ */
@RequiredArgsConstructor
public class SqlGeneratorSource { public class SqlGeneratorSource {
private final Map<Class<?>, SqlGenerator> CACHE = new ConcurrentReferenceHashMap<>(); private final Map<Class<?>, SqlGenerator> CACHE = new ConcurrentReferenceHashMap<>();
@ -39,6 +37,17 @@ public class SqlGeneratorSource {
private final JdbcConverter converter; private final JdbcConverter converter;
private final Dialect dialect; private final Dialect dialect;
public SqlGeneratorSource(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
Assert.notNull(context, "Context must not be null.");
Assert.notNull(converter, "Converter must not be null.");
Assert.notNull(dialect, "Dialect must not be null.");
this.context = context;
this.converter = converter;
this.dialect = dialect;
}
/** /**
* @return the {@link Dialect} used by the created {@link SqlGenerator} instances. Guaranteed to be not * @return the {@link Dialect} used by the created {@link SqlGenerator} instances. Guaranteed to be not
* {@literal null}. * {@literal null}.

37
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java

@ -15,11 +15,10 @@
*/ */
package org.springframework.data.jdbc.core.mapping; package org.springframework.data.jdbc.core.mapping;
import lombok.EqualsAndHashCode; import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/** /**
* A reference to the aggregate root of a different aggregate. * A reference to the aggregate root of a different aggregate.
@ -49,16 +48,42 @@ public interface AggregateReference<T, ID> {
* @param <T> * @param <T>
* @param <ID> * @param <ID>
*/ */
@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
class IdOnlyAggregateReference<T, ID> implements AggregateReference<T, ID> { class IdOnlyAggregateReference<T, ID> implements AggregateReference<T, ID> {
private final ID id; private final ID id;
public IdOnlyAggregateReference(ID id) {
Assert.notNull(id, "Id must not be null.");
this.id = id;
}
@Override @Override
public ID getId() { public ID getId() {
return id; return id;
} }
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
IdOnlyAggregateReference<?, ?> that = (IdOnlyAggregateReference<?, ?>) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "IdOnlyAggregateReference{" + "id=" + id + '}';
}
} }
} }

58
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryCreator.java

@ -15,10 +15,9 @@
*/ */
package org.springframework.data.jdbc.repository.query; package org.springframework.data.jdbc.repository.query;
import lombok.Value;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@ -312,10 +311,55 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
/** /**
* Value object representing a {@code JOIN} association. * Value object representing a {@code JOIN} association.
*/ */
@Value static private final class Join {
static private class Join {
Table joinTable; private final Table joinTable;
Column joinColumn; private final Column joinColumn;
Column parentId; private final Column parentId;
Join(Table joinTable, Column joinColumn, Column parentId) {
Assert.notNull(joinTable, "JoinTable must not be null.");
Assert.notNull(joinColumn, "JoinColumn must not be null.");
Assert.notNull(parentId, "ParentId must not be null.");
this.joinTable = joinTable;
this.joinColumn = joinColumn;
this.parentId = parentId;
}
Table getJoinTable() {
return this.joinTable;
}
Column getJoinColumn() {
return this.joinColumn;
}
Column getParentId() {
return this.parentId;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Join join = (Join) o;
return joinTable.equals(join.joinTable) && joinColumn.equals(join.joinColumn) && parentId.equals(join.parentId);
}
@Override
public int hashCode() {
return Objects.hash(joinTable, joinColumn, parentId);
}
@Override
public String toString() {
return "Join{" + "joinTable=" + joinTable + ", joinColumn=" + joinColumn + ", parentId=" + parentId + '}';
}
} }
} }

25
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

@ -15,21 +15,18 @@
*/ */
package org.springframework.data.jdbc.repository.support; package org.springframework.data.jdbc.repository.support;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.JdbcAggregateOperations; import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.util.Streamable; import org.springframework.data.util.Streamable;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface. * Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface.
@ -38,12 +35,20 @@ import org.springframework.transaction.annotation.Transactional;
* @author Oliver Gierke * @author Oliver Gierke
* @author Milan Milanov * @author Milan Milanov
*/ */
@RequiredArgsConstructor
@Transactional(readOnly = true) @Transactional(readOnly = true)
public class SimpleJdbcRepository<T, ID> implements PagingAndSortingRepository<T, ID> { public class SimpleJdbcRepository<T, ID> implements PagingAndSortingRepository<T, ID> {
private final @NonNull JdbcAggregateOperations entityOperations; private final JdbcAggregateOperations entityOperations;
private final @NonNull PersistentEntity<T, ?> entity; private final PersistentEntity<T, ?> entity;
public SimpleJdbcRepository(JdbcAggregateOperations entityOperations,PersistentEntity<T, ?> entity) {
Assert.notNull(entityOperations, "EntityOperations must not be null.");
Assert.notNull(entity, "Entity must not be null.");
this.entityOperations = entityOperations;
this.entity = entity;
}
/* /*
* (non-Javadoc) * (non-Javadoc)

9
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/support/JdbcUtil.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.jdbc.support; package org.springframework.data.jdbc.support;
import lombok.experimental.UtilityClass;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Date; import java.sql.Date;
@ -37,8 +35,7 @@ import org.springframework.util.Assert;
* @author Jens Schauder * @author Jens Schauder
* @author Thomas Lang * @author Thomas Lang
*/ */
@UtilityClass public final class JdbcUtil {
public class JdbcUtil {
private static final Map<Class<?>, Integer> sqlTypeMappings = new HashMap<>(); private static final Map<Class<?>, Integer> sqlTypeMappings = new HashMap<>();
@ -67,6 +64,10 @@ public class JdbcUtil {
sqlTypeMappings.put(Timestamp.class, Types.TIMESTAMP); sqlTypeMappings.put(Timestamp.class, Types.TIMESTAMP);
} }
private JdbcUtil() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
/** /**
* Returns the {@link Types} value suitable for passing a value of the provided type to a * Returns the {@link Types} value suitable for passing a value of the provided type to a
* {@link java.sql.PreparedStatement}. * {@link java.sql.PreparedStatement}.

86
spring-data-relational/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java

@ -15,20 +15,16 @@
*/ */
package org.springframework.data.jdbc.core.convert; package org.springframework.data.jdbc.core.convert;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.Value;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -41,8 +37,6 @@ import org.springframework.util.ClassUtils;
* @author Mark Paluch * @author Mark Paluch
* @since 1.1 * @since 1.1
*/ */
@EqualsAndHashCode
@ToString
public final class Identifier { public final class Identifier {
private static final Identifier EMPTY = new Identifier(Collections.emptyList()); private static final Identifier EMPTY = new Identifier(Collections.emptyList());
@ -185,13 +179,55 @@ public final class Identifier {
* *
* @author Jens Schauder * @author Jens Schauder
*/ */
@Value static final class SingleIdentifierValue {
@AllArgsConstructor(access = AccessLevel.PRIVATE)
static class SingleIdentifierValue { private final SqlIdentifier name;
private final Object value;
private final Class<?> targetType;
private SingleIdentifierValue(SqlIdentifier name, @Nullable Object value, Class<?> targetType) {
Assert.notNull(name, "Name must not be null.");
Assert.notNull(targetType, "TargetType must not be null.");
this.name = name;
this.value = value;
this.targetType = targetType;
}
public SqlIdentifier getName() {
return this.name;
}
public Object getValue() {
return this.value;
}
public Class<?> getTargetType() {
return this.targetType;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SingleIdentifierValue that = (SingleIdentifierValue) o;
return name.equals(that.name) && value.equals(that.value) && targetType.equals(that.targetType);
}
SqlIdentifier name; @Override
Object value; public int hashCode() {
Class<?> targetType; return Objects.hash(name, value, targetType);
}
@Override
public String toString() {
return "SingleIdentifierValue{" + "name=" + name + ", value=" + value + ", targetType=" + targetType + '}';
}
} }
/** /**
@ -213,7 +249,7 @@ public final class Identifier {
void accept(SqlIdentifier name, Object value, Class<?> targetType); void accept(SqlIdentifier name, Object value, Class<?> targetType);
} }
private static class StringKeyedLinkedHashMap<V> extends LinkedHashMap<SqlIdentifier,V> { private static class StringKeyedLinkedHashMap<V> extends LinkedHashMap<SqlIdentifier, V> {
public StringKeyedLinkedHashMap(int initialCapacity) { public StringKeyedLinkedHashMap(int initialCapacity) {
super(initialCapacity); super(initialCapacity);
@ -234,4 +270,24 @@ public final class Identifier {
return super.get(key); return super.get(key);
} }
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Identifier that = (Identifier) o;
return Objects.equals(parts, that.parts);
}
@Override
public int hashCode() {
return Objects.hash(parts);
}
@Override
public String toString() {
return "Identifier{" + "parts=" + parts + '}';
}
} }

18
spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java

@ -15,12 +15,6 @@
*/ */
package org.springframework.data.relational.core.conversion; package org.springframework.data.relational.core.conversion;
import lombok.RequiredArgsConstructor;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Function;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.ConfigurableConversionService; import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.DefaultConversionService;
@ -43,6 +37,10 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Function;
/** /**
* {@link RelationalConverter} that uses a {@link MappingContext} to apply basic conversion of relational values to * {@link RelationalConverter} that uses a {@link MappingContext} to apply basic conversion of relational values to
* property values. * property values.
@ -249,11 +247,17 @@ public class BasicRelationalConverter implements RelationalConverter {
* @param <P> * @param <P>
* @author Mark Paluch * @author Mark Paluch
*/ */
@RequiredArgsConstructor
class ConvertingParameterValueProvider<P extends PersistentProperty<P>> implements ParameterValueProvider<P> { class ConvertingParameterValueProvider<P extends PersistentProperty<P>> implements ParameterValueProvider<P> {
private final Function<Parameter<?, P>, Object> delegate; private final Function<Parameter<?, P>, Object> delegate;
ConvertingParameterValueProvider(Function<Parameter<?, P>, Object> delegate) {
Assert.notNull(delegate, "Delegate must not be null.");
this.delegate = delegate;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter) * @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter)

40
spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/PathNode.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.conversion; package org.springframework.data.relational.core.conversion;
import lombok.Value;
import org.springframework.data.mapping.PersistentPropertyPath; import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.util.Pair; import org.springframework.data.util.Pair;
@ -28,34 +26,58 @@ import org.springframework.lang.Nullable;
* *
* @author Jens Schauder * @author Jens Schauder
*/ */
@Value final class PathNode {
class PathNode {
/** /**
* The path to this entity * The path to this entity
*/ */
PersistentPropertyPath<RelationalPersistentProperty> path; private final PersistentPropertyPath<RelationalPersistentProperty> path;
/** /**
* The parent {@link PathNode}. This is {@code null} if this is the root entity. * The parent {@link PathNode}. This is {@code null} if this is the root entity.
*/ */
@Nullable PathNode parent; @Nullable private final PathNode parent;
/** /**
* The value of the entity. * The value of the entity.
*/ */
Object value; private final Object value;
PathNode(PersistentPropertyPath<RelationalPersistentProperty> path, @Nullable PathNode parent, Object value) {
this.path = path;
this.parent = parent;
this.value = value;
}
/** /**
* If the node represents a qualified property (i.e. a {@link java.util.List} or {@link java.util.Map}) the actual * If the node represents a qualified property (i.e. a {@link java.util.List} or {@link java.util.Map}) the actual
* value is an element of the {@literal List} or a value of the {@literal Map}, while the {@link #value} is actually a * value is an element of the {@literal List} or a value of the {@literal Map}, while the {@link #value} is actually a
* {@link Pair} with the index or key as the first element and the actual value as second element. * {@link Pair} with the index or key as the first element and the actual value as second element.
*
*/ */
Object getActualValue() { Object getActualValue() {
return getPath().getRequiredLeafProperty().isQualified() // return getPath().getRequiredLeafProperty().isQualified() //
? ((Pair) getValue()).getSecond() // ? ((Pair<?,?>) getValue()).getSecond() //
: getValue(); : getValue();
} }
public PersistentPropertyPath<RelationalPersistentProperty> getPath() {
return this.path;
}
@Nullable
public PathNode getParent() {
return this.parent;
}
public Object getValue() {
return this.value;
}
@Override
public String toString() {
return "PathNode{" + "path=" + path + ", parent=" + parent + ", value=" + value + '}';
}
} }

19
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/AbstractDialect.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.dialect; package org.springframework.data.relational.core.dialect;
import lombok.RequiredArgsConstructor;
import java.util.OptionalLong; import java.util.OptionalLong;
import java.util.function.Function; import java.util.function.Function;
@ -74,8 +72,7 @@ public abstract class AbstractDialect implements Dialect {
Function<Select, ? extends CharSequence> afterOrderByLimit = getAfterOrderByLimit(); Function<Select, ? extends CharSequence> afterOrderByLimit = getAfterOrderByLimit();
Function<Select, ? extends CharSequence> afterOrderByLock = getAfterOrderByLock(); Function<Select, ? extends CharSequence> afterOrderByLock = getAfterOrderByLock();
return select -> String.valueOf(afterOrderByLimit.apply(select)) + return select -> String.valueOf(afterOrderByLimit.apply(select)) + afterOrderByLock.apply(select);
afterOrderByLock.apply(select);
} }
private Function<Select, ? extends CharSequence> getAfterOrderByLimit() { private Function<Select, ? extends CharSequence> getAfterOrderByLimit() {
@ -109,8 +106,7 @@ public abstract class AbstractDialect implements Dialect {
private final Function<Select, ? extends CharSequence> afterFromTable; private final Function<Select, ? extends CharSequence> afterFromTable;
private final Function<Select, ? extends CharSequence> afterOrderBy; private final Function<Select, ? extends CharSequence> afterOrderBy;
DialectSelectRenderContext( DialectSelectRenderContext(Function<Select, ? extends CharSequence> afterFromTable,
Function<Select, ? extends CharSequence> afterFromTable,
Function<Select, ? extends CharSequence> afterOrderBy) { Function<Select, ? extends CharSequence> afterOrderBy) {
this.afterFromTable = afterFromTable; this.afterFromTable = afterFromTable;
@ -139,11 +135,14 @@ public abstract class AbstractDialect implements Dialect {
/** /**
* After {@code ORDER BY} function rendering the {@link LimitClause}. * After {@code ORDER BY} function rendering the {@link LimitClause}.
*/ */
@RequiredArgsConstructor
static class AfterOrderByLimitRenderFunction implements Function<Select, CharSequence> { static class AfterOrderByLimitRenderFunction implements Function<Select, CharSequence> {
private final LimitClause clause; private final LimitClause clause;
public AfterOrderByLimitRenderFunction(LimitClause clause) {
this.clause = clause;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see java.util.function.Function#apply(java.lang.Object) * @see java.util.function.Function#apply(java.lang.Object)
@ -173,11 +172,14 @@ public abstract class AbstractDialect implements Dialect {
/** /**
* {@code LOCK} function rendering the {@link LockClause}. * {@code LOCK} function rendering the {@link LockClause}.
*/ */
@RequiredArgsConstructor
static class LockRenderFunction implements Function<Select, CharSequence> { static class LockRenderFunction implements Function<Select, CharSequence> {
private final LockClause clause; private final LockClause clause;
public LockRenderFunction(LockClause clause) {
this.clause = clause;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see java.util.function.Function#apply(java.lang.Object) * @see java.util.function.Function#apply(java.lang.Object)
@ -198,7 +200,6 @@ public abstract class AbstractDialect implements Dialect {
/** /**
* Prepends a non-empty rendering result with a leading whitespace, * Prepends a non-empty rendering result with a leading whitespace,
*/ */
@RequiredArgsConstructor
enum PrependWithLeadingWhitespace implements Function<CharSequence, CharSequence> { enum PrependWithLeadingWhitespace implements Function<CharSequence, CharSequence> {
INSTANCE; INSTANCE;

3
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/AnsiDialect.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.dialect; package org.springframework.data.relational.core.dialect;
import lombok.RequiredArgsConstructor;
import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.LockOptions; import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -127,7 +125,6 @@ public class AnsiDialect extends AbstractDialect {
return ARRAY_COLUMNS; return ARRAY_COLUMNS;
} }
@RequiredArgsConstructor
static class AnsiArrayColumns implements ArrayColumns { static class AnsiArrayColumns implements ArrayColumns {
/* /*

3
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/H2Dialect.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.dialect; package org.springframework.data.relational.core.dialect;
import lombok.RequiredArgsConstructor;
import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing; import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting; import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
@ -107,7 +105,6 @@ public class H2Dialect extends AbstractDialect {
return ARRAY_COLUMNS; return ARRAY_COLUMNS;
} }
@RequiredArgsConstructor
static class H2ArrayColumns implements ArrayColumns { static class H2ArrayColumns implements ArrayColumns {
/* /*

10
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java

@ -15,19 +15,16 @@
*/ */
package org.springframework.data.relational.core.dialect; package org.springframework.data.relational.core.dialect;
import lombok.RequiredArgsConstructor; import java.util.List;
import org.springframework.data.relational.core.sql.From;
import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
import org.springframework.data.relational.core.sql.LockOptions; import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.data.relational.core.sql.Table; import org.springframework.data.relational.core.sql.Table;
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import java.util.List;
/** /**
* An SQL dialect for Postgres. * An SQL dialect for Postgres.
* *
@ -159,7 +156,6 @@ public class PostgresDialect extends AbstractDialect {
} }
}; };
@RequiredArgsConstructor
static class PostgresArrayColumns implements ArrayColumns { static class PostgresArrayColumns implements ArrayColumns {
/* /*

16
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/RenderContextFactory.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.dialect; package org.springframework.data.relational.core.dialect;
import lombok.RequiredArgsConstructor;
import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.render.NamingStrategies; import org.springframework.data.relational.core.sql.render.NamingStrategies;
import org.springframework.data.relational.core.sql.render.RenderContext; import org.springframework.data.relational.core.sql.render.RenderContext;
@ -75,15 +73,23 @@ public class RenderContextFactory {
/** /**
* {@link RenderContext} derived from {@link Dialect} specifics. * {@link RenderContext} derived from {@link Dialect} specifics.
*/ */
@RequiredArgsConstructor
static class DialectRenderContext implements RenderContext { static class DialectRenderContext implements RenderContext {
private final RenderNamingStrategy renderNamingStrategy; private final RenderNamingStrategy renderNamingStrategy;
private final IdentifierProcessing identifierProcessing; private final IdentifierProcessing identifierProcessing;
private final SelectRenderContext selectRenderContext; private final SelectRenderContext selectRenderContext;
DialectRenderContext(RenderNamingStrategy renderNamingStrategy, IdentifierProcessing identifierProcessing, SelectRenderContext selectRenderContext) {
Assert.notNull(renderNamingStrategy, "RenderNamingStrategy must not be null");
Assert.notNull(identifierProcessing, "IdentifierProcessing must not be null");
Assert.notNull(selectRenderContext, "SelectRenderContext must not be null");
this.renderNamingStrategy = renderNamingStrategy;
this.identifierProcessing = identifierProcessing;
this.selectRenderContext = selectRenderContext;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.relational.core.sql.render.RenderContext#getNamingStrategy() * @see org.springframework.data.relational.core.sql.render.RenderContext#getNamingStrategy()

19
spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.mapping; package org.springframework.data.relational.core.mapping;
import lombok.EqualsAndHashCode;
import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyPath; import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.MappingContext;
@ -26,6 +24,8 @@ import org.springframework.data.util.Lazy;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.util.Objects;
/** /**
* A wrapper around a {@link org.springframework.data.mapping.PersistentPropertyPath} for making common operations * A wrapper around a {@link org.springframework.data.mapping.PersistentPropertyPath} for making common operations
* available used in SQL generation and conversion * available used in SQL generation and conversion
@ -33,7 +33,6 @@ import org.springframework.util.Assert;
* @author Jens Schauder * @author Jens Schauder
* @since 1.1 * @since 1.1
*/ */
@EqualsAndHashCode(exclude = { "columnAlias", "context" })
public class PersistentPropertyPathExtension { public class PersistentPropertyPathExtension {
private final RelationalPersistentEntity<?> entity; private final RelationalPersistentEntity<?> entity;
@ -436,4 +435,18 @@ public class PersistentPropertyPathExtension {
: columnName.transform(name -> tableAlias.getReference(IdentifierProcessing.NONE) + "_" + name); : columnName.transform(name -> tableAlias.getReference(IdentifierProcessing.NONE) + "_" + name);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PersistentPropertyPathExtension that = (PersistentPropertyPathExtension) o;
return entity.equals(that.entity) &&
path.equals(that.path);
}
@Override
public int hashCode() {
return Objects.hash(entity, path);
}
} }

8
spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.mapping; package org.springframework.data.relational.core.mapping;
import lombok.Getter;
import org.springframework.data.mapping.context.AbstractMappingContext; import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.Property; import org.springframework.data.mapping.model.Property;
@ -36,7 +34,7 @@ import org.springframework.util.Assert;
public class RelationalMappingContext public class RelationalMappingContext
extends AbstractMappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> { extends AbstractMappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> {
@Getter private final NamingStrategy namingStrategy; private final NamingStrategy namingStrategy;
private boolean forceQuote = true; private boolean forceQuote = true;
/** /**
@ -107,4 +105,8 @@ public class RelationalMappingContext
return persistentProperty; return persistentProperty;
} }
public NamingStrategy getNamingStrategy() {
return this.namingStrategy;
}
} }

12
spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/event/RelationalAuditingCallback.java

@ -15,12 +15,10 @@
*/ */
package org.springframework.data.relational.core.mapping.event; package org.springframework.data.relational.core.mapping.event;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.data.auditing.IsNewAwareAuditingHandler; import org.springframework.data.auditing.IsNewAwareAuditingHandler;
import org.springframework.data.relational.core.mapping.event.BeforeConvertCallback; import org.springframework.util.Assert;
/** /**
* {@link BeforeConvertCallback} to capture auditing information on persisting and updating entities. * {@link BeforeConvertCallback} to capture auditing information on persisting and updating entities.
@ -31,7 +29,6 @@ import org.springframework.data.relational.core.mapping.event.BeforeConvertCallb
* @author Mark Paluch * @author Mark Paluch
* @since 1.1 * @since 1.1
*/ */
@RequiredArgsConstructor
public class RelationalAuditingCallback implements BeforeConvertCallback<Object>, Ordered { public class RelationalAuditingCallback implements BeforeConvertCallback<Object>, Ordered {
/** /**
@ -45,6 +42,13 @@ public class RelationalAuditingCallback implements BeforeConvertCallback<Object>
private final IsNewAwareAuditingHandler handler; private final IsNewAwareAuditingHandler handler;
public RelationalAuditingCallback(IsNewAwareAuditingHandler handler) {
Assert.notNull(handler, "Handler must not be null;");
this.handler = handler;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder() * @see org.springframework.core.Ordered#getOrder()

15
spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/NamingStrategies.java

@ -15,16 +15,14 @@
*/ */
package org.springframework.data.relational.core.sql.render; package org.springframework.data.relational.core.sql.render;
import lombok.RequiredArgsConstructor;
import java.util.Locale;
import java.util.function.Function;
import org.springframework.data.relational.core.sql.Column; import org.springframework.data.relational.core.sql.Column;
import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.core.sql.Table; import org.springframework.data.relational.core.sql.Table;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.util.Locale;
import java.util.function.Function;
/** /**
* Factory for {@link RenderNamingStrategy} objects. * Factory for {@link RenderNamingStrategy} objects.
* *
@ -115,12 +113,17 @@ public abstract class NamingStrategies {
INSTANCE; INSTANCE;
} }
@RequiredArgsConstructor
static class DelegatingRenderNamingStrategy implements RenderNamingStrategy { static class DelegatingRenderNamingStrategy implements RenderNamingStrategy {
private final RenderNamingStrategy delegate; private final RenderNamingStrategy delegate;
private final Function<String, String> mappingFunction; private final Function<String, String> mappingFunction;
DelegatingRenderNamingStrategy(RenderNamingStrategy delegate, Function<String, String> mappingFunction) {
this.delegate = delegate;
this.mappingFunction = mappingFunction;
}
@Override @Override
public SqlIdentifier getName(Column column) { public SqlIdentifier getName(Column column) {
return delegate.getName(column).transform(mappingFunction::apply); return delegate.getName(column).transform(mappingFunction::apply);

21
spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/SimpleRenderContext.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.core.sql.render; package org.springframework.data.relational.core.sql.render;
import lombok.Value;
import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.IdentifierProcessing;
/** /**
@ -25,11 +23,14 @@ import org.springframework.data.relational.core.sql.IdentifierProcessing;
* @author Mark Paluch * @author Mark Paluch
* @since 1.1 * @since 1.1
*/ */
@Value final class SimpleRenderContext implements RenderContext {
class SimpleRenderContext implements RenderContext {
private final RenderNamingStrategy namingStrategy; private final RenderNamingStrategy namingStrategy;
SimpleRenderContext(RenderNamingStrategy namingStrategy) {
this.namingStrategy = namingStrategy;
}
@Override @Override
public IdentifierProcessing getIdentifierProcessing() { public IdentifierProcessing getIdentifierProcessing() {
return IdentifierProcessing.NONE; return IdentifierProcessing.NONE;
@ -40,6 +41,18 @@ class SimpleRenderContext implements RenderContext {
return DefaultSelectRenderContext.INSTANCE; return DefaultSelectRenderContext.INSTANCE;
} }
public RenderNamingStrategy getNamingStrategy() {
return this.namingStrategy;
}
@Override
public String toString() {
return "SimpleRenderContext{" +
"namingStrategy=" + namingStrategy +
'}';
}
enum DefaultSelectRenderContext implements SelectRenderContext { enum DefaultSelectRenderContext implements SelectRenderContext {
INSTANCE; INSTANCE;
} }

8
spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/SimpleRelationalEntityMetadata.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.relational.repository.query; package org.springframework.data.relational.repository.query;
import lombok.Getter;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -29,7 +27,7 @@ import org.springframework.util.Assert;
public class SimpleRelationalEntityMetadata<T> implements RelationalEntityMetadata<T> { public class SimpleRelationalEntityMetadata<T> implements RelationalEntityMetadata<T> {
private final Class<T> type; private final Class<T> type;
private final @Getter RelationalPersistentEntity<?> tableEntity; private final RelationalPersistentEntity<?> tableEntity;
/** /**
* Creates a new {@link SimpleRelationalEntityMetadata} using the given type and {@link RelationalPersistentEntity} to * Creates a new {@link SimpleRelationalEntityMetadata} using the given type and {@link RelationalPersistentEntity} to
@ -60,4 +58,8 @@ public class SimpleRelationalEntityMetadata<T> implements RelationalEntityMetada
public SqlIdentifier getTableName() { public SqlIdentifier getTableName() {
return tableEntity.getTableName(); return tableEntity.getTableName();
} }
public RelationalPersistentEntity<?> getTableEntity() {
return this.tableEntity;
}
} }

Loading…
Cancel
Save