From: Erik B. <ebe...@us...> - 2007-04-29 16:25:25
|
Update of /cvsroot/jpox/JPOX/Core/src/java/org/jpox/store/rdbms/query In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11824/src/java/org/jpox/store/rdbms/query Modified Files: JPQLQuery.java Log Message: [CORE-3240] JPQL: function CONCAT; fixes to BETWEEN and NOT operators Index: JPQLQuery.java =================================================================== RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/store/rdbms/query/JPQLQuery.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** JPQLQuery.java 23 Apr 2007 23:34:56 -0000 1.17 --- JPQLQuery.java 29 Apr 2007 16:25:21 -0000 1.18 *************** *** 517,551 **** // Compile and apply the grouping to the query ScalarExpression[] groupingFieldExprs = null; - ScalarExpression[] havingFieldExprs = null; if (grouping != null && grouping.length() > 0) { - // The "grouping" string will be of the form "...., ...., ... HAVING ...." - // so we parse it into the former part as a grouping clause, and the latter part as a having clause - String groupingClause = null; - String havingClause = null; - if (grouping.indexOf("HAVING") >= 0) - { - havingClause = grouping.substring(grouping.indexOf("HAVING") + 7); - groupingClause = grouping.substring(0, grouping.indexOf("HAVING")-1); - } - else if (grouping.indexOf("having") >= 0) - { - havingClause = grouping.substring(grouping.indexOf("having") + 7); - groupingClause = grouping.substring(0, grouping.indexOf("having")-1); - } - else - { - groupingClause = grouping; - } - // Compile the "grouping" fieldExpressions.clear(); ! compileGrouping(qs, groupingClause); groupingFieldExprs = (ScalarExpression[])fieldExpressions.toArray(new ScalarExpression[fieldExpressions.size()]); - // Compile the "having" - fieldExpressions.clear(); - compileHaving(qs, havingClause); - havingFieldExprs = (ScalarExpression[])fieldExpressions.toArray(new ScalarExpression[fieldExpressions.size()]); } --- 517,527 ---- // Compile and apply the grouping to the query ScalarExpression[] groupingFieldExprs = null; if (grouping != null && grouping.length() > 0) { // Compile the "grouping" fieldExpressions.clear(); ! compileGrouping(qs, grouping); groupingFieldExprs = (ScalarExpression[])fieldExpressions.toArray(new ScalarExpression[fieldExpressions.size()]); } *************** *** 555,558 **** --- 531,539 ---- ScalarExpression[] orderingFieldExprs = (ScalarExpression[])fieldExpressions.toArray(new ScalarExpression[fieldExpressions.size()]); + if (having != null && having.length() > 0) + { + compileHaving(qs, having); + } + // Check that all result expression fields, having fields and ordering fields are defined in any grouping specification if (groupingFieldExprs != null) *************** *** 561,571 **** checkExpressionsAgainstGrouping(orderingFieldExprs, groupingFieldExprs, "JDOQL.FieldInOrderingNotSpecifiedInGrouping"); ! // Check having fields against what is in the grouping spec ! checkExpressionsAgainstGrouping(havingFieldExprs, groupingFieldExprs, "JDOQL.FieldInHavingNotSpecifiedInGrouping"); ! // Check that all result clause fields are in the grouping clause checkExpressionsAgainstGrouping(resultFieldExprs, groupingFieldExprs, "JDOQL.FieldInResultNotSpecifiedInGrouping"); } // Compile and apply the range to the query compileRange(qs); --- 542,554 ---- checkExpressionsAgainstGrouping(orderingFieldExprs, groupingFieldExprs, "JDOQL.FieldInOrderingNotSpecifiedInGrouping"); ! // Check that all result clause fields are in the grouping clause ! //checkExpressionsAgainstGrouping(havingFieldExprs, groupingFieldExprs, "JDOQL.FieldInResultNotSpecifiedInGrouping"); ! // Check that all result clause fields are in the grouping clause checkExpressionsAgainstGrouping(resultFieldExprs, groupingFieldExprs, "JDOQL.FieldInResultNotSpecifiedInGrouping"); } + groupingFieldExprs = (ScalarExpression[])fieldExpressions.toArray(new ScalarExpression[fieldExpressions.size()]); + // Compile and apply the range to the query compileRange(qs); *************** *** 1214,1242 **** } ! private ScalarExpression compileNotExpression() { ScalarExpression expr = compileEqualityExpression(); ! ! for (;;) { ! if (p.parseStringIgnoreCase("NOT")) { ! if (p.parseStringIgnoreCase("BETWEEN")) { ! expr = compileBetweenExpression(expr).not(); } else { ! expr = compileEqualityExpression().not(); } } ! else if (p.parseStringIgnoreCase("BETWEEN")) { ! expr = compileBetweenExpression(expr); } else { ! break; } } return expr; --- 1197,1248 ---- } ! private ScalarExpression compileBetweenExpression() { ScalarExpression expr = compileEqualityExpression(); ! if (p.parseStringIgnoreCase("NOT")) { ! if (p.parseStringIgnoreCase("BETWEEN")) { ! ScalarExpression leftexpr = compileAdditiveExpression(); ! ScalarExpression rightexpr = null; ! if (p.parseStringIgnoreCase("AND")) { ! rightexpr = compileAdditiveExpression(); } else { ! throw new ExpressionSyntaxException("Expected: 'AND' but got "+p.remaining()); } + return expr.lt(leftexpr).ior(expr.gt(rightexpr)); } ! throw new ExpressionSyntaxException("Expected: 'BETWEEN' but got "+p.remaining()); ! } ! else if (p.parseStringIgnoreCase("BETWEEN")) ! { ! ScalarExpression leftexpr = compileAdditiveExpression(); ! ScalarExpression rightexpr = null; ! if (p.parseStringIgnoreCase("AND")) { ! rightexpr = compileAdditiveExpression(); } else { ! throw new ExpressionSyntaxException("Expected: 'AND' but got "+p.remaining()); } + return expr.gteq(leftexpr).and(expr.lteq(rightexpr)); + } + return expr; + } + + private ScalarExpression compileNotExpression() + { + ScalarExpression expr = null; + if (p.parseStringIgnoreCase("NOT")) + { + expr = compileEqualityExpression().not(); + } + else + { + expr = compileBetweenExpression(); } return expr; *************** *** 1294,1313 **** } - private ScalarExpression compileBetweenExpression(ScalarExpression expr) - { - ScalarExpression leftexpr = compileAdditiveExpression(); - ScalarExpression rightexpr = null; - if (p.parseStringIgnoreCase("AND")) - { - rightexpr = compileAdditiveExpression(); - } - else - { - throw new ExpressionSyntaxException("Expected: 'AND' but got "+p.remaining()); - } - return expr.gteq(leftexpr).and(expr.lteq(rightexpr)); - } - - private ScalarExpression compileRelationalExpression() { --- 1300,1303 ---- *************** *** 1556,1576 **** } //TODO make these functions pluggable ! if( methodId.equals("ABS") ) { return new MathExpression(qs).absMethod(((ScalarExpression)args.get(0))); } ! else if( methodId.equals("SQRT") ) { return new MathExpression(qs).sqrtMethod(((ScalarExpression)args.get(0))); } ! else if( methodId.equals("MOD") ) { return ((ScalarExpression)args.get(0)).mod((ScalarExpression)args.get(1)); } ! else if( methodId.equals("LENGTH") ) { return ((ScalarExpression)args.get(0)).callMethod(methodId.toLowerCase(), Collections.EMPTY_LIST); } ! else if( methodId.equals("SUBSTRING") ) { List argscall = new ArrayList(); --- 1546,1570 ---- } //TODO make these functions pluggable ! if( methodId.equalsIgnoreCase("ABS") ) { return new MathExpression(qs).absMethod(((ScalarExpression)args.get(0))); } ! else if( methodId.equalsIgnoreCase("SQRT") ) { return new MathExpression(qs).sqrtMethod(((ScalarExpression)args.get(0))); } ! else if( methodId.equalsIgnoreCase("CONCAT") ) ! { ! return ((ScalarExpression)args.get(0)).add((ScalarExpression)args.get(1)); ! } ! else if( methodId.equalsIgnoreCase("MOD") ) { return ((ScalarExpression)args.get(0)).mod((ScalarExpression)args.get(1)); } ! else if( methodId.equalsIgnoreCase("LENGTH") ) { return ((ScalarExpression)args.get(0)).callMethod(methodId.toLowerCase(), Collections.EMPTY_LIST); } ! else if( methodId.equalsIgnoreCase("SUBSTRING") ) { List argscall = new ArrayList(); *************** *** 1584,1600 **** return ((ScalarExpression)args.get(0)).callMethod(methodId.toLowerCase(), argscall); } ! else if( methodId.equals("LOWER") ) { return ((ScalarExpression)args.get(0)).callMethod("toLowerCase", Collections.EMPTY_LIST); } ! else if( methodId.equals("UPPER") ) { return ((ScalarExpression)args.get(0)).callMethod("toUpperCase", Collections.EMPTY_LIST); } ! else if( methodId.equals("SIZE") ) { return ((ScalarExpression)args.get(0)).callMethod(methodId.toLowerCase(), Collections.EMPTY_LIST); } ! else if( methodId.equals("LOCATE") ) { List argscall = new ArrayList(); --- 1578,1594 ---- return ((ScalarExpression)args.get(0)).callMethod(methodId.toLowerCase(), argscall); } ! else if( methodId.equalsIgnoreCase("LOWER") ) { return ((ScalarExpression)args.get(0)).callMethod("toLowerCase", Collections.EMPTY_LIST); } ! else if( methodId.equalsIgnoreCase("UPPER") ) { return ((ScalarExpression)args.get(0)).callMethod("toUpperCase", Collections.EMPTY_LIST); } ! else if( methodId.equalsIgnoreCase("SIZE") ) { return ((ScalarExpression)args.get(0)).callMethod(methodId.toLowerCase(), Collections.EMPTY_LIST); } ! else if( methodId.equalsIgnoreCase("LOCATE") ) { List argscall = new ArrayList(); *************** *** 1760,1763 **** --- 1754,1769 ---- } + if (id.equalsIgnoreCase("false")) + { + JavaTypeMapping m = qs.getStoreManager().getDatastoreAdapter().getMapping(Boolean.class, + qs.getStoreManager(), qs.getClassLoaderResolver()); + return m.newLiteral(qs, Boolean.FALSE); + } + else if (id.equalsIgnoreCase("true")) + { + JavaTypeMapping m = qs.getStoreManager().getDatastoreAdapter().getMapping(Boolean.class, + qs.getStoreManager(), qs.getClassLoaderResolver()); + return m.newLiteral(qs, Boolean.TRUE); + } if (id.startsWith(":")) { |