Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.QueryException


                throw new DTXException("Missing WHERE clause");
            }
            addField(_clsMapping, token, expr);
            while (token.hasMoreTokens()) {
                if (!token.nextToken().equals("AND")) {
                throw new QueryException("Only AND supported in WHERE clause");
                }
                addField(_clsMapping, token, expr);
            }
            }
View Full Code Here


        ClassMolder molder = null;
        for (int i = 0; i < _engines.length; i++) {           
            molder = _engines[i].getClassMolderByQuery(query);           
        }
        if (molder == null) {
            throw new QueryException("Cannot find a named query with the name " + query);
        }
        return molder;
    }
View Full Code Here

                    Persistence persistenceEngine;
                    try {
                        persistenceEngine = _factory.getPersistence(classDescriptor);
                    } catch (MappingException e) {
                        throw new QueryException(
                                "Problem obtaining persistence engine for ClassDescriptor "
                                + classDescriptor.getJavaClass().getName(), e);
                    }

                    SQLEngine engine = (SQLEngine) persistenceEngine;
View Full Code Here

        Parser parser = new Parser(lexer);
        ParseTreeNode parseTree = parser.getParseTree();

        _dbEngine = ((AbstractDatabaseImpl) _database).getLockEngine();
        if (_dbEngine == null) {
            throw new QueryException("Could not get a persistence engine");
        }

        TransactionContext trans = ((AbstractDatabaseImpl) _database).getTransaction();
        DbMetaInfo dbInfo = trans.getConnectionInfo(_dbEngine);
View Full Code Here

        ParamInfo info;
        StringBuffer sb;
        Integer paramNo;

        if (!oql.startsWith("CALL ")) {
            throw new QueryException("Stored procedure call must start with CALL");
        }

        // Fix for bug #995
        // as = oql.indexOf( " AS " );
        as = oql.lastIndexOf(" AS ");
        if (as < 0) {
            throw new QueryException("Stored procedure call must end with \"AS <class-name>\"");
        }
        leftParen = oql.indexOf("(");
        rightParen = oql.indexOf(")");
        sql = new StringBuffer();
        paramCnt = 0;
        _paramInfo = new Hashtable();
        if (oql.startsWith("CALL SQL")) {
            int startOff = oql.toUpperCase().indexOf("WHERE "); // parameters begin here!

            if (!(startOff < 0)) {
                startOff += 6;
                sql.append(oql.substring(5, startOff));

                int i = startOff;
                while (i < as) {
                    if (oql.charAt(i) == '$') {
                        // get parameter number if given
                        sb = new StringBuffer();
                        for (int j = i + 1; j < as; j++) {
                            char c = oql.charAt(j);
                            if (!Character.isDigit(c)) {
                                break;
                            }
                            sb.append(c);
                        }
                        sql.append('?'); // replace "$" with "?"
                        if (sb.length() > 0) {
                            sql.append(sb); // and add parameter number to it
                            paramNo = Integer.valueOf(sb.toString());
                        } else {
                            paramNo = new Integer(paramCnt + 1);
                        }
                        info = (ParamInfo) _paramInfo.get(paramNo);
                        if (info == null) {
                            info = new ParamInfo("", "java.lang.Object", null,
                                    _database.getClassLoader());
                        }
                        //info.mapToSQLParam( paramCnt + 1 );
                        _paramInfo.put(paramNo , info);
                        paramCnt++;

                        i += sb.length() + 1;
                    } else {
                        sql.append(oql.charAt(i));
                        i++;
                    }
                }
            } else {
                sql.append(oql.substring(5, as));
            }
        } else if ((leftParen < 0) && (rightParen < 0)) {
            sql.append(oql.substring(5, as));
        } else {
            if (((leftParen < 0) && (rightParen >= 0))
                    || (leftParen > rightParen)) {
                throw new QueryException("Syntax error: parenthesis");
            }
            sql.append(oql.substring(5, leftParen));
            sql.append('(');
            for (int i = leftParen + 1; i < rightParen; i++) {
                if (oql.charAt(i) == '$') {
                    // get parameter number if given
                    sb = new StringBuffer();
                    for (int j = i + 1; j < rightParen; j++) {
                        char c = oql.charAt(j);
                        if (!Character.isDigit(c)) {
                            break;
                        }
                        sb.append(c);
                    }
                    if (sb.length() > 0) {
                        paramNo = Integer.valueOf(sb.toString());
                    } else {
                        paramNo = new Integer(paramCnt + 1);
                    }
                    info = (ParamInfo) _paramInfo.get(paramNo);
                    if (info == null) {
                        info = new ParamInfo("", "java.lang.Object", null,
                                _database.getClassLoader());
                    }
                    //info.mapToSQLParam( paramCnt + 1 );
                    _paramInfo.put(paramNo , info);
                    paramCnt++;
                }
            }
            for (int i = 0; i < paramCnt; i++) {
                sql.append('?');
                if (i < paramCnt - 1) {
                    sql.append(',');
                }
            }
            sql.append(')');
        }
        _spCall = sql.toString();
        _projectionType = ParseTreeWalker.PARENT_OBJECT;
        _bindTypes = new Class[ paramCnt ];
        for (int i = 0; i < paramCnt; i++) {
            _bindTypes[i] = Object.class;
        }

        objType = oql.substring(as + 4).trim();
        if (objType.length() == 0) {
            throw new QueryException("Missing object name");
        }
        try {
            _objClass = ClassLoadingUtils.loadClass(_database.getClassLoader(), objType);
        } catch (ClassNotFoundException except) {
            throw new QueryException("Could not find class " + objType);
        }
        _dbEngine = ((AbstractDatabaseImpl) _database).getLockEngine();
        if ((_dbEngine == null) || (_dbEngine.getPersistence(_objClass) == null)) {
            throw new QueryException("Could not find an engine supporting class " + objType);
        }
    }
View Full Code Here

                            for (int i = 0; i < _bindValues.length; ++i) {
                                _query.setParameter(i, _bindValues[i]);
                            }
                        }
                    } catch (QueryException except) {
                        throw new QueryException(except.getMessage());
                    }
                    results = ((AbstractDatabaseImpl) _database).getTransaction().query(
                            _dbEngine, _query, accessMode, scrollable);
                    _fieldNum = 0;

                    if (_projectionType == ParseTreeWalker.PARENT_OBJECT) {
                        _results = new OQLEnumeration(results);
                    } else {
                        _results = new OQLEnumeration(results, _projectionInfo, _clsDesc);
                    }
                    break;

                case ParseTreeWalker.DEPENDANT_VALUE:
                case ParseTreeWalker.AGGREGATE:
                case ParseTreeWalker.FUNCTION:
                    try {
                        TransactionContext tx = ((AbstractDatabaseImpl) _database).getTransaction();
                        java.sql.Connection conn = tx.getConnection(_dbEngine);
                        SimpleQueryExecutor sqe = new SimpleQueryExecutor(_database);
                        _results =  sqe.execute(conn, _expr, _bindValues);
                    } catch (QueryException except) {
                        throw new QueryException(Messages.message(
                                "persist.simple.query.failed"), except);
                    }
                    _fieldNum = 0;
                    break;
                default:
View Full Code Here

            }
                   
            _rset = null;
            _stmt = null;
           
            throw new QueryException(s.toString());
        }
    }
View Full Code Here

    Class userClass = null;
    Class systemClass = null;
    try {
        systemClass = ClassLoadingUtils.loadClass (_classLoader, systemType);
    } catch (Exception e) {
      throw new QueryException("Error: Could not find system defined class: " + systemType);
    }

    if (!userDefinedType.equals("")) {
      try {
        userClass = Types.typeFromName(getClass().getClassLoader(), userDefinedType);

        if (userClass.isPrimitive()) {
            userClass = Types.typeFromPrimitive(userClass);
        }
      } catch (Exception e) {
        throw new QueryException("The class " + userClass + " could not be found.");
      }

      if (!systemClass.isAssignableFrom(userClass)) {
        if (!(java.lang.Number.class.isAssignableFrom(userClass)
                && java.lang.Number.class.isAssignableFrom(systemClass))) {
            throw new QueryException("The class " + userClass
                    + " is incompatible with the system defined class " + systemType);
        }
      }

      _class = userClass;
    } else {
      _class = systemClass;
    }
    if (desc != null) {
        _fieldType = desc.getFieldType();
        try {
            _sqlType = SQLTypeInfos.sqlTypeNum2javaType(
                    new FieldDescriptorJDONature(desc).getSQLType()[0]);
        } catch (Exception ex) {
            throw new QueryException("Can't determine SQL class: " + ex);
        }
        _convertor = new FieldDescriptorJDONature(desc).getConvertor();
    }
  }
View Full Code Here

   *    one prevuiously specified in the constructor, or if the systemType is
   *    not convertable to the original systemType.
   */
  public void check(final String userDefinedType, final String systemType) throws QueryException {
    if (!_userDefinedType.equals(userDefinedType)) {
        throw new QueryException("Different types were specified for the same numbered parameter.");
    }

    if (!systemType.equals(_systemType)) {
      Class systemClass = null;
      try {
          systemClass = ClassLoadingUtils.loadClass (_classLoader, systemType);
      } catch (Exception e) {
        throw new QueryException("Error: Could notfind system defined class: " + systemType);
      }

      if (!userDefinedType.equals("")) {
        Class userClass = null;
        try {
            userClass = ClassLoadingUtils.loadClass(_classLoader, _userDefinedType);
        } catch (Exception e) {
          throw new QueryException("The class " + userClass + " could not be found.");
        }

        if (!systemClass.isAssignableFrom(userClass)) {
            throw new QueryException("The class " + userDefinedType
                    + " is incompatible with the system defined class " + systemType);
        }
      }
    }
  }
View Full Code Here

        _parseTree = parseTree;
        _classLoader = classLoader;
        _dbInfo = dbInfo;

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

        checkErrors();
        createQueryExpression();
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.