use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testloadMatViewInternal.
@Test
public void testloadMatViewInternal() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.VIRTUAL);
mmd.addSourceMetadata("DDL", "create view T options (materialized true) as select 1");
server.deployVDB("test", mmd);
Connection c = server.getDriver().connect("jdbc:teiid:test", null);
CallableStatement s = c.prepareCall("call sysadmin.loadMatView('x', 'T', true)");
assertFalse(s.execute());
assertEquals(1, s.getInt(1));
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testInternalWithManagement.
@Test
public void testInternalWithManagement() throws Exception {
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("view1");
mmd2.setModelType(Type.VIRTUAL);
mmd2.addSourceMetadata("DDL", "CREATE VIEW v1 ( col integer, col1 string, primary key (col, col1) ) " + "OPTIONS (MATERIALIZED true, \"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, \"teiid_rel:MATVIEW_TTL\" 200) AS select 1, current_database(); " + "CREATE VIEW v2 ( col integer, col1 string, primary key (col, col1) ) " + "OPTIONS (MATERIALIZED true, \"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true) AS select 1, current_database()");
VDBMetaData vdb = new VDBMetaData();
vdb.setXmlDeployment(true);
vdb.setName("comp");
vdb.setModels(Arrays.asList(mmd2));
vdb.addProperty("lazy-invalidate", "true");
server.deployVDB(vdb);
Connection c = server.getDriver().connect("jdbc:teiid:comp", null);
Statement s = c.createStatement();
Thread.sleep(5000);
// ensure that we are preloaded
ResultSet rs = s.executeQuery("select * from MatViews where name = 'v1'");
assertTrue(rs.next());
assertTrue("LOADED".equals(rs.getString("loadstate")));
assertEquals(true, rs.getBoolean("valid"));
Timestamp ts = rs.getTimestamp("updated");
rs = s.executeQuery("select * from MatViews where name = 'v2'");
assertTrue(rs.next());
assertEquals("LOADED", rs.getString("loadstate"));
assertEquals(true, rs.getBoolean("valid"));
Timestamp v2ts = rs.getTimestamp("updated");
// and queryable
rs = s.executeQuery("select * from v1");
rs.next();
assertEquals("1", rs.getString(1));
rs = s.executeQuery("select * from v2");
rs.next();
assertEquals("1", rs.getString(1));
// wait for ttl to expire
Thread.sleep(1000);
rs = s.executeQuery("select * from MatViews where name = 'v1'");
assertTrue(rs.next());
assertTrue("LOADED".equals(rs.getString("loadstate")) || "NEEDS_LOADING".equals(rs.getString("loadstate")));
assertEquals(true, rs.getBoolean("valid"));
Timestamp ts1 = rs.getTimestamp("updated");
assertTrue(ts1.compareTo(ts) > 0);
rs = s.executeQuery("select * from MatViews where name = 'v2'");
assertTrue(rs.next());
assertEquals("LOADED", rs.getString("loadstate"));
assertEquals(true, rs.getBoolean("valid"));
Timestamp v2ts1 = rs.getTimestamp("updated");
assertEquals(v2ts, v2ts1);
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testCompositeRowUpdate.
@Test
public void testCompositeRowUpdate() 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 refreshMatViewRow('view1.v1', 0)) p");
fail();
} catch (SQLException e) {
// not enough key parameters
}
rs = s.executeQuery("select * from (call refreshMatViewRow('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 refreshMatViewRow('view1.v1', '1', 'comp')) p");
assertTrue(rs.next());
// row does exist
assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODBCSchema method testPGTableConflicts.
@Test
public void testPGTableConflicts() throws Exception {
// $NON-NLS-1$
execute("select name FROM sys.tables where schemaname='pg_catalog'");
ArrayList<String> names = new ArrayList<String>();
while (internalResultSet.next()) {
names.add(internalResultSet.getString(1));
}
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.VIRTUAL);
mmd.setSchemaSourceType("ddl");
StringBuffer ddl = new StringBuffer();
for (String name : names) {
ddl.append("create view \"" + name + "\" as select 1;\n");
}
mmd.setSchemaText(ddl.toString());
server.deployVDB("x", mmd);
this.internalConnection.close();
// $NON-NLS-1$ //$NON-NLS-2$
this.internalConnection = server.createConnection("jdbc:teiid:x");
for (String name : names) {
execute("select * from pg_catalog." + name);
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODBCSchema method test_PG_ATTRIBUTE_overflow.
@Test
public void test_PG_ATTRIBUTE_overflow() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.VIRTUAL);
mmd.addSourceMetadata("ddl", "create view t (c bigdecimal(2147483647,2147483647)) as select 1.0;");
server.deployVDB("overflow", mmd);
// $NON-NLS-1$ //$NON-NLS-2$
this.internalConnection = server.createConnection("jdbc:teiid:overflow");
// $NON-NLS-1$
execute("select * FROM pg_attribute order by oid");
TestMMDatabaseMetaData.compareResultSet(this.internalResultSet);
}
Aggregations