Search in sources :

Example 66 with ModelMetaData

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

the class TestExternalMatViews method setupSourceModel.

private ModelMetaData setupSourceModel() {
    ModelMetaData sourceModel = new ModelMetaData();
    sourceModel.setName("source");
    sourceModel.setModelType(Type.PHYSICAL);
    sourceModel.addSourceMetadata("DDL", "create foreign table physicalTbl (col integer, col1 string) options (updatable true);");
    sourceModel.addSourceMapping("s1", "fixed", null);
    return sourceModel;
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 67 with ModelMetaData

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

the class TestExternalMatViews method testRestartServerInMiddleOfLoading.

@Test
public void testRestartServerInMiddleOfLoading() 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);
    // test that the matview loaded
    conn = server.createConnection("jdbc:teiid:comp");
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select * from view1.v1 order by col");
    rs.next();
    assertEquals(1, rs.getInt(1));
    assertEquals("town", rs.getString(2));
    // now change the status table underneath
    h2DataSource = getDatasource();
    Connection c = h2DataSource.getConnection();
    assertNotNull(c);
    Statement stmt = c.createStatement();
    boolean update = stmt.execute("UPDATE status SET LOADSTATE = 'LOADING' WHERE NAME = 'v1'");
    // this is update
    assertFalse(update);
    assertEquals(1, stmt.getUpdateCount());
    rs = c.createStatement().executeQuery("SELECT LOADSTATE, NODENAME FROM status");
    assertTrue(rs.next());
    assertEquals("LOADING", rs.getString(1));
    assertEquals("localhost", rs.getString(2));
    server.stop();
    server = new FakeServer(true);
    setupData(server);
    setupSourceModel();
    setupMatViewModel();
    server.deployVDB("comp", sourceModel, viewModel, matViewModel);
    Thread.sleep(1000);
    rs = c.createStatement().executeQuery("SELECT LOADSTATE, NODENAME FROM STATUS WHERE NAME = 'v1'");
    assertTrue(rs.next());
    assertEquals("LOADED", rs.getString(1));
    assertEquals("localhost", rs.getString(2));
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 68 with ModelMetaData

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

the class TestExternalMatViews method setupMatViewModel.

private ModelMetaData setupMatViewModel() {
    ModelMetaData matViewModel = new ModelMetaData();
    matViewModel.setName("matview");
    matViewModel.setModelType(Type.PHYSICAL);
    matViewModel.addSourceMapping("s2", "translator-h2", "java:/matview-ds");
    matViewModel.addProperty("importer.schemaPattern", "PUBLIC");
    matViewModel.addProperty("importer.tableTypes", "TABLE");
    matViewModel.addProperty("importer.useFullSchemaName", "false");
    return matViewModel;
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 69 with ModelMetaData

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

the class TestExternalMatViews method testViewChaining.

@Test
public void testViewChaining() throws Exception {
    DelayableHardCodedExectionFactory 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_V1a', " + "\"teiid_rel:MATVIEW_TTL\" 5000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum', " + "\"teiid_rel:MATVIEW_ONERROR_ACTION\" 'THROW_EXCEPTION') " + "AS select col, col1 from source.physicalTbl;" + "CREATE VIEW v2 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 5000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum'," + "\"teiid_rel:MATVIEW_ONERROR_ACTION\" 'THROW_EXCEPTION') " + "AS select col, col1 from v1");
    server.deployVDB("chain", sourceModel, viewModel, matViewModel);
    hcef.delay = 100;
    Connection c = server.getDriver().connect("jdbc:teiid:chain", null);
    Statement s = c.createStatement();
    // should succeed before the ttl
    for (int i = 0; i < 5; i++) {
        try {
            s.execute("select count(*) from v2");
            if (i == 0) {
                System.out.println("expected first iteration to fail");
            }
            ResultSet rs = s.getResultSet();
            rs.next();
            assertTrue(rs.getInt(1) > 0);
            return;
        } catch (SQLException e) {
        }
        Thread.sleep(400);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 70 with ModelMetaData

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

the class TestMatViews method testCompositeRowsUpdate.

@Test
public void testCompositeRowsUpdate() throws Exception {
    ModelMetaData mmd2 = new ModelMetaData();
    mmd2.setName("view1");
    mmd2.setModelType(Type.VIRTUAL);
    mmd2.setSchemaSourceType("DDL");
    mmd2.setSchemaText("CREATE VIEW v1 ( col integer, col1 string, primary key (col, col1) ) OPTIONS (MATERIALIZED true) AS /*+ cache(updatable) */ select 1, current_database()");
    server.deployVDB("comp", mmd2);
    Connection c = server.getDriver().connect("jdbc:teiid:comp", null);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select * from v1");
    rs.next();
    assertEquals("1", rs.getString(1));
    try {
        rs = s.executeQuery("select * from (call refreshMatViewRows('view1.v1', (0,))) p");
        fail();
    } catch (SQLException e) {
    // not enough key parameters
    }
    rs = s.executeQuery("select * from (call refreshMatViewRows('view1.v1', (0, 'a'))) p");
    assertTrue(rs.next());
    // row doesn't exist
    assertEquals(0, rs.getInt(1));
    assertFalse(rs.next());
    rs = s.executeQuery("select * from (call refreshMatViewRows('view1.v1', ('1', 'comp'), ('2', 'comp'))) p");
    assertTrue(rs.next());
    // row does exist
    assertEquals(1, rs.getInt(1));
    assertFalse(rs.next());
}
Also used : SQLException(java.sql.SQLException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) 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