use of org.apache.cayenne.dba.JdbcPkGenerator in project cayenne by apache.
the class DataContextExtrasIT method testCommitChangesError.
@Test
public void testCommitChangesError() {
DataDomain domain = context.getParentDataDomain();
// setup mockup PK generator that will blow on PK request
// to emulate an exception
JdbcAdapter jdbcAdapter = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
PkGenerator newGenerator = new JdbcPkGenerator(jdbcAdapter) {
@Override
public Object generatePk(DataNode node, DbAttribute pk) throws Exception {
throw new CayenneRuntimeException("Intentional");
}
};
PkGenerator oldGenerator = domain.getDataNodes().iterator().next().getAdapter().getPkGenerator();
JdbcAdapter adapter = (JdbcAdapter) domain.getDataNodes().iterator().next().getAdapter();
adapter.setPkGenerator(newGenerator);
try {
Artist newArtist = context.newObject(Artist.class);
newArtist.setArtistName("aaa");
context.commitChanges();
fail("Exception expected but not thrown due to missing PK generation routine.");
} catch (CayenneRuntimeException ex) {
// exception expected
} finally {
adapter.setPkGenerator(oldGenerator);
}
}
Aggregations