-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from itsallcode/convert-legacy-data-types
Allow converting legacy types Timestamp & Date
- Loading branch information
Showing
25 changed files
with
644 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
rootProject.name = 'simple-jdbc' | ||
|
||
|
||
dependencyResolutionManagement { | ||
repositories { | ||
mavenCentral() | ||
} | ||
versionCatalogs { | ||
libs { | ||
library('assertj', 'org.assertj:assertj-core:3.24.2') | ||
library('h2', 'com.h2database:h2:2.2.224') | ||
library('junitPioneer', 'org.junit-pioneer:junit-pioneer:2.2.0') | ||
library('equalsverifier', 'nl.jqno.equalsverifier:equalsverifier:3.15.3') | ||
library('tostringverifier', 'com.jparams:to-string-verifier:1.4.8') | ||
library('hamcrest', 'org.hamcrest:hamcrest-all:1.3') | ||
library('hamcrestResultSetMatcher', 'com.exasol:hamcrest-resultset-matcher:1.6.3') | ||
library('mockito', 'org.mockito:mockito-core:5.7.0') | ||
library('slf4jLogger', 'org.slf4j:slf4j-jdk14:2.0.9') | ||
library('exasolJdbc', 'com.exasol:exasol-jdbc:7.1.20') | ||
library('exasolTestcontainers', 'com.exasol:exasol-testcontainers:7.0.0') | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/integrationTest/java/org/itsallcode/jdbc/LegacyTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.itsallcode.jdbc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.util.stream.Stream; | ||
|
||
import org.itsallcode.jdbc.resultset.Row; | ||
import org.itsallcode.jdbc.resultset.SimpleResultSet; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import com.exasol.containers.ExasolContainer; | ||
import com.exasol.containers.ExasolService; | ||
|
||
class LegacyTypeITest { | ||
|
||
private static final ExasolContainer<?> container = new ExasolContainer<>("8.23.1") | ||
.withRequiredServices(ExasolService.JDBC).withReuse(true); | ||
|
||
@BeforeAll | ||
static void startDb() { | ||
container.start(); | ||
} | ||
|
||
@AfterAll | ||
static void stopDb() { | ||
container.stop(); | ||
} | ||
|
||
SimpleConnection connect() { | ||
return ConnectionFactory.create(Context.builder().useModernTypes(true).build()).create(container.getJdbcUrl(), | ||
container.getUsername(), container.getPassword()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("testTypes") | ||
void type(final TypeTest test) { | ||
try (SimpleResultSet<Row> result = connect() | ||
.query("select cast('" + test.value() + "' as " + test.type() + ")")) { | ||
final Object value = result.toList().get(0).getColumnValue(0).getValue(); | ||
assertAll( | ||
() -> assertThat(value.getClass()).isEqualTo(test.expectedValue().getClass()), | ||
() -> assertThat(value).isEqualTo(test.expectedValue())); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("testTypes") | ||
void nullValue(final TypeTest test) { | ||
try (SimpleResultSet<Row> result = connect() | ||
.query("select cast(NULL as " + test.type() + ")")) { | ||
assertThat(result.toList().get(0).getColumnValue(0).getValue()) | ||
.isNull(); | ||
} | ||
} | ||
|
||
static Stream<Arguments> testTypes() { | ||
return Stream.of( | ||
typeTest("2023-11-25 16:18:46", "timestamp", Instant.parse("2023-11-25T16:18:46.0Z")), | ||
typeTest("2023-11-25", "date", LocalDate.parse("2023-11-25")), | ||
typeTest("5-3", "INTERVAL YEAR TO MONTH", "+05-03"), | ||
typeTest("2 12:50:10.123", "INTERVAL DAY TO SECOND", "+02 12:50:10.123"), | ||
typeTest("POINT(1 2)", "GEOMETRY", "POINT (1 2)"), | ||
typeTest("550e8400-e29b-11d4-a716-446655440000", "HASHTYPE", "550e8400e29b11d4a716446655440000"), | ||
typeTest("text", "VARCHAR(10)", "text"), | ||
typeTest("text", "CHAR(10)", "text "), | ||
typeTest("123.456", "DECIMAL", 123L), | ||
typeTest("123.457", "DECIMAL(6,3)", BigDecimal.valueOf(123.457d)), | ||
typeTest("123.458", "DOUBLE PRECISION", 123.458d), | ||
typeTest("true", "BOOLEAN", true)); | ||
} | ||
|
||
private static Arguments typeTest(final String value, final String type, final Object expectedValue) { | ||
return Arguments.of(new TypeTest(value, type, expectedValue)); | ||
} | ||
|
||
record TypeTest(String value, String type, Object expectedValue) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.