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

com.github.gkutiel.ParamHandler Maven / Gradle / Ivy

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;

interface ParamHandler {

	static class BigDecimalHandler implements ParamHandler {

		@Override
		public BigDecimal get(final ResultSet rs, final int paramIndex) throws SQLException {
			return rs.getBigDecimal(paramIndex);
		}

		@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 int paramIndex) throws SQLException {
			return rs.getBlob(paramIndex);
		}

		@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 int paramIndex) throws SQLException {
			return rs.getBoolean(paramIndex);
		}

		@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 int paramIndex) throws SQLException {
			return rs.getByte(paramIndex);
		}

		@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 int paramIndex) throws SQLException {
			return rs.getDate(paramIndex);
		}

		@Override
		public void set(final PreparedStatement ps, final int paramIndex, final Object param) throws SQLException {
			ps.setDate(paramIndex, (Date) param);
		}
	}

	static class IntHandler implements ParamHandler {

		@Override
		public Integer get(final ResultSet rs, final int paramIndex) throws SQLException {
			return rs.getInt(paramIndex);
		}

		@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 int paramIndex) throws SQLException {
			return rs.getLong(paramIndex);
		}

		@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 int paramIndex) throws SQLException {
			return rs.getString(paramIndex);
		}

		@Override
		public void set(final PreparedStatement ps, final int paramIndex, final Object param) throws SQLException {
			ps.setString(paramIndex, (String) param);
		}
	}

	T get(ResultSet rs, int paramIndex) throws SQLException;
	void set(PreparedStatement ps, int paramIndex, Object param) throws SQLException;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy