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