Search in sources :

Example 66 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextEJBQLQueryIT method testSelectFromWhereLess.

@Test
public void testSelectFromWhereLess() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice < 5000";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals("P1", p.getPaintingTitle());
    assertEquals(3000d, p.getEstimatedPrice().doubleValue(), 0.00001);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 67 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextEJBQLQueryIT method testSelectFromWhereMatchRelationshipAndScalar.

@Test
public void testSelectFromWhereMatchRelationshipAndScalar() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.toArtist = 33002";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals(33002, Cayenne.intPKForObject(p));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 68 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextExtrasIT method testPhantomRelationshipModificationValidate.

@Test
public void testPhantomRelationshipModificationValidate() throws Exception {
    createPhantomRelationshipModificationCommitDataSet();
    List<Painting> objects = ObjectSelect.query(Painting.class).select(context);
    assertEquals(1, objects.size());
    Painting p1 = objects.get(0);
    Artist oldArtist = p1.getToArtist();
    Artist newArtist = Cayenne.objectForPK(context, Artist.class, 33002);
    assertNotSame(oldArtist, newArtist);
    p1.setToArtist(newArtist);
    p1.setToArtist(oldArtist);
    p1.resetValidationFlags();
    context.commitChanges();
    assertFalse(p1.isValidateForSaveCalled());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 69 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextExtrasIT method testPhantomRelationshipModificationCommit.

@Test
public void testPhantomRelationshipModificationCommit() throws Exception {
    createPhantomRelationshipModificationCommitDataSet();
    List<Painting> objects = ObjectSelect.query(Painting.class).select(context);
    assertEquals(1, objects.size());
    Painting p1 = objects.get(0);
    Artist oldArtist = p1.getToArtist();
    Artist newArtist = Cayenne.objectForPK(context, Artist.class, 33002);
    assertNotSame(oldArtist, newArtist);
    p1.setToArtist(newArtist);
    p1.setToArtist(oldArtist);
    context.commitChanges();
    assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
    assertEquals(PersistenceState.COMMITTED, oldArtist.getPersistenceState());
    assertEquals(PersistenceState.COMMITTED, newArtist.getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 70 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextExtrasIT method testPhantomModificationsValidateToOne.

@Test
public void testPhantomModificationsValidateToOne() throws Exception {
    createPhantomModificationsValidateToOneDataSet();
    List<Painting> objects = ObjectSelect.query(Painting.class).select(context);
    Painting p1 = objects.get(0);
    p1.setPaintingTitle(p1.getPaintingTitle());
    p1.resetValidationFlags();
    context.commitChanges();
    assertFalse("To-one relationship presence caused incorrect validation call.", p1.isValidateForSaveCalled());
}
Also used : 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