use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRefreshingIT method testRefetchRootWithNullifiedToOne.
@Test
public void testRefetchRootWithNullifiedToOne() throws Exception {
createSingleArtistAndPaintingDataSet();
Painting painting = (Painting) context.performQuery(new SelectQuery(Painting.class)).get(0);
assertNotNull(painting.getToArtist());
assertEquals("artist2", painting.getToArtist().getArtistName());
assertEquals(1, tPainting.update().set("ARTIST_ID", null, Types.BIGINT).execute());
// select without prefetch
painting = (Painting) context.performQuery(new SelectQuery(Painting.class)).get(0);
assertNotNull(painting);
assertNull(painting.getToArtist());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRefreshingIT method testInvalidateRootWithChangedToOneTarget.
@Test
public void testInvalidateRootWithChangedToOneTarget() throws Exception {
createTwoArtistsAndPaintingDataSet();
Painting painting = (Painting) context.performQuery(new SelectQuery(Painting.class)).get(0);
Artist artistBefore = painting.getToArtist();
assertNotNull(artistBefore);
assertEquals("artist2", artistBefore.getArtistName());
assertEquals(1, tPainting.update().set("ARTIST_ID", 6).execute());
context.invalidateObjects(painting);
assertNotSame(artistBefore, painting.getToArtist());
assertEquals("artist3", painting.getToArtist().getArtistName());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRefreshingIT method testInvalidateRootWithNullToOneTargetChangedToNotNull.
@Test
public void testInvalidateRootWithNullToOneTargetChangedToNotNull() throws Exception {
createSingleArtistAndUnrelatedPaintingDataSet();
Painting painting = (Painting) context.performQuery(new SelectQuery(Painting.class)).get(0);
assertNull(painting.getToArtist());
assertEquals(1, tPainting.update().set("ARTIST_ID", 5).execute());
context.invalidateObjects(painting);
assertNotNull(painting.getToArtist());
assertEquals("artist2", painting.getToArtist().getArtistName());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRelationshipQueryIT method testUnrefreshingToOne.
@Test
public void testUnrefreshingToOne() throws Exception {
createOneArtistOnePaintingDataSet();
Painting p = Cayenne.objectForPK(context, Painting.class, 1);
// resolve artist once before running non-refreshing query, to check that we do
// not refresh the object
Artist a = Cayenne.objectForPK(context, Artist.class, 1);
long v = a.getSnapshotVersion();
int writeCalls = a.getPropertyWrittenDirectly();
assertEquals("a1", a.getArtistName());
assertEquals(1, tArtist.update().set("ARTIST_NAME", "a2").where("ARTIST_ID", 1).execute());
RelationshipQuery toOne = new RelationshipQuery(p.getObjectId(), Painting.TO_ARTIST.getName(), false);
List<Artist> related = context.performQuery(toOne);
assertEquals(1, related.size());
assertTrue(related.contains(a));
assertEquals("a1", a.getArtistName());
assertEquals(v, a.getSnapshotVersion());
assertEquals("Looks like relationship query caused snapshot refresh", writeCalls, a.getPropertyWrittenDirectly());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRelationshipQueryIT method testRefreshingToOne.
@Test
public void testRefreshingToOne() throws Exception {
createOneArtistOnePaintingDataSet();
Painting p = Cayenne.objectForPK(context, Painting.class, 1);
// resolve artist once before running non-refreshing query, to check that we do
// not refresh the object
Artist a = Cayenne.objectForPK(context, Artist.class, 1);
long v = a.getSnapshotVersion();
int writeCalls = a.getPropertyWrittenDirectly();
assertEquals("a1", a.getArtistName());
assertEquals(1, tArtist.update().set("ARTIST_NAME", "a2").where("ARTIST_ID", 1).execute());
RelationshipQuery toOne = new RelationshipQuery(p.getObjectId(), Painting.TO_ARTIST.getName(), true);
List<Artist> related = context.performQuery(toOne);
assertEquals(1, related.size());
assertTrue(related.contains(a));
assertEquals("a2", a.getArtistName());
assertTrue("Looks like relationship query didn't cause a snapshot refresh", v < a.getSnapshotVersion());
assertTrue("Looks like relationship query didn't cause a snapshot refresh", writeCalls < a.getPropertyWrittenDirectly());
}
Aggregations