tech.ydb.jooq.binding.TzDateBinding Maven / Gradle / Ivy
The newest version!
package tech.ydb.jooq.binding;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.impl.AbstractBinding;
import org.jooq.impl.IdentityConverter;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;
import java.sql.SQLException;
import java.time.ZonedDateTime;
import static tech.ydb.jooq.binding.BindingTools.indexType;
@SuppressWarnings("resource")
public final class TzDateBinding extends AbstractBinding {
private static final int INDEX_TYPE = indexType(PrimitiveType.TzDate);
@Override
public Converter converter() {
return new IdentityConverter<>(ZonedDateTime.class);
}
@Override
public void set(BindingSetStatementContext ctx) throws SQLException {
if (ctx.value() == null) {
ctx.statement().setNull(ctx.index(), INDEX_TYPE);
} else {
ctx.statement().setObject(ctx.index(), PrimitiveValue.newTzDate(ctx.value()), INDEX_TYPE);
}
}
@Override
public void get(BindingGetResultSetContext ctx) throws SQLException {
ZonedDateTime value = (ZonedDateTime) ctx.resultSet().getObject(ctx.index());
ctx.value(value);
}
}