use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestSystemVirtualModel method testTriggers.
@Test
public void testTriggers() throws Exception {
this.internalConnection.close();
ModelMetaData mmd3 = new ModelMetaData();
mmd3.setName("x");
mmd3.setModelType(Type.PHYSICAL);
mmd3.addSourceMapping("x", "x", null);
mmd3.addSourceMetadata("DDL", "create foreign table t (intkey integer); " + " create trigger tr on t after insert as for each row begin select intkey from t where intkey = new.intkey; end; " + " create trigger tr1 on t after update as for each row begin select intkey from t where intkey = new.intkey + old.intkey; end;");
HardCodedExecutionFactory ef = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
ef.addData("SELECT t.intkey FROM t WHERE t.intkey = 1", new ArrayList<List<?>>());
server.addTranslator("x", ef);
server.deployVDB("test3", mmd3);
this.internalConnection = server.createConnection("jdbc:teiid:test3");
// $NON-NLS-1$ //$NON-NLS-2$
checkResult("testTriggers", "select * from sysadmin.triggers");
closeStatement();
// insert event
ResultsFuture<?> future = server.getEventDistributor().dataModification("test3", "1", "x", "t", null, new Object[] { 1 }, null);
future.get(2, TimeUnit.SECONDS);
assertEquals("SELECT t.intkey FROM t WHERE t.intkey = 1", ef.getCommands().get(0).toString());
ef.addData("SELECT t.intkey FROM t WHERE t.intkey = 3", new ArrayList<List<?>>());
// update event
future = server.getEventDistributor().dataModification("test3", "1", "x", "t", new Object[] { 2 }, new Object[] { 1 }, null);
future.get(2, TimeUnit.SECONDS);
assertEquals("SELECT t.intkey FROM t WHERE t.intkey = 3", ef.getCommands().get(1).toString());
// delete event
future = server.getEventDistributor().dataModification("test3", "1", "x", "t", new Object[] { 2 }, null, null);
future.get(2, TimeUnit.SECONDS);
// no trigger
assertEquals(2, ef.getCommands().size());
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestJDBCSocketTransport method testStreamingLob.
@Test
public void testStreamingLob() throws Exception {
HardCodedExecutionFactory ef = new HardCodedExecutionFactory();
ef.addData("SELECT helloworld.x FROM helloworld", Arrays.asList(Arrays.asList(new BlobType(new BinaryWSProcedureExecution.StreamingBlob(new ByteArrayInputStream(new byte[100]))))));
server.addTranslator("custom", ef);
server.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"test\" translator-name=\"custom\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table helloworld (x blob);]]> </metadata></model></vdb>".getBytes("UTF-8")));
conn = TeiidDriver.getInstance().connect("jdbc:teiid:test@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), null);
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select to_chars(x, 'UTF-8') from helloworld");
rs.next();
// TODO: if we use getString streaming will still fail because the string logic gets the length first
assertEquals(100, ObjectConverterUtil.convertToCharArray(rs.getCharacterStream(1), -1).length);
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestMaterializationPerformance method testIndexPerformance.
@Test
public void testIndexPerformance() throws Exception {
ModelMetaData mmm = new ModelMetaData();
mmm.setName("test");
mmm.setSchemaSourceType("ddl");
mmm.setSchemaText("create foreign table x (col1 integer, col2 string); " + "create view matx (col1 integer, col2 string, constraint idx index (col2)) options (materialized true) as select * from x;");
mmm.addSourceMapping("x", "hc", null);
HardCodedExecutionFactory hardCodedExecutionFactory = new HardCodedExecutionFactory();
hardCodedExecutionFactory.addData("SELECT x.col1, x.col2 FROM x", Arrays.asList(TestEnginePerformance.sampleData(10000)));
es.addTranslator("hc", hardCodedExecutionFactory);
es.deployVDB("test", mmm);
setConnection(es.getDriver().connect("jdbc:teiid:test", null));
for (int i = 0; i < 10000; i++) {
execute("SELECT * from matx where col2 = ?", new Object[] { String.valueOf(i) });
assertEquals(String.valueOf(i), getRowCount(), 1);
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestMaterializationPerformance method testFunctionBasedIndexPerformance.
@Test
public void testFunctionBasedIndexPerformance() throws Exception {
ModelMetaData mmm = new ModelMetaData();
mmm.setName("test");
mmm.setSchemaSourceType("ddl");
mmm.setSchemaText("create foreign table x (col1 integer, col2 string); " + "create view matx (col1 integer, col2 string, constraint idx index (upper(col2))) options (materialized true) as select * from x;");
mmm.addSourceMapping("x", "hc", null);
HardCodedExecutionFactory hardCodedExecutionFactory = new HardCodedExecutionFactory();
hardCodedExecutionFactory.addData("SELECT x.col1, x.col2 FROM x", Arrays.asList(TestEnginePerformance.sampleData(10000)));
es.addTranslator("hc", hardCodedExecutionFactory);
es.deployVDB("test", mmm);
setConnection(es.getDriver().connect("jdbc:teiid:test", null));
for (int i = 0; i < 10000; i++) {
execute("SELECT * from matx where upper(col2) = ?", new Object[] { String.valueOf(i) });
assertEquals(String.valueOf(i), getRowCount(), 1);
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestSystemPerformance method setup.
@Before
public void setup() throws VirtualDatabaseException, ConnectorManagerException, TranslatorException {
es = new EmbeddedServer();
es.start(new EmbeddedConfiguration());
ModelMetaData mmm = new ModelMetaData();
mmm.setName("test");
mmm.setSchemaSourceType("native");
mmm.addSourceMapping("x", "hc", null);
HardCodedExecutionFactory hardCodedExecutionFactory = new HardCodedExecutionFactory() {
@Override
public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
String[] colNames = new String[COLS];
for (int i = 0; i < colNames.length; i++) {
colNames[i] = "col" + i;
}
for (int i = 0; i < TABLES; i++) {
Table t = metadataFactory.addTable("x" + i);
for (int j = 0; j < COLS; j++) {
metadataFactory.addColumn(colNames[j], "string", t);
}
}
}
@Override
public boolean isSourceRequiredForMetadata() {
return false;
}
};
es.addTranslator("hc", hardCodedExecutionFactory);
es.deployVDB("test", mmm);
}
Aggregations