use of org.teiid.jdbc.TeiidDriver in project teiid by teiid.
the class TestEmbeddedServer method testWithPushdownChangeName.
@Test
public void testWithPushdownChangeName() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {
@Override
public boolean supportsCommonTableExpressions() {
return true;
}
@Override
public boolean supportsSelfJoins() {
return true;
}
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
@Override
public boolean supportsAliasedTable() {
return true;
}
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public String getExcludedCommonTableExpressionName() {
return "a";
}
@Override
public boolean supportsInnerJoins() {
return true;
}
};
es.addTranslator("y", hcef);
hcef.addData("WITH a__2 (x) AS (SELECT g_0.e1 FROM pm1.g1 AS g_0) SELECT g_0.x FROM a__2 AS g_0, a__2 AS g_1", Arrays.asList(Arrays.asList("a")));
ModelMetaData mmd = new ModelMetaData();
mmd.setName("my-schema");
mmd.addSourceMapping("x", "y", null);
mmd.addSourceMetadata("ddl", "create foreign table \"pm1.g1\" (e1 string)");
es.deployVDB("test", mmd);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
// see the correct pushdown in hcef.addData above
// $NON-NLS-1$
s.execute("with a (x) as (select e1 from pm1.g1) SELECT a.x from a, a z");
}
use of org.teiid.jdbc.TeiidDriver in project teiid by teiid.
the class TestEmbeddedServer method testTransactions.
@Test
public void testTransactions() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
ec.setUseDisk(false);
es.start(ec);
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("b");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText("create view v as select 1; " + "create virtual procedure proc () options (updatecount 2) as begin select * from v; end; " + "create virtual procedure proc0 () as begin atomic select * from v; end; " + "create virtual procedure proc1 () as begin atomic insert into #temp values (1); insert into #temp values (1); end; " + "create virtual procedure proc2 (x integer) as begin atomic insert into #temp values (1); insert into #temp values (1); select 1; begin select 1/x; end exception e end; " + "create virtual procedure proc3 (x integer) as begin begin atomic call proc (); select 1; end create local temporary table x (y string); begin atomic call proc (); select 1; end end;");
es.deployVDB("test", mmd1);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:test", null);
// local txn
c.setAutoCommit(false);
Statement s = c.createStatement();
s.execute("select 1");
c.setAutoCommit(true);
assertEquals(1, tm.txnHistory.size());
Transaction txn = tm.txnHistory.remove(0);
Mockito.verify(txn).commit();
// should be an auto-commit txn (could also force with autoCommitTxn=true)
s.execute("call proc ()");
assertEquals(1, tm.txnHistory.size());
txn = tm.txnHistory.remove(0);
Mockito.verify(txn).commit();
// no txn needed
s.execute("call proc0()");
assertEquals(0, tm.txnHistory.size());
// block txn
s.execute("call proc1()");
assertEquals(1, tm.txnHistory.size());
txn = tm.txnHistory.remove(0);
Mockito.verify(txn).commit();
s.execute("set autoCommitTxn on");
s.execute("set noexec on");
s.execute("select 1");
assertFalse(s.getResultSet().next());
s.execute("set autoCommitTxn off");
s.execute("set noexec off");
s.execute("call proc2(0)");
// verify that the block txn was committed because the exception was caught
assertEquals(1, tm.txnHistory.size());
txn = tm.txnHistory.remove(0);
Mockito.verify(txn).rollback();
// test detection
tm.txnHistory.clear();
tm.begin();
try {
c.setAutoCommit(false);
// needed since we lazily start the transaction
s.execute("select 1");
fail("should fail since we aren't allowing a nested transaction");
} catch (TeiidSQLException e) {
}
txn = tm.txnHistory.remove(0);
Mockito.verify(txn, Mockito.times(0)).commit();
tm.commit();
c.setAutoCommit(true);
tm.txnHistory.clear();
// ensure that we properly reset the txn context
s.execute("call proc3(0)");
assertEquals(2, tm.txnHistory.size());
txn = tm.txnHistory.remove(0);
Mockito.verify(txn, Mockito.times(0)).registerSynchronization((Synchronization) Mockito.any());
}
use of org.teiid.jdbc.TeiidDriver in project teiid by teiid.
the class TestDDLMetadataStore method testRoles.
@Test
public void testRoles() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
ec.setSecurityHelper(new ThreadLocalSecurityHelper());
es.addTranslator("y", new TestEmbeddedServer.FakeTranslator(false));
es.addTranslator("y2", new TestEmbeddedServer.FakeTranslator(false));
final AtomicInteger counter = new AtomicInteger();
ConnectionFactoryProvider<AtomicInteger> cfp = new EmbeddedServer.SimpleConnectionFactoryProvider<AtomicInteger>(counter);
es.addConnectionFactoryProvider("z", cfp);
es.start(ec);
es.addMetadataRepository("myrepo", Mockito.mock(MetadataRepository.class));
es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataPath() + "/first-db.ddl"), true);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:empty", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from mytable");
assertFalse(rs.next());
assertEquals("my-column", rs.getMetaData().getColumnLabel(1));
s.execute("update mytable set \"my-column\" = 'a'");
assertEquals(2, s.getUpdateCount());
try {
s.execute("delete from mytable where \"my-column\" = 'a'");
fail("should have stopped by roles");
} catch (Exception e) {
// pass
}
}
use of org.teiid.jdbc.TeiidDriver in project teiid by teiid.
the class TestEmbeddedServer method testDeploy.
@Test
public void testDeploy() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
es.addTranslator("y", new FakeTranslator(false));
final AtomicInteger counter = new AtomicInteger();
ConnectionFactoryProvider<AtomicInteger> cfp = new EmbeddedServer.SimpleConnectionFactoryProvider<AtomicInteger>(counter);
es.addConnectionFactoryProvider("z", cfp);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("my-schema");
mmd.addSourceMapping("x", "y", "z");
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("virt");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");
es.deployVDB("test", mmd, mmd1);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from \"my-view\"");
assertFalse(rs.next());
assertEquals("my-column", rs.getMetaData().getColumnLabel(1));
s.execute("update \"my-view\" set \"my-column\" = 'a'");
assertEquals(2, s.getUpdateCount());
es.deployVDB("empty");
c = es.getDriver().connect("jdbc:teiid:empty", null);
s = c.createStatement();
s.execute("select * from sys.tables");
assertNotNull(es.getSchemaDdl("empty", "SYS"));
assertNull(es.getSchemaDdl("empty", "xxx"));
}
use of org.teiid.jdbc.TeiidDriver in project teiid by teiid.
the class TestEmbeddedServer method testTranslatorCreation.
@Test
public void testTranslatorCreation() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
es.addTranslator(DummyExecutionFactory.class);
Map<String, String> props = new HashMap<String, String>();
props.put("supportsOrderBy", "true");
es.addTranslator("dummy-override", "dummy", props);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("test-one");
mmd.addSourceMapping("one", "dummy", null);
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("test-two");
mmd2.addSourceMapping("two", "dummy", null);
ModelMetaData mmd3 = new ModelMetaData();
mmd3.setName("test-three");
mmd3.addSourceMapping("three", "dummy-override", null);
es.deployVDB("test", mmd, mmd2, mmd3);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
s.execute("select count(distinct name) from sys.tables where name like 'test%'");
s.getResultSet().next();
assertEquals(3, s.getResultSet().getInt(1));
s.execute("select count(distinct name) from sys.columns where tablename like 'test%'");
s.getResultSet().next();
assertEquals(2, s.getResultSet().getInt(1));
}
Aggregations