io.dropwizard.jdbi.args.LocalDateMapper Maven / Gradle / Ivy
package io.dropwizard.jdbi.args;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.ResultColumnMapper;
import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDate;
/**
* A {@link ResultColumnMapper} to map {@link LocalDate} objects.
*/
public class LocalDateMapper implements ResultColumnMapper {
@Override
@Nullable
public LocalDate mapColumn(ResultSet r, String columnLabel, StatementContext ctx) throws SQLException {
final Timestamp timestamp = r.getTimestamp(columnLabel);
if (timestamp == null) {
return null;
}
return timestamp.toLocalDateTime().toLocalDate();
}
@Override
@Nullable
public LocalDate mapColumn(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException {
final Timestamp timestamp = r.getTimestamp(columnNumber);
if (timestamp == null) {
return null;
}
return timestamp.toLocalDateTime().toLocalDate();
}
}