Search in sources :

Example 16 with Session

use of org.h2.engine.Session in project ignite by apache.

the class IgniteH2Indexing method executeSqlQuery.

/**
 * Executes sql query statement.
 *
 * @param conn Connection,.
 * @param stmt Statement.
 * @param timeoutMillis Query timeout.
 * @param cancel Query cancel.
 * @return Result.
 * @throws IgniteCheckedException If failed.
 */
private ResultSet executeSqlQuery(final Connection conn, final PreparedStatement stmt, int timeoutMillis, @Nullable GridQueryCancel cancel) throws IgniteCheckedException {
    final MapQueryLazyWorker lazyWorker = MapQueryLazyWorker.currentWorker();
    if (cancel != null) {
        cancel.set(new Runnable() {

            @Override
            public void run() {
                if (lazyWorker != null) {
                    lazyWorker.submit(new Runnable() {

                        @Override
                        public void run() {
                            cancelStatement(stmt);
                        }
                    });
                } else
                    cancelStatement(stmt);
            }
        });
    }
    Session ses = H2Utils.session(conn);
    if (timeoutMillis > 0)
        ses.setQueryTimeout(timeoutMillis);
    if (lazyWorker != null)
        ses.setLazyQueryExecution(true);
    try {
        return stmt.executeQuery();
    } catch (SQLException e) {
        // Throw special exception.
        if (e.getErrorCode() == ErrorCode.STATEMENT_WAS_CANCELED)
            throw new QueryCancelledException();
        throw new IgniteCheckedException("Failed to execute SQL query. " + e.getMessage(), e);
    } finally {
        if (timeoutMillis > 0)
            ses.setQueryTimeout(0);
        if (lazyWorker != null)
            ses.setLazyQueryExecution(false);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) MapQueryLazyWorker(org.apache.ignite.internal.processors.query.h2.twostep.MapQueryLazyWorker) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) Session(org.h2.engine.Session)

Example 17 with Session

use of org.h2.engine.Session in project ignite by apache.

the class H2PkHashIndex method getRowCount.

/**
 * {@inheritDoc}
 */
@Override
public long getRowCount(Session ses) {
    Cursor cursor = find(ses, null, null);
    long res = 0;
    while (cursor.next()) res++;
    return res;
}
Also used : GridCursor(org.apache.ignite.internal.util.lang.GridCursor) Cursor(org.h2.index.Cursor)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 SingleRowCursor (org.h2.index.SingleRowCursor)5 ArrayList (java.util.ArrayList)4 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)4 Session (org.h2.engine.Session)4 Cursor (org.h2.index.Cursor)4 Index (org.h2.index.Index)4 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)3 SpatialIndex (org.h2.index.SpatialIndex)3 SQLException (java.sql.SQLException)2 Node (javax.jcr.Node)2 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)2 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)2 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)2 Profiler (org.h2.util.Profiler)2 Test (org.junit.Test)2 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1