use of org.teiid.jdbc.TeiidSQLException 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.TeiidSQLException in project teiid by teiid.
the class TestEmbeddedServer method testSemanticVersioningAny.
@Test
public void testSemanticVersioningAny() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
es.start(ec);
es.deployVDB(new ByteArrayInputStream(createVDB("x", "0.9").getBytes("UTF-8")));
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));
es.deployVDB(new ByteArrayInputStream(createVDB("x", "1.1.1").getBytes("UTF-8")));
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.1.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.1", rs.getString(1));
es.deployVDB(new ByteArrayInputStream(createVDB("x", "1.11.1").getBytes("UTF-8")));
es.deployVDB(new ByteArrayInputStream(createVDB("x", "1.0.1").getBytes("UTF-8")));
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.1", rs.getString(1));
c = es.getDriver().connect("jdbc:teiid:x.1.0.", null);
s = c.createStatement();
rs = s.executeQuery("select version from virtualdatabases");
rs.next();
assertEquals("1.0.1", rs.getString(1));
try {
c = es.getDriver().connect("jdbc:teiid:x.1.12.0", null);
fail();
} catch (TeiidSQLException e) {
}
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class CommonTransactionTests method testMultipleSourceTimeout.
/**
* Sources = 2
* Commands = multiple - Success
* Batching = Full Processing, Single Connector Batch
* result = rollback
*/
@Test
public void testMultipleSourceTimeout() throws Exception {
AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceTimeout") {
public void testCase() throws Exception {
// time out after 1 sec
executeBatch(getMultipleSourceBatch(), 1);
}
public boolean exceptionExpected() {
return true;
}
public void after() {
if (!exceptionOccurred()) {
Assert.assertTrue("should have failed with time out exception", false);
} else {
if (getLastException() != null) {
String msg = "NA";
SQLException s = getLastException();
Throwable t = s.getCause();
if (t instanceof TimeoutException) {
msg = t.getMessage();
} else if (s instanceof TeiidSQLException) {
TeiidSQLException mm = (TeiidSQLException) t;
if (mm.getNextException() != null) {
SQLException next = mm.getNextException();
msg = next.getMessage();
} else {
msg = mm.getMessage();
}
} else {
msg = s.getMessage();
}
boolean isfound = (msg.indexOf("Operation timed out before completion") != -1 ? true : false);
Assert.assertTrue("Exception Message didnt match 'Operation timed out before completion' found: " + msg, isfound);
} else {
Assert.assertTrue("Program Error: it indicates exception occured, but no exception is found", false);
}
}
}
};
getTransactionContainter().runTransaction(userTxn);
// now verify the results (this may finish under one second, then this test is not valid)
AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
test.execute("select * from g1 where e1 >= 600 and e1 < 750");
test.assertRowCount(0);
test.execute("select * from g2 where e1 >= 600 and e1 < 750");
test.assertRowCount(0);
test.execute("select distinct e2 from g1 where e1 >= 600 and e1 < 750");
test.assertRowCount(0);
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class CommandContext method getConnection.
@Override
public TeiidConnection getConnection() throws TeiidSQLException {
LocalProfile ep = getDQPWorkContext().getConnectionProfile();
// TODO: this is problematic as the client properties are not conveyed
Properties info = new Properties();
info.put(LocalProfile.DQP_WORK_CONTEXT, getDQPWorkContext());
// $NON-NLS-1$ //$NON-NLS-2$
String url = "jdbc:teiid:" + getVdbName() + "." + getVdbVersion();
ServerConnection sc;
try {
sc = ep.createServerConnection(info);
} catch (TeiidException e) {
throw TeiidSQLException.create(e);
}
return new ConnectionImpl(sc, info, url) {
@Override
public void close() throws SQLException {
// just ignore
}
@Override
public void rollback() throws SQLException {
// just ignore
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
// TODO: detect if attempted set conflicts with current txn state
throw new TeiidSQLException();
}
@Override
public void commit() throws SQLException {
throw new TeiidSQLException();
}
@Override
public void changeUser(String userName, String newPassword) throws SQLException {
throw new TeiidSQLException();
}
@Override
protected synchronized long nextRequestID() {
// need to choose ids that won't conflict with the user connection
return -(long) (Math.random() * Long.MAX_VALUE);
}
};
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class TestMatViews method testMatViewProceduresWithSameName.
@Test
public void testMatViewProceduresWithSameName() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.VIRTUAL);
mmd.addSourceMetadata("DDL", "create view T as select 1");
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("y");
mmd1.setModelType(Type.VIRTUAL);
mmd1.addSourceMetadata("DDL", "create view T as select 1");
server.deployVDB("test", mmd, mmd1);
Connection c = server.getDriver().connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
try {
s.execute("call sysadmin.matviewstatus('x', 'T')");
} catch (TeiidSQLException e) {
e.getTeiidCode().equals("TEIID30167");
}
try {
s.execute("call sysadmin.loadmatview('x', 'T')");
} catch (TeiidSQLException e) {
e.getTeiidCode().equals("TEIID30167");
}
try {
s.execute("call sysadmin.updateMatView('x', 'T')");
} catch (TeiidSQLException e) {
e.getTeiidCode().equals("TEIID30167");
}
}
Aggregations