Search in sources :

Example 16 with TeiidException

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

the class BaseQueryExecution method buildRow.

@SuppressWarnings("unchecked")
<T extends AbstractMetadataRecord> List<?> buildRow(T record, List<Column> columns, Class<?>[] expectedType, Map<String, Object> values) throws TranslatorException {
    List<Object> results = new ArrayList<Object>();
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i);
        T columnParent = (T) column.getParent();
        String colName = column.getName();
        if (!columnParent.equals(record)) {
            // $NON-NLS-1$
            colName = getName(columnParent) + "/" + column.getName();
        }
        Object value;
        try {
            value = ODataTypeManager.convertToTeiidRuntimeType(expectedType[i], values.get(colName), ODataMetadataProcessor.getNativeType(column));
        } catch (TeiidException e) {
            throw new TranslatorException(e);
        }
        results.add(value);
    }
    return results;
}
Also used : Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) TeiidException(org.teiid.core.TeiidException)

Example 17 with TeiidException

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

the class ReflectionHelper method create.

public static final Object create(String className, Object[] ctorObjs, Class<?>[] argTypes, final ClassLoader classLoader) throws TeiidException {
    Class<?> cls;
    try {
        cls = loadClass(className, classLoader);
    } catch (Exception e) {
        throw new TeiidException(CorePlugin.Event.TEIID10034, e);
    }
    Constructor<?> ctor = null;
    try {
        ctor = cls.getDeclaredConstructor(argTypes);
    } catch (NoSuchMethodException e) {
    }
    if (ctor == null && argTypes != null && argTypes.length > 0) {
        List<Class<?>> argumentsClasses = Arrays.asList(argTypes);
        List<Class<?>> argumentsClassList = convertArgumentClassesToPrimitives(argumentsClasses);
        for (Constructor<?> possible : cls.getDeclaredConstructors()) {
            if (argsMatch(argumentsClasses, argumentsClassList, possible.getParameterTypes())) {
                ctor = possible;
                break;
            }
        }
    }
    if (ctor == null) {
        throw new TeiidException(CorePlugin.Event.TEIID10035, className + CorePlugin.Event.TEIID10035 + Arrays.toString(argTypes));
    }
    try {
        return ctor.newInstance(ctorObjs);
    } catch (InvocationTargetException e) {
        throw new TeiidException(CorePlugin.Event.TEIID10036, e.getTargetException());
    } catch (Exception e) {
        throw new TeiidException(CorePlugin.Event.TEIID10036, e);
    }
}
Also used : TeiidException(org.teiid.core.TeiidException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeiidException(org.teiid.core.TeiidException)

Example 18 with TeiidException

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

the class JDBCExecutionFactory method getDialect.

public SQLDialect getDialect() {
    if (dialect == null) {
        String name = getHibernateDialectClassName();
        if (name != null) {
            try {
                Object impl = ReflectionHelper.create(name, null, this.getClass().getClassLoader());
                InvocationHandler handler = new MixinProxy(new Object[] { impl });
                this.dialect = (SQLDialect) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { SQLDialect.class }, handler);
            } catch (TeiidException e) {
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, name, "could not be loaded");
            }
        }
        if (dialect == null) {
            dialect = new DefaultSQLDialect();
        }
    }
    return dialect;
}
Also used : MixinProxy(org.teiid.core.util.MixinProxy) InvocationHandler(java.lang.reflect.InvocationHandler) TeiidException(org.teiid.core.TeiidException)

Example 19 with TeiidException

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

the class QueryProcessor method nextBatchDirect.

private TupleBatch nextBatchDirect() throws BlockedException, TeiidProcessingException, TeiidComponentException {
    boolean done = false;
    TupleBatch result = null;
    try {
        init();
        long currentTime = System.currentTimeMillis();
        Assertion.assertTrue(!processorClosed);
        while (currentTime < context.getTimeSliceEnd() || context.isNonBlocking()) {
            if (requestCanceled) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, this.context.getRequestId()));
            }
            if (currentTime > context.getTimeoutEnd()) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30161, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30161));
            }
            result = processPlan.nextBatch();
            if (continuous) {
                result.setRowOffset(rowOffset);
                if (result.getTerminationFlag()) {
                    result.setTermination(TupleBatch.ITERATION_TERMINATED);
                    List<Object> terminationTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
                    result.getTuples().add(terminationTuple);
                    this.context.getTupleSourceCache().close();
                    this.processPlan.close();
                    this.processPlan.reset();
                    this.context.incrementReuseCount();
                    this.open = false;
                }
                rowOffset = result.getEndRow() + 1;
            }
            if (result.getTermination() != TupleBatch.NOT_TERMINATED) {
                if (result.getTerminationFlag()) {
                    done = true;
                }
                break;
            }
            if (result.getRowCount() > 0) {
                break;
            }
        }
    } catch (BlockedException e) {
        throw e;
    } catch (TeiidException e) {
        closeProcessing();
        if (e instanceof TeiidProcessingException) {
            throw (TeiidProcessingException) e;
        }
        if (e instanceof TeiidComponentException) {
            throw (TeiidComponentException) e;
        }
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30162, e);
    }
    if (done) {
        closeProcessing();
    }
    if (result == null) {
        RequestWorkItem workItem = this.getContext().getWorkItem();
        if (workItem != null) {
            // if we have a workitem (non-test scenario) then before
            // throwing exprired time slice we need to indicate there's more work
            workItem.moreWork();
        }
        throw EXPIRED_TIME_SLICE;
    }
    return result;
}
Also used : RequestWorkItem(org.teiid.dqp.internal.process.RequestWorkItem) TeiidComponentException(org.teiid.core.TeiidComponentException) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException)

Example 20 with TeiidException

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

the class TestUpdateValidator method helpTest.

private UpdateValidator helpTest(String sql, TransformationMetadata md, boolean failInsert, boolean failUpdate, boolean failDelete) {
    try {
        String vGroup = "gx";
        Command command = createView(sql, md, vGroup);
        UpdateValidator uv = new UpdateValidator(md, UpdateType.INHERENT, UpdateType.INHERENT, UpdateType.INHERENT);
        GroupSymbol gs = new GroupSymbol(vGroup);
        ResolverUtil.resolveGroup(gs, md);
        uv.validate(command, ResolverUtil.resolveElementsInGroup(gs, md));
        UpdateInfo info = uv.getUpdateInfo();
        assertEquals(uv.getReport().getFailureMessage(), failInsert, info.getInsertValidationError() != null);
        assertEquals(uv.getReport().getFailureMessage(), failUpdate, info.getUpdateValidationError() != null);
        assertEquals(uv.getReport().getFailureMessage(), failDelete, info.getDeleteValidationError() != null);
        return uv;
    } catch (TeiidException e) {
        throw new RuntimeException(e);
    }
}
Also used : Command(org.teiid.query.sql.lang.Command) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) UpdateInfo(org.teiid.query.validator.UpdateValidator.UpdateInfo) 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