tech.ydb.jooq.binding.DateBinding 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.LocalDate;
import static tech.ydb.jooq.binding.BindingTools.indexType;
@SuppressWarnings("resource")
public final class DateBinding extends AbstractBinding {
private static final int INDEX_TYPE = indexType(PrimitiveType.Date);
@Override
public Converter converter() {
return new IdentityConverter<>(LocalDate.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.newDate(ctx.value()), INDEX_TYPE);
}
}
@Override
public void get(BindingGetResultSetContext ctx) throws SQLException {
LocalDate value = (LocalDate) ctx.resultSet().getObject(ctx.index());
ctx.value(value);
}
}