use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.
the class TestProcedureProcessor method testBeginAtomic.
@Test
public void testBeginAtomic() throws Exception {
String proc = // $NON-NLS-1$
"CREATE VIRTUAL PROCEDURE " + // $NON-NLS-1$
"BEGIN ATOMIC" + // $NON-NLS-1$
" select e1, e2, e3, e4 into #t1 from pm1.g1;\n" + // $NON-NLS-1$
" update #t1 set e1 = 1 where e4 < 2;\n" + // $NON-NLS-1$
" delete from #t1 where e4 > 2;\n" + // $NON-NLS-1$
" select e2/\"in\" from #t1;\n" + // $NON-NLS-1$
"END";
TransformationMetadata tm = RealMetadataFactory.example1();
addProc(tm, "sq1", proc, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
FakeDataManager dataMgr = exampleDataManager(tm);
// $NON-NLS-1$
CommandContext context = new CommandContext("pID", null, null, null, 1);
QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
context.setMetadata(metadata);
TransactionContext tc = new TransactionContext();
TransactionService ts = Mockito.mock(TransactionService.class);
context.setTransactionService(ts);
context.setTransactionContext(tc);
// $NON-NLS-1$
String userQuery = "EXEC pm1.sq1(1)";
ProcessorPlan plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
List[] expected = new List[] { Arrays.asList(5) };
TestProcessor.helpProcess(plan, context, dataMgr, expected);
Mockito.verify(ts, Mockito.times(3)).begin(tc);
Mockito.verify(ts, Mockito.times(3)).commit(tc);
tc = new TransactionContext();
ts = Mockito.mock(TransactionService.class);
context.setTransactionService(ts);
context.setTransactionContext(tc);
// $NON-NLS-1$
userQuery = "EXEC pm1.sq1(0)";
plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
expected = null;
try {
TestProcessor.helpProcess(plan, context, dataMgr, expected);
fail();
} catch (TeiidProcessingException e) {
}
Mockito.verify(ts).begin(tc);
Mockito.verify(ts, Mockito.times(2)).resume(tc);
Mockito.verify(ts, Mockito.times(0)).commit(tc);
Mockito.verify(ts).rollback(tc);
}
use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.
the class TestResolver method testSelectIntoWithNullLiteral.
@Test
public void testSelectIntoWithNullLiteral() {
// $NON-NLS-1$
String sql = "select null as x into #temp from pm1.g1";
Query query = (Query) helpResolve(sql);
TempMetadataStore store = query.getTemporaryMetadata();
// $NON-NLS-1$
TempMetadataID id = store.getTempElementID("#temp.x");
assertEquals(DataTypeManager.DefaultDataClasses.STRING, id.getType());
}
Aggregations