Search in sources :

Example 36 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestAsynch method oneTimeSetup.

@BeforeClass
public static void oneTimeSetup() throws Exception {
    server = new FakeServer(true);
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("v");
    mmd.setModelType(Type.PHYSICAL);
    mmd.setSchemaSourceType("ddl");
    mmd.addSourceMapping("z", "z", null);
    mmd.setSchemaText("create view test (col integer) as select 1; create foreign table someTable (col integer);");
    ef = new HardCodedExecutionFactory() {

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            partIds.add(executionContext.getPartIdentifier());
            return super.createResultSetExecution(command, executionContext, metadata, connection);
        }
    };
    server.addTranslator("z", ef);
    server.deployVDB("x", mmd);
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) FakeServer(org.teiid.jdbc.FakeServer) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) BeforeClass(org.junit.BeforeClass)

Example 37 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestExternalMatViews method testInternalWriteThroughMativew.

@Test
public void testInternalWriteThroughMativew() throws Exception {
    HardCodedExecutionFactory hcef = setupData(true, server);
    ModelMetaData sourceModel = setupSourceModel();
    ModelMetaData matViewModel = setupMatViewModel();
    ModelMetaData viewModel = new ModelMetaData();
    viewModel.setName("view1");
    viewModel.setModelType(Type.VIRTUAL);
    viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true," + "UPDATABLE true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:MATVIEW_WRITE_THROUGH\" true, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
    server.deployVDB("comp", sourceModel, viewModel, matViewModel);
    Connection c = server.createConnection("jdbc:teiid:comp");
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select count(*) from v1");
    rs.next();
    assertEquals(3, rs.getInt(1));
    hcef.addUpdate("INSERT INTO physicalTbl (col, col1) VALUES (4, 'continent')", new int[] { 1 });
    s.execute("insert into v1 (col, col1) values (4, 'continent')");
    assertEquals(1, s.getUpdateCount());
    rs = s.executeQuery("select count(*) from v1");
    rs.next();
    assertEquals(4, rs.getInt(1));
    // check that not specifying the pk doesn't update the mat view
    // TODO: this may be addressed in some cases eventually
    hcef.addUpdate("INSERT INTO physicalTbl (col1) VALUES ('continent')", new int[] { 1 });
    s.execute("insert into v1 (col1) values ('continent')");
    rs = s.executeQuery("select count(*) from v1");
    rs.next();
    assertEquals(4, rs.getInt(1));
    hcef.addUpdate("DELETE FROM physicalTbl WHERE physicalTbl.col1 = 'continent'", new int[] { 1 });
    s.execute("delete from v1 where v1.col1 = 'continent'");
    assertEquals(1, s.getUpdateCount());
    rs = s.executeQuery("select count(*) from v1");
    rs.next();
    assertEquals(3, rs.getInt(1));
    hcef.addUpdate("UPDATE physicalTbl SET col1 = 'town' WHERE physicalTbl.col1 = 'city'", new int[] { 1 });
    s.execute("update v1 set col1 = 'town' where col1 = 'city'");
    assertEquals(1, s.getUpdateCount());
    rs = s.executeQuery("select col, col1 from v1 where col = 1");
    rs.next();
    assertEquals("town", rs.getString(2));
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 38 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestExternalMatViews method withMergeDelete.

private void withMergeDelete(boolean useUpdateScript) throws Exception {
    HardCodedExecutionFactory hcef = setupData(server);
    ModelMetaData sourceModel = setupSourceModel();
    ModelMetaData matViewModel = setupMatViewModel();
    ModelMetaData viewModel = new ModelMetaData();
    viewModel.setName("view1");
    viewModel.setModelType(Type.VIRTUAL);
    viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
    server.deployVDB("comp", sourceModel, viewModel, matViewModel);
    Thread.sleep(1000);
    assertTest(useUpdateScript, hcef);
}
Also used : HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 39 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestExternalMatViews method testLazyUpdate.

@Test
public void testLazyUpdate() throws Exception {
    HardCodedExecutionFactory hcef = setupData(server);
    ModelMetaData sourceModel = setupSourceModel();
    ModelMetaData matViewModel = setupMatViewModel();
    ModelMetaData viewModel = new ModelMetaData();
    viewModel.setName("view1");
    viewModel.setModelType(Type.VIRTUAL);
    viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_MAX_STALENESS_PCT\" '10', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
    server.deployVDB("comp", sourceModel, viewModel, matViewModel);
    Thread.sleep(1000);
    // check if materilization is loaded
    Connection c = h2DataSource.getConnection();
    ResultSet rs = c.createStatement().executeQuery("SELECT LoadState, StaleCount FROM Status WHERE VDBName = 'comp'");
    rs.next();
    assertEquals("LOADED", rs.getString(1));
    assertEquals(0, rs.getInt(2));
    // verify with querying the database.
    conn = server.createConnection("jdbc:teiid:comp");
    Statement s = conn.createStatement();
    rs = s.executeQuery("select * from view1.v1 order by col");
    rs.next();
    assertEquals(1, rs.getInt(1));
    assertEquals("town", rs.getString(2));
    // send a row update
    EventDistributor ed = server.getEventDistributor();
    ResultsFuture<?> f = ed.dataModification("comp", "1", "source", "physicalTbl", new Object[] { 1, "town" }, new Object[] { 1, "town-modified" }, new String[] { "col1", "col2" });
    f.get();
    f = ed.dataModification("comp", "1", "source", "physicalTbl", new Object[] { 1, "town" }, new Object[] { 1, "town-modified" }, new String[] { "col1", "col2" });
    f.get();
    // check the stale count incremented
    rs = c.createStatement().executeQuery("SELECT LoadState, StaleCount FROM Status WHERE VDBName = 'comp'");
    rs.next();
    assertEquals("NEEDS_LOADING", rs.getString(1));
    assertEquals(1, rs.getInt(2));
    // now reload the view, this should reset the stalecount. If you can wait one minute this occurs automatically
    conn.createStatement().execute("exec SYSADMIN.loadMatView(schemaName=>'view1', viewName=>'v1', invalidate=>false)");
    // check the stale count to zero
    rs = c.createStatement().executeQuery("SELECT LoadState, StaleCount FROM Status WHERE VDBName = 'comp'");
    rs.next();
    assertEquals("LOADED", rs.getString(1));
    assertEquals(0, rs.getInt(2));
    String ddl = server.getAdmin().getSchema("comp", "1", "source", null, null);
    assertFalse(ddl.contains("AFTER INSERT"));
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) EventDistributor(org.teiid.events.EventDistributor) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 40 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestExternalMatViews method test.

@Test
public void test() throws Exception {
    HardCodedExecutionFactory hcef = setupData(server);
    ModelMetaData sourceModel = setupSourceModel();
    ModelMetaData matViewModel = setupMatViewModel();
    ModelMetaData viewModel = new ModelMetaData();
    viewModel.setName("view1");
    viewModel.setModelType(Type.VIRTUAL);
    viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
    server.deployVDB("comp", sourceModel, viewModel, matViewModel);
    Connection admin = server.createConnection("jdbc:teiid:comp");
    execute(admin, "select * from SYSADMIN.Usage where Name = 'mat_v1'");
    admin.close();
}
Also used : Connection(java.sql.Connection) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)46 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)43 Test (org.junit.Test)40 Properties (java.util.Properties)27 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)27 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)10 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)7 CallableStatement (java.sql.CallableStatement)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FakeServer (org.teiid.jdbc.FakeServer)4 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 Table (org.teiid.metadata.Table)3 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BeforeClass (org.junit.BeforeClass)2 AbstractQueryTest (org.teiid.jdbc.AbstractQueryTest)2