net.morimekta.providence.jdbi.v2.EnumValueArgument Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of providence-jdbi-v2 Show documentation
Show all versions of providence-jdbi-v2 Show documentation
Utilities for handling providence messages using jdbi v2.
package net.morimekta.providence.jdbi.v2;
import net.morimekta.providence.PEnumValue;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.Argument;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
public class EnumValueArgument implements Argument {
private final PEnumValue value;
public EnumValueArgument(PEnumValue value) {
this.value = value;
}
@Override
public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException {
if (value == null) {
statement.setNull(position, Types.INTEGER);
} else {
statement.setInt(position, value.asInteger());
}
}
}