use of org.apache.cayenne.query.SelectQuery 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.query.SelectQuery 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.query.SelectQuery in project cayenne by apache.
the class DataContextRollbackIT method testRollbackModifiedObject.
@Test
public void testRollbackModifiedObject() {
String artistName = "initialTestArtist";
Artist artist = (Artist) context.newObject("Artist");
artist.setArtistName(artistName);
context.commitChanges();
artist.setArtistName("a new value");
context.rollbackChanges();
// Make sure the inmemory changes have been rolled back
assertEquals(artistName, artist.getArtistName());
// Commit what's in memory...
context.commitChanges();
// .. and ensure that the correct data is in the db
DataContext freshContext = (DataContext) serverRuntime.newContext();
assertNotSame(this.context, freshContext);
SelectQuery query = new SelectQuery(Artist.class);
query.setQualifier(ExpressionFactory.matchExp("artistName", artistName));
List<?> queryResults = freshContext.performQuery(query);
assertEquals(1, queryResults.size());
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class DataContextRollbackIT method testRollbackWithMultipleNewObjects.
// Catches a bug where new objects were unregistered within an object iterator, thus
// modifying the collection the iterator was iterating over
// (ConcurrentModificationException)
@Test
public void testRollbackWithMultipleNewObjects() {
String artistName = "rollbackTestArtist";
String paintingTitle = "rollbackTestPainting";
Artist artist = (Artist) context.newObject("Artist");
artist.setArtistName(artistName);
Painting painting = (Painting) context.newObject("Painting");
painting.setPaintingTitle(paintingTitle);
painting.setToArtist(artist);
context.rollbackChanges();
assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
context.commitChanges();
// The commit should have made no changes, so
// perform a fetch to ensure that this artist hasn't been persisted to the db
DataContext freshContext = (DataContext) serverRuntime.newContext();
assertNotSame(this.context, freshContext);
SelectQuery query = new SelectQuery(Artist.class);
query.setQualifier(ExpressionFactory.matchExp("artistName", artistName));
List<?> queryResults = freshContext.performQuery(query);
assertEquals(0, queryResults.size());
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class DataContextSelectQuerySplitAliasesIT method testAliasPathSplits_SplitJoin.
@Test
public void testAliasPathSplits_SplitJoin() throws Exception {
createTwoArtistsThreePaintingsDataSet();
SelectQuery query = new SelectQuery(Artist.class);
query.andQualifier(ExpressionFactory.matchExp("p1.paintingTitle", "X"));
query.andQualifier(ExpressionFactory.matchExp("p2.paintingTitle", "Y"));
query.aliasPathSplits("paintingArray", "p1", "p2");
List<Artist> artists = context.performQuery(query);
assertEquals(1, artists.size());
assertEquals("BB", artists.get(0).getArtistName());
}
Aggregations