Search in sources :

Example 6 with TeiidRuntimeException

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceIt info) {
    if (info.getType() instanceof SingletonPrimitiveType) {
        org.teiid.query.sql.symbol.Expression ex = null;
        if (this.ctxQuery.getIterator() == null) {
            String group = this.nameGenerator.getNextGroup();
            GroupSymbol groupSymbol = new GroupSymbol(group);
            StoredProcedure procedure = new StoredProcedure();
            procedure.setProcedureName("arrayiterate");
            // the projected should only be the collection property at this point
            // we may need more checks here to ensure that is valid
            Collection<ProjectedColumn> values = this.ctxQuery.getProjectedColumns().values();
            Assertion.assertTrue(values.size() == 1);
            ProjectedColumn projectedColumn = values.iterator().next();
            ElementSymbol projectedEs = (ElementSymbol) projectedColumn.getExpression();
            List<SPParameter> params = new ArrayList<SPParameter>();
            SPParameter param = new SPParameter(1, SPParameter.IN, "val");
            param.setExpression(projectedEs);
            params.add(param);
            procedure.setParameter(param);
            SubqueryFromClause fromClause = new SubqueryFromClause(group, procedure);
            fromClause.setLateral(true);
            ElementSymbol es = new ElementSymbol("col", groupSymbol);
            String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
            Function castFunction = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
            DocumentNode itResource = new DocumentNode();
            org.teiid.query.sql.symbol.Expression clone = (org.teiid.query.sql.symbol.Expression) castFunction.clone();
            AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, clone);
            AliasSymbol expression = new AliasSymbol(projectedEs.getShortName(), symbol);
            itResource.setFromClause(fromClause);
            itResource.setGroupSymbol(groupSymbol);
            itResource.addProjectedColumn(expression, info.getType(), projectedColumn.getProperty(), true);
            this.ctxQuery.getProjectedColumns().remove(projectedColumn.getExpression());
            this.ctxQuery.setIterator(itResource);
            ex = castFunction;
        } else {
            GroupSymbol groupSymbol = this.ctxQuery.getIterator().getGroupSymbol();
            ElementSymbol es = new ElementSymbol("col", groupSymbol);
            String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
            ex = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
        }
        this.stack.push(ex);
    } else {
        boolean ex = true;
        if (this.ctxQuery instanceof ExpandDocumentNode) {
            ExpandDocumentNode node = (ExpandDocumentNode) this.ctxQuery;
            DocumentNode parent = node.getCollectionContext();
            if (parent != null) {
                this.ctxExpression = parent;
                ex = false;
            }
        }
        if (ex) {
            throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16010, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16010)));
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ProjectedColumn(org.teiid.olingo.ProjectedColumn) Function(org.teiid.query.sql.symbol.Function) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 7 with TeiidRuntimeException

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceLambdaVariable resource) {
    try {
        if (this.ctxLambda == null) {
            DocumentNode lambda = DocumentNode.build((EdmEntityType) resource.getType(), null, this.metadata, this.odata, this.nameGenerator, false, this.uriInfo, this.parseService);
            lambda.setGroupSymbol(new GroupSymbol(resource.getVariableName(), lambda.getFullName()));
            this.ctxLambda = lambda;
        }
        this.ctxExpression = ctxLambda;
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 8 with TeiidRuntimeException

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

the class TestSQLException method testCreateThrowable_01.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various simple exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_01() {
    testCreateThrowable(new CommunicationException(// $NON-NLS-1$
    "A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(// $NON-NLS-1$
    "A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
    "A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(// $NON-NLS-1$
    new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
    testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
    "A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
    testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
    "A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new NullPointerException("A test NPE"), SQLStates.DEFAULT);
    testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
    "A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
    testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
    "A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
Also used : MalformedURLException(java.net.MalformedURLException) CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) NoRouteToHostException(java.net.NoRouteToHostException) TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionException(org.teiid.net.ConnectionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 9 with TeiidRuntimeException

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

the class TestSocketServiceRegistry method testExceptionConversionNoException.

public void testExceptionConversionNoException() throws Exception {
    Method m = Foo.class.getMethod("somemethod", new Class[] {});
    Throwable t = ExceptionUtil.convertException(m, new TeiidComponentException());
    assertTrue(t instanceof TeiidRuntimeException);
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) Method(java.lang.reflect.Method) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 10 with TeiidRuntimeException

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

the class TestExceptionHolder method testSQLExceptionChain.

@Test
public void testSQLExceptionChain() throws Exception {
    // $NON-NLS-1$
    ClassLoader cl = new URLClassLoader(new URL[] { UnitTestUtil.getTestDataFile("test.jar").toURI().toURL() });
    // $NON-NLS-1$
    Exception obj = (Exception) ReflectionHelper.create("test.UnknownException", null, cl);
    SQLException se = new SQLException("something bad happened");
    // $NON-NLS-1$
    se.initCause(obj);
    SQLException next = se;
    for (int i = 0; i < 10; i++) {
        SQLException se1 = new SQLException("something else bad happened");
        // $NON-NLS-1$
        se1.initCause(obj);
        next.setNextException(se1);
        next = se1;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CustomStream oos = new CustomStream(baos);
    // $NON-NLS-1$
    oos.writeObject(new ExceptionHolder(se, false));
    oos.flush();
    assertEquals(22, oos.count.get());
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ExceptionHolder holder = (ExceptionHolder) ois.readObject();
    Throwable e = holder.getException();
    assertTrue(e instanceof SQLException);
    // $NON-NLS-1$
    assertEquals("Remote java.sql.SQLException: something bad happened", e.getMessage());
    assertTrue(e.getCause() instanceof TeiidRuntimeException);
    e = ((SQLException) e).getNextException();
    assertTrue(e instanceof SQLException);
    // $NON-NLS-1$
    assertEquals("Remote java.sql.SQLException: something else bad happened", e.getMessage());
    int count = 0;
    while ((e = ((SQLException) e).getNextException()) != null) {
        count++;
    }
    assertEquals(9, count);
}
Also used : SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) SQLException(java.sql.SQLException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4