Search in sources :

Example 1 with TeiidSQLException

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());
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) TeiidDriver(org.teiid.jdbc.TeiidDriver) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 2 with TeiidSQLException

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) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) Test(org.junit.Test)

Example 3 with TeiidSQLException

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);
}
Also used : AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) SQLException(java.sql.SQLException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) QueryExecution(org.teiid.test.framework.query.QueryExecution) TimeoutException(java.util.concurrent.TimeoutException) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) Test(org.junit.Test)

Example 4 with TeiidSQLException

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);
        }
    };
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ServerConnection(org.teiid.net.ServerConnection) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) LocalProfile(org.teiid.jdbc.LocalProfile) TeiidException(org.teiid.core.TeiidException)

Example 5 with TeiidSQLException

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");
    }
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) Connection(java.sql.Connection) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

TeiidSQLException (org.teiid.jdbc.TeiidSQLException)13 Test (org.junit.Test)8 SQLException (java.sql.SQLException)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Statement (java.sql.Statement)2 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 TeiidComponentException (org.teiid.core.TeiidComponentException)2 ConnectionImpl (org.teiid.jdbc.ConnectionImpl)2 TeiidDriver (org.teiid.jdbc.TeiidDriver)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)2 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StreamCorruptedException (java.io.StreamCorruptedException)1 Array (java.sql.Array)1 Blob (java.sql.Blob)1