use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class ObjEntityIT method testLastPathComponent.
@Test
public void testLastPathComponent() {
ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
Map<String, String> aliases = new HashMap<>();
aliases.put("a", "paintingArray.toGallery");
PathComponent<ObjAttribute, ObjRelationship> lastAttribute = artistE.lastPathComponent(ExpressionFactory.exp("paintingArray.paintingTitle"), aliases);
assertTrue(lastAttribute.getAttribute() != null);
assertEquals("paintingTitle", lastAttribute.getAttribute().getName());
PathComponent<ObjAttribute, ObjRelationship> lastRelationship = artistE.lastPathComponent(ExpressionFactory.exp("paintingArray.toGallery"), aliases);
assertTrue(lastRelationship.getRelationship() != null);
assertEquals("toGallery", lastRelationship.getRelationship().getName());
PathComponent<ObjAttribute, ObjRelationship> lastLeftJoinRelationship = artistE.lastPathComponent(new ASTObjPath("paintingArray+.toGallery+"), aliases);
assertTrue(lastLeftJoinRelationship.getRelationship() != null);
assertEquals("toGallery", lastLeftJoinRelationship.getRelationship().getName());
PathComponent<ObjAttribute, ObjRelationship> lastAliasedRelationship = artistE.lastPathComponent(new ASTObjPath("a"), aliases);
assertTrue(lastAliasedRelationship.getRelationship() != null);
assertEquals("toGallery", lastAliasedRelationship.getRelationship().getName());
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class ExpressionFactory method matchAnyExp.
/**
* Creates an expression that matches any of the key-values pairs in the
* <code>map</code>.
* <p>
* For each pair <code>pairType</code> operator is used to build a binary
* expression. Key is considered to be a OBJ_PATH expression. OR is used to
* join pair binary expressions.
*/
public static Expression matchAnyExp(Map<String, ?> map, int pairType) {
List<Expression> pairs = new ArrayList<>(map.size());
for (Map.Entry<String, ?> entry : map.entrySet()) {
Expression exp = expressionOfType(pairType);
exp.setOperand(0, new ASTObjPath(entry.getKey()));
exp.setOperand(1, wrapPathOperand(entry.getValue()));
pairs.add(exp);
}
return joinExp(Expression.OR, pairs);
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class ExpressionFactory method matchAllExp.
/**
* @since 3.0
*/
public static Expression matchAllExp(String path, Object... values) {
if (values == null) {
throw new NullPointerException("Null values collection");
}
if (values.length == 0) {
return new ASTTrue();
}
int split = path.indexOf(SPLIT_SEPARATOR);
List<Expression> matches = new ArrayList<>(values.length);
if (split >= 0 && split < path.length() - 1) {
int splitEnd = path.indexOf(Entity.PATH_SEPARATOR, split + 1);
String beforeSplit = split > 0 ? path.substring(0, split) + "." : "";
String afterSplit = splitEnd > 0 ? "." + path.substring(splitEnd + 1) : "";
String aliasBase = "split" + autoAliasId++ + "_";
String splitChunk = splitEnd > 0 ? path.substring(split + 1, splitEnd) : path.substring(split + 1);
// fix the path - replace split with dot if it's in the middle, or
// strip it if
// it's in the beginning
path = split == 0 ? path.substring(1) : path.replace(SPLIT_SEPARATOR, '.');
int i = 0;
for (Object value : values) {
String alias = aliasBase + i;
String aliasedPath = beforeSplit + alias + afterSplit;
i++;
ASTPath pathExp = new ASTObjPath(aliasedPath);
pathExp.setPathAliases(Collections.singletonMap(alias, splitChunk));
matches.add(new ASTEqual(pathExp, value));
}
} else {
for (Object value : values) {
matches.add(new ASTEqual(new ASTObjPath(path), value));
}
}
return joinExp(Expression.AND, matches);
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class ExpressionFactory method matchAllExp.
/**
* Creates an expression that matches all key-values pairs in
* <code>map</code>.
* <p>
* For each pair <code>pairType</code> operator is used to build a binary
* expression. Key is considered to be a OBJ_PATH expression. AND is used to
* join pair binary expressions.
*/
public static Expression matchAllExp(Map<String, ?> map, int pairType) {
List<Expression> pairs = new ArrayList<>(map.size());
for (Map.Entry<String, ?> entry : map.entrySet()) {
Expression exp = expressionOfType(pairType);
exp.setOperand(0, new ASTObjPath(entry.getKey()));
exp.setOperand(1, wrapPathOperand(entry.getValue()));
pairs.add(exp);
}
return joinExp(Expression.AND, pairs);
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class SelectQueryReturnTypesIT method testSelectBitwiseNot.
@Test
public void testSelectBitwiseNot() throws Exception {
if (!accessStackAdapter.supportsBitwiseOps()) {
return;
}
createNumericsDataSet();
// to simplify result checking, do double NOT
Expression left = new ASTBitwiseNot(new ASTBitwiseNot(new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName())));
Expression right = new ASTScalar(2);
Expression greater = new ASTGreater();
greater.setOperand(0, left);
greater.setOperand(1, right);
SelectQuery query = new SelectQuery(ReturnTypesMap1.class);
query.setQualifier(greater);
List<ReturnTypesMap1> objects = context.performQuery(query);
assertEquals(2, objects.size());
}
Aggregations