Search in sources :

Example 76 with ModelMetaData

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));
}
Also used : CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 77 with ModelMetaData

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);
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 78 with ModelMetaData

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

Example 79 with ModelMetaData

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 80 with ModelMetaData

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