Search in sources :

Example 1 with GridQueryIndexing

use of org.apache.ignite.internal.processors.query.GridQueryIndexing in project ignite by apache.

the class JdbcConnection method prepareStatement.

/** {@inheritDoc} */
@Override
public PreparedStatement prepareStatement(String sql, int resSetType, int resSetConcurrency, int resSetHoldability) throws SQLException {
    ensureNotClosed();
    if (resSetType != TYPE_FORWARD_ONLY)
        throw new SQLFeatureNotSupportedException("Invalid result set type (only forward is supported.)");
    if (resSetConcurrency != CONCUR_READ_ONLY)
        throw new SQLFeatureNotSupportedException("Invalid concurrency (updates are not supported).");
    if (!txAllowed && resSetHoldability != HOLD_CURSORS_OVER_COMMIT)
        throw new SQLFeatureNotSupportedException("Invalid holdability (transactions are not supported).");
    JdbcPreparedStatement stmt;
    if (!stream)
        stmt = new JdbcPreparedStatement(this, sql);
    else {
        GridQueryIndexing idx = ignite().context().query().getIndexing();
        PreparedStatement nativeStmt = prepareNativeStatement(sql);
        if (!idx.isInsertStatement(nativeStmt))
            throw new IgniteSQLException("Only INSERT operations are supported in streaming mode", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
        IgniteDataStreamer streamer = ignite().dataStreamer(cacheName);
        streamer.autoFlushFrequency(streamFlushTimeout);
        streamer.allowOverwrite(streamAllowOverwrite);
        if (streamNodeBufSize > 0)
            streamer.perNodeBufferSize(streamNodeBufSize);
        if (streamNodeParOps > 0)
            streamer.perNodeParallelOperations(streamNodeParOps);
        stmt = new JdbcStreamedPreparedStatement(this, sql, streamer, nativeStmt);
    }
    statements.add(stmt);
    return stmt;
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) PreparedStatement(java.sql.PreparedStatement) GridQueryIndexing(org.apache.ignite.internal.processors.query.GridQueryIndexing)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)1 GridQueryIndexing (org.apache.ignite.internal.processors.query.GridQueryIndexing)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1