BidirectionalChildJDO bidir2,
BidirectionalChildJDO bidir3, StartEnd startEnd) throws EntityNotFoundException {
pojo.setVal("yar");
bidir2.setChildVal("another yam");
bidir3.setChildVal("yet another yam");
Flight f = newFlight();
Flight f2 = newFlight();
Flight f3 = newFlight();
f2.setName("another name");
f3.setName("yet another name");
HasKeyPkJDO hasKeyPk = new HasKeyPkJDO();
HasKeyPkJDO hasKeyPk2 = new HasKeyPkJDO();
HasKeyPkJDO hasKeyPk3 = new HasKeyPkJDO();
hasKeyPk2.setStr("another str");
hasKeyPk3.setStr("yet another str");
pojo.addFlight(f);
pojo.addFlight(f2);
pojo.addFlight(f3);
pojo.addHasKeyPk(hasKeyPk);
pojo.addHasKeyPk(hasKeyPk2);
pojo.addHasKeyPk(hasKeyPk3);
pojo.addBidirChild(bidir1);
pojo.addBidirChild(bidir2);
pojo.addBidirChild(bidir3);
startEnd.start();
pm.makePersistent(pojo);
startEnd.end();
assertCountsInDatastore(pojo.getClass(), bidir1.getClass(), 1, 3);
startEnd.start();
pojo = pm.getObjectById(pojo.getClass(), pojo.getId());
String bidir1Id = pojo.getBidirChildren().iterator().next().getId();
String flight1Id = pojo.getFlights().iterator().next().getId();
Key hasKeyPk1Key = pojo.getHasKeyPks().iterator().next().getKey();
pojo.removeBidirChildAtPosition(0);
pojo.removeFlightAtPosition(0);
pojo.removeHasKeyPkAtPosition(0);
startEnd.end();
startEnd.start();
assertNotNull(pojo.getId());
assertEquals(2, pojo.getFlights().size());
assertEquals(2, pojo.getHasKeyPks().size());
assertEquals(2, pojo.getBidirChildren().size());
Entity pojoEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
assertNotNull(pojoEntity);
assertEquals(4, pojoEntity.getProperties().size());
assertEquals(Utils.newArrayList(
KeyFactory.stringToKey(bidir2.getId()),
KeyFactory.stringToKey(bidir3.getId())), pojoEntity.getProperty("bidirChildren"));
assertEquals(Utils.newArrayList(
KeyFactory.stringToKey(f2.getId()),
KeyFactory.stringToKey(f3.getId())), pojoEntity.getProperty("flights"));
assertEquals(Utils.newArrayList(
hasKeyPk2.getKey(),
hasKeyPk3.getKey()), pojoEntity.getProperty("hasKeyPks"));
startEnd.end();
try {
ds.get(KeyFactory.stringToKey(bidir1Id));
fail("expected EntityNotFoundException");
} catch (EntityNotFoundException enfe) {
// good
}
try {
ds.get(KeyFactory.stringToKey(flight1Id));
fail("expected EntityNotFoundException");
} catch (EntityNotFoundException enfe) {
// good
}
try {
ds.get(hasKeyPk1Key);
fail("expected EntityNotFoundException");
} catch (EntityNotFoundException enfe) {
// good
}
Entity bidirChildEntity = ds.get(KeyFactory.stringToKey(bidir2.getId()));
assertNotNull(bidirChildEntity);
assertEquals("another yam", bidirChildEntity.getProperty("childVal"));
assertEquals(KeyFactory.stringToKey(bidir2.getId()), bidirChildEntity.getKey());
assertKeyParentEquals(pojo.getId(), bidirChildEntity, bidir2.getId());
if (isIndexed() && getStorageVersion(pm) == StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN) {
assertEquals(0L, bidirChildEntity.getProperty("bidirChildren_INTEGER_IDX"));
}
bidirChildEntity = ds.get(KeyFactory.stringToKey(bidir3.getId()));
assertNotNull(bidirChildEntity);
assertEquals("yet another yam", bidirChildEntity.getProperty("childVal"));
assertEquals(KeyFactory.stringToKey(bidir3.getId()), bidirChildEntity.getKey());
assertKeyParentEquals(pojo.getId(), bidirChildEntity, bidir2.getId());
if (isIndexed() && getStorageVersion(pm) == StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN) {
assertEquals(1L, bidirChildEntity.getProperty("bidirChildren_INTEGER_IDX"));
}
Entity flightEntity = ds.get(KeyFactory.stringToKey(f2.getId()));
assertNotNull(flightEntity);
assertEquals("bos", flightEntity.getProperty("origin"));
assertEquals("mia", flightEntity.getProperty("dest"));
assertEquals("another name", flightEntity.getProperty("name"));
assertEquals(KeyFactory.stringToKey(f2.getId()), flightEntity.getKey());
assertKeyParentEquals(pojo.getId(), flightEntity, f2.getId());
if (isIndexed() && getStorageVersion(pm) == StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN) {
assertEquals(0L, flightEntity.getProperty("flights_INTEGER_IDX"));
}
flightEntity = ds.get(KeyFactory.stringToKey(f3.getId()));
assertNotNull(flightEntity);
assertEquals("bos", flightEntity.getProperty("origin"));
assertEquals("mia", flightEntity.getProperty("dest"));
assertEquals("yet another name", flightEntity.getProperty("name"));
assertEquals(KeyFactory.stringToKey(f3.getId()), flightEntity.getKey());
assertKeyParentEquals(pojo.getId(), flightEntity, f2.getId());
if (isIndexed() && getStorageVersion(pm) == StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN) {
assertEquals(1L, flightEntity.getProperty("flights_INTEGER_IDX"));
}
Entity hasKeyPkEntity = ds.get(hasKeyPk2.getKey());
assertNotNull(hasKeyPkEntity);
assertEquals("another str", hasKeyPkEntity.getProperty("str"));
assertEquals(hasKeyPk2.getKey(), hasKeyPkEntity.getKey());
assertKeyParentEquals(pojo.getId(), hasKeyPkEntity, hasKeyPk2.getKey());
if (isIndexed() && getStorageVersion(pm) == StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN) {
assertEquals(0L, hasKeyPkEntity.getProperty("hasKeyPks_INTEGER_IDX"));
}
hasKeyPkEntity = ds.get(hasKeyPk3.getKey());
assertNotNull(hasKeyPkEntity);
assertEquals("yet another str", hasKeyPkEntity.getProperty("str"));
assertEquals(hasKeyPk3.getKey(), hasKeyPkEntity.getKey());
assertKeyParentEquals(pojo.getId(), hasKeyPkEntity, hasKeyPk2.getKey());
if (isIndexed() && getStorageVersion(pm) == StorageVersion.PARENTS_DO_NOT_REFER_TO_CHILDREN) {
assertEquals(1L, hasKeyPkEntity.getProperty("hasKeyPks_INTEGER_IDX"));
}
Entity parentEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
assertNotNull(parentEntity);
assertEquals(4, parentEntity.getProperties().size());
assertEquals("yar", parentEntity.getProperty("val"));
assertEquals(Utils.newArrayList(
KeyFactory.stringToKey(bidir2.getId()),
KeyFactory.stringToKey(bidir3.getId())), parentEntity.getProperty("bidirChildren"));
assertEquals(Utils.newArrayList(
KeyFactory.stringToKey(f2.getId()),
KeyFactory.stringToKey(f3.getId())), parentEntity.getProperty("flights"));
assertEquals(Utils.newArrayList(
hasKeyPk2.getKey(),
hasKeyPk3.getKey()), parentEntity.getProperty("hasKeyPks"));
assertCountsInDatastore(pojo.getClass(), bidir2.getClass(), 1, 2);