Search in sources :

Example 11 with Expression

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

the class ClientExpressionIT method testExpressionFactoryBetween.

@Test
public void testExpressionFactoryBetween() throws Exception {
    createDataSet();
    SelectQuery<ClientMtTable1> table1Query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
    table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
    List<ClientMtTable1> table1List = context.select(table1Query);
    ClientMtTable1 element_1 = table1List.get(0);
    ClientMtTable1 element_7 = table1List.get(6);
    // between
    Expression exp = ExpressionFactory.betweenExp(ClientMtTable2.TABLE1_PROPERTY, element_1, element_7);
    SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    List<ClientMtTable2> table2List = context.select(table2Query);
    assertEquals(14, table2List.size());
    // not between
    exp = ExpressionFactory.notBetweenExp(ClientMtTable2.TABLE1_PROPERTY, element_1, element_7);
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(6, table2List.size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 12 with Expression

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

the class RemoteIncrementalFaultListIT method testLastIndexOf.

@Test
public void testLastIndexOf() throws Exception {
    prepareList(6);
    Expression qual = ExpressionFactory.matchExp(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, "g20");
    SelectQuery<ClientMtTable1> query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class, qual);
    List<?> objects = list.context.performQuery(query);
    assertEquals(1, objects.size());
    ClientMtTable1 row = (ClientMtTable1) objects.get(0);
    assertEquals(19, list.lastIndexOf(row));
    assertEquals(-1, list.lastIndexOf(list.context.newObject(ClientMtTable1.class)));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 13 with Expression

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

the class ValueInjectorIT method testServer.

@Test
public void testServer() {
    ObjEntity entity = serverContext.getEntityResolver().getObjEntity(MtTable1Subclass1.class);
    Expression qualifier = entity.getDeclaredQualifier();
    try {
        MtTable1Subclass1 ee = serverContext.newObject(MtTable1Subclass1.class);
        assertEquals(ee.getGlobalAttribute1(), "sub1");
        // check AND
        entity.setDeclaredQualifier(qualifier.andExp(ExpressionFactory.exp("serverAttribute1 = 'sa'")));
        ee = serverContext.newObject(MtTable1Subclass1.class);
        assertEquals(ee.getGlobalAttribute1(), "sub1");
        assertEquals(ee.getServerAttribute1(), "sa");
    } finally {
        entity.setDeclaredQualifier(qualifier);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Expression(org.apache.cayenne.exp.Expression) ClientMtTable1Subclass1(org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1) MtTable1Subclass1(org.apache.cayenne.testdo.mt.MtTable1Subclass1) Test(org.junit.Test)

Example 14 with Expression

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

the class DbEntityTab method setQualifier.

void setQualifier(String qualifier) {
    if (qualifier != null && qualifier.trim().length() == 0) {
        qualifier = null;
    }
    DbEntity ent = mediator.getCurrentDbEntity();
    if (ent != null && !Util.nullSafeEquals(ent.getQualifier(), qualifier)) {
        ExpressionConvertor convertor = new ExpressionConvertor();
        try {
            String oldQualifier = convertor.valueAsString(ent.getQualifier());
            if (!Util.nullSafeEquals(oldQualifier, qualifier)) {
                Expression exp = (Expression) convertor.stringAsValue(qualifier);
                ent.setQualifier(exp);
                mediator.fireDbEntityEvent(new EntityEvent(this, ent));
            }
        } catch (IllegalArgumentException ex) {
            // unparsable qualifier
            throw new ValidationException(ex.getMessage());
        }
    }
}
Also used : ValidationException(org.apache.cayenne.validation.ValidationException) DbEntity(org.apache.cayenne.map.DbEntity) Expression(org.apache.cayenne.exp.Expression) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ExpressionConvertor(org.apache.cayenne.modeler.util.ExpressionConvertor)

Example 15 with Expression

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

the class CAY_115IT method testDistinctClobFetchWithToManyJoin.

@Test
public void testDistinctClobFetchWithToManyJoin() throws Exception {
    if (!accessStackAdapter.supportsLobInsertsAsStrings()) {
        return;
    }
    createDistinctClobFetchWithToManyJoin();
    Expression qual = ExpressionFactory.exp("details.name like 'cd%'");
    SelectQuery query = new SelectQuery(ClobMaster.class, qual);
    List<?> result = context.performQuery(query);
    assertEquals(3, result.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) 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