Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.QueryException


                _objClass = Class.forName(_fromClassName);
            } else {
                _objClass = _classLoader.loadClass(_fromClassName);
            }
        } catch (ClassNotFoundException except) {
            throw new QueryException("Could not find class " + _fromClassName, except);
        }
        _engine = (SQLEngine) _dbEngine.getPersistence(_objClass);
        if (_engine == null) {
            throw new QueryException(
                    "Could not find mapping for class " + _fromClassName);
        }
        _clsDesc = _engine.getDescriptor();
        // This should never happen
        if (_clsDesc == null) {
            throw new QueryException(
                    "Could not get a descriptor for class " + _fromClassName);
        }
    }
View Full Code Here


        if (projection.getChildCount() == 0) {
            if (topLevel) {
                _projectionType = PARENT_OBJECT;
                _projectionName = projection.getToken().getTokenValue();
                if (!_projectionName.equals(_fromClassAlias)) {
                    throw new QueryException("Object name not the same in SELECT and "
                            + "FROM - select: " + _projectionName + ", from: "
                            + _fromClassAlias);
                }
            } else {
                if (onlySimple) {
                    throw new QueryException("Only primitive values are allowed to be "
                            + "passed as parameters to Aggregate and SQL functions.");
                }
                return null;
            }
        } else {
            int tokenType = projection.getToken().getTokenType();
            switch (tokenType) {
            case TokenType.IDENTIFIER:
                //a SQL function call -- check the arguments
                _projectionType = FUNCTION;
                for (Iterator iter = projection.getChild(0).children(); iter.hasNext(); ) {
                    checkProjection((ParseTreeNode) iter.next(), false, true);
                }
                break;
            case TokenType.DOT:
                //a path expression -- check if it is valid, and create a paramInfo
                Iterator iter = projection.children();
                ParseTreeNode curNode = null;
                String curName = null;
                StringBuffer projectionName = new StringBuffer();
                Vector projectionInfo = new Vector();

                //check that the first word before the dot is our class
                if (iter.hasNext()) {
                    curNode = (ParseTreeNode) iter.next();
                    curName = curNode.getToken().getTokenValue();
                    if ((!curName.equals(_projectionName))
                            && (!curName.equals(_projectionAlias))
                            && (!curName.equals(_fromClassName))
                            && (!curName.equals(_fromClassAlias))) {
                       
                        // reset the enumeration
                        iter = projection.children();
                        curName = _fromClassAlias;
                    }
                    projectionName.append(curName);
                    projectionInfo.addElement(curName);
                }

                //use the ClassDescriptor to check that the rest of the path is valid.
                ClassDescriptor curClassDesc = _clsDesc;
                FieldDescriptor curField = null;
                int count = 0;
                String curToken;
                while (iter.hasNext()) {
                    // there may be nested attribute name
                    curField = null;
                    curName = null;
                    while ((curField == null) && iter.hasNext()) {
                        curNode = (ParseTreeNode) iter.next();
                        curToken = curNode.getToken().getTokenValue();
                        if (curName == null) {
                            curName = curToken;
                        } else {
                            curName = curName + "." + curToken;
                        }
                        curField = getFieldDesc(curName, curClassDesc);
                    }
                    if (curField == null) {
                        throw new QueryException("An unknown field was requested: "
                                + curName + " (" + curClassDesc + ")");
                    }
                    projectionName.append(".").append(curName);
                    projectionInfo.addElement(curName);
                    curClassDesc = curField.getClassDescriptor();
                    if ((curClassDesc == null) && iter.hasNext()) {
                        throw new QueryException("An non-reference field was requested: "
                                + curName + " (" + curClassDesc + ")");
                    }
                    count++;
                }
                field = curField;

                getPathInfo().put(projection, projectionInfo);
                getFieldInfo().put(projection, curField);

                Class theClass = curField.getFieldType();
                // is it actually a Java primitive, or String, or a subclass of Number
                boolean isSimple = Types.isSimpleType(theClass);

                if (topLevel) {
                    _projectionName = projectionName.toString();
                    if (!isSimple) {
                        _projectionType = DEPENDANT_OBJECT;
                    } else if (count > 1) {
                        _projectionType = DEPENDANT_OBJECT_VALUE;
                    } else if (field.getContainingClassDescriptor() != _clsDesc) {
                        _projectionType = DEPENDANT_OBJECT_VALUE;
                    } else {
                        _projectionType = DEPENDANT_VALUE;
                    }
                } else {
                    if (!isSimple && onlySimple) {
                        throw new QueryException("Only primitive values are allowed "
                                + "to be passed as parameters to Aggregate and SQL "
                                + "functions.");
                    }
                }
                break;
View Full Code Here

            if (field != null) {
                getFieldInfo().put(fieldTree, field);
            }
        }
        if (field == null) {
            throw new QueryException("The field " + fieldTree.getToken().getTokenValue()
                    + " was not found.");
        }
        return field;
    }
View Full Code Here

            default:
                break;
            }
        }

        throw new QueryException("Could not get type for comparison.");
    }
View Full Code Here

                if (curChild.getChildCount() == 2) {
                    String udt = curChild.getChild(0).getToken().getTokenValue();
                    try {
                        return Types.typeFromName(_classLoader, udt).getName();
                    } catch (ClassNotFoundException e1) {
                        throw new QueryException("Could not find class " + udt);
                    }
                }
            default:
                break;
            }
View Full Code Here

     *         contains non literals.
     */
    private void checkInClauseRightSide(final ParseTreeNode theList)
    throws QueryException {
        if (theList.getToken().getTokenType() != TokenType.KEYWORD_LIST) {
            throw new QueryException("The right side of the IN operator must be a LIST.");
        }

        for (Iterator iter = theList.children(); iter.hasNext(); ) {
            ParseTreeNode node = (ParseTreeNode) iter.next();
            int tokenType = node.getToken().getTokenType();

            switch (tokenType) {
            case TokenType.KEYWORD_NIL: case TokenType.KEYWORD_UNDEFINED:
            case TokenType.BOOLEAN_LITERAL: case TokenType.LONG_LITERAL:
            case TokenType.DOUBLE_LITERAL: case TokenType.CHAR_LITERAL:
            case TokenType.STRING_LITERAL: case TokenType.DATE_LITERAL:
            case TokenType.TIME_LITERAL: case TokenType.TIMESTAMP_LITERAL:
                break;
            case TokenType.DOLLAR:    // bind variable parameter
                checkParameter(node);
                break;
            default:
                throw new QueryException("The LIST can only contain literals, bind "
                        + "variables and the keywords 'nil' and 'undefined'.");
            }
        }
    }
View Full Code Here

     * @throws QueryException if an error is detected.
     */
    private void checkOrderClause(final ParseTreeNode orderClause)
    throws QueryException {
        if (orderClause.getToken().getTokenType() != TokenType.KEYWORD_ORDER) {
            throw new QueryException("checkOrderClause was called on a subtree which "
                    + "is not an order clause.");
        }

        ParseTreeNode prevChild = null;
        for (Iterator iter = orderClause.children(); iter.hasNext(); ) {
            ParseTreeNode curChild = (ParseTreeNode) iter.next();

            int tokenType = curChild.getToken().getTokenType();
            switch (tokenType) {
            case TokenType.KEYWORD_ASC:
            case TokenType.KEYWORD_DESC:
                // iterate on child
                curChild = curChild.getChild(0);
                tokenType = curChild.getToken().getTokenType();
                break;
            default:
                break;
            }
           
            switch (tokenType) {
            case TokenType.DOT:
                checkProjection(curChild, false, false);
                break;
            case TokenType.IDENTIFIER:
                if (curChild.children().hasNext()) {
                    int type = curChild.getChild(0).getToken().getTokenType();
                    if (type == TokenType.LPAREN) {
                        // A function, skip to next element
                        Iterator arguments = curChild.getChild(0).children();
                        while (arguments.hasNext()) {
                            ParseTreeNode nn = (ParseTreeNode) arguments.next();
                            checkWhereClause(nn);
                        }
                    }
                } else {
                    checkField(curChild);
                }
                break;
            case TokenType.LPAREN:
                int type = prevChild.getToken().getTokenType();
                if ((prevChild == null) || (type != TokenType.IDENTIFIER)) {
                    throw new QueryException("Illegal use of left parenthesis in "
                            + "ORDER BY clause.");
                }
                break;
            default:
                throw new QueryException("Only identifiers, path expressions, and the "
                        + "keywords ASC and DESC are allowed in the ORDER BY clause.");
            }
            prevChild = curChild;
        }
    }
View Full Code Here

     *      java.lang.String)
     */
    public String getNamedQuery(final ClassMolder molder, final String name)
    throws QueryException    {
        if (molder == null) {
            throw new QueryException("Invalid argument - molder is null");
        }
        return molder.getNamedQuery(name);
    }
View Full Code Here

        try { _stmt.close(); } catch (SQLException e) {}
       
      _rset = null;
      _stmt = null;
     
      throw new QueryException( s.toString() );
    }
  }
View Full Code Here

    _pathInfo = new Hashtable();

    _allPaths = new Hashtable();

    if ( ! _parseTree.isRoot() )
      throw (new QueryException( "ParseTreeWalker must be created with the root node of the parse tree."));

    //_log.debug (ParseTest.treeToString(_parseTree, ParseTest.NODE_TYPES));
    //_log.debug (ParseTest.treeToString(_parseTree, ParseTest.NODE_VALUES));

View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.QueryException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.