}
}
void testNonTxnAddOfChildToParentFailsPartwayThrough(HasOneToManyJDO pojo)
throws Throwable {
Flight flight1 = new Flight();
pojo.addFlight(flight1);
beginTxn();
pm.makePersistent(pojo);
commitTxn();
final String kind = kindForObject(pojo);
DatastoreServiceInterceptor.Policy policy = new DatastoreServiceInterceptor.Policy() {
public void intercept(Object o, Method method, Object[] params) {
if (method.getName().equals("put") && ((Entity) params[0]).getKind().equals(kind)) {
throw new ConcurrentModificationException("kaboom");
}
}
};
DatastoreServiceInterceptor.install(getStoreManager(), policy);
Flight flight2 = new Flight();
try {
pmf.close();
switchDatasource(PersistenceManagerFactoryName.nontransactional);
pojo = pm.getObjectById(pojo.getClass(), pojo.getId());
pojo.addFlight(flight2);
pm.close();
fail("expected exception");
} catch (ConcurrentModificationException cme) {
// good
} finally {
DatastoreServiceInterceptor.uninstall();
}
// prove that the book entity exists
ds.get(KeyFactory.stringToKey(flight2.getId()));
Entity pojoEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
// the parent has a reference to the first book that was already there
// but no reference to the second book
assertEquals(
Collections.singletonList(KeyFactory.stringToKey(flight1.getId())),