Search in sources :

Example 41 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SelectQueryIT method testSelectLikeSingle_WildcardMatch.

@Test
public void testSelectLikeSingle_WildcardMatch() throws Exception {
    createArtistsDataSet();
    SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
    Expression qual = ExpressionFactory.likeExp("artistName", "artist11%");
    query.setQualifier(qual);
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 42 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SelectQueryIT method testSelectOne.

@Test
public void testSelectOne() throws Exception {
    createArtistsDataSet();
    SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
    Expression qual = ExpressionFactory.matchExp("artistName", "artist1");
    query.setQualifier(qual);
    Artist artist = (Artist) query.selectOne(context);
    assertEquals("artist1", artist.getArtistName());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 43 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SelectQueryIT method testRouteQueryWithPrefetchesPrefetchExpressionPath.

/**
 * Test prefetching with qualifier on the root query being the path to the
 * prefetch.
 */
@Test
public void testRouteQueryWithPrefetchesPrefetchExpressionPath() {
    // find the painting not matching the artist (this is the case where
    // such prefetch
    // at least makes sense)
    Expression exp = ExpressionFactory.noMatchExp("toArtist", new Object());
    SelectQuery<Painting> q = new SelectQuery<>(Painting.class, exp);
    q.addPrefetch("toArtist");
    // test how prefetches are resolved in this case - this was a stumbling
    // block for
    // a while
    EntityResolver resolver = context.getEntityResolver();
    MockQueryRouter router = new MockQueryRouter();
    q.route(router, resolver, null);
    assertEquals(2, router.getQueryCount());
}
Also used : Expression(org.apache.cayenne.exp.Expression) EntityResolver(org.apache.cayenne.map.EntityResolver) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 44 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SelectQueryIT method testSelectParameterizedEmptyIn.

@Test
public void testSelectParameterizedEmptyIn() throws Exception {
    createArtistsDataSet();
    SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
    Expression qual = ExpressionFactory.exp("artistName in $list");
    query.setQualifier(qual);
    query = query.queryWithParameters(Collections.singletonMap("list", new Object[] {}));
    List<?> objects = context.performQuery(query);
    assertEquals(0, objects.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 45 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SelectQueryReturnTypesIT method testSelectBitwiseXor.

@Test
public void testSelectBitwiseXor() throws Exception {
    if (!accessStackAdapter.supportsBitwiseOps()) {
        return;
    }
    createNumericsDataSet();
    // to simplify result checking, do double NOT
    Expression left = new ASTBitwiseXor(new Object[] { new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName()), new ASTScalar(1) });
    Expression right = new ASTScalar(5);
    Expression equal = new ASTEqual();
    equal.setOperand(0, left);
    equal.setOperand(1, right);
    SelectQuery query = new SelectQuery(ReturnTypesMap1.class);
    query.setQualifier(equal);
    List<ReturnTypesMap1> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    assertEquals(4, objects.get(0).getIntegerColumn().intValue());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTBitwiseXor(org.apache.cayenne.exp.parser.ASTBitwiseXor) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Aggregations

Expression (org.apache.cayenne.exp.Expression)298 Test (org.junit.Test)265 Artist (org.apache.cayenne.testdo.testmap.Artist)69 SelectQuery (org.apache.cayenne.query.SelectQuery)47 Painting (org.apache.cayenne.testdo.testmap.Painting)29 BigDecimal (java.math.BigDecimal)23 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)16 ObjEntity (org.apache.cayenne.map.ObjEntity)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 DbEntity (org.apache.cayenne.map.DbEntity)10 List (java.util.List)9 HashMap (java.util.HashMap)8 DataRow (org.apache.cayenne.DataRow)8 DbAttribute (org.apache.cayenne.map.DbAttribute)8 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)7 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjAttribute (org.apache.cayenne.map.ObjAttribute)6 ObjRelationship (org.apache.cayenne.map.ObjRelationship)6 Gallery (org.apache.cayenne.testdo.testmap.Gallery)6