All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.jdbi.args.LocalDateArgument Maven / Gradle / Ivy

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 {@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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy