Package org.jboss.ejb.plugins.cmp.ejbql

Examples of org.jboss.ejb.plugins.cmp.ejbql.ASTPath


      StringBuffer buf = (StringBuffer) data;

      final Node child0 = node.jjtGetChild(0);
      if(child0 instanceof ASTPath)
      {
         ASTPath path = (ASTPath) child0;

         if(path.isCMRField())
         {
            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
            if(cmrField.getRelationMetaData().isTableMappingStyle())
            {
               existsClause(path, buf, !node.not);
               return buf;
            }
         }

         String alias = aliasManager.getAlias(path.getPath(path.size() - 2));
         JDBCFieldBridge field = (JDBCFieldBridge) path.getField();

         // if jdbc type is null then it should be a cmr field in
         // a one-to-one mapping that isn't a foreign key.
         // handle it the way the IS EMPTY on the one side of one-to-many
         // relationship is handled
View Full Code Here


   }

   public Object visit(ASTIsEmpty node, Object data)
   {
      StringBuffer buf = (StringBuffer) data;
      ASTPath path = (ASTPath) node.jjtGetChild(0);

      existsClause(path, buf, !node.not);
      return buf;
   }
View Full Code Here

   public Object visit(ASTMemberOf node, Object data)
   {
      StringBuffer buf = (StringBuffer) data;

      // setup compare to vars first, so we can compre types in from vars
      ASTPath toPath = (ASTPath) node.jjtGetChild(1);

      JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge) toPath.getCMRField();

      JDBCEntityBridge toChildEntity = (JDBCEntityBridge) toPath.getEntity();

      String pathStr = toPath.getPath(toPath.size() - 2);
      String toParentAlias = aliasManager.getAlias(pathStr);
      String toChildAlias = aliasManager.getAlias(toPath.getPath());
      String relationTableAlias = null;
      if(toCMRField.getRelationMetaData().isTableMappingStyle())
      {
         relationTableAlias = aliasManager.getRelationTableAlias(toPath.getPath());
      }

      // setup from variables
      String fromAlias = null;
      int fromParamNumber = -1;
      if(node.jjtGetChild(0) instanceof ASTParameter)
      {
         ASTParameter fromParam = (ASTParameter) node.jjtGetChild(0);

         // can only compare like kind entities
         verifyParameterEntityType(fromParam.number, toChildEntity);

         fromParamNumber = fromParam.number;
      }
      else
      {
         ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
         addJoinPath(fromPath);

         JDBCEntityBridge fromEntity = (JDBCEntityBridge) fromPath.getEntity();
         fromAlias = aliasManager.getAlias(fromPath.getPath());

         // can only compare like kind entities
         if(!fromEntity.equals(toChildEntity))
         {
            throw new IllegalStateException("Only like types can be " +
View Full Code Here

         buf.append(SQLUtil.NOT).append('(');
         comparison = "=";
      }

      // setup the from path
      ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
      addJoinPath(fromPath);
      String fromAlias = aliasManager.getAlias(fromPath.getPath(fromPath.size() - 2));
      JDBCCMPFieldBridge fromCMPField = (JDBCCMPFieldBridge) fromPath.getCMPField();

      Node toNode = node.jjtGetChild(1);
      if(toNode instanceof ASTParameter)
      {
         ASTParameter toParam = (ASTParameter) toNode;

         // can only compare like kind entities
         Class parameterType = getParameterType(toParam.number);
         if(!(fromCMPField.getFieldType().equals(parameterType)))
         {
            throw new IllegalStateException("Only like types can be " +
               "compared: from CMP field=" +
               fromCMPField.getFieldType() +
               " to parameter=" + parameterType);
         }

         inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromCMPField));
         SQLUtil.getWhereClause(fromCMPField.getJDBCType(), fromAlias, comparison, buf);
      }
      else
      {
         ASTPath toPath = (ASTPath) toNode;
         addJoinPath(toPath);
         String toAlias = aliasManager.getAlias(toPath.getPath(toPath.size() - 2));
         JDBCCMPFieldBridge toCMPField = (JDBCCMPFieldBridge) toPath.getCMPField();

         // can only compare like kind entities
         if(!(fromCMPField.getFieldType().equals(toCMPField.getFieldType())))
         {
            throw new IllegalStateException("Only like types can be " +
View Full Code Here

   {
      StringBuffer buf = (StringBuffer) data;
      node.setResultType(returnType);

      Object args[];
      final ASTPath cntPath = (ASTPath) node.jjtGetChild(0);
      if(cntPath.isCMPField())
      {
         args = new Object[]{node.distinct, new NodeStringWrapper(cntPath)};
      }
      else
      {
         JDBCEntityBridge entity = (JDBCEntityBridge) cntPath.getEntity();
         final JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
         if(pkFields.length > 1)
         {
            countCompositePk = true;
            forceDistinct = node.distinct.length() > 0;
            selectEntity(cntPath, forceDistinct, buf);
            return buf;
         }
         else
         {

            final String alias = aliasManager.getAlias(cntPath.getPath());
            StringBuffer keyColumn = new StringBuffer(20);
            SQLUtil.getColumnNamesClause(pkFields[0], alias, keyColumn);
            args = new Object[]{node.distinct, keyColumn.toString()};
         }
      }
View Full Code Here

         }
      }
      else if(selectObject instanceof SelectFunction)
      {
         Node funcNode = (Node) selectObject;
         ASTPath fieldPath = getPathFromChildren(funcNode);
         if(fieldPath.getCMPField() == cmpField)
         {
            selected = true;
         }
      }
View Full Code Here

/*  705 */     return data;
/*      */   }
/*      */
/*      */   public Object visit(ASTIsEmpty node, Object data)
/*      */   {
/*  710 */     ASTPath path = (ASTPath)node.jjtGetChild(0);
/*  711 */     if (!path.isCMRField())
/*      */     {
/*  713 */       throw new IllegalStateException("IS EMPTY can be applied only to collection valued CMR field.");
/*      */     }
/*      */
/*  716 */     addLeftJoinPath(path);
/*      */
/*  718 */     StringBuffer sql = (StringBuffer)data;
/*  719 */     JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge)path.getCMRField();
/*  720 */     JDBCAbstractEntityBridge relatedEntity = (JDBCAbstractEntityBridge)cmrField.getRelatedEntity();
/*  721 */     String alias = this.aliasManager.getAlias(path.getPath());
/*  722 */     SQLUtil.getIsNullClause(node.not, relatedEntity.getPrimaryKeyFields(), alias, sql);
/*      */
/*  724 */     return data;
/*      */   }
View Full Code Here

/*      */   }
/*      */
/*      */   public Object visit(ASTMemberOf node, Object data)
/*      */   {
/*  729 */     Node member = node.jjtGetChild(0);
/*  730 */     ASTPath colPath = (ASTPath)node.jjtGetChild(1);
/*  731 */     JDBCAbstractEntityBridge colEntity = (JDBCAbstractEntityBridge)colPath.getEntity();
/*      */
/*  733 */     StringBuffer sql = (StringBuffer)data;
/*      */
/*  735 */     if (node.not)
/*      */     {
/*  737 */       sql.append(" NOT ");
/*      */     }
/*      */
/*  740 */     sql.append("EXISTS ").append('(').append("SELECT ");
/*      */
/*  742 */     if ((member instanceof ASTParameter))
/*      */     {
/*  744 */       ASTParameter toParam = (ASTParameter)member;
/*  745 */       verifyParameterEntityType(toParam.number, colEntity);
/*  746 */       this.inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, colEntity));
/*      */
/*  748 */       String parentAlias = this.aliasManager.getAlias(colPath.getPath(0));
/*  749 */       String localParentAlias = this.aliasManager.getAlias(colPath.getPath(0) + "_local");
/*  750 */       JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge)colPath.getEntity(0);
/*  751 */       SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), localParentAlias, sql);
/*  752 */       sql.append(" FROM ").append(parentEntity.getQualifiedTableName()).append(' ').append(localParentAlias);
/*      */
/*  754 */       innerJoinPath(colPath, sql);
/*      */
/*  756 */       sql.append(" WHERE ");
/*      */
/*  758 */       JDBCAbstractEntityBridge col0 = (JDBCAbstractEntityBridge)colPath.getEntity(0);
/*  759 */       SQLUtil.getSelfCompareWhereClause(col0.getPrimaryKeyFields(), parentAlias, localParentAlias, sql);
/*  760 */       sql.append(" AND ");
/*      */
/*  762 */       String localColAlias = this.aliasManager.getAlias(colPath.getPath() + "_local");
/*  763 */       SQLUtil.getWhereClause(colEntity.getPrimaryKeyFields(), localColAlias, sql);
/*      */     }
/*      */     else
/*      */     {
/*  767 */       ASTPath memberPath = (ASTPath)member;
/*  768 */       JDBCAbstractEntityBridge memberEntity = (JDBCAbstractEntityBridge)memberPath.getEntity();
/*      */
/*  770 */       if (!memberEntity.equals(colEntity))
/*      */       {
/*  772 */         throw new IllegalStateException("Member must be if the same type as the collection, got: member=" + memberEntity.getEntityName() + ", collection=" + colEntity.getEntityName());
/*      */       }
/*      */
/*  778 */       String memberAlias = this.aliasManager.getAlias(memberPath.getPath());
/*      */
/*  780 */       if (memberPath.size() > 1)
/*      */       {
/*  782 */         String parentAlias = this.aliasManager.getAlias(memberPath.getPath(0) + "_local");
/*  783 */         JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge)memberPath.getEntity(0);
/*  784 */         SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
/*  785 */         sql.append(" FROM ").append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
/*      */
/*  787 */         innerJoinPath(memberPath, sql);
/*  788 */         innerJoinPath(colPath, sql);
/*      */       }
/*  790 */       else if (colPath.size() > 1)
/*      */       {
/*  792 */         String parentAlias = this.aliasManager.getAlias(colPath.getPath(0) + "_local");
/*  793 */         JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge)colPath.getEntity(0);
/*  794 */         SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
/*  795 */         sql.append(" FROM ").append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
/*      */
/*  797 */         innerJoinPath(colPath, sql);
/*      */       }
/*      */       else
/*      */       {
/*  801 */         throw new IllegalStateException("There should be collection valued path expression, not identification variable.");
/*      */       }
/*      */
/*  805 */       sql.append(" WHERE ");
/*      */
/*  807 */       JDBCAbstractEntityBridge member0 = (JDBCAbstractEntityBridge)memberPath.getEntity(0);
/*  808 */       String colAliasLocal = this.aliasManager.getAlias(colPath.getPath() + "_local");
/*  809 */       if (memberPath.size() > 1)
/*      */       {
/*  811 */         String memberAliasLocal = this.aliasManager.getAlias(memberPath.getPath() + "_local");
/*  812 */         SQLUtil.getSelfCompareWhereClause(colEntity.getPrimaryKeyFields(), memberAliasLocal, colAliasLocal, sql);
/*      */
/*  817 */         sql.append(" AND ");
/*      */
/*  819 */         String member0Alias = this.aliasManager.getAlias(memberPath.getPath(0));
/*  820 */         String member0AliasLocal = this.aliasManager.getAlias(memberPath.getPath(0) + "_local");
/*  821 */         SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(), member0Alias, member0AliasLocal, sql);
/*      */       }
/*      */       else
/*      */       {
/*  828 */         SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(), memberAlias, colAliasLocal, sql);
View Full Code Here

/*      */     {
/*  929 */       buf.append(" NOT ").append('(');
/*  930 */       comparison = "=";
/*      */     }
/*      */
/*  934 */     ASTPath fromPath = (ASTPath)node.jjtGetChild(0);
/*  935 */     addInnerJoinPath(fromPath);
/*  936 */     String fromAlias = this.aliasManager.getAlias(fromPath.getPath(fromPath.size() - 2));
/*  937 */     CMPFieldBridge fromCMPField = fromPath.getCMPField();
/*      */
/*  939 */     Node toNode = node.jjtGetChild(1);
/*  940 */     if ((toNode instanceof ASTParameter))
/*      */     {
/*  942 */       ASTParameter toParam = (ASTParameter)toNode;
/*      */
/*  945 */       Class parameterType = getParameterType(toParam.number);
/*  946 */       if (!fromCMPField.getFieldType().equals(parameterType))
/*      */       {
/*  948 */         throw new IllegalStateException("Only like types can be compared: from CMP field=" + fromCMPField.getFieldType() + " to parameter=" + parameterType);
/*      */       }
/*      */
/*  954 */       this.inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromCMPField));
/*  955 */       SQLUtil.getWhereClause(fromCMPField.getJDBCType(), fromAlias, comparison, buf);
/*      */     }
/*      */     else
/*      */     {
/*  959 */       ASTPath toPath = (ASTPath)toNode;
/*  960 */       addInnerJoinPath(toPath);
/*  961 */       String toAlias = this.aliasManager.getAlias(toPath.getPath(toPath.size() - 2));
/*  962 */       JDBCCMPFieldBridge toCMPField = (JDBCCMPFieldBridge)toPath.getCMPField();
/*      */
/*  965 */       if (!fromCMPField.getFieldType().equals(toCMPField.getFieldType()))
/*      */       {
/*  967 */         throw new IllegalStateException("Only like types can be compared: from CMP field=" + fromCMPField.getFieldType() + " to CMP field=" + toCMPField.getFieldType());
/*      */       }
View Full Code Here

/*      */   public Object visit(ASTCount node, Object data)
/*      */   {
/* 1195 */     StringBuffer buf = (StringBuffer)data;
/* 1196 */     node.setResultType(this.returnType);
/*      */
/* 1199 */     ASTPath cntPath = (ASTPath)node.jjtGetChild(0);
/*      */     Object[] args;
/*      */     Object[] args;
/* 1200 */     if (cntPath.isCMPField())
/*      */     {
/* 1202 */       args = new Object[] { node.distinct, node.jjtGetChild(0).jjtAccept(this, new StringBuffer()).toString() };
/*      */     }
/*      */     else
/*      */     {
/* 1206 */       JDBCAbstractEntityBridge entity = (JDBCAbstractEntityBridge)cntPath.getEntity();
/* 1207 */       JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
/* 1208 */       if (pkFields.length > 1)
/*      */       {
/* 1210 */         this.countCompositePk = true;
/* 1211 */         this.forceDistinct = (node.distinct.length() > 0);
/*      */
/* 1213 */         addLeftJoinPath(cntPath);
/*      */
/* 1215 */         String alias = this.aliasManager.getAlias(cntPath.getPath());
/* 1216 */         SQLUtil.getColumnNamesClause(entity.getPrimaryKeyFields(), alias, buf);
/*      */
/* 1220 */         return buf;
/*      */       }
/*      */
/* 1224 */       String alias = this.aliasManager.getAlias(cntPath.getPath());
/* 1225 */       StringBuffer keyColumn = new StringBuffer(20);
/* 1226 */       SQLUtil.getColumnNamesClause(pkFields[0], alias, keyColumn);
/* 1227 */       args = new Object[] { node.distinct, keyColumn.toString() };
/*      */     }
/*      */
View Full Code Here

TOP

Related Classes of org.jboss.ejb.plugins.cmp.ejbql.ASTPath

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.