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());
}
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)));
}
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);
}
}
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());
}
}
}
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());
}
Aggregations