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)));
}
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations