Search in sources :

Example 6 with EJBQLQuery

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

the class QuotedIdentifiersIT method testQuotedEJBQLQueryWithJoin.

@Test
public void testQuotedEJBQLQueryWithJoin() throws Exception {
    String ejbql = "select p from Quote_Person p join p.address_Rel a where p.name = 'Arcadi'";
    EJBQLQuery queryEJBQL = new EJBQLQuery(ejbql);
    List resultList = context.performQuery(queryEJBQL);
    assertEquals(1, resultList.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) List(java.util.List) Test(org.junit.Test)

Example 7 with EJBQLQuery

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

the class QuotedIdentifiersIT method testQuotedEJBQLCountQuery.

@Test
public void testQuotedEJBQLCountQuery() throws Exception {
    EJBQLQuery query = new EJBQLQuery("select count(p) from Quote_Person p");
    assertEquals(Collections.singletonList(2L), context.performQuery(query));
    query = new EJBQLQuery("select count(p.fULL_name) from Quote_Person p");
    assertEquals(Collections.singletonList(0L), context.performQuery(query));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 8 with EJBQLQuery

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

the class QuotedIdentifiersIT method testQuotedEJBQLQuery.

@Test
public void testQuotedEJBQLQuery() throws Exception {
    String ejbql = "select a from QuoteAdress a where a.group = '324'";
    EJBQLQuery queryEJBQL = new EJBQLQuery(ejbql);
    List objects11 = context.performQuery(queryEJBQL);
    assertEquals(1, objects11.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) List(java.util.List) Test(org.junit.Test)

Example 9 with EJBQLQuery

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

the class QuotedIdentifiersIT method testQuotedEJBQLQueryWithOrderBy.

@Test
public void testQuotedEJBQLQueryWithOrderBy() throws Exception {
    EJBQLQuery query = new EJBQLQuery("select p from Quote_Person p order by p.name");
    List<Quote_Person> resultList = (List<Quote_Person>) context.performQuery(query);
    assertEquals(2, resultList.size());
    assertEquals("Arcadi", resultList.get(0).getName());
    assertEquals("Name", resultList.get(1).getName());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) List(java.util.List) Quote_Person(org.apache.cayenne.testdo.quotemap.Quote_Person) Test(org.junit.Test)

Example 10 with EJBQLQuery

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

the class DataDomainCallbacksIT method testPostLoad_MixedResult.

@Test
public void testPostLoad_MixedResult() throws Exception {
    LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
    registry.addCallback(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
    MockCallingBackListener listener = new MockCallingBackListener();
    registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, listener, "publicCallback");
    Artist a1 = context.newObject(Artist.class);
    a1.setArtistName("XX");
    context.commitChanges();
    assertEquals(0, a1.getPostLoaded());
    assertNull(listener.getPublicCalledbackEntity());
    EJBQLQuery q = new EJBQLQuery("select a, a.artistName from Artist a");
    context.performQuery(q);
    assertEquals(1, a1.getPostLoaded());
    assertSame(a1, listener.getPublicCalledbackEntity());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) 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