use of org.apache.ignite.internal.processors.query.IgniteSQLException in project ignite by apache.
the class JdbcStatement method doUpdate.
/**
* Run update query.
* @param sql SQL query.
* @param args Update arguments.
* @return Number of affected items.
* @throws SQLException If failed.
*/
long doUpdate(String sql, Object[] args) throws SQLException {
if (F.isEmpty(sql))
throw new SQLException("SQL query is empty");
Ignite ignite = conn.ignite();
UUID nodeId = conn.nodeId();
UUID uuid = UUID.randomUUID();
boolean loc = nodeId == null;
if (!conn.isDmlSupported())
throw new SQLException("Failed to query Ignite: DML operations are supported in versions 1.8.0 and newer");
JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), conn.schemaName(), sql, false, loc, args, fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
try {
JdbcQueryTask.QueryResult qryRes = loc ? qryTask.call() : ignite.compute(ignite.cluster().forNodeId(nodeId)).call(qryTask);
return updateCnt = updateCounterFromQueryResult(qryRes.getRows());
} catch (IgniteSQLException e) {
throw e.toJdbcException();
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException("Failed to query Ignite.", e);
}
}
use of org.apache.ignite.internal.processors.query.IgniteSQLException in project ignite by apache.
the class JdbcUtils method convertToSqlException.
/**
* Convert exception to {@link SQLException}.
*
* @param e Converted Exception.
* @param msgForUnknown Message for non-convertable exception.
* @param sqlStateForUnknown SQLSTATE for non-convertable exception.
* @return JDBC {@link SQLException}.
* @see IgniteQueryErrorCode
*/
public static SQLException convertToSqlException(Exception e, String msgForUnknown, String sqlStateForUnknown) {
SQLException sqlEx = null;
Throwable t = e;
while (sqlEx == null && t != null) {
if (t instanceof SQLException)
return (SQLException) t;
else if (t instanceof IgniteSQLException)
return ((IgniteSQLException) t).toJdbcException();
t = t.getCause();
}
return new SQLException(msgForUnknown, sqlStateForUnknown, e);
}
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 || ALTER_COLUMN_AFTER_COL.get(addCol) != null)
throw new IgniteSQLException("ALTER TABLE ADD COLUMN BEFORE/AFTER 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;
}
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_ATOMICITY:
ensureNotEmpty(name, val);
CacheAtomicityMode atomicityMode;
if (CacheAtomicityMode.TRANSACTIONAL.name().equalsIgnoreCase(val))
atomicityMode = CacheAtomicityMode.TRANSACTIONAL;
else if (CacheAtomicityMode.ATOMIC.name().equalsIgnoreCase(val))
atomicityMode = CacheAtomicityMode.ATOMIC;
else
throw new IgniteSQLException("Invalid value of \"" + PARAM_ATOMICITY + "\" parameter " + "(should be either TRANSACTIONAL or ATOMIC): " + val, IgniteQueryErrorCode.PARSING);
res.atomicityMode(atomicityMode);
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;
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 parseColumn.
/**
* Turn H2 column to grid column and check requested features.
* @param col H2 column.
* @return Grid column.
*/
private static GridSqlColumn parseColumn(Column col) {
if (col.isAutoIncrement())
throw new IgniteSQLException("AUTO_INCREMENT columns are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (COLUMN_IS_COMPUTED.get(col))
throw new IgniteSQLException("Computed columns are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (col.getDefaultExpression() != null) {
if (!col.getDefaultExpression().isConstant()) {
throw new IgniteSQLException("Non-constant DEFAULT expressions are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
DataType colType = DataType.getDataType(col.getType());
DataType dfltType = DataType.getDataType(col.getDefaultExpression().getType());
if ((DataType.isStringType(colType.type) && !DataType.isStringType(dfltType.type)) || (DataType.supportsAdd(colType.type) && !DataType.supportsAdd(dfltType.type))) {
throw new IgniteSQLException("Invalid default value for column. [colName=" + col.getName() + ", colType=" + colType.name + ", dfltValueType=" + dfltType.name + ']', IgniteQueryErrorCode.UNEXPECTED_ELEMENT_TYPE);
}
}
if (col.getSequence() != null)
throw new IgniteSQLException("SEQUENCE columns are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (col.getSelectivity() != Constants.SELECTIVITY_DEFAULT)
throw new IgniteSQLException("SELECTIVITY column attribute is not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (COLUMN_CHECK_CONSTRAINT.get(col) != null)
throw new IgniteSQLException("Column CHECK constraints are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
GridSqlColumn gridCol = new GridSqlColumn(col, null, col.getName());
gridCol.resultType(GridSqlType.fromColumn(col));
return gridCol;
}
Aggregations