Search in sources :

Example 1 with ExpressionParameter

use of org.apache.cayenne.exp.ExpressionParameter 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();
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Expression(org.apache.cayenne.exp.Expression) ExpressionParameter(org.apache.cayenne.exp.ExpressionParameter) ASTList(org.apache.cayenne.exp.parser.ASTList)

Example 2 with ExpressionParameter

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

the class ASTNamedParameter method setValue.

@Override
public void setValue(Object value) {
    if (value == null) {
        throw new ExpressionException("Null Parameter value");
    }
    String name = value.toString().trim();
    if (name.length() == 0) {
        throw new ExpressionException("Empty Parameter value");
    }
    super.setValue(new ExpressionParameter(name));
}
Also used : ExpressionParameter(org.apache.cayenne.exp.ExpressionParameter) ExpressionException(org.apache.cayenne.exp.ExpressionException)

Aggregations

ExpressionParameter (org.apache.cayenne.exp.ExpressionParameter)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Expression (org.apache.cayenne.exp.Expression)1 ExpressionException (org.apache.cayenne.exp.ExpressionException)1 ASTList (org.apache.cayenne.exp.parser.ASTList)1 ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)1 Entity (org.apache.cayenne.map.Entity)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1