Search in sources :

Example 96 with Expression

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

the class ColumnSelectTest method and.

@Test
public void and() throws Exception {
    ColumnSelect q = new ColumnSelect();
    assertNull(q.getHaving());
    assertNull(q.getWhere());
    Expression expTrue = ExpressionFactory.expTrue();
    q.where(expTrue);
    q.and(expTrue);
    assertNull(q.getHaving());
    assertEquals(ExpressionFactory.exp("true and true"), q.getWhere());
    Expression expFalse = ExpressionFactory.expFalse();
    q.having("false");
    q.and(expFalse);
    assertEquals(ExpressionFactory.exp("false and false"), q.getHaving());
    assertEquals(ExpressionFactory.exp("true and true"), q.getWhere());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 97 with Expression

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

the class ColumnSelectTest method or.

@Test
public void or() throws Exception {
    ColumnSelect q = new ColumnSelect();
    assertNull(q.getHaving());
    assertNull(q.getWhere());
    Expression expTrue = ExpressionFactory.expTrue();
    q.where(expTrue);
    q.or(expTrue);
    assertNull(q.getHaving());
    assertEquals(ExpressionFactory.exp("true or true"), q.getWhere());
    Expression expFalse = ExpressionFactory.expFalse();
    q.having("false");
    q.or(expFalse);
    assertEquals(ExpressionFactory.exp("false or false"), q.getHaving());
    assertEquals(ExpressionFactory.exp("true or true"), q.getWhere());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 98 with Expression

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

the class ColumnSelectTest method havingExpression.

@Test
public void havingExpression() throws Exception {
    ColumnSelect q = new ColumnSelect();
    assertNull(q.getHaving());
    assertNull(q.getWhere());
    Expression expTrue = ExpressionFactory.expTrue();
    q.where(expTrue);
    assertNull(q.getHaving());
    assertEquals(expTrue, q.getWhere());
    Expression expFalse = ExpressionFactory.expFalse();
    q.having(expFalse);
    assertEquals(expFalse, q.getHaving());
    assertEquals(expTrue, q.getWhere());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 99 with Expression

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

the class ObjectSelect_RunIT method test_SelectFirst_SubstringInWhere.

@Test
public void test_SelectFirst_SubstringInWhere() throws Exception {
    Expression exp = FunctionExpressionFactory.substringExp(Artist.ARTIST_NAME.path(), 2, 3);
    Property<String> substrName = Property.create("substr", exp, String.class);
    Artist a = ObjectSelect.query(Artist.class).where(substrName.eq("rti")).orderBy("db:ARTIST_ID").selectFirst(context);
    assertNotNull(a);
    assertEquals("artist1", a.getArtistName());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 100 with Expression

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

the class OrderingTest method testOrderingWithExpression.

@Test
public void testOrderingWithExpression() {
    Expression exp = FunctionExpressionFactory.absExp("x");
    Ordering ord = new Ordering();
    ord.setSortSpec(exp);
    ord.setSortOrder(SortOrder.ASCENDING);
    Ordering ord2 = new Ordering(exp);
    assertEquals(ord, ord2);
    assertEquals(exp, ord2.getSortSpec());
    assertEquals(SortOrder.ASCENDING, ord2.getSortOrder());
}
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