Search in sources :

Example 56 with IgniteSQLException

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

the class H2ResultSetIterator method onClose.

/**
 * @throws IgniteCheckedException On error.
 */
public void onClose() throws IgniteCheckedException {
    if (data == null)
        // Nothing to close.
        return;
    lockTables();
    try {
        fetchSizeInterceptor.checkOnClose();
        data.close();
    } catch (SQLException e) {
        throw new IgniteSQLException(e);
    } finally {
        res = null;
        data = null;
        page = null;
        unlockTables();
    }
}
Also used : SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 57 with IgniteSQLException

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

the class IgniteTransactionSQLColumnConstraintTest method checkSQLThrows.

/**
 * {@inheritDoc}
 */
@Override
protected void checkSQLThrows(String sql, String sqlStateCode, Object... args) {
    runSQL("BEGIN TRANSACTION");
    IgniteSQLException err = (IgniteSQLException) GridTestUtils.assertThrowsWithCause(() -> {
        runSQL(sql, args);
        return 0;
    }, IgniteSQLException.class);
    runSQL("ROLLBACK TRANSACTION");
    assertEquals(err.sqlState(), sqlStateCode);
}
Also used : IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 58 with IgniteSQLException

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

the class IgniteSQLColumnConstraintsTest method checkSQLThrows.

/**
 */
protected void checkSQLThrows(String sql, String sqlStateCode, Object... args) {
    IgniteSQLException err = (IgniteSQLException) GridTestUtils.assertThrowsWithCause(() -> {
        execSQL(sql, args);
        return 0;
    }, IgniteSQLException.class);
    assertEquals(err.sqlState(), sqlStateCode);
}
Also used : IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 59 with IgniteSQLException

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

the class GridSqlQueryParser method processExtraParam.

/**
 * @param name Param name.
 * @param val Param value.
 * @param res Table params to update.
 */
private static void processExtraParam(String name, String val, GridSqlCreateTable res) {
    assert !F.isEmpty(name);
    switch(name) {
        case PARAM_TEMPLATE:
            ensureNotEmpty(name, val);
            res.templateName(val);
            break;
        case PARAM_BACKUPS:
            ensureNotEmpty(name, val);
            int backups = parseIntParam(PARAM_BACKUPS, val);
            if (backups < 0) {
                throw new IgniteSQLException("\"" + PARAM_BACKUPS + "\" cannot be negative: " + backups, IgniteQueryErrorCode.PARSING);
            }
            res.backups(backups);
            break;
        case PARAM_PARALLELISM:
            ensureNotEmpty(name, val);
            int qryPar = parseIntParam(PARAM_PARALLELISM, val);
            if (qryPar <= 0)
                throw new IgniteSQLException("\"" + PARAM_PARALLELISM + "\" must be positive: " + qryPar, IgniteQueryErrorCode.PARSING);
            res.parallelism(qryPar);
            break;
        case PARAM_ATOMICITY:
            ensureNotEmpty(name, val);
            try {
                res.atomicityMode(CacheAtomicityMode.valueOf(val.toUpperCase()));
            } catch (IllegalArgumentException e) {
                String validVals = Arrays.stream(CacheAtomicityMode.values()).map(Enum::name).collect(Collectors.joining(", "));
                throw new IgniteSQLException("Invalid value of \"" + PARAM_ATOMICITY + "\" parameter " + "(should be either " + validVals + "): " + val, IgniteQueryErrorCode.PARSING, e);
            }
            break;
        case PARAM_CACHE_NAME:
            ensureNotEmpty(name, val);
            res.cacheName(val);
            break;
        case PARAM_KEY_TYPE:
            ensureNotEmpty(name, val);
            res.keyTypeName(val);
            break;
        case PARAM_VAL_TYPE:
            ensureNotEmpty(name, val);
            res.valueTypeName(val);
            break;
        case PARAM_CACHE_GROUP_OLD:
        case PARAM_CACHE_GROUP:
            ensureNotEmpty(name, val);
            res.cacheGroup(val);
            break;
        case PARAM_AFFINITY_KEY_OLD:
        case PARAM_AFFINITY_KEY:
            ensureNotEmpty(name, val);
            String affColName = null;
            // Either strip column name off its quotes, or uppercase it.
            if (val.startsWith("'")) {
                if (val.length() == 1 || !val.endsWith("'")) {
                    throw new IgniteSQLException("Affinity key column name does not have trailing quote: " + val, IgniteQueryErrorCode.PARSING);
                }
                val = val.substring(1, val.length() - 1);
                ensureNotEmpty(name, val);
                affColName = val;
            } else {
                for (String colName : res.columns().keySet()) {
                    if (val.equalsIgnoreCase(colName)) {
                        if (affColName != null) {
                            throw new IgniteSQLException("Ambiguous affinity column name, use single quotes " + "for case sensitivity: " + val, IgniteQueryErrorCode.PARSING);
                        }
                        affColName = colName;
                    }
                }
            }
            if (affColName == null || !res.columns().containsKey(affColName)) {
                throw new IgniteSQLException("Affinity key column with given name not found: " + val, IgniteQueryErrorCode.PARSING);
            }
            if (!res.primaryKeyColumns().contains(affColName)) {
                throw new IgniteSQLException("Affinity key column must be one of key columns: " + affColName, IgniteQueryErrorCode.PARSING);
            }
            res.affinityKey(affColName);
            break;
        case PARAM_WRITE_SYNC:
            ensureNotEmpty(name, val);
            CacheWriteSynchronizationMode writeSyncMode;
            if (CacheWriteSynchronizationMode.FULL_ASYNC.name().equalsIgnoreCase(val))
                writeSyncMode = CacheWriteSynchronizationMode.FULL_ASYNC;
            else if (CacheWriteSynchronizationMode.FULL_SYNC.name().equalsIgnoreCase(val))
                writeSyncMode = CacheWriteSynchronizationMode.FULL_SYNC;
            else if (CacheWriteSynchronizationMode.PRIMARY_SYNC.name().equalsIgnoreCase(val))
                writeSyncMode = CacheWriteSynchronizationMode.PRIMARY_SYNC;
            else {
                throw new IgniteSQLException("Invalid value of \"" + PARAM_WRITE_SYNC + "\" parameter " + "(should be FULL_SYNC, FULL_ASYNC, or PRIMARY_SYNC): " + val, IgniteQueryErrorCode.PARSING);
            }
            res.writeSynchronizationMode(writeSyncMode);
            break;
        case PARAM_WRAP_KEY:
            {
                res.wrapKey(F.isEmpty(val) || Boolean.parseBoolean(val));
                break;
            }
        case PARAM_WRAP_VALUE:
            res.wrapValue(F.isEmpty(val) || Boolean.parseBoolean(val));
            break;
        case PARAM_DATA_REGION:
            ensureNotEmpty(name, val);
            res.dataRegionName(val);
            break;
        case PARAM_ENCRYPTED:
            res.encrypted(F.isEmpty(val) || Boolean.parseBoolean(val));
            break;
        case PARAM_PK_INLINE_SIZE:
            ensureNotEmpty(name, val);
            int pkInlineSize = parseIntParam(PARAM_PK_INLINE_SIZE, val);
            res.primaryKeyInlineSize(pkInlineSize);
            break;
        case PARAM_AFFINITY_INDEX_INLINE_SIZE:
            ensureNotEmpty(name, val);
            int affInlineSize = parseIntParam(PARAM_AFFINITY_INDEX_INLINE_SIZE, val);
            res.affinityKeyInlineSize(affInlineSize);
            break;
        default:
            throw new IgniteSQLException("Unsupported parameter: " + name, IgniteQueryErrorCode.PARSING);
    }
}
Also used : CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint)

Example 60 with IgniteSQLException

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

the class GridSqlQueryParser method parseAddColumn.

/**
 * Parse {@code ALTER TABLE ... ADD COLUMN} statement.
 * @param addCol H2 statement.
 * @return Grid SQL statement.
 *
 * @see <a href="http://www.h2database.com/html/grammar.html#alter_table_add"></a>
 */
private GridSqlStatement parseAddColumn(AlterTableAlterColumn addCol) {
    assert addCol.getType() == CommandInterface.ALTER_TABLE_ADD_COLUMN;
    if (ALTER_COLUMN_BEFORE_COL.get(addCol) != null)
        throw new IgniteSQLException("BEFORE keyword is not supported", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    if (ALTER_COLUMN_AFTER_COL.get(addCol) != null)
        throw new IgniteSQLException("AFTER keyword is not supported", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    if (ALTER_COLUMN_FIRST.get(addCol))
        throw new IgniteSQLException("FIRST keyword is not supported", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    GridSqlAlterTableAddColumn res = new GridSqlAlterTableAddColumn();
    ArrayList<Column> h2NewCols = ALTER_COLUMN_NEW_COLS.get(addCol);
    GridSqlColumn[] gridNewCols = new GridSqlColumn[h2NewCols.size()];
    for (int i = 0; i < h2NewCols.size(); i++) {
        Column col = h2NewCols.get(i);
        if (col.getDefaultExpression() != null) {
            throw new IgniteSQLException("ALTER TABLE ADD COLUMN with DEFAULT value is not supported " + "[col=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
        }
        gridNewCols[i] = parseColumn(h2NewCols.get(i));
    }
    res.columns(gridNewCols);
    if (gridNewCols.length == 1)
        res.ifNotExists(ALTER_COLUMN_IF_NOT_EXISTS.get(addCol));
    res.ifTableExists(ALTER_COLUMN_IF_TBL_EXISTS.get(addCol));
    Schema schema = SCHEMA_COMMAND_SCHEMA.get(addCol);
    res.schemaName(schema.getName());
    res.tableName(ALTER_COLUMN_TBL_NAME.get(addCol));
    return res;
}
Also used : GridSqlType.fromColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Schema(org.h2.schema.Schema) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint)

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