Search in sources :

Example 76 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLJoinsIT method testChainedJoins.

@Test
public void testChainedJoins() throws Exception {
    createTwoArtistsTwoPaintingsTwoGalleries();
    String ejbql = "SELECT a FROM Artist a JOIN a.paintingArray p JOIN p.toGallery g " + "WHERE g.galleryName = 'gallery2'";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> artists = context.performQuery(query);
    assertEquals(1, artists.size());
    assertEquals(33002, Cayenne.intPKForObject((Artist) artists.get(0)));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 77 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLJoinsIT method testImplicitJoins_OUTER_InTheMiddle.

@Test
public void testImplicitJoins_OUTER_InTheMiddle() throws Exception {
    tGallery.insert(33001, "gallery1");
    tGallery.insert(33002, "gallery2");
    tArtist.insert(33001, "AA1");
    tArtist.insert(33002, "AA2");
    tPainting.insert(33005, 33001, 33001, "CC1", 5000);
    tPainting.insert(33006, 33001, 33002, "CC2", 5000);
    String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray+.toGallery is null";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> artists = context.performQuery(query);
    assertEquals(1, artists.size());
    assertEquals(33002, Cayenne.intPKForObject((Artist) artists.get(0)));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 78 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLJoinsIT method testInnerJoins.

@Test
public void testInnerJoins() throws Exception {
    createTwoArtistsOnePainting();
    String ejbql = "SELECT a FROM Artist a INNER JOIN a.paintingArray p " + "WHERE a.artistName = 'AA1'";
    List<?> artists = context.performQuery(new EJBQLQuery(ejbql));
    assertEquals(1, artists.size());
    assertEquals(33001, Cayenne.intPKForObject((Artist) artists.get(0)));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 79 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLJoinsIT method testImplicitJoins.

@Test
public void testImplicitJoins() throws Exception {
    createTwoArtistsTwoPaintingsTwoGalleries();
    String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray.toGallery.galleryName = 'gallery2'";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> artists = context.performQuery(query);
    assertEquals(1, artists.size());
    assertEquals(33002, Cayenne.intPKForObject((Artist) artists.get(0)));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 80 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLJoinsIT method testPartialImplicitJoins2.

@Test
public void testPartialImplicitJoins2() throws Exception {
    createTwoArtistsTwoPaintingsTwoGalleries();
    String ejbql = "SELECT a " + "FROM Artist a JOIN a.paintingArray b " + "WHERE a.paintingArray.paintingTitle = 'CC2'";
    List<?> artists = context.performQuery(new EJBQLQuery(ejbql));
    assertEquals(1, artists.size());
    assertEquals(33002, Cayenne.intPKForObject((Artist) artists.get(0)));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Aggregations

EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)160 Test (org.junit.Test)158 Artist (org.apache.cayenne.testdo.testmap.Artist)39 HashSet (java.util.HashSet)35 Painting (org.apache.cayenne.testdo.testmap.Painting)15 QueryResponse (org.apache.cayenne.QueryResponse)12 BigDecimal (java.math.BigDecimal)10 Persistent (org.apache.cayenne.Persistent)10 List (java.util.List)9 ArrayList (java.util.ArrayList)7 FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)6 CompoundPainting (org.apache.cayenne.testdo.testmap.CompoundPainting)5 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 ValueHolder (org.apache.cayenne.ValueHolder)4 CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)4 Gallery (org.apache.cayenne.testdo.testmap.Gallery)4 Calendar (java.util.Calendar)3 EJBQLCompiledExpression (org.apache.cayenne.ejbql.EJBQLCompiledExpression)3