"Artist",
Artist.ARTIST_ID_PK_COLUMN,
33002)));
int modifiedId = 33003;
Artist modified = (Artist) DataObjectUtils.objectForQuery(
context,
new ObjectIdQuery(new ObjectId(
"Artist",
Artist.ARTIST_ID_PK_COLUMN,
modifiedId)));
modified.setArtistName("MODDED");
DataObject deleted = (DataObject) DataObjectUtils.objectForQuery(
context,
new ObjectIdQuery(new ObjectId(
"Artist",
Artist.ARTIST_ID_PK_COLUMN,
33004)));
context.deleteObject(deleted);
assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, committed.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
assertEquals(PersistenceState.NEW, _new.getPersistenceState());
// now check how objects in different state behave
// on the one hand sticking an alien NEW object to a peer DataContext doesn't look
// like a good idea, on the other hand the code detecting whether a given context
// is a child of another context breaks DataChannel encapsulation (i.e. using
// "instanceof" to check DataChannel type will make it impossible to use Proxies).
// try {
// peerContext.localObjects(Collections.singletonList(_new));
// fail("A presence of new object should have triggered an exception");
// }
// catch (CayenneRuntimeException e) {
// // expected
// }
blockQueries();
try {
Persistent hollowPeer = peerContext.localObject(hollow.getObjectId(), null);
assertEquals(PersistenceState.HOLLOW, hollowPeer.getPersistenceState());
assertEquals(hollow.getObjectId(), hollowPeer.getObjectId());
assertSame(peerContext, hollowPeer.getObjectContext());
assertSame(context, hollow.getObjectContext());
Persistent committedPeer = peerContext.localObject(
committed.getObjectId(),
null);
assertEquals(PersistenceState.HOLLOW, committedPeer.getPersistenceState());
assertEquals(committed.getObjectId(), committedPeer.getObjectId());
assertSame(peerContext, committedPeer.getObjectContext());
assertSame(context, committed.getObjectContext());
Persistent modifiedPeer = peerContext.localObject(
modified.getObjectId(),
null);
assertEquals(PersistenceState.HOLLOW, modifiedPeer.getPersistenceState());
assertEquals(modified.getObjectId(), modifiedPeer.getObjectId());
assertSame(peerContext, modifiedPeer.getObjectContext());
assertSame(context, modified.getObjectContext());
Persistent deletedPeer = peerContext.localObject(deleted.getObjectId(), null);
assertEquals(PersistenceState.HOLLOW, deletedPeer.getPersistenceState());
assertEquals(deleted.getObjectId(), deletedPeer.getObjectId());
assertSame(peerContext, deletedPeer.getObjectContext());