Search in sources :

Example 11 with QueryCompilerSyntaxException

use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.

the class JDOQLParser method processArray.

/**
 * Method to parse an array expression ("{a,b,c}"), creating an ARRAY node with the node value
 * being a List<Node> of the elements. Also handles processing of subsequent "length" 'method'
 * which is special case for arrays and not caught by processMethod() since it doesn't have "()".
 * @return Whether an array was parsed from the current position
 */
private boolean processArray() {
    if (lexer.parseChar('{')) {
        // Array
        List<Node> elements = new ArrayList();
        while (!lexer.parseChar('}')) {
            processPrimary();
            Node elementNode = stack.pop();
            elements.add(elementNode);
            if (lexer.parseChar('}')) {
                break;
            } else if (!lexer.parseChar(',')) {
                throw new QueryCompilerSyntaxException("',' or '}' expected", lexer.getIndex(), lexer.getInput());
            }
        }
        Node arrayNode = new Node(NodeType.ARRAY, elements);
        stack.push(arrayNode);
        // Check for "length" since won't be picked up by processMethod
        if (lexer.parseString(".length")) {
            Node lengthMethod = new Node(NodeType.INVOKE, "length");
            arrayNode.appendChildNode(lengthMethod);
        }
        return true;
    }
    return false;
}
Also used : QueryCompilerSyntaxException(org.datanucleus.store.query.QueryCompilerSyntaxException) ArrayList(java.util.ArrayList)

Example 12 with QueryCompilerSyntaxException

use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.

the class JDOQLParser method processUnaryExpression.

protected void processUnaryExpression() {
    if (lexer.parseString("++")) {
        throw new QueryCompilerSyntaxException("Unsupported operator '++'");
    } else if (lexer.parseString("--")) {
        throw new QueryCompilerSyntaxException("Unsupported operator '--'");
    }
    if (lexer.parseChar('+')) {
        // Just swallow + and leave remains on the stack
        processUnaryExpression();
    } else if (lexer.parseChar('-')) {
        processUnaryExpression();
        Node expr = new Node(NodeType.OPERATOR, "-");
        expr.insertChildNode(stack.pop());
        stack.push(expr);
    } else if (lexer.parseChar('~')) {
        processUnaryExpression();
        Node expr = new Node(NodeType.OPERATOR, "~");
        expr.insertChildNode(stack.pop());
        stack.push(expr);
    } else if (lexer.parseChar('!')) {
        processUnaryExpression();
        Node expr = new Node(NodeType.OPERATOR, "!");
        expr.insertChildNode(stack.pop());
        stack.push(expr);
    } else {
        processPrimary();
    }
}
Also used : QueryCompilerSyntaxException(org.datanucleus.store.query.QueryCompilerSyntaxException)

Example 13 with QueryCompilerSyntaxException

use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.

the class JDOQLParser method parseParameters.

/* (non-Javadoc)
     * @see org.datanucleus.query.compiler.Parser#parseParameters(java.lang.String)
     */
public Node[][] parseParameters(String expression) {
    List nodes = new ArrayList();
    StringTokenizer tokeniser = new StringTokenizer(expression, ",");
    while (tokeniser.hasMoreTokens()) {
        String token = tokeniser.nextToken();
        StringTokenizer subTokeniser = new StringTokenizer(token, " ");
        if (subTokeniser.countTokens() != 2) {
            throw new QueryCompilerSyntaxException(Localiser.msg("021101", expression));
        }
        String classDecl = subTokeniser.nextToken();
        String parameterName = subTokeniser.nextToken();
        Node declNode = new Node(NodeType.IDENTIFIER, classDecl);
        Node nameNode = new Node(NodeType.IDENTIFIER, parameterName);
        nodes.add(new Node[] { declNode, nameNode });
    }
    return (Node[][]) nodes.toArray(new Node[nodes.size()][2]);
}
Also used : StringTokenizer(java.util.StringTokenizer) QueryCompilerSyntaxException(org.datanucleus.store.query.QueryCompilerSyntaxException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with QueryCompilerSyntaxException

use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.

the class JDOQLParser method processCreator.

/**
 * Method to parse "new a.b.c(param1[,param2], ...)" and create a Node of type CREATOR.
 * The Node at the top of the stack after this call will have any arguments defined in its "properties".
 * @return whether method syntax was found.
 */
private boolean processCreator() {
    if (lexer.parseString("new ")) {
        int size = stack.size();
        if (!processMethod()) {
            if (!processIdentifier()) {
                throw new QueryCompilerSyntaxException("Identifier expected", lexer.getIndex(), lexer.getInput());
            }
            while (lexer.parseChar('.')) {
                if (processMethod()) {
                // "a.method(...)"
                } else if (processIdentifier()) {
                // "a.field"
                } else {
                    throw new QueryCompilerSyntaxException("Identifier expected", lexer.getIndex(), lexer.getInput());
                }
            }
        }
        while (stack.size() - 1 > size) {
            Node top = stack.pop();
            Node peek = stack.peek();
            peek.insertChildNode(top);
        }
        Node expr = stack.pop();
        Node newExpr = new Node(NodeType.CREATOR);
        newExpr.insertChildNode(expr);
        stack.push(newExpr);
        return true;
    }
    return false;
}
Also used : QueryCompilerSyntaxException(org.datanucleus.store.query.QueryCompilerSyntaxException)

Example 15 with QueryCompilerSyntaxException

use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.

the class JPQLParser method parseParameters.

/* (non-Javadoc)
     * @see org.datanucleus.query.compiler.Parser#parseParameters(java.lang.String)
     */
public Node[][] parseParameters(String expression) {
    lexer = new Lexer(expression, paramPrefixes, false);
    List nodes = new ArrayList();
    do {
        processPrimary();
        if (stack.isEmpty()) {
            throw new QueryCompilerSyntaxException("expected identifier", lexer.getIndex(), lexer.getInput());
        }
        if (!processIdentifier()) {
            throw new QueryCompilerSyntaxException("expected identifier", lexer.getIndex(), lexer.getInput());
        }
        Node nodeVariable = stack.pop();
        Node nodeType = stack.pop();
        nodes.add(new Node[] { nodeType, nodeVariable });
    } while (lexer.parseString(","));
    return (Node[][]) nodes.toArray(new Node[nodes.size()][2]);
}
Also used : QueryCompilerSyntaxException(org.datanucleus.store.query.QueryCompilerSyntaxException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

QueryCompilerSyntaxException (org.datanucleus.store.query.QueryCompilerSyntaxException)20 ArrayList (java.util.ArrayList)7 List (java.util.List)5 HashMap (java.util.HashMap)3 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)3 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)3 Map (java.util.Map)2 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)2 Symbol (org.datanucleus.query.compiler.Symbol)2 Expression (org.datanucleus.query.expression.Expression)2 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)2 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)2 VariableExpression (org.datanucleus.query.expression.VariableExpression)2 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)2 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 StringTokenizer (java.util.StringTokenizer)1 FetchPlanForClass (org.datanucleus.FetchPlanForClass)1 NucleusException (org.datanucleus.exceptions.NucleusException)1