Search in sources :

Example 31 with Painting

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());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 32 with Painting

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());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 33 with Painting

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));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 34 with Painting

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));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 35 with Painting

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));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SQLTemplate(org.apache.cayenne.query.SQLTemplate) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

Painting (org.apache.cayenne.testdo.testmap.Painting)222 Test (org.junit.Test)218 Artist (org.apache.cayenne.testdo.testmap.Artist)144 SelectQuery (org.apache.cayenne.query.SelectQuery)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)35 List (java.util.List)30 Expression (org.apache.cayenne.exp.Expression)29 ArrayList (java.util.ArrayList)21 BigDecimal (java.math.BigDecimal)19 PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)14 ObjectContext (org.apache.cayenne.ObjectContext)13 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)13 Gallery (org.apache.cayenne.testdo.testmap.Gallery)13 ValueHolder (org.apache.cayenne.ValueHolder)12 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 DataRow (org.apache.cayenne.DataRow)7 ProcedureQuery (org.apache.cayenne.query.ProcedureQuery)6 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)6 RefreshQuery (org.apache.cayenne.query.RefreshQuery)5