Search in sources :

Example 6 with QueryCommand

use of org.teiid.query.sql.lang.QueryCommand in project teiid by teiid.

the class ConnectorWorkItem method setExecution.

private void setExecution(Command command, org.teiid.language.Command translatedCommand, final Execution exec) {
    if (translatedCommand instanceof Call) {
        // $NON-NLS-1$
        this.execution = Assertion.isInstanceOf(exec, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions");
        StoredProcedure proc = (StoredProcedure) command;
        if (proc.returnParameters()) {
            this.procedureBatchHandler = new ProcedureBatchHandler((Call) translatedCommand, (ProcedureExecution) exec);
        }
    } else if (command instanceof QueryCommand) {
        // $NON-NLS-1$
        this.execution = Assertion.isInstanceOf(exec, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions");
    } else {
        final boolean singleUpdateCount = connector.returnsSingleUpdateCount() && (translatedCommand instanceof BatchedUpdates || (translatedCommand instanceof BulkCommand && ((BulkCommand) translatedCommand).getParameterValues() != null));
        // $NON-NLS-1$
        Assertion.isInstanceOf(exec, UpdateExecution.class, "Update Executions are expected to be UpdateExecutions");
        this.execution = new ResultSetExecution() {

            private int[] results;

            private int index;

            @Override
            public void cancel() throws TranslatorException {
                exec.cancel();
            }

            @Override
            public void close() {
                exec.close();
            }

            @Override
            public void execute() throws TranslatorException {
                exec.execute();
            }

            @Override
            public List<?> next() throws TranslatorException, DataNotAvailableException {
                if (results == null) {
                    results = ((UpdateExecution) exec).getUpdateCounts();
                }
                if (singleUpdateCount) {
                    if (index++ < results[0]) {
                        return CollectionTupleSource.UPDATE_ROW;
                    }
                    return null;
                }
                if (index < results.length) {
                    return Arrays.asList(results[index++]);
                }
                return null;
            }
        };
    }
}
Also used : Call(org.teiid.language.Call) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) BulkCommand(org.teiid.language.BulkCommand) QueryCommand(org.teiid.query.sql.lang.QueryCommand) BatchedUpdates(org.teiid.language.BatchedUpdates)

Example 7 with QueryCommand

use of org.teiid.query.sql.lang.QueryCommand in project teiid by teiid.

the class SetQueryResolver method resolveCommand.

/**
 * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
 */
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    SetQuery setQuery = (SetQuery) command;
    SimpleQueryResolver.resolveWith(metadata, setQuery);
    QueryCommand firstCommand = setQuery.getLeftQuery();
    QueryResolver.setChildMetadata(firstCommand, setQuery);
    QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false);
    QueryCommand rightCommand = setQuery.getRightQuery();
    QueryResolver.setChildMetadata(rightCommand, setQuery);
    QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false);
    resolveSetQuery(metadata, resolveNullLiterals, setQuery, firstCommand, rightCommand);
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) QueryCommand(org.teiid.query.sql.lang.QueryCommand)

Aggregations

QueryCommand (org.teiid.query.sql.lang.QueryCommand)7 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 Command (org.teiid.query.sql.lang.Command)2 SetQuery (org.teiid.query.sql.lang.SetQuery)2 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)2 Expression (org.teiid.query.sql.symbol.Expression)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 TeiidException (org.teiid.core.TeiidException)1 BatchedUpdates (org.teiid.language.BatchedUpdates)1 BulkCommand (org.teiid.language.BulkCommand)1 Call (org.teiid.language.Call)1 QueryNode (org.teiid.query.mapping.relational.QueryNode)1 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)1 CacheHint (org.teiid.query.sql.lang.CacheHint)1 Limit (org.teiid.query.sql.lang.Limit)1 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)1 WithQueryCommand (org.teiid.query.sql.lang.WithQueryCommand)1