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

@@ -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.