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);
}
}
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();
}
}
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);
}
}
}
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();
}
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");
}
}
Aggregations