Search in sources :

Example 96 with IgniteSQLException

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

the class H2Connection method prepareStatement.

/**
 * Prepare statement caching it if needed.
 *
 * @param sql SQL.
 * @return Prepared statement.
 */
PreparedStatement prepareStatement(String sql, byte qryFlags) {
    try {
        PreparedStatement stmt = cachedPreparedStatement(sql, qryFlags);
        if (stmt == null) {
            H2CachedStatementKey key = new H2CachedStatementKey(schema, sql, qryFlags);
            stmt = prepareStatementNoCache(sql);
            statementCache.put(key, stmt);
        }
        return stmt;
    } catch (SQLException e) {
        throw new IgniteSQLException("Failed to parse query. " + e.getMessage(), IgniteQueryErrorCode.PARSING, e);
    }
}
Also used : SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) PreparedStatement(java.sql.PreparedStatement)

Example 97 with IgniteSQLException

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

the class H2ResultSetIterator method fetchPage.

/**
 * @return {@code true} if the next page is available.
 * @throws IgniteCheckedException On cancel.
 */
private boolean fetchPage() throws IgniteCheckedException {
    lockTables();
    try (TraceSurroundings ignored = MTC.support(tracing.create(SQL_PAGE_FETCH, MTC.span()))) {
        GridH2Table.checkTablesVersions(ses);
        page.clear();
        try {
            if (data.isClosed())
                return false;
        } catch (SQLException e) {
            if (e.getErrorCode() == ErrorCode.STATEMENT_WAS_CANCELED)
                throw new QueryCancelledException();
            throw new IgniteSQLException(e);
        }
        for (int i = 0; i < pageSize; ++i) {
            try {
                if (!data.next())
                    break;
                row = new Object[colCnt];
                readRow();
                page.add(row);
            } catch (SQLException e) {
                close();
                if (e.getCause() instanceof IgniteSQLException)
                    throw (IgniteSQLException) e.getCause();
                if (e.getErrorCode() == ErrorCode.STATEMENT_WAS_CANCELED)
                    throw new QueryCancelledException();
                throw new IgniteSQLException(e);
            }
        }
        MTC.span().addTag(SQL_PAGE_ROWS, () -> Integer.toString(page.size()));
        if (F.isEmpty(page)) {
            rowIter = null;
            return false;
        } else {
            rowIter = page.iterator();
            return true;
        }
    } finally {
        unlockTables();
    }
}
Also used : SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 98 with IgniteSQLException

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

the class SchemaManager method dropTable.

/**
 * Drops table form h2 database and clear all related indexes (h2 text, lucene).
 *
 * @param tbl Table to unregister.
 * @param destroy {@code true} when table destroyed (cache destroyed) otherwise {@code false}.
 */
private void dropTable(H2TableDescriptor tbl, boolean destroy) {
    assert tbl != null;
    if (log.isDebugEnabled())
        log.debug("Removing query index table: " + tbl.fullTableName());
    try (H2PooledConnection c = connMgr.connection(tbl.schemaName())) {
        Statement stmt = null;
        try {
            stmt = c.connection().createStatement();
            String sql = "DROP TABLE IF EXISTS " + tbl.fullTableName();
            if (log.isDebugEnabled())
                log.debug("Dropping database index table with SQL: " + sql);
            stmt.executeUpdate(sql);
            if (destroy)
                afterDropTable(tbl.schemaName(), tbl.tableName());
        } catch (SQLException e) {
            throw new IgniteSQLException("Failed to drop database index table [type=" + tbl.type().name() + ", table=" + tbl.fullTableName() + "]", IgniteQueryErrorCode.TABLE_DROP_FAILED, e);
        } finally {
            U.close(stmt, log);
        }
    }
}
Also used : SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) Statement(java.sql.Statement) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 99 with IgniteSQLException

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

the class DmlAstUtils method gridTableForElement.

/**
 * @param target Expression to extract the table from.
 * @return Back end table for this element.
 */
public static GridSqlTable gridTableForElement(GridSqlElement target) {
    Set<GridSqlTable> tbls = new HashSet<>();
    collectAllGridTablesInTarget(target, tbls);
    if (tbls.size() != 1)
        throw new IgniteSQLException("Failed to determine target table", IgniteQueryErrorCode.TABLE_NOT_FOUND);
    return tbls.iterator().next();
}
Also used : GridSqlTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) HashSet(java.util.HashSet)

Example 100 with IgniteSQLException

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

the class SqlUnsupportedSelfTest method assertSqlUnsupported0.

/**
 * @param sql Sql.
 * @param msg Error message match
 */
private void assertSqlUnsupported0(final String sql, String msg) {
    Throwable t = GridTestUtils.assertThrowsWithCause((Callable<Void>) () -> {
        execSql(sql);
        return null;
    }, IgniteSQLException.class);
    IgniteSQLException sqlE = X.cause(t, IgniteSQLException.class);
    assert sqlE != null;
    if (IgniteQueryErrorCode.UNSUPPORTED_OPERATION != sqlE.statusCode() || !sqlE.getMessage().contains(msg)) {
        log.error("Unexpected exception", t);
        fail("Unexpected exception. See above");
    }
}
Also used : IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Aggregations

IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)112 SQLException (java.sql.SQLException)38 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)37 ArrayList (java.util.ArrayList)34 List (java.util.List)27 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)19 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)18 Column (org.h2.table.Column)18 IgniteException (org.apache.ignite.IgniteException)16 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)16 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)12 BatchUpdateException (java.sql.BatchUpdateException)11 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)11 LinkedHashMap (java.util.LinkedHashMap)10 CacheException (javax.cache.CacheException)9 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)9 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)9 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)9 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8