package com.github.fjdbc.util;

import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Keeps track if the statement is a batch statement or a single statement.
 */
public class PreparedStatementEx extends PreparedStatementDelegate {
	//@formatter:off
	public static final Set<Class<?>> jdbcTypes = new HashSet<>(Arrays.asList(
		String.class,
		BigDecimal.class,
		Boolean.class,
		Integer.class,
		Long.class,
		Float.class,
		Double.class,
		byte[].class,
		java.sql.Date.class,
		Time.class,
		Timestamp.class,
		Clob.class,
		Blob.class,
		Array.class,
		Ref.class,
		URL.class
	));
	//@formatter:on
	private boolean isBatch = false;

	public PreparedStatementEx(PreparedStatement ps) {
		super(ps);
	}

	@Override
	public void addBatch(String sql) throws SQLException {
		super.addBatch(sql);
		isBatch = true;
	}

	@Override
	public void addBatch() throws SQLException {
		super.addBatch();
		isBatch = true;
	}

	@Override
	public void clearBatch() throws SQLException {
		super.clearBatch();
		isBatch = false;
	}

	public boolean isBatch() {
		return isBatch;
	}

	public <T> void setAnyObject(int columnIndex, Object o, Class<T> type) throws SQLException {
		// if (o == null) {
		// ps.setNull(columnIndex, java.sql.Types.OTHER);
		if (type.equals(String.class)) {
			ps.setString(columnIndex, (String) o);
		} else if (type.equals(BigDecimal.class)) {
			ps.setBigDecimal(columnIndex, (BigDecimal) o);
		} else if (type.equals(Boolean.class)) {
			ps.setBoolean(columnIndex, (Boolean) o);
		} else if (type.equals(Integer.class)) {
			ps.setInt(columnIndex, (Integer) o);
		} else if (type.equals(Long.class)) {
			ps.setLong(columnIndex, (Long) o);
		} else if (type.equals(Float.class)) {
			ps.setFloat(columnIndex, (Float) o);
		} else if (type.equals(Double.class)) {
			ps.setDouble(columnIndex, (Double) o);
		} else if (type.equals(byte[].class)) {
			ps.setBytes(columnIndex, (byte[]) o);
		} else if (type.equals(java.sql.Date.class)) {
			ps.setDate(columnIndex, (Date) o);
		} else if (type.equals(Time.class)) {
			ps.setTime(columnIndex, (Time) o);
		} else if (type.equals(Timestamp.class)) {
			ps.setTimestamp(columnIndex, (Timestamp) o);
		} else if (type.equals(Clob.class)) {
			ps.setClob(columnIndex, (Clob) o);
		} else if (type.equals(Blob.class)) {
			ps.setBlob(columnIndex, (Blob) o);
		} else if (type.equals(Array.class)) {
			ps.setArray(columnIndex, (Array) o);
		} else if (type.equals(Ref.class)) {
			ps.setRef(columnIndex, (Ref) o);
		} else if (type.equals(URL.class)) {
			ps.setURL(columnIndex, (URL) o);
		}
	}

}

@@ -1437,1537 +1437,7 @@
 %09%7D%0D%0A
-%0D%0A%09public %3CT%3E void setAnyObject(int columnIndex, Object o, Class%3CT%3E type) throws SQLException %7B%0D%0A%09%09// if (o == null) %7B%0D%0A%09%09// ps.setNull(columnIndex, java.sql.Types.OTHER);%0D%0A%09%09if (type.equals(String.class)) %7B%0D%0A%09%09%09ps.setString(columnIndex, (String) o);%0D%0A%09%09%7D else if (type.equals(BigDecimal.class)) %7B%0D%0A%09%09%09ps.setBigDecimal(columnIndex, (BigDecimal) o);%0D%0A%09%09%7D else if (type.equals(Boolean.class)) %7B%0D%0A%09%09%09ps.setBoolean(columnIndex, (Boolean) o);%0D%0A%09%09%7D else if (type.equals(Integer.class)) %7B%0D%0A%09%09%09ps.setInt(columnIndex, (Integer) o);%0D%0A%09%09%7D else if (type.equals(Long.class)) %7B%0D%0A%09%09%09ps.setLong(columnIndex, (Long) o);%0D%0A%09%09%7D else if (type.equals(Float.class)) %7B%0D%0A%09%09%09ps.setFloat(columnIndex, (Float) o);%0D%0A%09%09%7D else if (type.equals(Double.class)) %7B%0D%0A%09%09%09ps.setDouble(columnIndex, (Double) o);%0D%0A%09%09%7D else if (type.equals(byte%5B%5D.class)) %7B%0D%0A%09%09%09ps.setBytes(columnIndex, (byte%5B%5D) o);%0D%0A%09%09%7D else if (type.equals(java.sql.Date.class)) %7B%0D%0A%09%09%09ps.setDate(columnIndex, (Date) o);%0D%0A%09%09%7D else if (type.equals(Time.class)) %7B%0D%0A%09%09%09ps.setTime(columnIndex, (Time) o);%0D%0A%09%09%7D else if (type.equals(Timestamp.class)) %7B%0D%0A%09%09%09ps.setTimestamp(columnIndex, (Timestamp) o);%0D%0A%09%09%7D else if (type.equals(Clob.class)) %7B%0D%0A%09%09%09ps.setClob(columnIndex, (Clob) o);%0D%0A%09%09%7D else if (type.equals(Blob.class)) %7B%0D%0A%09%09%09ps.setBlob(columnIndex, (Blob) o);%0D%0A%09%09%7D else if (type.equals(Array.class)) %7B%0D%0A%09%09%09ps.setArray(columnIndex, (Array) o);%0D%0A%09%09%7D else if (type.equals(Ref.class)) %7B%0D%0A%09%09%09ps.setRef(columnIndex, (Ref) o);%0D%0A%09%09%7D else if (type.equals(URL.class)) %7B%0D%0A%09%09%09ps.setURL(columnIndex, (URL) o);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A
 %7D%0D%0A

remove dead code