use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class DataMapUtils method getParameterNames.
private Map<String, String> getParameterNames(Expression expression, Object root) {
if (expression != null) {
Map<String, String> types = new HashMap<>();
String typeName = "";
List<String> names = new LinkedList<>();
for (int i = 0; i < expression.getOperandCount(); i++) {
Object operand = expression.getOperand(i);
if (operand instanceof Expression) {
types.putAll(getParameterNames((Expression) operand, root));
}
if (operand instanceof ASTObjPath) {
PathComponent<ObjAttribute, ObjRelationship> component = ((Entity) root).lastPathComponent((ASTObjPath) operand, null);
ObjAttribute attribute = component.getAttribute();
if (attribute != null) {
typeName = attribute.getType();
} else {
ObjRelationship relationship = component.getRelationship();
if (relationship != null) {
typeName = relationship.getTargetEntity().getClassName();
} else {
typeName = "Object";
}
}
}
if (operand instanceof ASTList) {
Object[] values = (Object[]) ((ASTList) operand).getOperand(0);
for (Object value : values) {
if (value instanceof ExpressionParameter) {
names.add(((ExpressionParameter) value).getName());
}
}
}
if (operand instanceof ExpressionParameter) {
names.add(((ExpressionParameter) operand).getName());
}
}
for (String name : names) {
types.put(Util.underscoredToJava(name, false), typeName);
}
return types;
}
return Collections.emptyMap();
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class SelectQueryReturnTypesIT method testSelectBitwiseXor.
@Test
public void testSelectBitwiseXor() throws Exception {
if (!accessStackAdapter.supportsBitwiseOps()) {
return;
}
createNumericsDataSet();
// to simplify result checking, do double NOT
Expression left = new ASTBitwiseXor(new Object[] { new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName()), new ASTScalar(1) });
Expression right = new ASTScalar(5);
Expression equal = new ASTEqual();
equal.setOperand(0, left);
equal.setOperand(1, right);
SelectQuery query = new SelectQuery(ReturnTypesMap1.class);
query.setQualifier(equal);
List<ReturnTypesMap1> objects = context.performQuery(query);
assertEquals(1, objects.size());
assertEquals(4, objects.get(0).getIntegerColumn().intValue());
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class LikeExpressionHelperTest method testEscape_TwoChars_Mix.
@Test
public void testEscape_TwoChars_Mix() {
PatternMatchNode node = new ASTLike(new ASTObjPath("x"), "ab%c_");
LikeExpressionHelper.escape(node);
assertEquals("ab!%c!_", node.getOperand(1));
assertEquals('!', node.getEscapeChar());
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class LikeExpressionHelperTest method testEscape_AltEscapeChar2.
@Test
public void testEscape_AltEscapeChar2() {
PatternMatchNode node = new ASTLike(new ASTObjPath("x"), "a!%c#_");
LikeExpressionHelper.escape(node);
assertEquals("a!$%c#$_", node.getOperand(1));
assertEquals('$', node.getEscapeChar());
}
use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.
the class PropertyTest method testCreationWithName.
@Test
public void testCreationWithName() {
Property<String> p1 = new Property<>("p1", String.class);
assertEquals(String.class, p1.getType());
assertEquals("p1", p1.getName());
assertEquals(new ASTObjPath("p1"), p1.getExpression());
Property<String> p2 = Property.create("p1", String.class);
assertEquals(p1, p2);
}
Aggregations