Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 3 additions & 2 deletions jooq-dialect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>tech.ydb.dialects</groupId>
<artifactId>jooq-ydb-dialect</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>

<name>YDB JOOQ Dialect module</name>
<description>YDB JOOQ Dialect module</description>
Expand Down Expand Up @@ -53,7 +53,7 @@
<jooq.version>3.19.0</jooq.version>

<ydb.sdk.version>2.3.8</ydb.sdk.version>
<ydb.jdbc.version>2.3.7</ydb.jdbc.version>
<ydb.jdbc.version>2.3.11</ydb.jdbc.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -134,6 +134,7 @@
<configuration>
<environmentVariables>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
<YDB_DOCKER_IMAGE>ydbplatform/local-ydb:trunk</YDB_DOCKER_IMAGE>
</environmentVariables>
</configuration>
</plugin>
Expand Down
7 changes: 6 additions & 1 deletion jooq-dialect/src/main/java/tech/ydb/jooq/YdbTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ public static DataType<BigDecimal> DECIMAL(int precision, int scale) {
public static final DataType<LocalDate> DATE = newDataType(SQLDataType.LOCALDATE, "date", new DateBinding());
public static final DataType<LocalDateTime> DATETIME = newDataType(SQLDataType.LOCALDATETIME, "datetime", new DatetimeBinding());
public static final DataType<Instant> TIMESTAMP = newDataType(SQLDataType.INSTANT, "timestamp", new TimestampBinding());
public static final DataType<Duration> INTERVAL = newDataType(SQLDataType.BIGINTUNSIGNED, "interval", new IntervalBinding());
public static final DataType<Duration> INTERVAL = newDataType(SQLDataType.INTERVAL, "interval", new IntervalBinding());

public static final DataType<LocalDate> DATE32 = newDataType(SQLDataType.LOCALDATE, "date32", new Date32Binding());
public static final DataType<LocalDateTime> DATETIME64 = newDataType(SQLDataType.LOCALDATETIME, "datetime64", new Datetime64Binding());
public static final DataType<Instant> TIMESTAMP64 = newDataType(SQLDataType.INSTANT, "timestamp64", new Timestamp64Binding());
public static final DataType<Duration> INTERVAL64 = newDataType(SQLDataType.INTERVAL, "interval64", new Interval64Binding());

public static final DataType<ZonedDateTime> TZ_DATE = newDataType(SQLDataType.OTHER, "tzdate", new TzDateBinding());
public static final DataType<ZonedDateTime> TZ_DATETIME = newDataType(SQLDataType.OTHER, "tzdateTime", new TzDatetimeBinding());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tech.ydb.jooq.binding;

import java.sql.SQLException;
import java.time.LocalDate;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.impl.AbstractBinding;
import org.jooq.impl.IdentityConverter;
import static tech.ydb.jooq.binding.BindingTools.indexType;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

public final class Date32Binding extends AbstractBinding<LocalDate, LocalDate> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Date32);

@Override
public Converter<LocalDate, LocalDate> converter() {
return new IdentityConverter<>(LocalDate.class);
}

@Override
public void set(BindingSetStatementContext<LocalDate> ctx) throws SQLException {
if (ctx.value() == null) {
ctx.statement().setNull(ctx.index(), INDEX_TYPE);
} else {
ctx.statement().setObject(ctx.index(), PrimitiveValue.newDate32(ctx.value()), INDEX_TYPE);
}
}

@Override
public void get(BindingGetResultSetContext<LocalDate> ctx) throws SQLException {
LocalDate value = (LocalDate) ctx.resultSet().getObject(ctx.index());
ctx.value(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class DateBinding extends AbstractBinding<LocalDate, LocalDate> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Date);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tech.ydb.jooq.binding;

import java.sql.SQLException;
import java.time.LocalDateTime;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.impl.AbstractBinding;
import org.jooq.impl.IdentityConverter;
import static tech.ydb.jooq.binding.BindingTools.indexType;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

public final class Datetime64Binding extends AbstractBinding<LocalDateTime, LocalDateTime> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Datetime64);

@Override
public Converter<LocalDateTime, LocalDateTime> converter() {
return new IdentityConverter<>(LocalDateTime.class);
}

@Override
public void set(BindingSetStatementContext<LocalDateTime> ctx) throws SQLException {
if (ctx.value() == null) {
ctx.statement().setNull(ctx.index(), INDEX_TYPE);
} else {
ctx.statement().setObject(ctx.index(), PrimitiveValue.newDatetime64(ctx.value()), INDEX_TYPE);
}
}

@Override
public void get(BindingGetResultSetContext<LocalDateTime> ctx) throws SQLException {
LocalDateTime value = (LocalDateTime) ctx.resultSet().getObject(ctx.index());
ctx.value(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class DatetimeBinding extends AbstractBinding<LocalDateTime, LocalDateTime> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Datetime);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package tech.ydb.jooq.binding;

import java.sql.SQLException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.impl.AbstractBinding;
import org.jooq.types.ULong;
import static tech.ydb.jooq.binding.BindingTools.indexType;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

/**
* @author Kirill Kurdyukov
*/
public class Interval64Binding extends AbstractBinding<ULong, Duration> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Interval64);

@Override
public Converter<ULong, Duration> converter() {
return new IntervalConverter();
}

@Override
public void set(BindingSetStatementContext<Duration> ctx) throws SQLException {
if (ctx.value() == null) {
ctx.statement().setNull(ctx.index(), INDEX_TYPE);
} else {
ctx.statement().setObject(ctx.index(), PrimitiveValue.newInterval64(ctx.value()), INDEX_TYPE);
}
}

@Override
public void get(BindingGetResultSetContext<Duration> ctx) throws SQLException {
Duration value = (Duration) ctx.resultSet().getObject(ctx.index());
ctx.value(value);
}

private static class IntervalConverter implements Converter<ULong, Duration> {

@Override
public Duration from(ULong databaseObject) {
return Duration.of(databaseObject.longValue(), ChronoUnit.MICROS);
}

@Override
public ULong to(Duration userObject) {
return ULong.valueOf(TimeUnit.NANOSECONDS.toMicros(userObject.toNanos()));
}

@Override
public Class<ULong> fromType() {
return ULong.class;
}

@Override
public Class<Duration> toType() {
return Duration.class;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

@SuppressWarnings("resource")
public final class IntervalBinding extends AbstractBinding<YearToSecond, Duration> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Interval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class JsonBinding extends AbstractBinding<JSON, JSON> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

@SuppressWarnings("resource")
public final class JsonDocumentBinding extends AbstractBinding<JSONB, JSONB> {

private static final int INDEX_TYPE = indexType(PrimitiveType.JsonDocument);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tech.ydb.jooq.binding;

import java.sql.SQLException;
import java.time.Instant;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.impl.AbstractBinding;
import org.jooq.impl.IdentityConverter;
import static tech.ydb.jooq.binding.BindingTools.indexType;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

/**
* @author Kirill Kurdyukov
*/
public class Timestamp64Binding extends AbstractBinding<Instant, Instant> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Timestamp64);

@Override
public Converter<Instant, Instant> converter() {
return new IdentityConverter<>(Instant.class);
}

@Override
public void set(BindingSetStatementContext<Instant> ctx) throws SQLException {
if (ctx.value() == null) {
ctx.statement().setNull(ctx.index(), INDEX_TYPE);
} else {
ctx.statement().setObject(ctx.index(), PrimitiveValue.newTimestamp64(ctx.value()), INDEX_TYPE);
}
}

@Override
public void get(BindingGetResultSetContext<Instant> ctx) throws SQLException {
Instant value = (Instant) ctx.resultSet().getObject(ctx.index());
ctx.value(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

@SuppressWarnings("resource")
public final class TimestampBinding extends AbstractBinding<LocalDateTime, Instant> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class TzDateBinding extends AbstractBinding<ZonedDateTime, ZonedDateTime> {

private static final int INDEX_TYPE = indexType(PrimitiveType.TzDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class TzDatetimeBinding extends AbstractBinding<ZonedDateTime, ZonedDateTime> {

private static final int INDEX_TYPE = indexType(PrimitiveType.TzDatetime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;

@SuppressWarnings("resource")
public final class TzTimestampBinding extends AbstractBinding<ZonedDateTime, ZonedDateTime> {

private static final int INDEX_TYPE = indexType(PrimitiveType.TzTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class Uint16Binding extends AbstractBinding<UShort, UShort> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Uint16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class Uint32Binding extends AbstractBinding<UInteger, UInteger> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Uint32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class Uint64Binding extends AbstractBinding<ULong, ULong> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Uint64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class Uint8Binding extends AbstractBinding<UByte, UByte> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Uint8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import static tech.ydb.jooq.binding.BindingTools.indexType;

@SuppressWarnings("resource")
public final class YsonBinding extends AbstractBinding<Object, YSON> {

private static final int INDEX_TYPE = indexType(PrimitiveType.Yson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private TableDefinition getTableDefinition(String tableName, String dirPathFull,
tableName,
"",
tableDescription,
tablePath
tablePath,
getContext().getTypes()
);
}

Expand Down
Loading