Examples of JDOFieldDescriptor


Examples of org.exolab.castor.jdo.engine.JDOFieldDescriptor

   */
  private JDOFieldDescriptor checkProjection( ParseTreeNode projection,
                                boolean topLevel,
                                boolean onlySimple )
          throws QueryException {
    JDOFieldDescriptor field = null;

    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 ) {
View Full Code Here

Examples of org.exolab.castor.jdo.engine.JDOFieldDescriptor

   */
  private JDOFieldDescriptor checkField(ParseTreeNode fieldTree)
        throws QueryException {

    //see if we've checked this field before.
    JDOFieldDescriptor field = (JDOFieldDescriptor)_fieldInfo.get(fieldTree);
    if ( field != null )
      return field;

    if ( fieldTree.getToken().getTokenType() == DOT ) {
        field = checkProjection( fieldTree, false, false );
View Full Code Here

Examples of org.exolab.castor.jdo.engine.JDOFieldDescriptor

    }

    //Get the system defined type
    String systemType = "";
    // Get the SQL type if known
    JDOFieldDescriptor desc = null;
    int operation = paramTree.getParent().getToken().getTokenType();
    switch (operation) {
      case PLUS: case MINUS: case TIMES:
      case DIVIDE: case KEYWORD_MOD: case KEYWORD_ABS:
      case KEYWORD_LIMIT: //Alex
View Full Code Here

Examples of org.exolab.castor.jdo.engine.JDOFieldDescriptor

      ParseTreeNode curChild = (ParseTreeNode) e.nextElement();
      int tokenType = curChild.getToken().getTokenType();

      if ((tokenType == DOT) || (tokenType == IDENTIFIER)) {
        JDOFieldDescriptor field = checkField(curChild);
        return field.getFieldType().getName();
      }
    }

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

Examples of org.exolab.castor.jdo.engine.JDOFieldDescriptor

    // the class for the join is even this class
    // or one of the base classes
    JDOClassDescriptor sourceClass = _clsDesc;

    for ( int i = 1; i < path.size() - 1; i++ ) {
        JDOFieldDescriptor fieldDesc = null;

        // Find the sourceclass and the fielsddescriptor
        // in the class hierachie
        Object[] fieldAndClass = getFieldAndClassDesc((String) path.elementAt(i), sourceClass,
                                                      _queryExpr, path, i - 1);
        if (fieldAndClass == null) {
            throw new IllegalStateException( "Field not found:" + path.elementAt(i));
        }
        fieldDesc = (JDOFieldDescriptor) fieldAndClass[0];
        sourceClass = (JDOClassDescriptor) fieldAndClass[1];

        JDOClassDescriptor clsDesc = (JDOClassDescriptor) fieldDesc.getClassDescriptor();
        if ( clsDesc != null /*&& clsDesc != sourceClass*/ ) {
            //we must add this table as a join
            if ( fieldDesc.getManyKey() == null ) {
                //a many -> one relationship
                JDOFieldDescriptor foreignKey = (JDOFieldDescriptor) clsDesc.getIdentity();
                String sourceTableAlias = sourceClass.getTableName();
                if ( i > 1 )
                    sourceTableAlias = buildTableAlias( sourceTableAlias, path, i - 1 );

                _queryExpr.addInnerJoin( sourceClass.getTableName(),
                                         fieldDesc.getSQLName(),
                                         sourceTableAlias,
                                         clsDesc.getTableName(),
                                         foreignKey.getSQLName(),
                                         buildTableAlias( clsDesc.getTableName(), path, i ) );
            } else if ( fieldDesc.getManyTable() == null ) {
                //a one -> many relationship
                JDOFieldDescriptor identity = (JDOFieldDescriptor) sourceClass.getIdentity();
                String sourceTableAlias = sourceClass.getTableName();
                if ( i > 1 )
                    sourceTableAlias = buildTableAlias( sourceTableAlias, path, i - 1 );

                _queryExpr.addInnerJoin( sourceClass.getTableName(),
                                         identity.getSQLName(),
                                         sourceTableAlias,
                                         clsDesc.getTableName(),
                                         fieldDesc.getManyKey(),
                                         buildTableAlias( clsDesc.getTableName(), path, i ) );
            } else {
                //a many -> many relationship
                JDOFieldDescriptor identity = (JDOFieldDescriptor) sourceClass.getIdentity();
                JDOFieldDescriptor foreignKey = (JDOFieldDescriptor) clsDesc.getIdentity();
                String manyTableAlias = fieldDesc.getManyTable();
                String sourceTableAlias = sourceClass.getTableName();
                if ( i > 1 ) {
                    manyTableAlias = buildTableAlias( manyTableAlias, path, i - 1 );
                    sourceTableAlias = buildTableAlias( sourceTableAlias, path, i - 1 );
      }

                _queryExpr.addInnerJoin( sourceClass.getTableName(),
                                         identity.getSQLName(),
                                         sourceTableAlias,
                                         fieldDesc.getManyTable(),
                                         fieldDesc.getManyKey(),
                                         manyTableAlias);

                _queryExpr.addInnerJoin( fieldDesc.getManyTable(),
                                         fieldDesc.getSQLName(),
                                         manyTableAlias,
                                         clsDesc.getTableName(),
                                         foreignKey.getSQLName(),
                                         buildTableAlias( clsDesc.getTableName(), path, i ) );
            }
            sourceClass = clsDesc;
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.