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;
}
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));
}
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;
}
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);
}
}
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());
}
Aggregations