Search in sources :

Example 76 with IgniteSQLException

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

the class DdlStatementsProcessor method runDdlStatement.

/**
 * Execute DDL statement.
 *
 * @param sql SQL.
 * @param prepared Prepared.
 * @return Cursor on query results.
 * @throws IgniteCheckedException On error.
 */
@SuppressWarnings({ "unchecked", "ThrowableResultOfMethodCallIgnored" })
public FieldsQueryCursor<List<?>> runDdlStatement(String sql, Prepared prepared) throws IgniteCheckedException {
    IgniteInternalFuture fut = null;
    try {
        GridSqlStatement stmt0 = new GridSqlQueryParser(false).parse(prepared);
        if (stmt0 instanceof GridSqlCreateIndex) {
            GridSqlCreateIndex cmd = (GridSqlCreateIndex) stmt0;
            GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            if (tbl == null)
                throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
            assert tbl.rowDescriptor() != null;
            isDdlSupported(tbl);
            QueryIndex newIdx = new QueryIndex();
            newIdx.setName(cmd.index().getName());
            newIdx.setIndexType(cmd.index().getIndexType());
            LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>();
            // Let's replace H2's table and property names by those operated by GridQueryProcessor.
            GridQueryTypeDescriptor typeDesc = tbl.rowDescriptor().type();
            for (Map.Entry<String, Boolean> e : cmd.index().getFields().entrySet()) {
                GridQueryProperty prop = typeDesc.property(e.getKey());
                if (prop == null)
                    throw new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND, e.getKey());
                flds.put(prop.name(), e.getValue());
            }
            newIdx.setFields(flds);
            fut = ctx.query().dynamicIndexCreate(tbl.cacheName(), cmd.schemaName(), typeDesc.tableName(), newIdx, cmd.ifNotExists(), 0);
        } else if (stmt0 instanceof GridSqlDropIndex) {
            GridSqlDropIndex cmd = (GridSqlDropIndex) stmt0;
            GridH2Table tbl = idx.dataTableForIndex(cmd.schemaName(), cmd.indexName());
            if (tbl != null) {
                isDdlSupported(tbl);
                fut = ctx.query().dynamicIndexDrop(tbl.cacheName(), cmd.schemaName(), cmd.indexName(), cmd.ifExists());
            } else {
                if (cmd.ifExists())
                    fut = new GridFinishedFuture();
                else
                    throw new SchemaOperationException(SchemaOperationException.CODE_INDEX_NOT_FOUND, cmd.indexName());
            }
        } else if (stmt0 instanceof GridSqlCreateTable) {
            GridSqlCreateTable cmd = (GridSqlCreateTable) stmt0;
            if (!F.eq(QueryUtils.DFLT_SCHEMA, cmd.schemaName()))
                throw new SchemaOperationException("CREATE TABLE can only be executed on " + QueryUtils.DFLT_SCHEMA + " schema.");
            GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            if (tbl != null) {
                if (!cmd.ifNotExists())
                    throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, cmd.tableName());
            } else {
                QueryEntity e = toQueryEntity(cmd);
                CacheConfiguration<?, ?> ccfg = new CacheConfiguration<>(cmd.tableName());
                ccfg.setQueryEntities(Collections.singleton(e));
                ccfg.setSqlSchema(cmd.schemaName());
                SchemaOperationException err = QueryUtils.checkQueryEntityConflicts(ccfg, ctx.cache().cacheDescriptors().values());
                if (err != null)
                    throw err;
                ctx.query().dynamicTableCreate(cmd.schemaName(), e, cmd.templateName(), cmd.cacheName(), cmd.cacheGroup(), cmd.dataRegionName(), cmd.affinityKey(), cmd.atomicityMode(), cmd.writeSynchronizationMode(), cmd.backups(), cmd.ifNotExists());
            }
        } else if (stmt0 instanceof GridSqlDropTable) {
            GridSqlDropTable cmd = (GridSqlDropTable) stmt0;
            if (!F.eq(QueryUtils.DFLT_SCHEMA, cmd.schemaName()))
                throw new SchemaOperationException("DROP TABLE can only be executed on " + QueryUtils.DFLT_SCHEMA + " schema.");
            GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            if (tbl == null && cmd.ifExists()) {
                ctx.cache().createMissingQueryCaches();
                tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            }
            if (tbl == null) {
                if (!cmd.ifExists())
                    throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
            } else
                ctx.query().dynamicTableDrop(tbl.cacheName(), cmd.tableName(), cmd.ifExists());
        } else if (stmt0 instanceof GridSqlAlterTableAddColumn) {
            GridSqlAlterTableAddColumn cmd = (GridSqlAlterTableAddColumn) stmt0;
            GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            if (tbl == null && cmd.ifTableExists()) {
                ctx.cache().createMissingQueryCaches();
                tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            }
            if (tbl == null) {
                if (!cmd.ifTableExists())
                    throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
            } else {
                if (QueryUtils.isSqlType(tbl.rowDescriptor().type().valueClass()))
                    throw new SchemaOperationException("Cannot add column(s) because table was created " + "with " + PARAM_WRAP_VALUE + "=false option.");
                List<QueryField> cols = new ArrayList<>(cmd.columns().length);
                boolean allFieldsNullable = true;
                for (GridSqlColumn col : cmd.columns()) {
                    if (tbl.doesColumnExist(col.columnName())) {
                        if ((!cmd.ifNotExists() || cmd.columns().length != 1)) {
                            throw new SchemaOperationException(SchemaOperationException.CODE_COLUMN_EXISTS, col.columnName());
                        } else {
                            cols = null;
                            break;
                        }
                    }
                    QueryField field = new QueryField(col.columnName(), DataType.getTypeClassName(col.column().getType()), col.column().isNullable(), col.defaultValue());
                    cols.add(field);
                    allFieldsNullable &= field.isNullable();
                }
                if (cols != null) {
                    assert tbl.rowDescriptor() != null;
                    if (!allFieldsNullable)
                        QueryUtils.checkNotNullAllowed(tbl.cache().config());
                    fut = ctx.query().dynamicColumnAdd(tbl.cacheName(), cmd.schemaName(), tbl.rowDescriptor().type().tableName(), cols, cmd.ifTableExists(), cmd.ifNotExists());
                }
            }
        } else if (stmt0 instanceof GridSqlAlterTableDropColumn) {
            GridSqlAlterTableDropColumn cmd = (GridSqlAlterTableDropColumn) stmt0;
            GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            if (tbl == null && cmd.ifTableExists()) {
                ctx.cache().createMissingQueryCaches();
                tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
            }
            if (tbl == null) {
                if (!cmd.ifTableExists())
                    throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
            } else {
                assert tbl.rowDescriptor() != null;
                if (QueryUtils.isSqlType(tbl.rowDescriptor().type().valueClass()))
                    throw new SchemaOperationException("Cannot drop column(s) because table was created " + "with " + PARAM_WRAP_VALUE + "=false option.");
                List<String> cols = new ArrayList<>(cmd.columns().length);
                GridQueryTypeDescriptor type = tbl.rowDescriptor().type();
                for (String colName : cmd.columns()) {
                    if (!tbl.doesColumnExist(colName)) {
                        if ((!cmd.ifExists() || cmd.columns().length != 1)) {
                            throw new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND, colName);
                        } else {
                            cols = null;
                            break;
                        }
                    }
                    SchemaOperationException err = QueryUtils.validateDropColumn(type, colName);
                    if (err != null)
                        throw err;
                    cols.add(colName);
                }
                if (cols != null) {
                    fut = ctx.query().dynamicColumnRemove(tbl.cacheName(), cmd.schemaName(), type.tableName(), cols, cmd.ifTableExists(), cmd.ifExists());
                }
            }
        } else
            throw new IgniteSQLException("Unsupported DDL operation: " + sql, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
        if (fut != null)
            fut.get();
        QueryCursorImpl<List<?>> resCur = (QueryCursorImpl<List<?>>) new QueryCursorImpl(Collections.singletonList(Collections.singletonList(0L)), null, false);
        resCur.fieldsMeta(UPDATE_RESULT_META);
        return resCur;
    } catch (SchemaOperationException e) {
        U.error(null, "DDL operation failure", e);
        throw convert(e);
    } catch (IgniteSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new IgniteSQLException(e.getMessage(), e);
    }
}
Also used : GridSqlStatement(org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridSqlDropIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex) LinkedHashMap(java.util.LinkedHashMap) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) QueryField(org.apache.ignite.internal.processors.query.QueryField) GridSqlCreateIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateIndex) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) QueryIndex(org.apache.ignite.cache.QueryIndex) List(java.util.List) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) GridSqlCreateTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateTable) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) QueryEntity(org.apache.ignite.cache.QueryEntity) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) GridQueryProperty(org.apache.ignite.internal.processors.query.GridQueryProperty) GridSqlAlterTableAddColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableAddColumn) GridSqlAlterTableDropColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableDropColumn) GridSqlQueryParser(org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser) GridSqlColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridSqlDropTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropTable)

Example 77 with IgniteSQLException

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

the class IgniteH2Indexing method dropTable.

/**
 * Drops table form h2 database and clear all related indexes (h2 text, lucene).
 *
 * @param tbl Table to unregister.
 * @throws IgniteCheckedException If failed to unregister.
 */
private void dropTable(H2TableDescriptor tbl) throws IgniteCheckedException {
    assert tbl != null;
    if (log.isDebugEnabled())
        log.debug("Removing query index table: " + tbl.fullTableName());
    Connection c = connectionForThread(tbl.schemaName());
    Statement stmt = null;
    try {
        stmt = c.createStatement();
        String sql = "DROP TABLE IF EXISTS " + tbl.fullTableName();
        if (log.isDebugEnabled())
            log.debug("Dropping database index table with SQL: " + sql);
        stmt.executeUpdate(sql);
    } catch (SQLException e) {
        onSqlException();
        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) PreparedStatement(java.sql.PreparedStatement) JdbcStatement(org.h2.jdbc.JdbcStatement) Statement(java.sql.Statement) GridSqlStatement(org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement) Connection(java.sql.Connection) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString)

Example 78 with IgniteSQLException

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

the class IgniteH2Indexing method queryDistributedSql.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public <K, V> QueryCursor<Cache.Entry<K, V>> queryDistributedSql(String schemaName, String cacheName, SqlQuery qry, boolean keepBinary) {
    String type = qry.getType();
    H2TableDescriptor tblDesc = tableDescriptor(schemaName, cacheName, type);
    if (tblDesc == null)
        throw new IgniteSQLException("Failed to find SQL table for type: " + type, IgniteQueryErrorCode.TABLE_NOT_FOUND);
    String sql;
    try {
        sql = generateQuery(qry.getSql(), qry.getAlias(), tblDesc);
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }
    SqlFieldsQuery fqry = new SqlFieldsQuery(sql);
    fqry.setArgs(qry.getArgs());
    fqry.setPageSize(qry.getPageSize());
    fqry.setDistributedJoins(qry.isDistributedJoins());
    fqry.setPartitions(qry.getPartitions());
    fqry.setLocal(qry.isLocal());
    if (qry.getTimeout() > 0)
        fqry.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS);
    final QueryCursor<List<?>> res = querySqlFields(schemaName, fqry, null, keepBinary, true, null).get(0);
    final Iterable<Cache.Entry<K, V>> converted = new Iterable<Cache.Entry<K, V>>() {

        @Override
        public Iterator<Cache.Entry<K, V>> iterator() {
            final Iterator<List<?>> iter0 = res.iterator();
            return new Iterator<Cache.Entry<K, V>>() {

                @Override
                public boolean hasNext() {
                    return iter0.hasNext();
                }

                @Override
                public Cache.Entry<K, V> next() {
                    List<?> l = iter0.next();
                    return new CacheEntryImpl<>((K) l.get(0), (V) l.get(1));
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    // No metadata for SQL queries.
    return new QueryCursorImpl<Cache.Entry<K, V>>(converted) {

        @Override
        public void close() {
            res.close();
        }
    };
}
Also used : QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridEmptyCloseableIterator(org.apache.ignite.internal.util.GridEmptyCloseableIterator) GridQueryCacheObjectsIterator(org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator) Iterator(java.util.Iterator) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) ArrayList(java.util.ArrayList) List(java.util.List) Cache(javax.cache.Cache)

Example 79 with IgniteSQLException

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

the class IgniteH2Indexing method tryQueryDistributedSqlFieldsNative.

/**
 * Try executing query using native facilities.
 *
 * @param schemaName Schema name.
 * @param sql Query.
 * @param cliCtx Client context, or {@code null} if not applicable.
 * @return Result or {@code null} if cannot parse/process this query.
 */
private List<FieldsQueryCursor<List<?>>> tryQueryDistributedSqlFieldsNative(String schemaName, String sql, @Nullable SqlClientContext cliCtx) {
    // Heuristic check for fast return.
    if (!INTERNAL_CMD_RE.matcher(sql.trim()).find())
        return null;
    // Parse.
    SqlCommand cmd;
    try {
        SqlParser parser = new SqlParser(schemaName, sql);
        cmd = parser.nextCommand();
        // No support for multiple commands for now.
        if (parser.nextCommand() != null)
            return null;
        // CREATE/ALTER/DROP USER
        if (!(cmd instanceof SqlCreateIndexCommand || cmd instanceof SqlDropIndexCommand || cmd instanceof SqlAlterTableCommand || cmd instanceof SqlBulkLoadCommand || cmd instanceof SqlSetStreamingCommand || cmd instanceof SqlCreateUserCommand || cmd instanceof SqlAlterUserCommand || cmd instanceof SqlDropUserCommand))
            return null;
    } catch (Exception e) {
        // Cannot parse, return.
        if (log.isDebugEnabled())
            log.debug("Failed to parse SQL with native parser [qry=" + sql + ", err=" + e + ']');
        if (!IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_SQL_PARSER_DISABLE_H2_FALLBACK))
            return null;
        int code = IgniteQueryErrorCode.PARSING;
        if (e instanceof SqlParseException)
            code = ((SqlParseException) e).code();
        throw new IgniteSQLException("Failed to parse DDL statement: " + sql + ": " + e.getMessage(), code, e);
    }
    // Execute.
    if (cmd instanceof SqlBulkLoadCommand) {
        FieldsQueryCursor<List<?>> cursor = dmlProc.runNativeDmlStatement(sql, cmd);
        return Collections.singletonList(cursor);
    } else if (cmd instanceof SqlSetStreamingCommand) {
        if (cliCtx == null)
            throw new IgniteSQLException("SET STREAMING command can only be executed from JDBC or ODBC driver.");
        SqlSetStreamingCommand setCmd = (SqlSetStreamingCommand) cmd;
        boolean on = setCmd.isTurnOn();
        if (on)
            cliCtx.enableStreaming(setCmd.allowOverwrite(), setCmd.flushFrequency(), setCmd.perNodeBufferSize(), setCmd.perNodeParallelOperations());
        else
            cliCtx.disableStreaming();
        return Collections.singletonList(H2Utils.zeroCursor());
    } else {
        try {
            FieldsQueryCursor<List<?>> cursor = ddlProc.runDdlStatement(sql, cmd);
            return Collections.singletonList(cursor);
        } catch (IgniteCheckedException e) {
            throw new IgniteSQLException("Failed to execute DDL statement [stmt=" + sql + "]: " + e.getMessage(), e);
        }
    }
}
Also used : SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) SqlParser(org.apache.ignite.internal.sql.SqlParser) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) ArrayList(java.util.ArrayList) List(java.util.List) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand)

Example 80 with IgniteSQLException

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

the class DmlUtils method convert.

/**
 * Convert value to column's expected type by means of H2.
 *
 * @param val Source value.
 * @param desc Row descriptor.
 * @param expCls Expected value class.
 * @param type Expected column type to convert to.
 * @return Converted object.
 * @throws IgniteCheckedException if failed.
 */
@SuppressWarnings({ "ConstantConditions", "SuspiciousSystemArraycopy" })
public static Object convert(Object val, GridH2RowDescriptor desc, Class<?> expCls, int type) throws IgniteCheckedException {
    if (val == null)
        return null;
    Class<?> currCls = val.getClass();
    try {
        if (val instanceof Date && currCls != Date.class && expCls == Date.class) {
            // precise Date instance. Let's satisfy it.
            return new Date(((Date) val).getTime());
        }
        // User-given UUID is always serialized by H2 to byte array, so we have to deserialize manually
        if (type == Value.UUID && currCls == byte[].class)
            return U.unmarshal(desc.context().marshaller(), (byte[]) val, U.resolveClassLoader(desc.context().gridConfig()));
        if (LocalDateTimeUtils.isJava8DateApiPresent()) {
            if (val instanceof Timestamp && LocalDateTimeUtils.isLocalDateTime(expCls))
                return LocalDateTimeUtils.valueToLocalDateTime(ValueTimestamp.get((Timestamp) val));
            if (val instanceof Date && LocalDateTimeUtils.isLocalDate(expCls))
                return LocalDateTimeUtils.valueToLocalDate(ValueDate.fromDateValue(DateTimeUtils.dateValueFromDate(((Date) val).getTime())));
            if (val instanceof Time && LocalDateTimeUtils.isLocalTime(expCls))
                return LocalDateTimeUtils.valueToLocalTime(ValueTime.get((Time) val));
        }
        // Still, we only can convert from Object[] to something more precise.
        if (type == Value.ARRAY && currCls != expCls) {
            if (currCls != Object[].class)
                throw new IgniteCheckedException("Unexpected array type - only conversion from Object[] " + "is assumed");
            // Why would otherwise type be Value.ARRAY?
            assert expCls.isArray();
            Object[] curr = (Object[]) val;
            Object newArr = Array.newInstance(expCls.getComponentType(), curr.length);
            System.arraycopy(curr, 0, newArr, 0, curr.length);
            return newArr;
        }
        Object res = H2Utils.convert(val, desc, type);
        if (res instanceof Date && res.getClass() != Date.class && expCls == Date.class) {
            // without query - let's handle this
            return new Date(((Date) res).getTime());
        }
        return res;
    } catch (Exception e) {
        throw new IgniteSQLException("Value conversion failed [from=" + currCls.getName() + ", to=" + expCls.getName() + ']', IgniteQueryErrorCode.CONVERSION_FAILED, e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) Time(java.sql.Time) ValueTime(org.h2.value.ValueTime) Timestamp(java.sql.Timestamp) ValueTimestamp(org.h2.value.ValueTimestamp) Date(java.util.Date) ValueDate(org.h2.value.ValueDate) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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