public void testSerializeCommitted() throws Exception { Artist artist = (Artist) context.newObject("Artist"); artist.setArtistName("artist1"); assertNotNull(artist.getObjectId()); context.commitChanges(); DataContext deserializedContext = Util.cloneViaSerialization(context); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); // there should be only one object registered Artist deserializedArtist = (Artist) deserializedContext.getObjectStore().getObjectIterator().next(); assertNotNull(deserializedArtist); // deserialized as hollow... assertEquals(PersistenceState.HOLLOW, deserializedArtist.getPersistenceState()); assertFalse(deserializedArtist.getObjectId().isTemporary()); assertEquals("artist1", deserializedArtist.getArtistName()); assertSame(deserializedContext, deserializedArtist.getObjectContext()); // test that to-many relationships are initialized List<?> paintings = deserializedArtist.getPaintingArray(); assertNotNull(paintings); assertEquals(0, paintings.size()); }
public void testSerializeModified() throws Exception { Artist artist = (Artist) context.newObject("Artist"); artist.setArtistName("artist1"); assertNotNull(artist.getObjectId()); context.commitChanges(); artist.setArtistName("artist2"); DataContext deserializedContext = Util.cloneViaSerialization(context); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); // there should be only one object registered Artist deserializedArtist = (Artist) deserializedContext.getObjectStore().getObjectIterator().next(); assertNotNull(deserializedArtist); // deserialized as hollow... assertEquals(PersistenceState.MODIFIED, deserializedArtist.getPersistenceState()); assertFalse(deserializedArtist.getObjectId().isTemporary()); assertEquals("artist2", deserializedArtist.getArtistName()); assertSame(deserializedContext, deserializedArtist.getObjectContext()); }
public void testSerializeNew() throws Exception { Artist artist = (Artist) context.newObject("Artist"); artist.setArtistName("artist1"); assertNotNull(artist.getObjectId()); DataContext deserializedContext = Util.cloneViaSerialization(context); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); // there should be only one object registered Artist deserializedArtist = (Artist) deserializedContext.getObjectStore().getObjectIterator().next(); assertNotNull(deserializedArtist); assertEquals(PersistenceState.NEW, deserializedArtist.getPersistenceState()); assertTrue(deserializedArtist.getObjectId().isTemporary()); assertEquals("artist1", deserializedArtist.getArtistName()); assertSame(deserializedContext, deserializedArtist.getObjectContext()); }
public void testSerializeWithLocalCache() throws Exception { createSingleArtistDataSet(); // manually assemble a DataContext with local cache.... DataDomain domain = context.getParentDataDomain(); DataRowStore snapshotCache = new DataRowStore(domain.getName(), domain.getProperties(), domain.getEventManager()); Map<Object, Persistent> map = new HashMap<Object, Persistent>(); DataContext localCacheContext = new DataContext(domain, new ObjectStore(snapshotCache, map)); localCacheContext.setValidatingObjectsOnCommit(domain.isValidatingObjectsOnCommit()); localCacheContext.setUsingSharedSnapshotCache(false); assertNotSame( domain.getSharedSnapshotCache(), localCacheContext.getObjectStore().getDataRowCache()); DataContext deserializedContext = Util.cloneViaSerialization(localCacheContext); assertNotSame(localCacheContext, deserializedContext); assertNotSame(localCacheContext.getObjectStore(), deserializedContext.getObjectStore()); assertSame(localCacheContext.getParentDataDomain(), deserializedContext.getParentDataDomain()); assertNotSame( localCacheContext.getObjectStore().getDataRowCache(), deserializedContext.getObjectStore().getDataRowCache()); assertNotSame( deserializedContext.getParentDataDomain().getSharedSnapshotCache(), deserializedContext.getObjectStore().getDataRowCache()); Artist a = Cayenne.objectForPK(deserializedContext, Artist.class, 33001); assertNotNull(a); a.setArtistName(a.getArtistName() + "___"); // this blows per CAY-796 deserializedContext.commitChanges(); }
public void testSerializeWithSharedCache() throws Exception { createSingleArtistDataSet(); DataContext deserializedContext = Util.cloneViaSerialization(context); assertNotSame(context, deserializedContext); assertNotSame(context.getObjectStore(), deserializedContext.getObjectStore()); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); assertSame( context.getObjectStore().getDataRowCache(), deserializedContext.getObjectStore().getDataRowCache()); assertSame( deserializedContext.getParentDataDomain().getSharedSnapshotCache(), deserializedContext.getObjectStore().getDataRowCache()); assertNotNull(deserializedContext.getEntityResolver()); assertSame(context.getEntityResolver(), deserializedContext.getEntityResolver()); Artist a = Cayenne.objectForPK(deserializedContext, Artist.class, 33001); assertNotNull(a); a.setArtistName(a.getArtistName() + "___"); deserializedContext.commitChanges(); }