From 36b419e712fbb792c0396a859f72099fafb21adf Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 10 Jan 2020 09:09:46 +0100 Subject: [PATCH] DATAJDBC-386 - Polishing. Tests that used the `@Column` annotation to map multiple properties to a single database column failed. Mapping multiple values to one column is possible to allow for entities inside an aggregate to have the id of the aggregate as ID or as part of the ID. The reason for the test failures was that columns get referred to by different ways: Once per DerivedSqlIdentifier (i.e. with normalized spelling). And Once per `@Column` annotation. SqlIdentifier from an `@Column` annotation have always the same spelling, while the normalized version depends on the `Dialect`. In order to make the tests work for all databases all references to the column in question had to get a `@Column` annotation. This in turn required the create scripts to also use quoting when the normal case of the database did not match the case chosen in the annotation. Finally there were some tests that used hand coded SQL which now uses `SqlIdentifier` and an injected `Dialect` to arrive at the correct SQL syntax. Removed a couple of `@Ignore` annotations that got left in the code. Original pull request: #182. --- ...eChangeIdGenerationImmutableUnitTests.java | 2 - ...JdbcAggregateTemplateIntegrationTests.java | 2 +- .../DefaultDataAccessStrategyUnitTests.java | 1 - ...SqlIdentifierParameterSourceUnitTests.java | 1 - .../MyBatisDataAccessStrategyUnitTests.java | 1 - ...dedNotInAggregateRootIntegrationTests.java | 39 ++++++++++------ ...mbeddedWithCollectionIntegrationTests.java | 46 ++++++++++++------- ...EmbeddedWithReferenceIntegrationTests.java | 37 +++++++++------ .../src/test/resources/logback.xml | 2 +- ...egateTemplateIntegrationTests-postgres.sql | 19 ++++---- ...tInAggregateRootIntegrationTests-mysql.sql | 13 +++++- ...AggregateRootIntegrationTests-postgres.sql | 13 +++++- ...ithCollectionIntegrationTests-postgres.sql | 15 +++++- ...WithReferenceIntegrationTests-postgres.sql | 22 ++++++++- .../core/sql/CompositeSqlIdentifier.java | 1 + .../domain/IdentifierUnitTests.java | 2 - 16 files changed, 146 insertions(+), 70 deletions(-) diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java index b0086275..49a9b964 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationImmutableUnitTests.java @@ -486,8 +486,6 @@ public class AggregateChangeIdGenerationImmutableUnitTests { @With @AllArgsConstructor private static class ContentNoId { - // "foo_bar_single" - // "FOO_BAR_TAG_SET" @Column("single") Tag single; Set tagSet; List tagList; diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java index f35ff0a1..af89e71e 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java @@ -821,6 +821,7 @@ public class JdbcAggregateTemplateIntegrationTests { return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM " + tableName, emptyMap(), Long.class); } + @Table("ARRAY_OWNER") private static class ArrayOwner { @Id Long id; @@ -1039,7 +1040,6 @@ public class JdbcAggregateTemplateIntegrationTests { @Id private Long id; @Version private final Long version; - } @Data diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java index aa3ee6b0..24cdf408 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java @@ -50,7 +50,6 @@ import org.springframework.jdbc.support.KeyHolder; * @author Jens Schauder * @author Mark Paluch */ -@Ignore public class DefaultDataAccessStrategyUnitTests { public static final long ID_FROM_ADDITIONAL_VALUES = 23L; diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java index a753a232..aa172034 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java @@ -16,7 +16,6 @@ package org.springframework.data.jdbc.core.convert; import org.assertj.core.api.SoftAssertions; -import org.junit.Ignore; import org.junit.Test; import org.springframework.data.relational.core.sql.IdentifierProcessing; import org.springframework.data.relational.core.sql.SqlIdentifier; diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java index d86ef0ae..c6a65a2f 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java @@ -47,7 +47,6 @@ import org.springframework.data.relational.core.sql.IdentifierProcessing; * @author Mark Paluch * @author Tyler Van Gorder */ -@Ignore public class MyBatisDataAccessStrategyUnitTests { RelationalMappingContext context = new JdbcMappingContext(); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java index d9865108..c4df3155 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java @@ -20,6 +20,8 @@ import static org.assertj.core.api.Assertions.*; import lombok.Data; +import java.sql.SQLException; + import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -30,6 +32,7 @@ import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.TestConfiguration; +import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; @@ -75,17 +78,24 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { @Autowired NamedParameterJdbcTemplate template; @Autowired DummyEntityRepository repository; + @Autowired Dialect dialect; @Test // DATAJDBC-111 - public void savesAnEntity() { + public void savesAnEntity() throws SQLException { DummyEntity entity = repository.save(createDummyEntity()); - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity", - "id = " + entity.getId())).isEqualTo(1); + assertThat(countRowsInTable("dummy_entity", entity.getId())).isEqualTo(1); + assertThat(countRowsInTable("dummy_entity2", entity.getId())).isEqualTo(1); + } - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity2", - "id = " + entity.getId())).isEqualTo(1); + private int countRowsInTable(String name, long idValue) { + + SqlIdentifier id = SqlIdentifier.quoted("ID"); + String whereClause = id.toSql(dialect.getIdentifierProcessing()) + " = " + idValue; + + return JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), + name, whereClause); } @Test // DATAJDBC-111 @@ -96,7 +106,8 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { assertThat(repository.findById(entity.getId())).hasValueSatisfying(it -> { assertThat(it.getId()).isEqualTo(entity.getId()); assertThat(it.getDummyEntity2().getTest()).isEqualTo(entity.getDummyEntity2().getTest()); - assertThat(it.getDummyEntity2().getEmbeddable().getAttr()).isEqualTo(entity.getDummyEntity2().getEmbeddable().getAttr()); + assertThat(it.getDummyEntity2().getEmbeddable().getAttr()) + .isEqualTo(entity.getDummyEntity2().getEmbeddable().getAttr()); }); } @@ -131,7 +142,8 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { assertThat(repository.findById(entity.getId())).hasValueSatisfying(it -> { assertThat(it.getDummyEntity2().getTest()).isEqualTo(saved.getDummyEntity2().getTest()); - assertThat(it.getDummyEntity2().getEmbeddable().getAttr()).isEqualTo(saved.getDummyEntity2().getEmbeddable().getAttr()); + assertThat(it.getDummyEntity2().getEmbeddable().getAttr()) + .isEqualTo(saved.getDummyEntity2().getEmbeddable().getAttr()); }); } @@ -155,7 +167,8 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { assertThat(repository.findAll()) // .extracting(d -> d.getDummyEntity2().getEmbeddable().getAttr()) // - .containsExactlyInAnyOrder(entity.getDummyEntity2().getEmbeddable().getAttr(), other.getDummyEntity2().getEmbeddable().getAttr()); + .containsExactlyInAnyOrder(entity.getDummyEntity2().getEmbeddable().getAttr(), + other.getDummyEntity2().getEmbeddable().getAttr()); } @Test // DATAJDBC-111 @@ -234,22 +247,20 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { @Data static class DummyEntity { - @Id Long id; + @Column("ID") @Id Long id; String test; - @Column("ID") - DummyEntity2 dummyEntity2; + @Column("ID") DummyEntity2 dummyEntity2; } @Data static class DummyEntity2 { - @Id Long id; + @Column("ID") @Id Long id; String test; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") - Embeddable embeddable; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Embeddable embeddable; } @Data diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java index 06de107b..0244b482 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests.java @@ -20,6 +20,10 @@ import static org.assertj.core.api.Assertions.*; import lombok.Data; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -30,6 +34,7 @@ import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.TestConfiguration; +import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; @@ -44,9 +49,6 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; - /** * Very simple use cases for creation and usage of JdbcRepositories with test {@link Embedded} annotation in Entities. * @@ -79,17 +81,23 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests { @Autowired NamedParameterJdbcTemplate template; @Autowired DummyEntityRepository repository; + @Autowired Dialect dialect; @Test // DATAJDBC-111 - public void savesAnEntity() { + public void savesAnEntity() throws SQLException { DummyEntity entity = repository.save(createDummyEntity()); - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity", - "id = " + entity.getId())).isEqualTo(1); + assertThat(countRowsInTable("dummy_entity", entity.getId())).isEqualTo(1); + assertThat(countRowsInTable("dummy_entity2", entity.getId())).isEqualTo(2); + } - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity2", - "id = " + entity.getId())).isEqualTo(2); + private int countRowsInTable(String name, long idValue) { + + SqlIdentifier id = SqlIdentifier.quoted("ID"); + String whereClause = id.toSql(dialect.getIdentifierProcessing()) + " = " + idValue; + + return JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), name, whereClause); } @Test // DATAJDBC-111 @@ -101,8 +109,10 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests { assertThat(it.getId()).isEqualTo(entity.getId()); assertThat(it.getEmbeddable().getTest()).isEqualTo(entity.getEmbeddable().getTest()); assertThat(it.getEmbeddable().getList().size()).isEqualTo(entity.getEmbeddable().getList().size()); - assertThat(it.getEmbeddable().getList().get(0).getTest()).isEqualTo(entity.getEmbeddable().getList().get(0).getTest()); - assertThat(it.getEmbeddable().getList().get(1).getTest()).isEqualTo(entity.getEmbeddable().getList().get(1).getTest()); + assertThat(it.getEmbeddable().getList().get(0).getTest()) + .isEqualTo(entity.getEmbeddable().getList().get(0).getTest()); + assertThat(it.getEmbeddable().getList().get(1).getTest()) + .isEqualTo(entity.getEmbeddable().getList().get(1).getTest()); }); } @@ -139,8 +149,10 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests { assertThat(it.getId()).isEqualTo(saved.getId()); assertThat(it.getEmbeddable().getTest()).isEqualTo(saved.getEmbeddable().getTest()); assertThat(it.getEmbeddable().getList().size()).isEqualTo(saved.getEmbeddable().getList().size()); - assertThat(it.getEmbeddable().getList().get(0).getTest()).isEqualTo(saved.getEmbeddable().getList().get(0).getTest()); - assertThat(it.getEmbeddable().getList().get(1).getTest()).isEqualTo(saved.getEmbeddable().getList().get(1).getTest()); + assertThat(it.getEmbeddable().getList().get(0).getTest()) + .isEqualTo(saved.getEmbeddable().getList().get(0).getTest()); + assertThat(it.getEmbeddable().getList().get(1).getTest()) + .isEqualTo(saved.getEmbeddable().getList().get(1).getTest()); }); } @@ -164,7 +176,8 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests { assertThat(repository.findAll()) // .extracting(d -> d.getEmbeddable().getList().get(0).getTest()) // - .containsExactlyInAnyOrder(entity.getEmbeddable().getList().get(0).getTest(), other.getEmbeddable().getList().get(0).getTest()); + .containsExactlyInAnyOrder(entity.getEmbeddable().getList().get(0).getTest(), + other.getEmbeddable().getList().get(0).getTest()); } @Test // DATAJDBC-111 @@ -247,18 +260,17 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests { @Data private static class DummyEntity { + @Column("ID") @Id Long id; String test; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") - Embeddable embeddable; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable; } @Data private static class Embeddable { - @MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") - List list = new ArrayList<>(); + @MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List list = new ArrayList<>(); String test; } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java index 4c311bb9..5e2b19b0 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java @@ -20,6 +20,8 @@ import static org.assertj.core.api.Assertions.*; import lombok.Data; +import java.sql.SQLException; + import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -30,6 +32,7 @@ import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.TestConfiguration; +import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; import org.springframework.data.relational.core.mapping.Embedded.OnEmpty; @@ -75,17 +78,23 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { @Autowired NamedParameterJdbcTemplate template; @Autowired DummyEntityRepository repository; + @Autowired Dialect dialect; @Test // DATAJDBC-111 public void savesAnEntity() { DummyEntity entity = repository.save(createDummyEntity()); - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity", - "id = " + entity.getId())).isEqualTo(1); + assertThat(countRowsInTable("dummy_entity", entity.getId())).isEqualTo(1); + assertThat(countRowsInTable("dummy_entity2", entity.getId())).isEqualTo(1); + } - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity2", - "id = " + entity.getId())).isEqualTo(1); + private int countRowsInTable(String name, long idValue) { + + SqlIdentifier id = SqlIdentifier.quoted("ID"); + String whereClause = id.toSql(dialect.getIdentifierProcessing()) + " = " + idValue; + + return JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), name, whereClause); } @Test // DATAJDBC-111 @@ -96,7 +105,8 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { assertThat(repository.findById(entity.getId())).hasValueSatisfying(it -> { assertThat(it.getId()).isEqualTo(entity.getId()); assertThat(it.getEmbeddable().getTest()).isEqualTo(entity.getEmbeddable().getTest()); - assertThat(it.getEmbeddable().getDummyEntity2().getTest()).isEqualTo(entity.getEmbeddable().getDummyEntity2().getTest()); + assertThat(it.getEmbeddable().getDummyEntity2().getTest()) + .isEqualTo(entity.getEmbeddable().getDummyEntity2().getTest()); }); } @@ -131,7 +141,8 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { assertThat(repository.findById(entity.getId())).hasValueSatisfying(it -> { assertThat(it.getEmbeddable().getTest()).isEqualTo(saved.getEmbeddable().getTest()); - assertThat(it.getEmbeddable().getDummyEntity2().getTest()).isEqualTo(saved.getEmbeddable().getDummyEntity2().getTest()); + assertThat(it.getEmbeddable().getDummyEntity2().getTest()) + .isEqualTo(saved.getEmbeddable().getDummyEntity2().getTest()); }); } @@ -155,7 +166,8 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { assertThat(repository.findAll()) // .extracting(d -> d.getEmbeddable().getDummyEntity2().getTest()) // - .containsExactlyInAnyOrder(entity.getEmbeddable().getDummyEntity2().getTest(), other.getEmbeddable().getDummyEntity2().getTest()); + .containsExactlyInAnyOrder(entity.getEmbeddable().getDummyEntity2().getTest(), + other.getEmbeddable().getDummyEntity2().getTest()); } @Test // DATAJDBC-111 @@ -234,19 +246,18 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { @Data private static class DummyEntity { - @Id Long id; + + @Column("ID") @Id Long id; String test; - @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") - Embeddable embeddable; + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable; } @Data private static class Embeddable { - @Column("ID") - DummyEntity2 dummyEntity2; + @Column("ID") DummyEntity2 dummyEntity2; String test; } @@ -254,7 +265,7 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { @Data private static class DummyEntity2 { - @Id Long id; + @Column("ID") @Id Long id; String test; } diff --git a/spring-data-jdbc/src/test/resources/logback.xml b/spring-data-jdbc/src/test/resources/logback.xml index 8ef5ba09..ade0cc6e 100644 --- a/spring-data-jdbc/src/test/resources/logback.xml +++ b/spring-data-jdbc/src/test/resources/logback.xml @@ -8,7 +8,7 @@ - + diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-postgres.sql index ee8c090c..30b158fc 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-postgres.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-postgres.sql @@ -15,12 +15,12 @@ DROP TABLE WITH_READ_ONLY; CREATE TABLE LEGO_SET ( - "id1" SERIAL PRIMARY KEY, - NAME VARCHAR(30) + "id1" SERIAL PRIMARY KEY, + NAME VARCHAR(30) ); CREATE TABLE MANUAL ( - "id2" SERIAL PRIMARY KEY, + "id2" SERIAL PRIMARY KEY, LEGO_SET BIGINT, ALTERNATIVE BIGINT, CONTENT VARCHAR(2000) @@ -32,7 +32,7 @@ ALTER TABLE MANUAL CREATE TABLE ONE_TO_ONE_PARENT ( - "id3" SERIAL PRIMARY KEY, + "id3" SERIAL PRIMARY KEY, content VARCHAR(30) ); CREATE TABLE Child_No_Id @@ -43,9 +43,10 @@ CREATE TABLE Child_No_Id CREATE TABLE LIST_PARENT ( - "id4" SERIAL PRIMARY KEY, - NAME VARCHAR(100) + "id4" SERIAL PRIMARY KEY, + NAME VARCHAR(100) ); + CREATE TABLE element_no_id ( content VARCHAR(100), @@ -53,14 +54,14 @@ CREATE TABLE element_no_id LIST_PARENT INTEGER ); -CREATE TABLE ARRAY_OWNER +CREATE TABLE "ARRAY_OWNER" ( ID SERIAL PRIMARY KEY, DIGITS VARCHAR(20)[10], MULTIDIMENSIONAL VARCHAR(20)[10][10] ); -CREATE TABLE BYTE_ARRAY_OWNER RelationalPersistentEntityImplUnitTests. +CREATE TABLE BYTE_ARRAY_OWNER ( ID SERIAL PRIMARY KEY, BINARY_DATA BYTEA NOT NULL @@ -305,7 +306,7 @@ CREATE TABLE NO_ID_MAP_CHAIN0 ) ); -CREATE TABLE VERSIONED_AGGREGATE +CREATE TABLE "VERSIONED_AGGREGATE" ( ID SERIAL PRIMARY KEY, VERSION BIGINT diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-mysql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-mysql.sql index c9a201e6..c8ae948d 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-mysql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-mysql.sql @@ -1,2 +1,11 @@ -CREATE TABLE dummy_entity (id BIGINT AUTO_INCREMENT PRIMARY KEY, TEST VARCHAR(100)); -CREATE TABLE dummy_entity2 (id BIGINT AUTO_INCREMENT PRIMARY KEY, TEST VARCHAR(100), PREFIX_ATTR BIGINT); +CREATE TABLE dummy_entity +( + ID BIGINT AUTO_INCREMENT PRIMARY KEY, + TEST VARCHAR(100) +); +CREATE TABLE dummy_entity2 +( + ID BIGINT PRIMARY KEY, + TEST VARCHAR(100), + PREFIX_ATTR BIGINT +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-postgres.sql index 13d7c6a1..fa4b1a13 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-postgres.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-postgres.sql @@ -1,4 +1,13 @@ DROP TABLE dummy_entity; -CREATE TABLE dummy_entity (id SERIAL PRIMARY KEY, TEST VARCHAR(100)); +CREATE TABLE dummy_entity +( + "ID" SERIAL PRIMARY KEY, + TEST VARCHAR(100) +); DROP TABLE dummy_entity2; -CREATE TABLE dummy_entity2 (id SERIAL PRIMARY KEY, TEST VARCHAR(100), PREFIX_ATTR BIGINT); +CREATE TABLE dummy_entity2 +( + "ID" INTEGER PRIMARY KEY, + TEST VARCHAR(100), + PREFIX_ATTR BIGINT +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-postgres.sql index fa9cff08..4b49f1ef 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-postgres.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-postgres.sql @@ -1,4 +1,15 @@ DROP TABLE dummy_entity; -CREATE TABLE dummy_entity (id SERIAL PRIMARY KEY, TEST VARCHAR(100), PREFIX_TEST VARCHAR(100)); +CREATE TABLE dummy_entity +( + "ID" SERIAL PRIMARY KEY, + TEST VARCHAR(100), + PREFIX_TEST VARCHAR(100) +); DROP TABLE dummy_entity2; -CREATE TABLE dummy_entity2 (id BIGINT, ORDER_KEY BIGINT, TEST VARCHAR(100), PRIMARY KEY (id, ORDER_KEY)); +CREATE TABLE dummy_entity2 +( + "ID" BIGINT, + "ORDER_KEY" BIGINT, + TEST VARCHAR(100), + PRIMARY KEY ("ID", "ORDER_KEY") +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-postgres.sql index c4c8cef0..c8128208 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-postgres.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-postgres.sql @@ -1,4 +1,22 @@ DROP TABLE dummy_entity; -CREATE TABLE dummy_entity (id SERIAL PRIMARY KEY, TEST VARCHAR(100), PREFIX_TEST VARCHAR(100)); +CREATE TABLE dummy_entity +( + "ID" SERIAL PRIMARY KEY, + TEST VARCHAR(100), + PREFIX_TEST VARCHAR(100) +); DROP TABLE dummy_entity2; -CREATE TABLE dummy_entity2 (id SERIAL PRIMARY KEY, TEST VARCHAR(100)); +CREATE TABLE dummy_entity2 +( + "ID" SERIAL PRIMARY KEY, + TEST VARCHAR(100) +); +-- +-- SELECT "dummy_entity"."ID" AS "ID", +-- "dummy_entity"."test" AS "test", +-- "dummy_entity"."prefix_test" AS "prefix_test", +-- "PREFIX_dummyEntity2"."id" AS "prefix_dummyentity2_id", +-- "PREFIX_dummyEntity2"."test" AS "prefix_dummyentity2_test" +-- FROM "dummy_entity" +-- LEFT OUTER JOIN "dummy_entity2" AS "PREFIX_dummyEntity2" ON +-- "PREFIX_dummyEntity2"."ID" = "dummy_entity"."ID" \ No newline at end of file diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/CompositeSqlIdentifier.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/CompositeSqlIdentifier.java index 0995ee9d..16bc8789 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/CompositeSqlIdentifier.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/CompositeSqlIdentifier.java @@ -32,6 +32,7 @@ class CompositeSqlIdentifier implements SqlIdentifier { private final SqlIdentifier[] parts; CompositeSqlIdentifier(SqlIdentifier... parts) { + Assert.notNull(parts, "SqlIdentifier parts must not be null"); Assert.noNullElements(parts, "SqlIdentifier parts must not contain null elements"); Assert.isTrue(parts.length > 0, "SqlIdentifier parts must not be empty"); diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/domain/IdentifierUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/domain/IdentifierUnitTests.java index 64a83b59..f69997db 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/domain/IdentifierUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/domain/IdentifierUnitTests.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; -import org.junit.Ignore; import org.junit.Test; import org.springframework.data.relational.core.sql.IdentifierProcessing; @@ -35,7 +34,6 @@ import org.springframework.data.relational.core.sql.SqlIdentifier; * @author Jens Schauder * @author Mark Paluch */ -@Ignore public class IdentifierUnitTests { @Test // DATAJDBC-326