DATAJDBC-524 - Fixed dependency cycles triggered by DATAJDBC-318.

Moved Identifier and IdentifierBuilder to ...jdbc.core.convert.
Moved RelationaAuditingCallback to ..mapping.event.

Improved DependencyTests to properly consider "relational" a main module.
This commit is contained in:
Jens Schauder
2020-04-28 11:09:52 +02:00
parent d80614b4d8
commit 6420205eed
29 changed files with 21 additions and 44 deletions

View File

@@ -29,7 +29,9 @@ import java.util.function.BiConsumer;
import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.Identifier;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPath;
@@ -40,7 +42,6 @@ import org.springframework.data.relational.core.conversion.RelationalEntityVersi
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.util.Pair;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

View File

@@ -24,7 +24,6 @@ import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.CustomConversions;
@@ -41,7 +40,6 @@ import org.springframework.data.relational.core.mapping.PersistentPropertyPathEx
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;

View File

@@ -24,7 +24,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
/**
* Delegates each methods to the {@link DataAccessStrategy}s passed to the constructor in turn until the first that does
@@ -154,7 +153,7 @@ public class CascadingDataAccessStrategy implements DataAccessStrategy {
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.relational.domain.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.jdbc.support.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
*/
@Override
public Iterable<Object> findAllByPath(Identifier identifier,

View File

@@ -23,7 +23,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.lang.Nullable;
/**
@@ -171,7 +170,7 @@ public interface DataAccessStrategy extends RelationResolver {
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.relational.domain.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.jdbc.support.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
*/
@Override
Iterable<Object> findAllByPath(Identifier identifier,

View File

@@ -42,7 +42,6 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentEnti
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
@@ -304,7 +303,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.relational.domain.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.jdbc.support.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
*/
@Override
@SuppressWarnings("unchecked")

View File

@@ -19,7 +19,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.util.Assert;
/**
@@ -149,7 +148,7 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy {
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.relational.domain.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.jdbc.support.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
*/
@Override
public Iterable<Object> findAllByPath(Identifier identifier,

View File

@@ -19,7 +19,6 @@ import java.sql.ResultSet;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.jdbc.core.RowMapper;
/**

View File

@@ -21,7 +21,6 @@ import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;

View File

@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core;
package org.springframework.data.jdbc.core.convert;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

View File

@@ -25,7 +25,6 @@ import java.util.Map;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.NonNull;

View File

@@ -17,7 +17,6 @@ package org.springframework.data.jdbc.core.convert;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
/**
* Resolves relations within an aggregate.

View File

@@ -37,7 +37,6 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
import org.springframework.data.relational.core.sql.*;
import org.springframework.data.relational.core.sql.render.RenderContext;
import org.springframework.data.relational.core.sql.render.SqlRenderer;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.util.Lazy;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

View File

@@ -18,7 +18,7 @@ package org.springframework.data.jdbc.mybatis;
import java.util.Collections;
import java.util.Map;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.jdbc.core.convert.Identifier;
import org.springframework.lang.Nullable;
/**

View File

@@ -32,6 +32,7 @@ import org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.Identifier;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
import org.springframework.data.mapping.PersistentPropertyPath;
@@ -41,7 +42,6 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.util.Assert;

View File

@@ -24,7 +24,7 @@ import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.data.auditing.IsNewAwareAuditingHandler;
import org.springframework.data.auditing.config.AuditingBeanDefinitionRegistrarSupport;
import org.springframework.data.auditing.config.AuditingConfiguration;
import org.springframework.data.relational.domain.support.RelationalAuditingCallback;
import org.springframework.data.relational.core.mapping.event.RelationalAuditingCallback;
import org.springframework.util.Assert;
/**

View File

@@ -31,14 +31,15 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.Identifier;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
import org.springframework.data.relational.core.conversion.DbAction;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.lang.Nullable;
public class JdbcAggregateChangeExecutorContextImmutableUnitTests {

View File

@@ -28,14 +28,15 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.Identifier;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
import org.springframework.data.relational.core.conversion.DbAction;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.lang.Nullable;
/**

View File

@@ -27,7 +27,6 @@ import org.junit.Test;
import org.springframework.data.jdbc.core.convert.FunctionCollector.CombinedDataAccessException;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
/**
* Unit tests for {@link CascadingDataAccessStrategy}.

View File

@@ -39,7 +39,6 @@ import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

View File

@@ -61,7 +61,6 @@ 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.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.repository.query.Param;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2019-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.convert;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier;
/**
* Unit tests for {@link Identifier}.
*
* @author Jens Schauder
* @author Mark Paluch
*/
public class IdentifierUnitTests {
@Test // DATAJDBC-326
public void getParametersByName() {
Identifier identifier = Identifier.of(unquoted("aName"), "aValue", String.class);
assertThat(identifier.toMap()).hasSize(1).containsEntry(unquoted("aName"), "aValue");
}
@Test // DATAJDBC-326
public void parametersWithStringKeysUseObjectAsTypeForNull() {
HashMap<SqlIdentifier, Object> parameters = new HashMap<>();
parameters.put(unquoted("one"), null);
Identifier identifier = Identifier.from(parameters);
assertThat(identifier.getParts()) //
.extracting("name", "value", "targetType") //
.containsExactly( //
Assertions.tuple(unquoted("one"), null, Object.class) //
);
}
@Test // DATAJDBC-326
public void createsIdentifierFromMap() {
Identifier identifier = Identifier.from(Collections.singletonMap(unquoted("aName"), "aValue"));
assertThat(identifier.toMap()).hasSize(1).containsEntry(unquoted("aName"), "aValue");
}
@Test // DATAJDBC-326
public void withAddsNewEntries() {
Identifier identifier = Identifier.from(Collections.singletonMap(unquoted("aName"), "aValue"))
.withPart(unquoted("foo"), "bar", String.class);
assertThat(identifier.toMap()) //
.hasSize(2) //
.containsEntry(unquoted("aName"), "aValue") //
.containsEntry(unquoted("foo"), "bar");
}
@Test // DATAJDBC-326
public void withOverridesExistingEntries() {
Identifier identifier = Identifier.from(Collections.singletonMap(unquoted("aName"), "aValue"))
.withPart(unquoted("aName"), "bar", String.class);
assertThat(identifier.toMap()) //
.hasSize(1) //
.containsEntry(unquoted("aName"), "bar");
}
@Test // DATAJDBC-326
public void forEachIteratesOverKeys() {
List<String> keys = new ArrayList<>();
Identifier.from(Collections.singletonMap(unquoted("aName"), "aValue"))
.forEach((name, value, targetType) -> keys.add(name.toSql(IdentifierProcessing.ANSI)));
assertThat(keys).containsOnly("aName");
}
@Test // DATAJDBC-326
public void equalsConsidersEquality() {
Identifier one = Identifier.from(Collections.singletonMap(unquoted("aName"), "aValue"));
Identifier two = Identifier.from(Collections.singletonMap(unquoted("aName"), "aValue"));
Identifier three = Identifier.from(Collections.singletonMap(unquoted("aName"), "different"));
assertThat(one).isEqualTo(two);
assertThat(one).isNotEqualTo(three);
}
}

View File

@@ -25,10 +25,8 @@ import java.util.UUID;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.JdbcIdentifierBuilder;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.domain.Identifier;
/**
* Unit tests for the {@link JdbcIdentifierBuilder}.

View File

@@ -48,7 +48,6 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
import org.springframework.data.relational.core.sql.Aliased;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.core.sql.Table;
import org.springframework.data.relational.domain.Identifier;
/**
* Unit tests for the {@link SqlGenerator}.

View File

@@ -58,6 +58,7 @@ public class DependencyTests {
}) // exclude test code
.withSlicing("sub-modules", // sub-modules are defined by any of the following pattern.
"org.springframework.data.jdbc.(*).**", //
"org.springframework.data.relational.(*).**", //
"org.springframework.data.(*).**") //
.printTo("degraph-across-modules.graphml"), // writes a graphml to this location
JCheck.violationFree());

View File

@@ -30,13 +30,13 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.PropertyPathTestingUtils;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.Identifier;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.domain.Identifier;
/**
* Unit tests for the {@link MyBatisDataAccessStrategy}, mainly ensuring that the correct statements get's looked up.