use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRollbackIT method testRollbackNew.
@Test
public void testRollbackNew() {
Artist artist = (Artist) context.newObject("Artist");
artist.setArtistName("a");
Painting p1 = (Painting) context.newObject("Painting");
p1.setPaintingTitle("p1");
p1.setToArtist(artist);
Painting p2 = (Painting) context.newObject("Painting");
p2.setPaintingTitle("p2");
p2.setToArtist(artist);
Painting p3 = (Painting) context.newObject("Painting");
p3.setPaintingTitle("p3");
p3.setToArtist(artist);
// before:
assertEquals(artist, p1.getToArtist());
assertEquals(3, artist.getPaintingArray().size());
context.rollbackChanges();
// after:
assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
}
use of org.apache.cayenne.testdo.testmap.Painting 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.testdo.testmap.Painting in project cayenne by apache.
the class DataContextSQLTemplateIT method testBindObjectEqualNull.
@Test
public void testBindObjectEqualNull() throws Exception {
createFourArtistsAndThreePaintingsDataSet();
String template = "SELECT * FROM PAINTING t0" + " WHERE #bindObjectEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
SQLTemplate query = new SQLTemplate(Painting.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("a", null));
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Painting p = (Painting) objects.get(0);
assertEquals(8, Cayenne.intPKForObject(p));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextSQLTemplateIT method testBindObjectNotEqualNull.
@Test
public void testBindObjectNotEqualNull() throws Exception {
createFourArtistsAndThreePaintingsDataSet();
String template = "SELECT * FROM PAINTING t0" + " WHERE #bindObjectNotEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
SQLTemplate query = new SQLTemplate(Painting.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("a", null));
List<Painting> objects = context.performQuery(query);
assertEquals(2, objects.size());
Painting p1 = objects.get(0);
assertEquals(6, Cayenne.intPKForObject(p1));
Painting p2 = objects.get(1);
assertEquals(7, Cayenne.intPKForObject(p2));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextSQLTemplateIT method testBindObjectEqualFullNonArray.
@Test
public void testBindObjectEqualFullNonArray() throws Exception {
createFourArtistsAndThreePaintingsDataSet();
Artist a = Cayenne.objectForPK(context, Artist.class, 101);
String template = "SELECT * FROM PAINTING t0" + " WHERE #bindObjectEqual($a 't0.ARTIST_ID' 'ARTIST_ID' ) ORDER BY PAINTING_ID";
SQLTemplate query = new SQLTemplate(Painting.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("a", a));
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Painting p = (Painting) objects.get(0);
assertEquals(7, Cayenne.intPKForObject(p));
}
Aggregations