Package GenericDBMS

Source Code of GenericDBMS.BigDecimalParameter

package GenericDBMS;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import Framework.BooleanData;
import Framework.Constants;
import Framework.DynamicArray;
import Framework.LogMgr;
import Framework.ParameterHolder;

import com.sun.rowset.CachedRowSetImpl;

/**
* Note that this class only supports statements, not callable objects. In particular, it assumes that there will
* only be one result set, and it needs to prepare the statement via prepareStatement, not via prepareCall
* @author Tim
*
*/
public class OfflineStatement implements PreparedStatement {

  private abstract class Parameter {
    int index;
    protected Parameter(int index) {
      this.index = index;
    }
    public abstract void set(PreparedStatement stmnt) throws SQLException;
  }
 
  protected static interface StatementWorker {
    public void doWork(PreparedStatement statement)throws SQLException;
  }
 
  protected static StatementWorker noWorker = new StatementWorker() {
    public void doWork(PreparedStatement arg0) throws SQLException {
    }
  };
 
  private List<Parameter> parameters = new DynamicArray<Parameter>();
  private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
  private int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
  private int resultSetHoldability = ResultSet.HOLD_CURSORS_OVER_COMMIT;
  private int fetchDirection = ResultSet.FETCH_FORWARD;
  private int fetchSize = 0;
  private int maxRows = 0;
  private int maxFieldSize = 0;
  private int queryTimeout = 0;
  private int updateCount = 0;
  private boolean escapeProcessing = true;
  private String sql;
  private String cursorName = null;
  private final DBConnectionManager connection;
  private ResultSet resultSet;

  // JVM 1.6 This field is needed for java 1.6 and above, but is fine to leave there in other JVMs
  private boolean isPoolable = false;
 
  /**
   * Construct a new offline statement with the passed connection manager to the database
   * and the passed SQL.
   * <p>
   * By default, constructing this class will connect to the database and prepare the
   * statement and then discard the prepared statement and release the connection. This
   * enables the sql syntax to be verified and if it's invalid a spring database exception
   * will be thrown. This functionality can be disabled by setting the prf:db:4:50 flag.
   * @param pSQL
   * @param pConnMgr
   */
  public OfflineStatement(String pSQL, DBConnectionManager pConnMgr) {
    this.sql = pSQL;
    this.connection = pConnMgr;
   
    // Forte would actually prepare the statement at this point to syntax check it.
    // Hence we must do the same and throw an exception if it's invalid.
    // To disable this check, set the prf:db:4:50 flag
    if (!LogMgr.getInstance().test(Constants.SP_MT_PERFORMANCE,Constants.SP_ST_DB, 4, 50)) {
      try {
        // To prepare the statement and do nothing, just pass an empty worker
        useRealStatement(noWorker);
      }
      catch (SQLException e) {
          throw DBUtilities.translateSQLException(e);
      }
    }
  }
 
  /**
   * Connect to the database, prepare the statement and set it up identically to how we should have
   * been set up. The return this statement.
   * @return
   */
  protected void useRealStatement(StatementWorker worker) throws SQLException {
    Connection conn = connection.getConnection();
    PreparedStatement ps = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
    for (Parameter thisParam : parameters) {
      if (thisParam != null) {
        thisParam.set(ps);
      }
    }
    ps.setFetchDirection(fetchDirection);
    ps.setFetchSize(fetchSize);
    ps.setMaxRows(maxRows);
    ps.setMaxFieldSize(maxFieldSize);
    ps.setQueryTimeout(queryTimeout);
    if (cursorName != null) {
      ps.setCursorName(cursorName);
    }
    if (!escapeProcessing) {
      ps.setEscapeProcessing(false);
    }
    // JVM 1.6 ps.setPoolable(isPoolable);
    try {
      worker.doWork(ps);
    }
    finally {
        ps.close();
        connection.releaseConnection(conn);
    }
  }

  private void populateResults(PreparedStatement ps, ResultSet rs) throws SQLException {
    if (rs == null) {
      resultSet = null;
    }
    else {
      CachedRowSet rowSet = new CachedRowSetImpl();
      final ResultSetMetaData md = new DelegatingResultSetMetaData(rs.getMetaData()) {
        @Override
        public int getScale(int column) throws SQLException {
          int result = super.getScale(column);
          if (result < 0) {
            result = 0;
          }
          return result;
       
      };
     
      ResultSet rsNew = new DelegatingResultSet(rs) {
        @Override
        public ResultSetMetaData getMetaData() throws SQLException {
          return md;
        }
      };
     
      rowSet.populate(rsNew);
      resultSet = rowSet;
     
      this.resultSetType = rs.getType();
      this.resultSetConcurrency = rs.getConcurrency();
    }
  }

  private void populateResults(PreparedStatement ps, boolean pResultIsResultSet) throws SQLException {
    if (pResultIsResultSet) {
      ResultSet rs = ps.getResultSet();
      this.populateResults(ps, rs);
    }
    else {
      this.updateCount = ps.getUpdateCount();
    }
  }

  public void addBatch() throws SQLException {
    throw new UnsupportedOperationException("Unsupported operation addBatch()");
  }
 
  public void addBatch(String sql) throws SQLException {
    throw new UnsupportedOperationException("Unsupported operation addBatch()");
  }

  public void cancel() throws SQLException {
    // Unsupported, do nothing
  }

  public void clearBatch() throws SQLException {
    throw new UnsupportedOperationException("Unsupported operation addBatch()");
  }

  public void clearWarnings() throws SQLException {
    // Unsupported, statement is already closed so do nothing
  }

  public Connection getConnection() throws SQLException {
    // We have no connection, and we're certainly not going to go and get one just to return it...
    return null;
  }

  public int getFetchDirection() throws SQLException {
    return this.fetchDirection;
  }

  public int getFetchSize() throws SQLException {
    return fetchSize;
  }

  public ResultSet getGeneratedKeys() throws SQLException {
    // Unsupported, return null
    return null;
  }

  public boolean isPoolable() throws SQLException {
    return isPoolable;
  }
 
  public int getMaxFieldSize() throws SQLException {
    return maxFieldSize;
  }

  public int getMaxRows() throws SQLException {
    return maxRows;
  }

  public boolean getMoreResults() throws SQLException {
    // Unsupported operation, return false
    return false;
  }

  public boolean getMoreResults(int current) throws SQLException {
    // Unsupported operation, return false
    return false;
  }

  public int getQueryTimeout() throws SQLException {
    return queryTimeout;
  }

  public ResultSet getResultSet() throws SQLException {
    return this.resultSet;
  }

  public int getResultSetConcurrency() throws SQLException {
    return resultSetConcurrency;
  }

  public int getResultSetHoldability() throws SQLException {
    return resultSetHoldability;
  }

  public int getResultSetType() throws SQLException {
    return resultSetType;
  }

  public int getUpdateCount() throws SQLException {
    return updateCount;
  }

  public SQLWarning getWarnings() throws SQLException {
    // Unsupported operation, return null
    return null;
  }

  public void setCursorName(String name) throws SQLException {
    this.cursorName = name;
  }

  public void setEscapeProcessing(boolean enable) throws SQLException {
    this.escapeProcessing = enable;
  }

  public void setFetchDirection(int direction) throws SQLException {
    this.fetchDirection = direction;
  }

  public void setFetchSize(int rows) throws SQLException {
    this.fetchSize = rows;
  }

  public void setPoolable(boolean poolable) throws SQLException {
    this.isPoolable = poolable;
  }
 
  public void setMaxFieldSize(int max) throws SQLException {
    this.maxFieldSize = max;
  }

  public void setMaxRows(int max) throws SQLException {
    this.maxRows = max;
  }

  public void setQueryTimeout(int seconds) throws SQLException {
    this.queryTimeout = seconds;
  }

  public void clearParameters() throws SQLException {
    parameters.clear();
  }

  public void close() throws SQLException {
    // We're already closed, just discard the result set if any
    resultSet = null;
  }
 
  public boolean execute() throws SQLException {
    final BooleanData result = new BooleanData();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        result.setValue(ps.execute());
       
        // Now get the results sets and remember them
        populateResults(ps, result.getValue());
      }
    });
    return result.getValue();
  }

  public ResultSet executeQuery() throws SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        ResultSet rs = ps.executeQuery();
       
        // Now get the results sets and remember them
        populateResults(ps, rs);
      }
    });
    return resultSet;
  }

  public int executeUpdate() throws SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        updateCount = ps.executeUpdate();
      }
    });
    return updateCount;
  }

  public boolean execute(final String sql) throws SQLException {
    final BooleanData result = new BooleanData();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        result.setValue(ps.execute(sql));
       
        // Now get the results sets and remember them
        populateResults(ps, result.getValue());
      }
    });
    return result.getValue();
  }

  public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException {
    final BooleanData result = new BooleanData();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        result.setValue(ps.execute(sql, autoGeneratedKeys));
       
        // Now get the results sets and remember them
        populateResults(ps, result.getValue());
      }
    });
    return result.getValue();
  }

  public boolean execute(final String sql, final int[] columnIndexes) throws SQLException {
    final BooleanData result = new BooleanData();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        result.setValue(ps.execute(sql, columnIndexes));
       
        // Now get the results sets and remember them
        populateResults(ps, result.getValue());
      }
    });
    return result.getValue();
  }

  public boolean execute(final String sql, final String[] columnNames) throws SQLException {
    final BooleanData result = new BooleanData();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        result.setValue(ps.execute(sql, columnNames));
       
        // Now get the results sets and remember them
        populateResults(ps, result.getValue());
      }
    });
    return result.getValue();
  }

  public int[] executeBatch() throws SQLException {
    throw new UnsupportedOperationException("Unsupported operation executeBatch()");
  }

  public ResultSet executeQuery(String sql) throws SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        ResultSet rs = ps.executeQuery();
       
        // Now get the results sets and remember them
        populateResults(ps, rs);
      }
    });
    return resultSet;
  }

  public int executeUpdate(final String sql) throws SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        updateCount = ps.executeUpdate(sql);
      }
    });
    return updateCount;
  }

  public int executeUpdate(final String sql, final int autoGeneratedKeysthrows SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        updateCount = ps.executeUpdate(sql, autoGeneratedKeys);
      }
    });
    return updateCount;
  }

  public int executeUpdate(final String sql, final int[] columnIndexes) throws SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        updateCount = ps.executeUpdate(sql, columnIndexes);
      }
    });
    return updateCount;
  }

  public int executeUpdate(final String sql, final String[] columnNames) throws SQLException {
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        updateCount = ps.executeUpdate(sql, columnNames);
      }
    });
    return updateCount;
  }

  public ResultSetMetaData getMetaData() throws SQLException {
    if (this.resultSet != null) {
      this.resultSet.getMetaData();
    }
    return null;
  }

  public ParameterMetaData getParameterMetaData() throws SQLException {
    final ParameterHolder result = new ParameterHolder();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement ps) throws SQLException {
        result.setObject(ps.getParameterMetaData());
      }
    });
    return (ParameterMetaData)result.getObject();
  }

  public void setArray(int i, Array x) throws SQLException {
    class ArrayParameter extends Parameter {
      private Array value;
      public ArrayParameter(int index, Array b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setArray(index, value); }
    }
    parameters.set(i, new ArrayParameter(i, x));
  }

  public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
    class AsciiStreamParameter extends Parameter {
      private InputStream value;
      private int length;
      public AsciiStreamParameter(int index, InputStream x, int length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setAsciiStream(index, value, length); }
    }
    parameters.set(parameterIndex, new AsciiStreamParameter(parameterIndex, x, length));
  }

  public void setBigDecimal(int parameterIndex, BigDecimal xthrows SQLException {
    class BigDecimalParameter extends Parameter {
      private BigDecimal value;
      public BigDecimalParameter(int index, BigDecimal b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBigDecimal(index, value); }
    }
    parameters.set(parameterIndex, new BigDecimalParameter(parameterIndex, x));
  }

  public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
    class BinaryStreamParameter extends Parameter {
      private InputStream value;
      private int length;
      public BinaryStreamParameter(int index, InputStream x, int length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBinaryStream(index, value, length); }
    }
    parameters.set(parameterIndex, new BinaryStreamParameter(parameterIndex, x, length));
  }

  public void setBlob(int i, Blob x) throws SQLException {
    class BlobParameter extends Parameter {
      private Blob value;
      public BlobParameter(int index, Blob b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBlob(index, value); }
    }
    parameters.set(i, new BlobParameter(i, x));
  }

  public void setBoolean(int parameterIndex, boolean x) throws SQLException {
    class BooleanParameter extends Parameter {
      private boolean value;
      public BooleanParameter(int index, boolean b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBoolean(index, value); }
    }
    parameters.set(parameterIndex, new BooleanParameter(parameterIndex, x));
  }

  public void setByte(int parameterIndex, byte x) throws SQLException {
    class ByteParameter extends Parameter {
      private byte value;
      public ByteParameter(int index, byte b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setByte(index, value); }
    }
    parameters.set(parameterIndex, new ByteParameter(parameterIndex, x));
  }

  public void setBytes(int parameterIndex, byte[] x) throws SQLException {
    class BytesParameter extends Parameter {
      private byte[] value;
      public BytesParameter(int index, byte[] b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBytes(index, value); }
    }
    parameters.set(parameterIndex, new BytesParameter(parameterIndex, x));
  }

  public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
    class CharacterStreamParameter extends Parameter {
      private Reader value;
      private int length;
      public CharacterStreamParameter(int index, Reader x, int length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setCharacterStream(index, value, length); }
    }
    parameters.set(parameterIndex, new CharacterStreamParameter(parameterIndex, reader, length));
  }

  public void setClob(int i, Clob x) throws SQLException {
    class ClobParameter extends Parameter {
      private Clob value;
      public ClobParameter(int index, Clob b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setClob(index, value); }
    }
    parameters.set(i, new ClobParameter(i, x));
  }

  public void setDate(int parameterIndex, Date x) throws SQLException {
    class DateParameter extends Parameter {
      private Date value;
      public DateParameter(int index, Date b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setDate(index, value); }
    }
    parameters.set(parameterIndex, new DateParameter(parameterIndex, x));
  }

  public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
    class DateParameter extends Parameter {
      private Date value;
      private Calendar cal;
      public DateParameter(int index, Date b, Calendar call) { super(index); this.value = b; this.cal = call; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setDate(index, value, cal); }
    }
    parameters.set(parameterIndex, new DateParameter(parameterIndex, x, cal));
  }

  public void setDouble(int parameterIndex, double x) throws SQLException {
    class DoubleParameter extends Parameter {
      private double value;
      public DoubleParameter(int index, double b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setDouble(index, value); }
    }
    parameters.set(parameterIndex, new DoubleParameter(parameterIndex, x));
  }

  public void setFloat(int parameterIndex, float x) throws SQLException {
    class FloatParameter extends Parameter {
      private float value;
      public FloatParameter(int index, float b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setFloat(index, value); }
    }
    parameters.set(parameterIndex, new FloatParameter(parameterIndex, x));
  }

  public void setInt(int parameterIndex, int x) throws SQLException {
    class IntParameter extends Parameter {
      private int value;
      public IntParameter(int index, int b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setInt(index, value); }
    }
    parameters.set(parameterIndex, new IntParameter(parameterIndex, x));
  }

  public void setLong(int parameterIndex, long x) throws SQLException {
    class LongParameter extends Parameter {
      private long value;
      public LongParameter(int index, long b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setLong(index, value); }
    }
    parameters.set(parameterIndex, new LongParameter(parameterIndex, x));
  }

  public void setNull(int parameterIndex, int sqlType) throws SQLException {
    class NullParameter extends Parameter {
      private int value;
      public NullParameter(int index, int b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNull(index, value); }
    }
    parameters.set(parameterIndex, new NullParameter(parameterIndex, sqlType));
  }

  public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
    class NullParameter extends Parameter {
      private int value;
      private String typeName;
      public NullParameter(int index, int b, String typeName) { super(index); this.value = b; this.typeName = typeName;}
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNull(index, value, typeName); }
    }
    parameters.set(paramIndex, new NullParameter(paramIndex, sqlType, typeName));
  }

  public void setObject(int parameterIndex, Object x) throws SQLException {
    class ObjectParameter extends Parameter {
      private Object value;
      public ObjectParameter(int index, Object b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setObject(index, value); }
    }
    parameters.set(parameterIndex, new ObjectParameter(parameterIndex, x));
  }

  public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
    class ObjectParameter extends Parameter {
      private Object value;
      private int targetSqlType;
      public ObjectParameter(int index, Object b, int targetSqlType) { super(index); this.value = b; this.targetSqlType = targetSqlType;}
      public void set(PreparedStatement stmt) throws SQLException { stmt.setObject(index, value, targetSqlType); }
    }
    parameters.set(parameterIndex, new ObjectParameter(parameterIndex, x, targetSqlType));
  }

  public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
    class ObjectParameter extends Parameter {
      private Object value;
      private int targetSqlType;
      private int scale;
      public ObjectParameter(int index, Object b, int targetSqlType, int scale) { super(index); this.value = b; this.targetSqlType = targetSqlType; this.scale = scale;}
      public void set(PreparedStatement stmt) throws SQLException { stmt.setObject(index, value, targetSqlType, scale); }
    }
    parameters.set(parameterIndex, new ObjectParameter(parameterIndex, x, targetSqlType, scale));
  }

  public void setRef(int i, Ref x) throws SQLException {
    class RefParameter extends Parameter {
      private Ref value;
      public RefParameter(int index, Ref b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setRef(index, value); }
    }
    parameters.set(i, new RefParameter(i, x));
  }

  public void setShort(int parameterIndex, short x) throws SQLException {
    class ShortParameter extends Parameter {
      private short value;
      public ShortParameter(int index, short b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setShort(index, value); }
    }
    parameters.set(parameterIndex, new ShortParameter(parameterIndex, x));
  }

  public void setString(int parameterIndex, String x) throws SQLException {
    class StringParameter extends Parameter {
      private String value;
      public StringParameter(int index, String b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setString(index, value); }
    }
    parameters.set(parameterIndex, new StringParameter(parameterIndex, x));
  }

  public void setTime(int parameterIndex, Time x) throws SQLException {
    class TimeParameter extends Parameter {
      private Time value;
      public TimeParameter(int index, Time b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setTime(index, value); }
    }
    parameters.set(parameterIndex, new TimeParameter(parameterIndex, x));
  }

  public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
    class TimeParameter extends Parameter {
      private Time value;
      Calendar cal;
      public TimeParameter(int index, Time b, Calendar cal) { super(index); this.value = b; this.cal = cal;}
      public void set(PreparedStatement stmt) throws SQLException { stmt.setTime(index, value, cal); }
    }
    parameters.set(parameterIndex, new TimeParameter(parameterIndex, x, cal));
  }

  public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
    class TimestampParameter extends Parameter {
      private Timestamp value;
      public TimestampParameter(int index, Timestamp b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setTimestamp(index, value); }
    }
    parameters.set(parameterIndex, new TimestampParameter(parameterIndex, x));
  }

  public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
    class TimestampParameter extends Parameter {
      private Timestamp value;
      private Calendar cal;
      public TimestampParameter(int index, Timestamp b, Calendar cal) { super(index); this.value = b; this.cal = cal; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setTimestamp(index, value, cal); }
    }
    parameters.set(parameterIndex, new TimestampParameter(parameterIndex, x, cal));
  }

  public void setURL(int parameterIndex, URL x) throws SQLException {
    class URLParameter extends Parameter {
      private URL value;
      public URLParameter(int index, URL b) { super(index); this.value = b; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setURL(index, value); }
    }
    parameters.set(parameterIndex, new URLParameter(parameterIndex, x));
  }

  public void setUnicodeStream(int parameterIndex, InputStream x, int lengththrows SQLException {
    class UnicodeStreamParameter extends Parameter {
      private InputStream value;
      private int length;
      public UnicodeStreamParameter(int index, InputStream x, int length) { super(index); this.value = x; this.length = length; }
      @SuppressWarnings("deprecation")
      public void set(PreparedStatement stmt) throws SQLException { stmt.setUnicodeStream(index, value, length); }
    }
    parameters.set(parameterIndex, new UnicodeStreamParameter(parameterIndex, x, length));
  }

  /********** JVM 1.6 Methods *************/
 
  public boolean isClosed() throws SQLException {
    return true;
  }

  public void setAsciiStream(int parameterIndex, InputStream x)
      throws SQLException {
    class AsciiStreamParameter extends Parameter {
      private InputStream value;
      public AsciiStreamParameter(int index, InputStream x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setAsciiStream(index, value); }
    }
    parameters.set(parameterIndex, new AsciiStreamParameter(parameterIndex, x));
  }

  public void setAsciiStream(int parameterIndex, InputStream x, long length)
      throws SQLException {
    class AsciiStreamParameter extends Parameter {
      private InputStream value;
      private long length;
      public AsciiStreamParameter(int index, InputStream x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setAsciiStream(index, value, length); }
    }
    parameters.set(parameterIndex, new AsciiStreamParameter(parameterIndex, x, length));
  }

  public void setBinaryStream(int parameterIndex, InputStream x)
      throws SQLException {
    class BinaryStreamParameter extends Parameter {
      private InputStream value;
      public BinaryStreamParameter(int index, InputStream x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBinaryStream(index, value); }
    }
    parameters.set(parameterIndex, new BinaryStreamParameter(parameterIndex, x));
  }

  public void setBinaryStream(int parameterIndex, InputStream x, long length)
      throws SQLException {
    class BinaryStreamParameter extends Parameter {
      private InputStream value;
      private long length;
      public BinaryStreamParameter(int index, InputStream x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBinaryStream(index, value, length); }
    }
    parameters.set(parameterIndex, new BinaryStreamParameter(parameterIndex, x, length));
  }

  public void setBlob(int parameterIndex, InputStream inputStream)
      throws SQLException {
    class BlobParameter extends Parameter {
      private InputStream value;
      public BlobParameter(int index, InputStream x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBlob(index, value); }
    }
    parameters.set(parameterIndex, new BlobParameter(parameterIndex, inputStream));
  }

  public void setBlob(int parameterIndex, InputStream inputStream, long length)
      throws SQLException {
    class BlobParameter extends Parameter {
      private InputStream value;
      private long length;
      public BlobParameter(int index, InputStream x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setBlob(index, value, length); }
    }
    parameters.set(parameterIndex, new BlobParameter(parameterIndex, inputStream, length));
  }

  public void setCharacterStream(int parameterIndex, Reader reader)
      throws SQLException {
    class CharacterStreamParameter extends Parameter {
      private Reader value;
      public CharacterStreamParameter(int index, Reader x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setCharacterStream(index, value); }
    }
    parameters.set(parameterIndex, new CharacterStreamParameter(parameterIndex, reader));
  }

  public void setCharacterStream(int parameterIndex, Reader reader,
      long length) throws SQLException {
    class CharacterStreamParameter extends Parameter {
      private Reader value;
      private long length;
      public CharacterStreamParameter(int index, Reader x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setCharacterStream(index, value, length); }
    }
    parameters.set(parameterIndex, new CharacterStreamParameter(parameterIndex, reader, length));
  }

  public void setClob(int parameterIndex, Reader reader) throws SQLException {
    class ClobParameter extends Parameter {
      private Reader value;
      public ClobParameter(int index, Reader x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setClob(index, value); }
    }
    parameters.set(parameterIndex, new ClobParameter(parameterIndex, reader));
   
  }

  public void setClob(int parameterIndex, Reader reader, long length)
      throws SQLException {
    class ClobParameter extends Parameter {
      private Reader value;
      private long length;
      public ClobParameter(int index, Reader x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setClob(index, value, length); }
    }
    parameters.set(parameterIndex, new ClobParameter(parameterIndex, reader, length));   
  }

  public void setNCharacterStream(int parameterIndex, Reader value)
      throws SQLException {
    class NCharacterStreamParameter extends Parameter {
      private Reader value;
      public NCharacterStreamParameter(int index, Reader x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNCharacterStream(index, value); }
    }
    parameters.set(parameterIndex, new NCharacterStreamParameter(parameterIndex, value));
  }

  public void setNCharacterStream(int parameterIndex, Reader value,
      long length) throws SQLException {
    class NCharacterStreamParameter extends Parameter {
      private Reader value;
      private long length;
      public NCharacterStreamParameter(int index, Reader x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setCharacterStream(index, value, length); }
    }
    parameters.set(parameterIndex, new NCharacterStreamParameter(parameterIndex, value, length));
   
  }

  public void setNClob(int parameterIndex, Reader reader) throws SQLException {
    class NClobParameter extends Parameter {
      private Reader value;
      public NClobParameter(int index, Reader x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNClob(index, value); }
    }
    parameters.set(parameterIndex, new NClobParameter(parameterIndex, reader));
   
  }

  public void setNClob(int parameterIndex, Reader reader, long length)
      throws SQLException {
    class NClobParameter extends Parameter {
      private Reader value;
      private long length;
      public NClobParameter(int index, Reader x, long length) { super(index); this.value = x; this.length = length; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNClob(index, value, length); }
    }
    parameters.set(parameterIndex, new NClobParameter(parameterIndex, reader, length));   
  }


  public void setNClob(int parameterIndex, NClob value) throws SQLException {
    class NClobParameter extends Parameter {
      private NClob value;
      public NClobParameter(int index, NClob x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNClob(index, value); }
    }
    parameters.set(parameterIndex, new NClobParameter(parameterIndex, value));   
  }


  public void setNString(int parameterIndex, String value)
      throws SQLException {
    class NStringParameter extends Parameter {
      private String value;
      public NStringParameter(int index, String x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setNString(index, value); }
    }
    parameters.set(parameterIndex, new NStringParameter(parameterIndex, value));   
  }

  public void setRowId(int parameterIndex, RowId x) throws SQLException {
    class RowIdParameter extends Parameter {
      private RowId value;
      public RowIdParameter(int index, RowId x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setRowId(index, value); }
    }
    parameters.set(parameterIndex, new RowIdParameter(parameterIndex, x));   
  }

  public void setSQLXML(int parameterIndex, SQLXML xmlObject)
      throws SQLException {
    class SQLXMLParameter extends Parameter {
      private SQLXML value;
      public SQLXMLParameter(int index, SQLXML x) { super(index); this.value = x; }
      public void set(PreparedStatement stmt) throws SQLException { stmt.setSQLXML(index, value); }
    }
    parameters.set(parameterIndex, new SQLXMLParameter(parameterIndex, xmlObject));   
  }

  public boolean isWrapperFor(final Class<?> iface) throws SQLException {
    final ParameterHolder isWrapperHolder = new ParameterHolder();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement arg0) throws SQLException {
        isWrapperHolder.setBoolean(arg0.isWrapperFor(iface));
      }
    });
    return isWrapperHolder.getBoolean();
  }

  @SuppressWarnings("unchecked")
  public <T> T unwrap(final Class<T> iface) throws SQLException {
    final ParameterHolder THolder = new ParameterHolder();
    useRealStatement(new StatementWorker() {
      public void doWork(PreparedStatement arg0) throws SQLException {
        THolder.setObject(arg0.unwrap(iface));
      }
    });
    return (T)THolder.getObject();
  }
 
}
TOP

Related Classes of GenericDBMS.BigDecimalParameter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.