Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 0.9.2

### Improvements
- [jdbc-v2] `ResultSetImpl.getObject()` handles `java.time.Instant`

### Improvements
- [jdbc-v2] Classes `com.clickhouse.jdbc.ClientInfoProperties` and `com.clickhouse.jdbc.DriverProperties` moved to public
API. (https://github.com/ClickHouse/clickhouse-java/pull/2521)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
import java.sql.SQLException;
import java.sql.SQLType;
import java.sql.Types;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.*;
import java.time.chrono.ChronoZonedDateTime;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -260,6 +257,8 @@ public static Object convert(Object value, Class<?> type, ClickHouseColumn colum
return OffsetDateTime.from((TemporalAccessor) value);
} else if (type == ZonedDateTime.class && value instanceof TemporalAccessor) {
return ZonedDateTime.from((TemporalAccessor) value);
} else if (type == Instant.class && value instanceof TemporalAccessor) {
return Instant.from((TemporalAccessor) value);
} else if (type == Date.class && value instanceof TemporalAccessor) {
return Date.valueOf(LocalDate.from((TemporalAccessor) value));
} else if (type == java.sql.Timestamp.class && value instanceof TemporalAccessor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
import com.clickhouse.data.ClickHouseColumn;
import org.testng.annotations.Test;
import org.testng.annotations.*;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -78,4 +80,19 @@ public void testConvertToInetAddress() throws Exception {
ClickHouseColumn column = ClickHouseColumn.of("ip", "IPv4");
assertEquals(JdbcUtils.convert(java.net.InetAddress.getByName("192.168.0.1"), java.net.Inet6Address.class, column).toString(), "/0:0:0:0:0:ffff:c0a8:1");
}

@DataProvider(name = "timeZones")
public Object[][] timeZones() {
return new Object[][] {
{ ZoneId.of("UTC") },
{ ZoneId.of("Europe/Paris") },
};
}

@Test(groups = {"unit"})
public void testConvertToJavaTimeInstant() throws Exception {
Instant timestamp = Instant.parse("2016-06-07T21:30:00Z");
assertEquals(JdbcUtils.convert(timestamp.atZone(ZoneId.of("UTC")), Instant.class), timestamp);
assertEquals(JdbcUtils.convert(timestamp.atZone(ZoneId.of("UTC+7")), Instant.class), timestamp);
}
}
Loading