Search in sources :

Example 36 with ModelMetaData

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

Example 37 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testMultiSourcePreparedDynamicUpdate.

@Test
public void testMultiSourcePreparedDynamicUpdate() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    MockTransactionManager tm = new MockTransactionManager();
    ec.setTransactionManager(tm);
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("t", new ExecutionFactory<Void, Void>());
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("b");
    mmd1.setSchemaSourceType("ddl");
    mmd1.setSchemaText("create view v (i integer) OPTIONS (UPDATABLE true) as select 1; " + "create trigger on v instead of update as for each row begin atomic " + "IF (CHANGING.i)\n" + "EXECUTE IMMEDIATE 'select \"new\".i'; " + "end; ");
    mmd1.setSupportsMultiSourceBindings(true);
    mmd1.addSourceMapping("x", "t", null);
    mmd1.addSourceMapping("y", "t", null);
    es.deployVDB("vdb", mmd1);
    Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
    PreparedStatement ps = c.prepareStatement("update v set i = ? where i = ?");
    ps.setInt(1, 2);
    ps.setInt(2, 1);
    assertEquals(1, ps.executeUpdate());
    ps.setInt(1, 3);
    ps.setInt(2, 1);
    assertEquals(1, ps.executeUpdate());
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 38 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testBatchedUpdate.

@Test
public void testBatchedUpdate() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    es.bufferService.setProcessorBatchSize(1);
    es.start(ec);
    es.addTranslator("y", new FakeTranslator(true));
    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");
    es.deployVDB("test", mmd);
    Connection c = es.getDriver().connect("jdbc:teiid:test", null);
    PreparedStatement ps = c.prepareStatement("insert into \"my-table\" values (?)");
    for (int i = 0; i < 16; i++) {
        ps.setString(1, "a");
        ps.addBatch();
    }
    int[] result = ps.executeBatch();
    assertArrayEquals(new int[] { 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1 }, result);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 39 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData 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 40 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testTurnOffLobCleaning.

@Test
public void testTurnOffLobCleaning() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    es.start(ec);
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("y");
    mmd.setModelType(Type.VIRTUAL);
    mmd.addSourceMetadata("ddl", "create view dummy as select 1;");
    es.deployVDB("x", mmd);
    Connection c = es.getDriver().connect("jdbc:teiid:x", null);
    Statement s = c.createStatement();
    s.execute("select teiid_session_set('clean_lobs_onclose', false)");
    ResultSet rs = s.executeQuery("WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 5000 ) SELECT xmlelement(root, xmlagg(xmlelement(val, n))) FROM t");
    assertTrue(rs.next());
    SQLXML val = rs.getSQLXML(1);
    rs.close();
    assertEquals(73906, val.getString().length());
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)191 Test (org.junit.Test)131 Properties (java.util.Properties)50 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)45 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)43 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)36 Connection (java.sql.Connection)23 MetadataFactory (org.teiid.metadata.MetadataFactory)21 Statement (java.sql.Statement)19 ResultSet (java.sql.ResultSet)18 CallableStatement (java.sql.CallableStatement)16 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)15 ArrayList (java.util.ArrayList)13 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)11 Table (org.teiid.metadata.Table)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 List (java.util.List)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)9