use of org.teiid.translator.TranslatorBatchException in project teiid by teiid.
the class TestEmbeddedServer method testBatchedUpdateErrors.
@Test
public void testBatchedUpdateErrors() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hcef.addUpdate("UPDATE pm1.g1 SET e1 = 'a' WHERE pm1.g1.e2 = 1", new int[] { 1 });
hcef.addUpdate("UPDATE pm1.g1 SET e1 = 'b' WHERE pm1.g1.e2 = 2", new TranslatorException("i've failed"));
es.addTranslator("y", hcef);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("my-schema");
mmd.addSourceMapping("x", "y", null);
mmd.addSourceMetadata("ddl", "create foreign table \"pm1.g1\" (e1 string, e2 integer) options (updatable true)");
es.deployVDB("test", mmd);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
// $NON-NLS-1$
s.addBatch("update pm1.g1 set e1 = 'a' where e2 = 1");
// $NON-NLS-1$
s.addBatch("update pm1.g1 set e1 = 'b' where e2 = 2");
try {
s.executeBatch();
fail();
} catch (BatchUpdateException e) {
int[] updateCounts = e.getUpdateCounts();
assertArrayEquals(new int[] { 1 }, updateCounts);
assertEquals(-1, s.getUpdateCount());
}
// redeploy with batch support
hcef = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
@Override
public boolean supportsBatchedUpdates() {
return true;
}
};
es.addTranslator("z", hcef);
es.undeployVDB("test");
mmd = new ModelMetaData();
mmd.setName("my-schema");
mmd.addSourceMetadata("ddl", "create foreign table \"pm1.g1\" (e1 string, e2 integer) options (updatable true)");
mmd.addSourceMapping("y", "z", null);
es.deployVDB("test", mmd);
c = td.connect("jdbc:teiid:test", null);
s = c.createStatement();
// $NON-NLS-1$
s.addBatch("update pm1.g1 set e1 = 'a' where e2 = 1");
// $NON-NLS-1$
s.addBatch("update pm1.g1 set e1 = 'b' where e2 = 2");
hcef.updateMap.clear();
hcef.addUpdate("UPDATE pm1.g1 SET e1 = 'a' WHERE pm1.g1.e2 = 1;\nUPDATE pm1.g1 SET e1 = 'b' WHERE pm1.g1.e2 = 2;", new TranslatorBatchException(new SQLException(), new int[] { 1, -3 }));
try {
s.executeBatch();
fail();
} catch (BatchUpdateException e) {
int[] updateCounts = e.getUpdateCounts();
assertArrayEquals(new int[] { 1, -3 }, updateCounts);
assertEquals(-1, s.getUpdateCount());
}
}
Aggregations