Search in sources :

Example 1 with AvaticaPreparedStatement

use of org.apache.calcite.avatica.AvaticaPreparedStatement in project calcite-avatica by apache.

the class JdbcMeta method prepare.

public StatementHandle prepare(ConnectionHandle ch, String sql, long maxRowCount) {
    try {
        final Connection conn = getConnection(ch.id);
        final PreparedStatement statement = conn.prepareStatement(sql);
        final int id = getStatementIdGenerator().getAndIncrement();
        Meta.StatementType statementType = null;
        if (statement.isWrapperFor(AvaticaPreparedStatement.class)) {
            final AvaticaPreparedStatement avaticaPreparedStatement;
            avaticaPreparedStatement = statement.unwrap(AvaticaPreparedStatement.class);
            statementType = avaticaPreparedStatement.getStatementType();
        }
        // Set the maximum number of rows
        setMaxRows(statement, maxRowCount);
        getStatementCache().put(id, new StatementInfo(statement));
        StatementHandle h = new StatementHandle(ch.id, id, signature(statement.getMetaData(), statement.getParameterMetaData(), sql, statementType));
        LOG.trace("prepared statement {}", h);
        return h;
    } catch (SQLException e) {
        throw propagate(e);
    }
}
Also used : ProtobufMeta(org.apache.calcite.avatica.remote.ProtobufMeta) Meta(org.apache.calcite.avatica.Meta) AvaticaPreparedStatement(org.apache.calcite.avatica.AvaticaPreparedStatement) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) AvaticaPreparedStatement(org.apache.calcite.avatica.AvaticaPreparedStatement)

Aggregations

Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 AvaticaPreparedStatement (org.apache.calcite.avatica.AvaticaPreparedStatement)1 Meta (org.apache.calcite.avatica.Meta)1 ProtobufMeta (org.apache.calcite.avatica.remote.ProtobufMeta)1