
com.github.gkutiel.ParamHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lite Show documentation
Show all versions of lite Show documentation
The best micro sql framework
The newest version!
package com.github.gkutiel;
import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
interface ParamHandler {
static class BigDecimalHandler implements ParamHandler {
@Override public BigDecimal get(final ResultSet rs, final String colName) throws SQLException {
return rs.getBigDecimal(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setBigDecimal(paramIndex, (BigDecimal) param);
}
}
static class BlobHandler implements ParamHandler {
@Override public Blob get(final ResultSet rs, final String colName) throws SQLException {
return rs.getBlob(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setBlob(paramIndex, (Blob) param);
}
}
static class BooleanHandler implements ParamHandler {
@Override public Boolean get(final ResultSet rs, final String colName) throws SQLException {
return rs.getBoolean(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setBoolean(paramIndex, (boolean) param);
}
}
static class ByteHandler implements ParamHandler {
@Override public Byte get(final ResultSet rs, final String colName) throws SQLException {
return rs.getByte(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setByte(paramIndex, (byte) param);
}
}
static class DateHandler implements ParamHandler {
@Override public Date get(final ResultSet rs, final String colName) throws SQLException {
return rs.getDate(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setDate(paramIndex, (Date) param);
}
}
static class DoubleHandler implements ParamHandler {
@Override public Double get(final ResultSet rs, final String colName) throws SQLException {
return rs.getDouble(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setDouble(paramIndex, (double) param);
}
}
static class IntHandler implements ParamHandler {
@Override public Integer get(final ResultSet rs, final String colName) throws SQLException {
return rs.getInt(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setInt(paramIndex, (int) param);
}
}
static class LongHandler implements ParamHandler {
@Override public Long get(final ResultSet rs, final String colName) throws SQLException {
return rs.getLong(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setLong(paramIndex, (long) param);
}
}
static class StringHandler implements ParamHandler {
@Override public String get(final ResultSet rs, final String colName) throws SQLException {
return rs.getString(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setString(paramIndex, (String) param);
}
}
static class UUIDHandler implements ParamHandler {
@Override public UUID get(final ResultSet rs, final String colName) throws SQLException {
return (UUID) rs.getObject(colName);
}
@Override public void set(final PreparedStatement ps, final int paramIndex, final Object param)
throws SQLException {
ps.setObject(paramIndex, param);
}
}
T get(ResultSet rs, String colName) throws SQLException;
void set(PreparedStatement ps, int paramIndex, Object param) throws SQLException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy