編程生活

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            113 隨筆 :: 0 文章 :: 18 評論 :: 0 Trackbacks
          openJPA的0.9.7和1.0.0的構造型查詢均不支持distinct,但如果不使用構造型方式查詢又支持distinct,最后檢查JPQLExpressionBuilder.java的evalSelectClause(..)方法,發現是openJPA中的問題,我將其修改為:
          private Expression evalSelectClause(QueryExpressions exps) {
                  
          if (exps.operation != QueryOperations.OP_SELECT)
                      
          return null;

                  JPQLNode selectNode 
          = root();

                  JPQLNode constructor 
          = selectNode.findChildByID(JJTCONSTRUCTOR, true);
                  
          if (constructor != null{
                      
          // build up the fully-qualified result class name by
                      
          // appending together the components of the children
                      String resultClassName = assemble(left(constructor));
                      exps.resultClass 
          = resolver.classForName(resultClassName, null);

                      
          // now assign the arguments to the select clause as the projections
                      JPQLNode selectClause = selectNode.findChildByID(JJTSELECTCLAUSE, false);
                      
          if (selectClause != null && selectClause.hasChildID(JJTDISTINCT))
                        exps.distinct 
          = exps.DISTINCT_TRUE | exps.DISTINCT_AUTO;
                      
          else
                        exps.distinct 
          = exps.DISTINCT_FALSE;
                      
                      
          return assignProjections(right(constructor), exps);
                  }
           else {
                      JPQLNode selectClause 
          = selectNode.
                          findChildByID(JJTSELECTCLAUSE, 
          false);
                      
          if (selectClause != null && selectClause.hasChildID(JJTDISTINCT))
                          exps.distinct 
          = exps.DISTINCT_TRUE | exps.DISTINCT_AUTO;
                      
          else
                          exps.distinct 
          = exps.DISTINCT_FALSE;

                      
          // handle SELECT clauses
                      JPQLNode expNode = selectNode.
                          findChildByID(JJTSELECTEXPRESSIONS, 
          true);
                      
          if (expNode == null)
                          
          return null;

                      
          int selectCount = expNode.getChildCount();
                      JPQLNode selectChild 
          = firstChild(expNode);

                      
          // if we are selecting just one thing and that thing is the
                      
          // schema's alias, then do not treat it as a projection
                      if (selectCount == 1 && selectChild != null &&
                          selectChild.getChildCount() 
          == 1 &&
                          onlyChild(selectChild) 
          != null &&
                          assertSchemaAlias().
                              equalsIgnoreCase(onlyChild(selectChild).text)) 
          {
                          
          return null;
                      }
           else {
                          
          // JPQL does not filter relational joins for projections
                          exps.distinct &= ~exps.DISTINCT_AUTO;
                          
          return assignProjections(expNode, exps);
                      }

                  }

              }

          使用方式為:
          select DISTINCT new com.wile.test.AData(a.id, a.name,..) from A where a.id=?1
          目前已向openJPA提出此bug(bug-id:OPENJPA-420),希望他們能在1.0.1中進行修改
          posted on 2007-10-26 15:48 wilesun 閱讀(1121) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 德安县| 房山区| 正蓝旗| 昂仁县| 磐安县| 德化县| 闵行区| 英吉沙县| 神池县| 中宁县| 醴陵市| 库车县| 南岸区| 临西县| 汉阴县| 金溪县| 资中县| 凤城市| 郁南县| 林周县| 吉林市| 潜江市| 万山特区| 同江市| 海安县| 茌平县| 德格县| 阿瓦提县| 梨树县| 郎溪县| 桂阳县| 南阳市| 安阳县| 定远县| 资兴市| 绥化市| 巩留县| 澄迈县| 潜山县| 施甸县| 涡阳县|