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 );
    }
    _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." );
        else
          return null;
    }
    else {
      int tokenType = projection.getToken().getTokenType();
      switch( tokenType ) {
        case IDENTIFIER:
          //a SQL function call -- check the arguments
          _projectionType = FUNCTION;
          for (Enumeration e = projection.getChild(0).children();
               e.hasMoreElements(); )
            checkProjection( (ParseTreeNode) e.nextElement(), false, true );
          break;

        case DOT:
          //a path expression -- check if it is valid, and create a paramInfo
          Enumeration e = 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 ( e.hasMoreElements() ) {
            curNode = (ParseTreeNode) e.nextElement();
            curName = curNode.getToken().getTokenValue();
            if ( ( ! curName.equals(_projectionName) ) &&
                 ( ! curName.equals(_projectionAlias) ) &&
                 ( ! curName.equals(_fromClassName) ) &&
                 ( ! curName.equals(_fromClassAlias) ) ) {
              // reset the enumeration
              e = projection.children();
              curName = _fromClassAlias;
            }
            projectionName.append(curName);
            projectionInfo.addElement(curName);
          }

          //use the ClassDescriptor to check that the rest of the path is valid.
          JDOClassDescriptor curClassDesc = _clsDesc;
          JDOFieldDescriptor curField = null;
          int count = 0;
          String curToken;
          while ( e.hasMoreElements() ) {
            // there may be nested attribute name
            curField = null;
            curName = null;
            while ( curField == null && e.hasMoreElements() ) {
              curNode = (ParseTreeNode) e.nextElement();
              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 = (JDOClassDescriptor) curField.getClassDescriptor();
            if ( curClassDesc == null && e.hasMoreElements() )
                throw new QueryException( "An non-reference field was requested: " + curName + " (" + curClassDesc + ")" );
            count++;
          }
          field = curField;

          _pathInfo.put( projection, projectionInfo );
          _fieldInfo.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 )
              if ( count > 1 || field.getContainingClassDescriptor() != _clsDesc)
                _projectionType = DEPENDANT_OBJECT_VALUE;
              else
                _projectionType = DEPENDANT_VALUE;
            else
              _projectionType = DEPENDANT_OBJECT;
          }
          else
            if ( ! isSimple && onlySimple )
              throw new QueryException( "Only primitive values are allowed to be passed as parameters to Aggregate and SQL functions." );
          break;

        case KEYWORD_COUNT:
          //count a special case
          _projectionType = AGGREGATE;
View Full Code Here

        field = getFieldDesc( fieldTree.getToken().getTokenValue(), _clsDesc );
        if (field != null)
            _fieldInfo.put(fieldTree, field);
    }
    if (field == null)
        throw new QueryException( "The field " + fieldTree.getToken().getTokenValue() + " was not found." );
    return field;

  }
View Full Code Here

        JDOFieldDescriptor field = checkField(curChild);
        return field.getFieldType().getName();
      }
    }

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

   */
  private void checkInClauseRightSide(ParseTreeNode theList)
        throws QueryException {

    if ( theList.getToken().getTokenType() != KEYWORD_LIST )
      throw new QueryException( "The right side of the IN operator must be a LIST." );

    for ( Enumeration e = theList.children(); e.hasMoreElements(); ) {
      switch (( (ParseTreeNode) e.nextElement() ).getToken().getTokenType()) {
        case KEYWORD_NIL: case KEYWORD_UNDEFINED:
        case BOOLEAN_LITERAL: case LONG_LITERAL:
        case DOUBLE_LITERAL: case CHAR_LITERAL:
        case STRING_LITERAL: case DATE_LITERAL:
        case TIME_LITERAL: case TIMESTAMP_LITERAL:
          break;
        default:
          throw new QueryException( "The LIST can only contain literals and Keywords nil and undefined." );
      }
    }

  }
View Full Code Here

   */
  private void checkOrderClause(ParseTreeNode orderClause)
        throws QueryException {

    if ( orderClause.getToken().getTokenType() != KEYWORD_ORDER )
      throw new QueryException( "checkOrderClause was called on a subtree which is not an order clause.");

    ParseTreeNode prevChild = null;
    for (Enumeration e = orderClause.children(); e.hasMoreElements(); ) {
      ParseTreeNode curChild = (ParseTreeNode) e.nextElement();

      int tokenType = curChild.getToken().getTokenType();
      switch (tokenType) {
      case KEYWORD_ASC:
      case KEYWORD_DESC:
          // iterate on child
          curChild = curChild.getChild(0);
          tokenType = curChild.getToken().getTokenType();
      }
      switch (tokenType) {
      case DOT:
          checkProjection( curChild, false, false );
          break;
      case IDENTIFIER:
          if ( curChild.children().hasMoreElements() ) {
              if ( curChild.getChild(0).getToken().getTokenType() == LPAREN ) {
                  // A function, skip to next element
                  Enumeration arguments = curChild.getChild(0).children();
                  while(arguments.hasMoreElements()) {
                      ParseTreeNode nn = (ParseTreeNode)arguments.nextElement();
                      checkWhereClause(nn);
                  }
              }
          } else {
                checkField(curChild);
          }
          break;
      case LPAREN:
          if ( ( prevChild == null ) || ( prevChild.getToken().getTokenType() != 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

    Class systemClass = null;
    try {
      systemClass = Class.forName(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 = SQLTypes.typeFromSQLType(desc.getSQLType()[0]);
        } catch (Exception ex) {
            throw new QueryException( "Can't determine SQL class: " + ex );
        }
        _convertor = desc.getConvertor();
        _convertorParam = desc.getConvertorParam();
    }
  }
View Full Code Here

   */
  public void check( String userDefinedType, 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 = Class.forName(systemType);
      }
      catch (Exception e) {
        throw new QueryException( "Error: Could notfind system defined class: " + systemType );
      }

      if ( ! userDefinedType.equals("") ) {
        Class userClass = null;
        try {
          userClass = Class.forName(_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

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

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

        _dbEngine = _dbImpl.getLockEngine();
        if ( _dbEngine == null )
            throw new QueryException( "Could not get a persistence engine" );

        ParseTreeWalker walker = new ParseTreeWalker(_dbEngine, parseTree, _dbImpl.getClassLoader());

        _objClass = walker.getObjClass();
        _clsDesc = walker.getClassDescriptor();
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.