use of org.apache.cayenne.testdo.testmap.Artist 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.Artist in project cayenne by apache.
the class DataContextRefreshingIT method testRefetchRootWithUpdatedAttributes.
@Test
public void testRefetchRootWithUpdatedAttributes() throws Exception {
createSingleArtistDataSet();
String nameBefore = "artist2";
String nameAfter = "not an artist";
SelectQuery queryBefore = new SelectQuery(Artist.class, ExpressionFactory.matchExp("artistName", nameBefore));
Artist artist = (Artist) context.performQuery(queryBefore).get(0);
assertEquals(nameBefore, artist.getArtistName());
assertEquals(1, tArtist.update().set("ARTIST_NAME", nameAfter).execute());
// fetch into the same context
List<Artist> artists = context.performQuery(queryBefore);
assertEquals(0, artists.size());
SelectQuery queryAfter = new SelectQuery(Artist.class, ExpressionFactory.matchExp("artistName", nameAfter));
artist = (Artist) context.performQuery(queryAfter).get(0);
assertNotNull(artist);
assertEquals(nameAfter, artist.getArtistName());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataContextRefreshingIT method testInvalidateRootWithUpdatedAttributes.
@Test
public void testInvalidateRootWithUpdatedAttributes() throws Exception {
createSingleArtistDataSet();
String nameBefore = "artist2";
String nameAfter = "not an artist";
Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(0);
assertNotNull(artist);
assertEquals(nameBefore, artist.getArtistName());
// update via DataNode directly
assertEquals(1, tArtist.update().set("ARTIST_NAME", nameAfter).execute());
context.invalidateObjects(artist);
assertEquals(nameAfter, artist.getArtistName());
}
use of org.apache.cayenne.testdo.testmap.Artist 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.Artist 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