io.ifar.skidroad.jdbi.JodaArgumentFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of skid-road-jdbi Show documentation
Show all versions of skid-road-jdbi Show documentation
Provides JDBI-based LogFileTracker implementation
package io.ifar.skidroad.jdbi;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.Argument;
import org.skife.jdbi.v2.tweak.ArgumentFactory;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
/**
*
*/
public class JodaArgumentFactory implements ArgumentFactory
{
@Override public boolean accepts(final Class> expectedType, final Object value, final StatementContext ctx)
{
return value != null && DateTime.class.isAssignableFrom(value.getClass());
}
@Override public Argument build(final Class> expectedType, final DateTime value, final StatementContext ctx)
{
return new Argument()
{
@Override public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException
{
statement.setTimestamp(position, new Timestamp(value.toDate().getTime()));
}
public String toString() {
return value == null ? null : value.toString();
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy