Search in sources :

Example 86 with Expression

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

the class ASTLikeIgnoreCaseTest method testEvaluateUnicode.

@Test
public void testEvaluateUnicode() {
    Expression like = new ASTLikeIgnoreCase(new ASTObjPath("artistName"), "ÀБĞÞ%");
    Expression notLike = new ASTNotLikeIgnoreCase(new ASTObjPath("artistName"), "ÀБĞÞ%");
    Artist noMatch1 = new Artist();
    noMatch1.setArtistName("àbğþ");
    assertFalse(like.match(noMatch1));
    assertTrue(notLike.match(noMatch1));
    Artist match1 = new Artist();
    match1.setArtistName("àбğþd");
    assertTrue("Failed: " + like, like.match(match1));
    assertFalse("Failed: " + notLike, notLike.match(match1));
    Artist match2 = new Artist();
    match2.setArtistName("àБğÞ");
    assertTrue("Failed: " + like, like.match(match2));
    assertFalse("Failed: " + notLike, notLike.match(match2));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 87 with Expression

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

the class ASTLikeIgnoreCaseTest method testEvaluate.

@Test
public void testEvaluate() {
    Expression like = new ASTLikeIgnoreCase(new ASTObjPath("artistName"), "aBcD");
    Expression notLike = new ASTNotLikeIgnoreCase(new ASTObjPath("artistName"), "aBcD");
    Artist noMatch1 = new Artist();
    noMatch1.setArtistName("dabc");
    assertFalse(like.match(noMatch1));
    assertTrue(notLike.match(noMatch1));
    Artist match1 = new Artist();
    match1.setArtistName("abcd");
    assertTrue("Failed: " + like, like.match(match1));
    assertFalse("Failed: " + notLike, notLike.match(match1));
    Artist match2 = new Artist();
    match2.setArtistName("ABcD");
    assertTrue("Failed: " + like, like.match(match2));
    assertFalse("Failed: " + notLike, notLike.match(match2));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 88 with Expression

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

the class ASTLikeIgnoreCaseTest method testEvaluateWithCollection.

@Test
public void testEvaluateWithCollection() {
    Expression like = new ASTLikeIgnoreCase(new ASTObjPath("paintingArray.paintingTitle"), "aBcD");
    Expression notLike = new ASTNotLikeIgnoreCase(new ASTObjPath("paintingArray.paintingTitle"), "aBcD");
    Artist noMatch1 = new Artist();
    noMatch1.writePropertyDirectly("paintingArray", Arrays.asList(createPainting("xyz"), createPainting("abc")));
    assertFalse("Failed: " + like, like.match(noMatch1));
    assertTrue("Failed: " + like, notLike.match(noMatch1));
    Artist match1 = new Artist();
    match1.writePropertyDirectly("paintingArray", Arrays.asList(createPainting("AbCd"), createPainting("abcd")));
    assertTrue("Failed: " + like, like.match(match1));
    assertFalse("Failed: " + like, notLike.match(match1));
    Artist match2 = new Artist();
    match2.writePropertyDirectly("paintingArray", Arrays.asList(createPainting("Xzy"), createPainting("abcd")));
    assertTrue("Failed: " + like, like.match(match2));
    assertTrue("Failed: " + like, notLike.match(match2));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 89 with Expression

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

the class ASTLikeTest method testEvaluate_NotSoSpecialChars.

@Test
public void testEvaluate_NotSoSpecialChars() {
    // test special chars that are not LIKE pattern match chars
    Expression like = new ASTLike(new ASTObjPath("artistName"), "/./");
    Artist noMatch1 = new Artist();
    noMatch1.setArtistName("/a/");
    assertFalse(like.match(noMatch1));
    Artist match = new Artist();
    match.setArtistName("/./");
    assertTrue("Failed: " + like, like.match(match));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 90 with Expression

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

the class ASTLikeTest method testToEJBQL_likeEscape.

@Test
public void testToEJBQL_likeEscape() throws IOException {
    Expression like = new ASTLike(new ASTObjPath("mainName"), "|%|%?|_title|%", '|');
    assertEquals("x.mainName like '|%|%?|_title|%' escape '|'", like.toEJBQL("x"));
}
Also used : Expression(org.apache.cayenne.exp.Expression) 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