use of org.teiid.query.metadata.TempMetadataAdapter 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.TempMetadataAdapter in project teiid by teiid.
the class TestTempTables method testIsolateReads.
@Test
public void testIsolateReads() throws Exception {
GlobalTableStoreImpl gtsi = new GlobalTableStoreImpl(BufferManagerFactory.getStandaloneBufferManager(), RealMetadataFactory.example1Cached().getVdbMetaData(), RealMetadataFactory.example1Cached());
tempStore = gtsi.getTempTableStore();
metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), tempStore.getMetadataStore());
// $NON-NLS-1$
execute("create local temporary table x (e1 string, e2 integer)", new List[] { Arrays.asList(0) });
for (int i = 0; i < 300; i++) {
// $NON-NLS-1$
execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] { Arrays.asList(6) });
}
setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
execute("select count(e1) from x", new List[] { Arrays.asList(1500) });
gtsi.updateMatViewRow("X", Arrays.asList(2l), true);
tc = null;
// outside of the transaction we can see the row removed
execute("select count(e1) from x", new List[] { Arrays.asList(1499) });
// back in the transaction we see the original state
setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
execute("select count(e1) from x", new List[] { Arrays.asList(1500) });
synch.afterCompletion(Status.STATUS_COMMITTED);
}
use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.
the class TestProcedureResolving method resolveProcedure.
private Command resolveProcedure(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, TeiidComponentException, QueryMetadataException {
ProcedureContainer userCommand = (ProcedureContainer) QueryParser.getQueryParser().parseCommand(userUpdateStr);
QueryResolver.resolveCommand(userCommand, metadata);
metadata = new TempMetadataAdapter(metadata, userCommand.getTemporaryMetadata());
return QueryResolver.expandCommand(userCommand, metadata, null);
}
Aggregations