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