Search in sources :

Example 46 with ModelMetaData

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

the class TestEmbeddedServer method testPreparedLobUsage.

@Test
public void testPreparedLobUsage() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    es.start(ec);
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("b");
    mmd1.setModelType(Type.VIRTUAL);
    mmd1.addSourceMetadata("ddl", "create view v (i integer) as select 1; " + "CREATE VIRTUAL function clobfunction(p1 clob) RETURNS clob as return concat(p1, p1);" + "CREATE VIRTUAL function blobfunction(p1 blob) RETURNS clob as return concat(to_chars(p1, 'ascii'), to_chars(p1, 'utf-8'));");
    es.deployVDB("vdb", mmd1);
    Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
    // should expect a clob
    PreparedStatement ps = c.prepareStatement("select clobfunction(?), blobfunction(?)");
    ps.setCharacterStream(1, new StringReader("abc"));
    ps.setBinaryStream(2, new ByteArrayInputStream("cba".getBytes("UTF-8")));
    assertTrue(ps.execute());
    ResultSet rs = ps.getResultSet();
    rs.next();
    assertEquals("abcabc", rs.getString(1));
    assertEquals("cbacba", rs.getString(2));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 47 with ModelMetaData

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

the class TestEmbeddedServer method testPreparedTypeResolving.

@Test
public void testPreparedTypeResolving() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    MockTransactionManager tm = new MockTransactionManager();
    ec.setTransactionManager(tm);
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("t", new ExecutionFactory<Void, Void>());
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("b");
    mmd1.setModelType(Type.VIRTUAL);
    mmd1.setSchemaSourceType("ddl");
    mmd1.setSchemaText("create view v (i integer) as select 1");
    es.deployVDB("vdb", mmd1);
    Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
    // should expect a clob
    PreparedStatement ps = c.prepareStatement("select * from texttable(? columns a string) as x");
    ps.setCharacterStream(1, new StringReader("a\nb"));
    assertTrue(ps.execute());
    ResultSet rs = ps.getResultSet();
    rs.next();
    assertEquals("a", rs.getString(1));
}
Also used : StringReader(java.io.StringReader) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 48 with ModelMetaData

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

the class TestEmbeddedServer method testGeneratedKeysVirtualNone.

@Test
public void testGeneratedKeysVirtualNone() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    MockTransactionManager tm = new MockTransactionManager();
    ec.setTransactionManager(tm);
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("t", new ExecutionFactory<Void, Void>());
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("b");
    mmd1.setModelType(Type.VIRTUAL);
    mmd1.addSourceMetadata("ddl", "create view v (i integer, k integer auto_increment primary key) OPTIONS (UPDATABLE true) as select 1, 2; " + "create trigger on v instead of insert as for each row begin atomic " + "\ncreate local temporary table x (y serial, z integer, primary key (y));" + "\ninsert into x (z) values (1);" + "end; ");
    es.deployVDB("vdb", mmd1);
    Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
    PreparedStatement ps = c.prepareStatement("insert into v (i) values (1)", Statement.RETURN_GENERATED_KEYS);
    assertEquals(1, ps.executeUpdate());
    ResultSet rs = ps.getGeneratedKeys();
    assertFalse(rs.next());
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 49 with ModelMetaData

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

the class TestEmbeddedServer method testMultiSourceMetadata.

@Test
public void testMultiSourceMetadata() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    MockTransactionManager tm = new MockTransactionManager();
    ec.setTransactionManager(tm);
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("t", new ExecutionFactory<Void, Void>());
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("b");
    mmd1.setSchemaSourceType("ddl");
    mmd1.setSchemaText("create foreign table t (x string)");
    mmd1.setSupportsMultiSourceBindings(true);
    mmd1.addSourceMapping("x", "t", null);
    mmd1.addSourceMapping("y", "t", null);
    es.deployVDB("vdb", mmd1);
    Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
    PreparedStatement ps = c.prepareStatement("select * from t");
    ResultSetMetaData metadata = ps.getMetaData();
    assertEquals(1, metadata.getColumnCount());
    mmd1.addProperty("multisource.addColumn", Boolean.TRUE.toString());
    es.undeployVDB("vdb");
    es.deployVDB("vdb", mmd1);
    c = es.getDriver().connect("jdbc:teiid:vdb", null);
    ps = c.prepareStatement("select * from t");
    metadata = ps.getMetaData();
    assertEquals(2, metadata.getColumnCount());
    mmd1.addProperty("multisource.columnName", "y");
    es.undeployVDB("vdb");
    es.deployVDB("vdb", mmd1);
    c = es.getDriver().connect("jdbc:teiid:vdb", null);
    ps = c.prepareStatement("select * from t");
    metadata = ps.getMetaData();
    assertEquals(2, metadata.getColumnCount());
    assertEquals("y", metadata.getColumnName(2));
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 50 with ModelMetaData

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

the class TestEmbeddedServer method testCancelSystemQuery.

@Test(expected = TeiidSQLException.class)
public void testCancelSystemQuery() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    es.start(ec);
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("x");
    mmd.setModelType(Type.VIRTUAL);
    mmd.addSourceMetadata("ddl", "create view v as select 1;");
    es.deployVDB("x", mmd);
    Connection c = es.getDriver().connect("jdbc:teiid:x", null);
    final Statement s = c.createStatement();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                s.cancel();
            } catch (InterruptedException e) {
            } catch (SQLException e) {
            }
        }
    };
    t.start();
    ResultSet rs = s.executeQuery("select count(*) from columns c, columns c1, columns c2, columns c3, columns c4");
    rs.next();
    fail();
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) 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