use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class Evaluator method evaluate.
private Object evaluate(List<?> tuple, ExceptionExpression ee) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
String msg = (String) internalEvaluate(ee.getMessage(), tuple);
String sqlState = ee.getDefaultSQLState();
if (ee.getSqlState() != null) {
sqlState = (String) internalEvaluate(ee.getSqlState(), tuple);
}
Integer errorCode = null;
if (ee.getErrorCode() != null) {
errorCode = (Integer) internalEvaluate(ee.getErrorCode(), tuple);
}
Exception parent = null;
if (ee.getParent() != null) {
parent = (Exception) internalEvaluate(ee.getParent(), tuple);
}
Exception result = new TeiidSQLException(parent, msg, sqlState, errorCode != null ? errorCode : 0);
result.setStackTrace(SourceWarning.EMPTY_STACK_TRACE);
return result;
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class ProcedurePlan method processProcedure.
/**
* <p>Process the procedure, using the stack of Programs supplied by the
* ProcessorEnvironment. With each pass through the loop, the
* current Program is gotten off the top of the stack, and the
* current instruction is gotten from that program; each call
* to an instruction's process method may alter the Program
* Stack and/or the current instruction pointer of a Program,
* so it's important that this method's loop refer to the
* call stack of the ProcessorEnvironment each time, and not
* cache things in local variables. If the current Program's
* current instruction is null, then it's time to pop that
* Program off the stack.</p>
*
* @return List a single tuple containing one Integer: the update
* count resulting from the procedure execution.
*/
private TupleSource processProcedure() throws TeiidComponentException, TeiidProcessingException, BlockedException {
// execute plan
ProgramInstruction inst = null;
while (!this.programs.empty()) {
Program program = peek();
inst = program.getCurrentInstruction();
if (inst == null) {
// $NON-NLS-1$
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Finished program", program);
// look ahead to see if we need to process in place
VariableContext vc = this.cursorStates.getParentContext();
CursorState last = (CursorState) this.cursorStates.getValue(null);
if (last != null) {
if (last.resultsBuffer == null && (last.usesLocalTemp || !txnTupleSources.isEmpty())) {
last.resultsBuffer = bufferMgr.createTupleBuffer(last.processor.getOutputElements(), getContext().getConnectionId(), TupleSourceType.PROCESSOR);
last.returning = true;
}
if (last.returning) {
while (last.ts.hasNext()) {
List<?> tuple = last.ts.nextTuple();
last.resultsBuffer.addTuple(tuple);
}
last.resultsBuffer.close();
last.ts = last.resultsBuffer.createIndexedTupleSource(true);
last.returning = false;
}
}
this.pop(true);
continue;
}
try {
getContext().setCurrentTimestamp(System.currentTimeMillis());
if (inst instanceof RepeatedInstruction) {
// $NON-NLS-1$
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Executing repeated instruction", inst);
RepeatedInstruction loop = (RepeatedInstruction) inst;
if (loop.testCondition(this)) {
// $NON-NLS-1$
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Passed condition, executing program " + loop.getNestedProgram());
inst.process(this);
this.push(loop.getNestedProgram());
continue;
}
// $NON-NLS-1$
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Exiting repeated instruction", inst);
loop.postInstruction(this);
} else {
// $NON-NLS-1$
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Executing instruction", inst);
inst.process(this);
this.evaluator.close();
}
} catch (TeiidComponentException e) {
throw e;
} catch (Exception e) {
// processing or teiidsqlexception
boolean atomic = program.isAtomic();
while (program.getExceptionGroup() == null) {
this.pop(false);
if (this.programs.empty()) {
// reached the top without a handler, so throw
if (e instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e;
}
throw new ProcedureErrorInstructionException(QueryPlugin.Event.TEIID30167, e);
}
program = peek();
atomic |= program.isAtomic();
}
try {
// allow the current program to go out of scope
this.pop(false);
if (atomic) {
TransactionContext tc = this.getContext().getTransactionContext();
if (tc != null && tc.getTransactionType() != Scope.NONE) {
// a non-completing atomic block under a higher level transaction
// this will not work correctly until we support
// checkpoints/subtransactions
tc.getTransaction().setRollbackOnly();
getContext().addWarning(TeiidSQLException.create(e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31266)));
}
}
} catch (IllegalStateException | SystemException | TeiidComponentException e1) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, "Caught exception while rolling back transaction", e1);
} catch (Throwable e1) {
LogManager.logWarning(LogConstants.CTX_DQP, e1);
}
if (e instanceof RuntimeException) {
LogManager.logWarning(LogConstants.CTX_DQP, e);
} else {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, "Caught exception in exception hanlding block", e);
}
if (program.getExceptionProgram() == null) {
continue;
}
Program exceptionProgram = program.getExceptionProgram();
this.push(exceptionProgram);
TeiidSQLException tse = TeiidSQLException.create(e);
GroupSymbol gs = new GroupSymbol(program.getExceptionGroup());
this.currentVarContext.setValue(exceptionSymbol(gs, 0), tse.getSQLState());
this.currentVarContext.setValue(exceptionSymbol(gs, 1), tse.getErrorCode());
this.currentVarContext.setValue(exceptionSymbol(gs, 2), tse.getTeiidCode());
this.currentVarContext.setValue(exceptionSymbol(gs, 3), tse);
this.currentVarContext.setValue(exceptionSymbol(gs, 4), tse.getCause());
continue;
}
program.incrementProgramCounter();
}
CursorState last = (CursorState) this.cursorStates.getValue(null);
if (last == null) {
return CollectionTupleSource.createNullTupleSource();
}
return last.ts;
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class TestProcErrors method testExceptionAndWarning.
@Test
public void testExceptionAndWarning() throws Exception {
String ddl = "create virtual procedure vproc (x integer) returns integer as begin declare exception e = sqlexception 'hello'; raise sqlwarning e; raise sqlexception 'hello world' sqlstate 'abc', 1 chain e; end;";
TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
// $NON-NLS-1$
String sql = "call vproc(1)";
ProcessorPlan plan = getProcedurePlan(sql, tm);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
try {
helpTestProcess(plan, null, dataManager, tm);
fail();
} catch (TeiidProcessingException e) {
TeiidSQLException tsw = (TeiidSQLException) plan.getContext().getAndClearWarnings().get(0);
assertEquals("hello", tsw.getMessage());
assertEquals(e.getCause().getCause(), tsw);
TeiidSQLException tse = (TeiidSQLException) e.getCause();
assertEquals("hello world", tse.getMessage());
assertEquals("abc", tse.getSQLState());
assertEquals(1, tse.getErrorCode());
}
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class TestProcErrors method testExceptionHandling.
@Test
public void testExceptionHandling() throws Exception {
String ddl = "create virtual procedure vproc (x integer) returns integer as begin " + "raise sqlexception 'hello world' sqlstate 'abc', 1;" + "exception e " + "raise sqlwarning sqlexception 'caught' chain e.exception; " + "\"return\" = 1;" + "end;";
TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
// $NON-NLS-1$
String sql = "call vproc(1)";
ProcessorPlan plan = getProcedurePlan(sql, tm);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
helpTestProcess(plan, new List[] { Arrays.asList(1) }, dataManager, tm);
TeiidSQLException tse = (TeiidSQLException) plan.getContext().getAndClearWarnings().get(0);
assertEquals("caught", tse.getMessage());
assertEquals("hello world", tse.getCause().getMessage());
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class TestEmbeddedServer method testSemanticVersioning.
@Test
public void testSemanticVersioning() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
es.start(ec);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.VIRTUAL);
mmd.addSourceMetadata("ddl", "create view v as select 1;");
es.deployVDB("x.0.9.0", mmd);
es.deployVDB("x.1.0.1", mmd);
es.deployVDB("x.1.1.0", mmd);
Connection c = es.getDriver().connect("jdbc:teiid:x", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("values (current_database())");
rs.next();
assertEquals("x", rs.getString(1));
rs = s.executeQuery("select version from virtualdatabases");
rs.next();
assertEquals("0.9.0", rs.getString(1));
try {
// v1.0.0 does not exist
c = es.getDriver().connect("jdbc:teiid:x.v1.0", null);
fail();
} catch (TeiidSQLException e) {
}
c = es.getDriver().connect("jdbc:teiid:x.1.0.1", null);
s = c.createStatement();
rs = s.executeQuery("select version from virtualdatabases");
rs.next();
assertEquals("1.0.1", rs.getString(1));
try {
// old style non-semantic version
c = es.getDriver().connect("jdbc:teiid:x.1", null);
fail();
} catch (TeiidSQLException e) {
}
c = es.getDriver().connect("jdbc:teiid:x.1.", null);
s = c.createStatement();
rs = s.executeQuery("select version from virtualdatabases");
rs.next();
assertEquals("1.0.1", rs.getString(1));
c = es.getDriver().connect("jdbc:teiid:x.1.1.", null);
s = c.createStatement();
rs = s.executeQuery("select version from virtualdatabases");
rs.next();
assertEquals("1.1.0", rs.getString(1));
}
Aggregations