Search in sources :

Example 31 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestProcessor method helpProcessException.

private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
    TupleBuffer tsId = null;
    BufferManager bufferMgr = null;
    try {
        bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
        // $NON-NLS-1$ //$NON-NLS-2$
        CommandContext context = new CommandContext("0", "test", null, null, 1);
        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
        processor.setNonBlocking(true);
        BatchCollector collector = processor.createBatchCollector();
        tsId = collector.collectTuples();
        // $NON-NLS-1$
        fail("Expected error during processing, but got none.");
    } catch (TeiidException e) {
        // ignore - this is expected
        if (expectedErrorMessage != null) {
            assertEquals(expectedErrorMessage, e.getMessage());
        }
    } finally {
        if (tsId != null) {
            tsId.remove();
        }
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) TeiidException(org.teiid.core.TeiidException)

Example 32 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class JPQLUpdateExecution method handleInsert.

private Object handleInsert(Insert insert) throws TranslatorException {
    try {
        String entityClassName = insert.getTable().getMetadataObject().getProperty(JPAMetadataProcessor.ENTITYCLASS, false);
        Object entity = ReflectionHelper.create(entityClassName, null, this.executionContext.getCommandContext().getVDBClassLoader());
        List<ColumnReference> columns = insert.getColumns();
        List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
        if (columns.size() != values.size()) {
            throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14007));
        }
        for (int i = 0; i < columns.size(); i++) {
            Column column = columns.get(i).getMetadataObject();
            Object value = values.get(i);
            // do not add the derived columns
            String name = column.getProperty(JPAMetadataProcessor.KEY_ASSOSIATED_WITH_FOREIGN_TABLE, false);
            if (name == null) {
                if (value instanceof Literal) {
                    Literal literalValue = (Literal) value;
                    PropertiesUtils.setBeanProperty(entity, column.getName(), literalValue.getValue());
                } else {
                    PropertiesUtils.setBeanProperty(entity, column.getName(), value);
                }
            }
        }
        return entity;
    } catch (TeiidException e) {
        throw new TranslatorException(e);
    }
}
Also used : Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) TranslatorException(org.teiid.translator.TranslatorException) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource) TeiidException(org.teiid.core.TeiidException)

Example 33 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestCriteriaCapabilityValidatorVisitor method helpTestVisitorWithCommand.

// Assume there is a wrapped command - this will allow subqueries to be properly resolved
public void helpTestVisitorWithCommand(String sql, Object modelID, TransformationMetadata metadata, CapabilitiesFinder capFinder, boolean isValid, boolean expectException) {
    try {
        Command command = QueryParser.getQueryParser().parseCommand(sql);
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        assertEquals("Got incorrect isValid flag", isValid, CriteriaCapabilityValidatorVisitor.canPushLanguageObject(command, modelID, metadata, capFinder, null));
    } catch (QueryMetadataException e) {
        if (!expectException) {
            throw new RuntimeException(e);
        }
    } catch (TeiidException e) {
        throw new RuntimeException(e);
    }
}
Also used : Command(org.teiid.query.sql.lang.Command) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidException(org.teiid.core.TeiidException)

Example 34 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class ValidationVisitor method validateUpdate.

protected void validateUpdate(Update update) {
    try {
        UpdateInfo info = update.getUpdateInfo();
        // list of elements that are being updated
        for (SetClause entry : update.getChangeList().getClauses()) {
            ElementSymbol elementID = entry.getSymbol();
            // Check that left side element is updatable
            if (!getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.UPDATE)) {
                // $NON-NLS-1$
                handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0059", elementID), elementID);
            }
            Object metadataID = elementID.getMetadataID();
            if (getMetadata().isMultiSourceElement(metadataID)) {
                // $NON-NLS-1$
                handleValidationError(QueryPlugin.Util.getString("multi_source_update_not_allowed", elementID), elementID);
            }
            // Check that right expression is a constant and is non-null
            Expression value = entry.getValue();
            if (EvaluatableVisitor.isFullyEvaluatable(value, true)) {
                try {
                    value = new Constant(Evaluator.evaluate(value));
                } catch (ExpressionEvaluationException err) {
                }
            }
            if (value instanceof Constant) {
                // If value is null, check that element supports this as a nullable column
                if (((Constant) value).isNull() && !getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL)) {
                    // $NON-NLS-1$
                    handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060", SQLStringVisitor.getSQLString(elementID)), elementID);
                }
            // end of if
            }
        }
        if (info != null && info.isInherentUpdate()) {
            validateUpdate(update, Command.TYPE_UPDATE, info);
            Set<ElementSymbol> updateCols = update.getChangeList().getClauseMap().keySet();
            if (!info.hasValidUpdateMapping(updateCols)) {
                handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, updateCols), update);
            }
        }
    } catch (TeiidException e) {
        handleException(e, update);
    }
    validateSetClauseList(update.getChangeList());
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) SaxonXQueryExpression(org.teiid.query.xquery.saxon.SaxonXQueryExpression) LanguageObject(org.teiid.query.sql.LanguageObject) UpdateInfo(org.teiid.query.validator.UpdateValidator.UpdateInfo) TeiidException(org.teiid.core.TeiidException)

Example 35 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class CommandContext method getConnection.

@Override
public TeiidConnection getConnection() throws TeiidSQLException {
    LocalProfile ep = getDQPWorkContext().getConnectionProfile();
    // TODO: this is problematic as the client properties are not conveyed
    Properties info = new Properties();
    info.put(LocalProfile.DQP_WORK_CONTEXT, getDQPWorkContext());
    // $NON-NLS-1$ //$NON-NLS-2$
    String url = "jdbc:teiid:" + getVdbName() + "." + getVdbVersion();
    ServerConnection sc;
    try {
        sc = ep.createServerConnection(info);
    } catch (TeiidException e) {
        throw TeiidSQLException.create(e);
    }
    return new ConnectionImpl(sc, info, url) {

        @Override
        public void close() throws SQLException {
        // just ignore
        }

        @Override
        public void rollback() throws SQLException {
        // just ignore
        }

        @Override
        public void setAutoCommit(boolean autoCommit) throws SQLException {
            // TODO: detect if attempted set conflicts with current txn state
            throw new TeiidSQLException();
        }

        @Override
        public void commit() throws SQLException {
            throw new TeiidSQLException();
        }

        @Override
        public void changeUser(String userName, String newPassword) throws SQLException {
            throw new TeiidSQLException();
        }

        @Override
        protected synchronized long nextRequestID() {
            // need to choose ids that won't conflict with the user connection
            return -(long) (Math.random() * Long.MAX_VALUE);
        }
    };
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ServerConnection(org.teiid.net.ServerConnection) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) LocalProfile(org.teiid.jdbc.LocalProfile) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidException (org.teiid.core.TeiidException)85 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)26 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 SQLException (java.sql.SQLException)9 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)8 BigInteger (java.math.BigInteger)6 Column (org.teiid.metadata.Column)6 Command (org.teiid.query.sql.lang.Command)6 TranslatorException (org.teiid.translator.TranslatorException)6 IOException (java.io.IOException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 List (java.util.List)4 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)4 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 UpdateResponse (org.teiid.odata.api.UpdateResponse)4 Update (org.teiid.query.sql.lang.Update)4 SocketTimeoutException (java.net.SocketTimeoutException)3