Skip to content

Commit 0db0b36

Browse files
authored
Implement conversion for Oracle TIMESTAMPZ (#1100)
Fixes #1092 Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent d0d4c55 commit 0db0b36

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/Helper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import io.vertx.core.VertxException;
1616
import io.vertx.core.impl.ContextInternal;
1717
import io.vertx.sqlclient.Tuple;
18-
import oracle.jdbc.OraclePreparedStatement;
18+
import oracle.sql.TIMESTAMPTZ;
1919

2020
import java.math.BigDecimal;
2121
import java.sql.*;
@@ -191,6 +191,10 @@ public static Object convertSqlValue(Object value) throws SQLException {
191191
return ((Timestamp) value).toInstant().atOffset(ZoneOffset.UTC);
192192
}
193193

194+
if (value instanceof TIMESTAMPTZ) {
195+
return ((TIMESTAMPTZ) value).toZonedDateTime().toOffsetDateTime();
196+
}
197+
194198
// large objects
195199
if (value instanceof Clob) {
196200
Clob c = (Clob) value;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
12+
package io.vertx.oracleclient.test;
13+
14+
import io.vertx.ext.unit.TestContext;
15+
import io.vertx.ext.unit.junit.VertxUnitRunner;
16+
import io.vertx.oracleclient.OraclePool;
17+
import io.vertx.oracleclient.test.junit.OracleRule;
18+
import io.vertx.sqlclient.PoolOptions;
19+
import org.junit.After;
20+
import org.junit.Before;
21+
import org.junit.ClassRule;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
25+
import java.time.OffsetDateTime;
26+
27+
import static java.time.temporal.ChronoUnit.MINUTES;
28+
import static org.hamcrest.CoreMatchers.instanceOf;
29+
import static org.hamcrest.CoreMatchers.is;
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
import static org.junit.Assert.assertEquals;
32+
33+
@RunWith(VertxUnitRunner.class)
34+
public class OracleQueriesTest extends OracleTestBase {
35+
36+
@ClassRule
37+
public static OracleRule oracle = OracleRule.SHARED_INSTANCE;
38+
39+
OraclePool pool;
40+
41+
@Before
42+
public void setUp() throws Exception {
43+
pool = OraclePool.pool(vertx, oracle.options(), new PoolOptions());
44+
}
45+
46+
@Test
47+
public void testCurrentTimestampType(TestContext ctx) {
48+
pool.query("SELECT CURRENT_TIMESTAMP FROM dual").execute(ctx.asyncAssertSuccess(rows -> {
49+
ctx.verify(v -> {
50+
assertEquals(1, rows.size());
51+
Object value = rows.iterator().next().getValue(0);
52+
assertThat(value, is(instanceOf(OffsetDateTime.class)));
53+
assertEquals(0, MINUTES.between((OffsetDateTime) value, OffsetDateTime.now()));
54+
});
55+
}));
56+
}
57+
58+
@After
59+
public void tearDown(TestContext ctx) throws Exception {
60+
pool.close(ctx.asyncAssertSuccess());
61+
}
62+
}

0 commit comments

Comments
 (0)