DATAJDBC-544 - Removes all Lombok from production code.

This commit is contained in:
Jens Schauder
2020-05-20 13:59:54 +02:00
parent dedaf34614
commit 4ee9eb8df5
23 changed files with 429 additions and 140 deletions

View File

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

View File

@@ -15,21 +15,57 @@
*/
package org.springframework.data.jdbc.core.convert;
import lombok.Value;
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
* {@link java.sql.PreparedStatement}. Register a converter from any type to {@link JdbcValue} in order to control
* the value and the {@link JDBCType} as which a value should get passed to the JDBC driver.
* {@link java.sql.PreparedStatement}. Register a converter from any type to {@link JdbcValue} in order to control the
* value and the {@link JDBCType} as which a value should get passed to the JDBC driver.
*
* @author Jens Schauder
* @since 1.1
*/
@Value(staticConstructor = "of")
public class JdbcValue {
public final class JdbcValue {
Object value;
JDBCType jdbcType;
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;
}
@Override
public int hashCode() {
return Objects.hash(value, jdbcType);
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.jdbc.core.convert;
import lombok.RequiredArgsConstructor;
import java.sql.ResultSet;
import java.sql.SQLException;
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.SqlIdentifier;
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
@@ -35,7 +32,6 @@ import org.springframework.lang.NonNull;
*
* @author Jens Schauder
*/
@RequiredArgsConstructor
class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
private final PersistentPropertyPathExtension path;
@@ -44,7 +40,16 @@ class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
private final SqlIdentifier keyColumn;
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
public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException {

View File

@@ -15,13 +15,6 @@
*/
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.Sort;
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.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}
*
@@ -722,11 +720,60 @@ class SqlGenerator {
/**
* Value object representing a {@code JOIN} association.
*/
@Value
static class Join {
Table joinTable;
Column joinColumn;
Column parentId;
static final class Join {
private final Table joinTable;
private final Column joinColumn;
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 +
'}';
}
}
/**

View File

@@ -15,12 +15,11 @@
*/
package org.springframework.data.jdbc.core.convert;
import lombok.RequiredArgsConstructor;
import java.util.Map;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
/**
@@ -31,7 +30,6 @@ import org.springframework.util.ConcurrentReferenceHashMap;
* @author Mark Paluch
* @author Milan Milanov
*/
@RequiredArgsConstructor
public class SqlGeneratorSource {
private final Map<Class<?>, SqlGenerator> CACHE = new ConcurrentReferenceHashMap<>();
@@ -39,6 +37,17 @@ public class SqlGeneratorSource {
private final JdbcConverter converter;
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
* {@literal null}.

View File

@@ -15,11 +15,10 @@
*/
package org.springframework.data.jdbc.core.mapping;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import java.util.Objects;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* A reference to the aggregate root of a different aggregate.
@@ -49,16 +48,42 @@ public interface AggregateReference<T, ID> {
* @param <T>
* @param <ID>
*/
@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
class IdOnlyAggregateReference<T, ID> implements AggregateReference<T, ID> {
private final ID id;
public IdOnlyAggregateReference(ID id) {
Assert.notNull(id, "Id must not be null.");
this.id = id;
}
@Override
public ID getId() {
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 + '}';
}
}
}

View File

@@ -15,10 +15,9 @@
*/
package org.springframework.data.jdbc.repository.query;
import lombok.Value;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -312,10 +311,55 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
/**
* Value object representing a {@code JOIN} association.
*/
@Value
static private class Join {
Table joinTable;
Column joinColumn;
Column parentId;
static private final class Join {
private final Table joinTable;
private final Column joinColumn;
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 + '}';
}
}
}

View File

@@ -15,21 +15,18 @@
*/
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.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.util.Streamable;
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.
@@ -38,12 +35,20 @@ import org.springframework.transaction.annotation.Transactional;
* @author Oliver Gierke
* @author Milan Milanov
*/
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class SimpleJdbcRepository<T, ID> implements PagingAndSortingRepository<T, ID> {
private final @NonNull JdbcAggregateOperations entityOperations;
private final @NonNull PersistentEntity<T, ?> entity;
private final JdbcAggregateOperations entityOperations;
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)

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.jdbc.support;
import lombok.experimental.UtilityClass;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
@@ -37,8 +35,7 @@ import org.springframework.util.Assert;
* @author Jens Schauder
* @author Thomas Lang
*/
@UtilityClass
public class JdbcUtil {
public final class JdbcUtil {
private static final Map<Class<?>, Integer> sqlTypeMappings = new HashMap<>();
@@ -67,6 +64,10 @@ public class JdbcUtil {
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
* {@link java.sql.PreparedStatement}.