}
private void writeAndRead()
throws Exception {
MarshalledObject o1 = new MarshalledObject("data1", "pk1", "ik1", "");
assertNull(storeMap1.put(null, o1));
assertEquals(o1, storeMap1.get("pk1"));
assertEquals(o1, indexMap1.get("ik1"));
MarshalledObject o2 = new MarshalledObject("data2", "pk2", "", "pk1");
assertNull(storeMap2.put(null, o2));
assertEquals(o2, storeMap2.get("pk2"));
assertEquals(o2, indexMap2.get("pk1"));
/*
* store1 contains o1 with primary key "pk1" and index key "ik1"
* store2 contains o2 with primary key "pk2" and foreign key "pk1"
* which is the primary key of store1
*/
switch (onDelete) {
case ForeignKeyIndex.ON_DELETE_ABORT:
try {
storeMap1.remove("pk1");
fail();
}
catch (IntegrityConstraintException expected) {}
o2 = new MarshalledObject("data2", "pk2", "", "");
assertNotNull(storeMap2.put(null, o2));
assertEquals(o2, storeMap2.get("pk2"));
assertNull(indexMap2.get("pk1"));
storeMap1.remove("pk1");
assertNull(storeMap1.get("pk1"));
assertNull(indexMap1.get("ik1"));
break;
case ForeignKeyIndex.ON_DELETE_CLEAR:
storeMap1.remove("pk1");
assertNull(storeMap1.get("pk1"));
assertNull(indexMap1.get("ik1"));
o2 = (MarshalledObject) storeMap2.get("pk2");
assertNotNull(o2);
assertEquals("data2", o2.getData());
assertEquals("pk2", o2.getPrimaryKey());
assertEquals("", o2.getIndexKey1());
assertEquals("", o2.getIndexKey2());
break;
case ForeignKeyIndex.ON_DELETE_CASCADE:
storeMap1.remove("pk1");
assertNull(storeMap1.get("pk1"));
assertNull(indexMap1.get("ik1"));