org.apache.calcite.avatica

## Class AvaticaPreparedStatement

- java.lang.Object
- - org.apache.calcite.avatica.AvaticaStatement
  - - org.apache.calcite.avatica.AvaticaPreparedStatement

All Implemented Interfaces:
  AutoCloseable, ParameterMetaData, PreparedStatement, Statement, Wrapper

Direct Known Subclasses:
  AvaticaJdbc41Factory.AvaticaJdbc41PreparedStatement

    public abstract class AvaticaPreparedStatement
    extends AvaticaStatement
    implements PreparedStatement, ParameterMetaData

Implementation of `PreparedStatement` for the Avatica engine.

This class has sub-classes which implement JDBC 3.0 and JDBC 4.0 APIs; it is instantiated using `AvaticaFactory.newPreparedStatement(org.apache.calcite.avatica.AvaticaConnection, org.apache.calcite.avatica.Meta.StatementHandle, org.apache.calcite.avatica.Meta.Signature, int, int, int)`.

### Field Summary

Fields
`private Calendar` `calendar`
`protected List<List<TypedValue>>` `parameterValueBatch`
`private ResultSetMetaData` `resultSetMetaData`
`protected TypedValue[]` `slots`

### Fields inherited from class org.apache.calcite.avatica.AvaticaStatement

`cancelFlag, closed, closeOnCompletion, connection, DEFAULT_FETCH_SIZE, handle, maxRowCount, openResultSet, resultSetConcurrency, resultSetHoldability, resultSetType, updateCount`

### Fields inherited from interface java.sql.Statement

`CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO`

### Fields inherited from interface java.sql.ParameterMetaData

`parameterModeIn, parameterModeInOut, parameterModeOut, parameterModeUnknown, parameterNoNulls, parameterNullable, parameterNullableUnknown`

### Constructor Summary

Constructors
`protected` `AvaticaPreparedStatement(AvaticaConnection connection, Meta.StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability)` Creates an AvaticaPreparedStatement.

### Method Summary

Methods
`void` `addBatch()`
`void` `clearBatch()`
`void` `clearParameters()`
`protected List<TypedValue>` `copyParameterValues()` Returns a copy of the current parameter values.
`boolean` `execute()`
`int[]` `executeBatch()`
`long[]` `executeLargeBatch()`
`long` `executeLargeUpdate()`
`ResultSet` `executeQuery()`
`int` `executeUpdate()`
`protected Calendar` `getCalendar()` Returns a calendar in the connection's time zone, creating one the first time this method is called.
`ResultSetMetaData` `getMetaData()`
`protected AvaticaParameter` `getParameter(int param)`
`String` `getParameterClassName(int index)`
`int` `getParameterCount()`
`ParameterMetaData` `getParameterMetaData()`
`int` `getParameterMode(int param)`
`int` `getParameterType(int index)`
`String` `getParameterTypeName(int index)`
`protected List<List<TypedValue>>` `getParameterValueBatch()`
`protected List<TypedValue>` `getParameterValues()` Returns the list of values of this statement's parameters.
`int` `getPrecision(int index)`
`int` `getScale(int index)`
`protected AvaticaSite` `getSite(int param)`
`int` `isNullable(int param)`
`boolean` `isSigned(int index)`
`void` `setArray(int parameterIndex, Array x)`
`void` `setAsciiStream(int parameterIndex, InputStream x, int length)`
`void` `setBigDecimal(int parameterIndex, BigDecimal x)`
`void` `setBinaryStream(int parameterIndex, InputStream x, int length)`
`void` `setBlob(int parameterIndex, Blob x)`
`void` `setBoolean(int parameterIndex, boolean x)`
`void` `setByte(int parameterIndex, byte x)`
`void` `setBytes(int parameterIndex, byte[] x)`
`void` `setCharacterStream(int parameterIndex, Reader reader, int length)`
`void` `setClob(int parameterIndex, Clob x)`
`void` `setDate(int parameterIndex, Date x)`
`void` `setDate(int parameterIndex, Date x, Calendar calendar)`
`void` `setDouble(int parameterIndex, double x)`
`void` `setFloat(int parameterIndex, float x)`
`void` `setInt(int parameterIndex, int x)`
`void` `setLong(int parameterIndex, long x)`
`void` `setNull(int parameterIndex, int sqlType)`
`void` `setNull(int parameterIndex, int sqlType, String typeName)`
`void` `setObject(int parameterIndex, Object x)`
`void` `setObject(int parameterIndex, Object x, int targetSqlType)`
`void` `setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)`
`void` `setRef(int parameterIndex, Ref x)`
`void` `setShort(int parameterIndex, short x)`
`void` `setString(int parameterIndex, String x)`
`void` `setTime(int parameterIndex, Time x)`
`void` `setTime(int parameterIndex, Time x, Calendar calendar)`
`void` `setTimestamp(int parameterIndex, Timestamp x)`
`void` `setTimestamp(int parameterIndex, Timestamp x, Calendar calendar)`
`void` `setUnicodeStream(int parameterIndex, InputStream x, int length)`
`void` `setURL(int parameterIndex, URL x)`

### Methods inherited from class org.apache.calcite.avatica.AvaticaStatement

`addBatch, cancel, clearWarnings, close_, close, closeOnCompletion, execute, execute, execute, execute, executeBatchInternal, executeInternal, executeInternal, executeLargeUpdate, executeQuery, executeQueryInternal, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getBoundParameterValues, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getId, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getQueryTimeoutMillis, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getSignature, getStatementType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, onResultSetClose, resetStatement, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, setQueryTimeoutMillis, setSignature, syncResults, unwrap`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.sql.PreparedStatement

`setAsciiStream, setAsciiStream, setBinaryStream, setBinaryStream, setBlob, setBlob, setCharacterStream, setCharacterStream, setClob, setClob, setNCharacterStream, setNCharacterStream, setNClob, setNClob, setNClob, setNString, setRowId, setSQLXML`

### Methods inherited from interface java.sql.Statement

`addBatch, cancel, clearWarnings, close, closeOnCompletion, execute, execute, execute, execute, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout`

### Methods inherited from interface java.sql.Wrapper

`isWrapperFor, unwrap`

### Field Detail

#### resultSetMetaData

    private final ResultSetMetaData resultSetMetaData

#### calendar

    private Calendar calendar

#### slots

    protected final TypedValue[] slots

#### parameterValueBatch

    protected final List<List<TypedValue>> parameterValueBatch

### Constructor Detail

#### AvaticaPreparedStatement

    protected AvaticaPreparedStatement(AvaticaConnection connection,
                            Meta.StatementHandle h,
                            Meta.Signature signature,
                            int resultSetType,
                            int resultSetConcurrency,
                            int resultSetHoldability)
                                throws SQLException

Creates an AvaticaPreparedStatement.

Parameters:
  `connection` - Connection
  `h` - Statement handle
  `signature` - Result of preparing statement
  `resultSetType` - Result set type
  `resultSetConcurrency` - Result set concurrency
  `resultSetHoldability` - Result set holdability
Throws:
  `SQLException` - If fails due to underlying implementation reasons.

### Method Detail

#### getParameterValues

    protected List<TypedValue> getParameterValues()

Description copied from class: `AvaticaStatement`
Returns the list of values of this statement's parameters.

Called at execute time. Not a public API.

The default implementation returns the empty list, because non-prepared statements have no parameters.

Overrides:
  `getParameterValues` in class `AvaticaStatement`
See Also:
  `AvaticaConnection.Trojan.getParameterValues(AvaticaStatement)`

#### copyParameterValues

    protected List<TypedValue> copyParameterValues()

Returns a copy of the current parameter values.

Returns:
  A copied list of the parameter values

#### getCalendar

    protected Calendar getCalendar()

Returns a calendar in the connection's time zone, creating one the first time this method is called.

Uses the calendar to offset date-time values when calling methods such as `setDate(int, Date)`.

A note on thread-safety. This method does not strictly need to be `synchronized`, because JDBC does not promise thread safety if different threads are accessing the same statement, or even different objects within a particular connection.

The calendar returned is to be used only within this statement, and JDBC only allows access to a statement from within one thread, so therefore does not need to be synchronized when accessed.

#### getParameterValueBatch

    protected List<List<TypedValue>> getParameterValueBatch()

#### executeQuery

    public ResultSet executeQuery()
                           throws SQLException

Specified by:
  `executeQuery` in interface `PreparedStatement`
Throws:
  `SQLException`

#### getParameterMetaData

    public ParameterMetaData getParameterMetaData()
                                           throws SQLException

Specified by:
  `getParameterMetaData` in interface `PreparedStatement`
Throws:
  `SQLException`

#### executeUpdate

    public final int executeUpdate()
                            throws SQLException

Specified by:
  `executeUpdate` in interface `PreparedStatement`
Throws:
  `SQLException`

#### executeLargeUpdate

    public long executeLargeUpdate()
                            throws SQLException

Throws:
  `SQLException`

#### setNull

    public void setNull(int parameterIndex,
               int sqlType)
                 throws SQLException

Specified by:
  `setNull` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setBoolean

    public void setBoolean(int parameterIndex,
                  boolean x)
                    throws SQLException

Specified by:
  `setBoolean` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setByte

    public void setByte(int parameterIndex,
               byte x)
                 throws SQLException

Specified by:
  `setByte` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setShort

    public void setShort(int parameterIndex,
                short x)
                  throws SQLException

Specified by:
  `setShort` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setInt

    public void setInt(int parameterIndex,
              int x)
                throws SQLException

Specified by:
  `setInt` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setLong

    public void setLong(int parameterIndex,
               long x)
                 throws SQLException

Specified by:
  `setLong` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setFloat

    public void setFloat(int parameterIndex,
                float x)
                  throws SQLException

Specified by:
  `setFloat` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setDouble

    public void setDouble(int parameterIndex,
                 double x)
                   throws SQLException

Specified by:
  `setDouble` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setBigDecimal

    public void setBigDecimal(int parameterIndex,
                     BigDecimal x)
                       throws SQLException

Specified by:
  `setBigDecimal` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setString

    public void setString(int parameterIndex,
                 String x)
                   throws SQLException

Specified by:
  `setString` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setBytes

    public void setBytes(int parameterIndex,
                byte[] x)
                  throws SQLException

Specified by:
  `setBytes` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setAsciiStream

    public void setAsciiStream(int parameterIndex,
                      InputStream x,
                      int length)
                        throws SQLException

Specified by:
  `setAsciiStream` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setUnicodeStream

    public void setUnicodeStream(int parameterIndex,
                        InputStream x,
                        int length)
                          throws SQLException

Specified by:
  `setUnicodeStream` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setBinaryStream

    public void setBinaryStream(int parameterIndex,
                       InputStream x,
                       int length)
                         throws SQLException

Specified by:
  `setBinaryStream` in interface `PreparedStatement`
Throws:
  `SQLException`

#### clearParameters

    public void clearParameters()
                         throws SQLException

Specified by:
  `clearParameters` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setObject

    public void setObject(int parameterIndex,
                 Object x,
                 int targetSqlType)
                   throws SQLException

Specified by:
  `setObject` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setObject

    public void setObject(int parameterIndex,
                 Object x)
                   throws SQLException

Specified by:
  `setObject` in interface `PreparedStatement`
Throws:
  `SQLException`

#### execute

    public boolean execute()
                    throws SQLException

Specified by:
  `execute` in interface `PreparedStatement`
Throws:
  `SQLException`

#### addBatch

    public void addBatch()
                  throws SQLException

Specified by:
  `addBatch` in interface `PreparedStatement`
Throws:
  `SQLException`

#### clearBatch

    public void clearBatch()

Specified by:
  `clearBatch` in interface `Statement`
Overrides:
  `clearBatch` in class `AvaticaStatement`

#### executeBatch

    public int[] executeBatch()
                       throws SQLException

Specified by:
  `executeBatch` in interface `Statement`
Overrides:
  `executeBatch` in class `AvaticaStatement`
Throws:
  `SQLException`

#### executeLargeBatch

    public long[] executeLargeBatch()
                             throws SQLException

Overrides:
  `executeLargeBatch` in class `AvaticaStatement`
Throws:
  `SQLException`

#### setCharacterStream

    public void setCharacterStream(int parameterIndex,
                          Reader reader,
                          int length)
                            throws SQLException

Specified by:
  `setCharacterStream` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setRef

    public void setRef(int parameterIndex,
              Ref x)
                throws SQLException

Specified by:
  `setRef` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setBlob

    public void setBlob(int parameterIndex,
               Blob x)
                 throws SQLException

Specified by:
  `setBlob` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setClob

    public void setClob(int parameterIndex,
               Clob x)
                 throws SQLException

Specified by:
  `setClob` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setArray

    public void setArray(int parameterIndex,
                Array x)
                  throws SQLException

Specified by:
  `setArray` in interface `PreparedStatement`
Throws:
  `SQLException`

#### getMetaData

    public ResultSetMetaData getMetaData()

Specified by:
  `getMetaData` in interface `PreparedStatement`

#### setDate

    public void setDate(int parameterIndex,
               Date x,
               Calendar calendar)
                 throws SQLException

Specified by:
  `setDate` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setDate

    public void setDate(int parameterIndex,
               Date x)
                 throws SQLException

Specified by:
  `setDate` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setTime

    public void setTime(int parameterIndex,
               Time x,
               Calendar calendar)
                 throws SQLException

Specified by:
  `setTime` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setTime

    public void setTime(int parameterIndex,
               Time x)
                 throws SQLException

Specified by:
  `setTime` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setTimestamp

    public void setTimestamp(int parameterIndex,
                    Timestamp x,
                    Calendar calendar)
                      throws SQLException

Specified by:
  `setTimestamp` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setTimestamp

    public void setTimestamp(int parameterIndex,
                    Timestamp x)
                      throws SQLException

Specified by:
  `setTimestamp` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setNull

    public void setNull(int parameterIndex,
               int sqlType,
               String typeName)
                 throws SQLException

Specified by:
  `setNull` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setURL

    public void setURL(int parameterIndex,
              URL x)
                throws SQLException

Specified by:
  `setURL` in interface `PreparedStatement`
Throws:
  `SQLException`

#### setObject

    public void setObject(int parameterIndex,
                 Object x,
                 int targetSqlType,
                 int scaleOrLength)
                   throws SQLException

Specified by:
  `setObject` in interface `PreparedStatement`
Throws:
  `SQLException`

#### getParameter

    protected AvaticaParameter getParameter(int param)
                                     throws SQLException

Throws:
  `SQLException`

#### getSite

    protected AvaticaSite getSite(int param)
                           throws SQLException

Throws:
  `SQLException`

#### getParameterCount

    public int getParameterCount()

Specified by:
  `getParameterCount` in interface `ParameterMetaData`

#### isNullable

    public int isNullable(int param)
                   throws SQLException

Specified by:
  `isNullable` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### isSigned

    public boolean isSigned(int index)
                     throws SQLException

Specified by:
  `isSigned` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### getPrecision

    public int getPrecision(int index)
                     throws SQLException

Specified by:
  `getPrecision` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### getScale

    public int getScale(int index)
                 throws SQLException

Specified by:
  `getScale` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### getParameterType

    public int getParameterType(int index)
                         throws SQLException

Specified by:
  `getParameterType` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### getParameterTypeName

    public String getParameterTypeName(int index)
                                throws SQLException

Specified by:
  `getParameterTypeName` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### getParameterClassName

    public String getParameterClassName(int index)
                                 throws SQLException

Specified by:
  `getParameterClassName` in interface `ParameterMetaData`
Throws:
  `SQLException`

#### getParameterMode

    public int getParameterMode(int param)
                         throws SQLException

Specified by:
  `getParameterMode` in interface `ParameterMetaData`
Throws:
  `SQLException`