package io.dropwizard.jdbi.args;

import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.Argument;

import javax.annotation.Nullable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.LocalDate;

An Argument for LocalDate objects.
/** * An {@link Argument} for {@link LocalDate} objects. */
public class LocalDateArgument implements Argument { @Nullable private final LocalDate value; public LocalDateArgument(@Nullable LocalDate value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setTimestamp(position, Timestamp.valueOf(value.atStartOfDay())); } else { statement.setNull(position, Types.TIMESTAMP); } } }