Search in sources :

Example 16 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class LikeExpressionHelperTest method testEscape_AltEscapeChar1.

@Test
public void testEscape_AltEscapeChar1() {
    PatternMatchNode node = new ASTLike(new ASTObjPath("x"), "a!%c");
    LikeExpressionHelper.escape(node);
    assertEquals("a!#%c", node.getOperand(1));
    assertEquals('#', node.getEscapeChar());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ASTLike(org.apache.cayenne.exp.parser.ASTLike) PatternMatchNode(org.apache.cayenne.exp.parser.PatternMatchNode) Test(org.junit.Test)

Example 17 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class PropertyTest method testExpressionConstructor.

@Test
public void testExpressionConstructor() {
    Property<Integer> p = Property.create("testPath", new ASTObjPath("test.path"), Integer.class);
    assertEquals("testPath", p.getName());
    Expression ex = p.getExpression();
    assertEquals("test.path", ex.toString());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) Test(org.junit.Test)

Example 18 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class EOQuery method initBindings.

private void initBindings(Map bindings, Entity entity, Map qualifier) {
    if (qualifier == null) {
        return;
    }
    if ("EOKeyValueQualifier".equals(qualifier.get("class"))) {
        String key = (String) qualifier.get("key");
        if (key == null) {
            return;
        }
        Object value = qualifier.get("value");
        if (!(value instanceof Map)) {
            return;
        }
        Map valueMap = (Map) value;
        if (!"EOQualifierVariable".equals(valueMap.get("class")) || !valueMap.containsKey("_key")) {
            return;
        }
        String name = (String) valueMap.get("_key");
        String className = null;
        // so we will use Object type for all DB path...
        try {
            Object lastObject = new ASTObjPath(key).evaluate(entity);
            if (lastObject instanceof ObjAttribute) {
                className = ((ObjAttribute) lastObject).getType();
            } else if (lastObject instanceof ObjRelationship) {
                ObjEntity target = ((ObjRelationship) lastObject).getTargetEntity();
                if (target != null) {
                    className = target.getClassName();
                }
            }
        } catch (ExpressionException ex) {
            className = "java.lang.Object";
        }
        if (className == null) {
            className = "java.lang.Object";
        }
        bindings.put(name, className);
        return;
    }
    List children = (List) qualifier.get("qualifiers");
    if (children != null) {
        Iterator it = children.iterator();
        while (it.hasNext()) {
            initBindings(bindings, entity, (Map) it.next());
        }
    }
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ExpressionException(org.apache.cayenne.exp.ExpressionException)

Aggregations

ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)18 Test (org.junit.Test)13 ASTLike (org.apache.cayenne.exp.parser.ASTLike)6 PatternMatchNode (org.apache.cayenne.exp.parser.PatternMatchNode)6 Expression (org.apache.cayenne.exp.Expression)5 ArrayList (java.util.ArrayList)4 ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)4 ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)4 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExpressionException (org.apache.cayenne.exp.ExpressionException)1 ExpressionParameter (org.apache.cayenne.exp.ExpressionParameter)1 ASTBitwiseAnd (org.apache.cayenne.exp.parser.ASTBitwiseAnd)1