Skip to content

DATAJDBC-257 - Adds DB2 support. … #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh './accept-third-party-license.sh'
sh 'mkdir -p /tmp/jenkins-home'
sh 'chown -R 1001:1001 .'
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,all-dbs clean dependency:list test -Dsort -U -B'
Expand All @@ -55,6 +56,7 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh './accept-third-party-license.sh'
sh 'mkdir -p /tmp/jenkins-home'
sh 'chown -R 1001:1001 .'
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,all-dbs,java11 clean dependency:list test -Dsort -U -B'
Expand All @@ -73,7 +75,8 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'mkdir -p /tmp/jenkins-home'
sh './accept-third-party-license.sh'
sh 'mkdir -p /tmp/jenkins-home'
sh 'chown -R 1001:1001 .'
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,all-dbs,java11 clean dependency:list test -Dsort -U -B'
sh 'chown -R 1001:1001 .'
Expand Down
6 changes: 6 additions & 0 deletions accept-third-party-license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

{
echo "mcr.microsoft.com/mssql/server:2017-CU12"
echo "ibmcom/db2:11.5.0.0a"
} > spring-data-jdbc/src/test/resources/container-license-acceptance.txt
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAJDBC-257-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand All @@ -25,6 +25,7 @@

<degraph-check.version>0.1.4</degraph-check.version>

<db2.version>11.5.0.0</db2.version>
<h2.version>1.4.200</h2.version>
<hsqldb.version>2.2.8</hsqldb.version>
<mssql.version>7.0.0.jre8</mssql.version>
Expand Down Expand Up @@ -170,6 +171,24 @@
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>db2-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>db2</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<!--<execution>-->
<!--<id>mssql-test</id>-->
<!--<phase>test</phase>-->
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAJDBC-257-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
16 changes: 14 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAJDBC-257-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAJDBC-257-SNAPSHOT</version>
</parent>

<properties>
Expand Down Expand Up @@ -186,6 +186,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.1.4.4</version>
</dependency>

<dependency>
<groupId>de.schauderhaft.degraph</groupId>
<artifactId>degraph-check</artifactId>
Expand Down Expand Up @@ -223,6 +229,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>db2</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.data.relational.core.dialect.Db2Dialect;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.H2Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
Expand Down Expand Up @@ -123,7 +124,9 @@ private static Dialect getDialect(Connection connection) throws SQLException {
if (name.contains("microsoft")) {
return SqlServerDialect.INSTANCE;
}

if (name.contains("db2")) {
return Db2Dialect.INSTANCE;
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ public void saveAndLoadAnEntityWithArray() {
assumeNot("mysql");
assumeNot("mariadb");
assumeNot("mssql");
assumeNot("db2");

ArrayOwner arrayOwner = new ArrayOwner();
arrayOwner.digits = new String[] { "one", "two", "three" };
Expand All @@ -539,6 +540,7 @@ public void saveAndLoadAnEntityWithMultidimensionalArray() {
assumeNot("mariadb");
assumeNot("mssql");
assumeNot("hsqldb");
assumeNot("db2");

ArrayOwner arrayOwner = new ArrayOwner();
arrayOwner.multidimensional = new String[][] { { "one-a", "two-a", "three-a" }, { "one-b", "two-b", "three-b" } };
Expand All @@ -563,6 +565,7 @@ public void saveAndLoadAnEntityWithList() {
assumeNot("mysql");
assumeNot("mariadb");
assumeNot("mssql");
assumeNot("db2");

ListOwner arrayOwner = new ListOwner();
arrayOwner.digits.addAll(Arrays.asList("one", "two", "three"));
Expand All @@ -586,6 +589,7 @@ public void saveAndLoadAnEntityWithSet() {
assumeNot("mysql");
assumeNot("mariadb");
assumeNot("mssql");
assumeNot("db2");

SetOwner setOwner = new SetOwner();
setOwner.digits.addAll(Arrays.asList("one", "two", "three"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@

import lombok.Value;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.junit.Assume;
import org.assertj.core.api.SoftAssertions;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -42,7 +40,7 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.ProfileValueUtils;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -55,7 +53,8 @@
* @author Mark Paluch
*/
@Transactional
public class QueryAnnotationIntegrationTests {
@ActiveProfiles("hsql")
public class QueryAnnotationHsqlIntegrationTests {

@Configuration
@Import(TestConfiguration.class)
Expand All @@ -64,7 +63,7 @@ static class Config {

@Bean
Class<?> testClass() {
return QueryAnnotationIntegrationTests.class;
return QueryAnnotationHsqlIntegrationTests.class;
}
}

Expand All @@ -76,8 +75,6 @@ Class<?> testClass() {
@Test // DATAJDBC-164
public void executeCustomQueryWithoutParameter() {

assumeNot("mysql");

repository.save(dummyEntity("Example"));
repository.save(dummyEntity("example"));
repository.save(dummyEntity("EXAMPLE"));
Expand Down Expand Up @@ -180,8 +177,6 @@ public void executeCustomQueryWithReturnTypeIsStream() {
@Test // DATAJDBC-175
public void executeCustomQueryWithReturnTypeIsNumber() {

assumeNot("mysql");

repository.save(dummyEntity("aaa"));
repository.save(dummyEntity("bbb"));
repository.save(dummyEntity("cac"));
Expand All @@ -194,40 +189,29 @@ public void executeCustomQueryWithReturnTypeIsNumber() {
@Test // DATAJDBC-175
public void executeCustomQueryWithReturnTypeIsBoolean() {

assumeNot("mysql");

repository.save(dummyEntity("aaa"));
repository.save(dummyEntity("bbb"));
repository.save(dummyEntity("cac"));

assertThat(repository.existsByNameContaining("a")).isTrue();
assertThat(repository.existsByNameContaining("d")).isFalse();
SoftAssertions.assertSoftly(softly -> {

softly.assertThat(repository.existsByNameContaining("a")).describedAs("entities with A in the name").isTrue();
softly.assertThat(repository.existsByNameContaining("d")).describedAs("entities with D in the name").isFalse();
});
}

@Test // DATAJDBC-175
public void executeCustomQueryWithReturnTypeIsDate() {

assumeNot("mysql");

// Since Timestamp extends Date the repository returns the Timestamp as it comes from the database.
// Trying to compare that to an actual Date results in non deterministic results, so we have to use an actual
// Timestamp.
Date now = new Timestamp(System.currentTimeMillis());
assertThat(repository.nowWithDate()).isAfterOrEqualsTo(now);

assertThat(repository.nowWithDate()).isInstanceOf(Date.class);
}

@Test // DATAJDBC-175
public void executeCustomQueryWithReturnTypeIsLocalDateTimeList() {

// mysql does not support plain VALUES(…)
assumeNot("mysql");

LocalDateTime preciseNow = LocalDateTime.now();
LocalDateTime truncatedNow = truncateSubmillis(preciseNow);

repository.nowWithLocalDateTimeList() //
.forEach(d -> assertThat(d).isAfterOrEqualTo(truncatedNow));
assertThat(repository.nowWithLocalDateTimeList()) //
.hasSize(2) //
.allSatisfy(d -> assertThat(d).isInstanceOf(LocalDateTime.class));
}

@Test // DATAJDBC-182
Expand Down Expand Up @@ -270,33 +254,16 @@ public void executeCustomModifyingQueryWithReturnTypeVoid() {
@Test // DATAJDBC-175
public void executeCustomQueryWithImmutableResultType() {

// mysql does not support plain VALUES(…)

assumeNot("mysql");

assertThat(repository.immutableTuple()).isEqualTo(new DummyEntityRepository.ImmutableTuple("one", "two", 3));
}

private static LocalDateTime truncateSubmillis(LocalDateTime now) {

int NANOS_IN_MILLIS = 1_000_000;
return now.withNano((now.getNano() / NANOS_IN_MILLIS) * 1_000_000);
}

private DummyEntity dummyEntity(String name) {

DummyEntity entity = new DummyEntity();
entity.name = name;
return entity;
}

private static void assumeNot(String dbProfileName) {

Assume.assumeTrue(
"true".equalsIgnoreCase(ProfileValueUtils.retrieveProfileValueSource(QueryAnnotationIntegrationTests.class)
.get("current.database.is.not." + dbProfileName)));
}

private static class DummyEntity {

@Id Long id;
Expand Down Expand Up @@ -327,11 +294,11 @@ private interface DummyEntityRepository extends CrudRepository<DummyEntity, Long
Stream<DummyEntity> findAllWithReturnTypeIsStream();

// DATAJDBC-175
@Query("SELECT count(*) FROM DUMMY_ENTITY WHERE name like '%' || :name || '%'")
@Query("SELECT count(*) FROM DUMMY_ENTITY WHERE name like concat('%', :name, '%')")
int countByNameContaining(@Param("name") String name);

// DATAJDBC-175
@Query("SELECT count(*) FROM DUMMY_ENTITY WHERE name like '%' || :name || '%'")
@Query("SELECT case when count(*) > 0 THEN 'true' ELSE 'false' END FROM DUMMY_ENTITY WHERE name like '%' || :name || '%'")
boolean existsByNameContaining(@Param("name") String name);

// DATAJDBC-175
Expand All @@ -358,7 +325,7 @@ private interface DummyEntityRepository extends CrudRepository<DummyEntity, Long
void insert(@Param("name") String name);

// DATAJDBC-252
@Query("SELECT 'one' one, 'two' two, 3 three FROM (VALUES (0))")
@Query("SELECT 'one' one, 'two' two, 3 three FROM (VALUES (0)) as tableName")
ImmutableTuple immutableTuple();

@Value
Expand Down
Loading