From: <leg...@at...> - 2003-11-03 15:09:14
|
The following comment has been added to this issue: Author: Michail Jekimov Created: Mon, 3 Nov 2003 9:08 AM Body: Hello, I tried to implement the discussed functionality. Here is the result as a patch. Unfortunately I had problems with cvs connection to the sourceforge host. So, this is the diff patch for Hibernate 2.1 beta 4. Surely I cannot guarantee that these changes won't produce any side effects, but I hope it will help you if you decide to implement this feature. --- SelectParser_old.java Mon Nov 3 15:59:06 2003 +++ SelectParser.java Mon Nov 3 15:59:06 2003 @@ -35,6 +35,7 @@ private boolean first; private boolean afterNew; private boolean insideNew; + private boolean aggregateAddSelectScalar; private Class holderClass; private final SelectPathExpressionParser pathExpressionParser; @@ -71,7 +72,7 @@ insideNew = true; } else if ( token.equals(StringHelper.COMMA) ) { - if (ready) throw new QueryException("alias or expression expected in SELECT"); + if (!aggregate && ready) throw new QueryException("alias or expression expected in SELECT"); q.appendScalarSelectToken(StringHelper.COMMA_SPACE); ready=true; } @@ -118,6 +119,7 @@ // the name of an SQL function if (!ready) throw new QueryException(", expected before aggregate function in SELECT: " + token); aggregate = true; + aggregateAddSelectScalar = true; aggregateFuncTokenList.add(lctoken); ready = false; q.appendScalarSelectToken(token); @@ -136,18 +138,31 @@ } } else if (aggregate) { + boolean constantToken = false; if (!ready) throw new QueryException("( expected after aggregate function in SELECT"); + try { ParserHelper.parse(aggregatePathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q); + } catch (QueryException qex) { + constantToken = true; + } - if ( aggregatePathExpressionParser.isCollectionValued() ) { - q.addCollection( - aggregatePathExpressionParser.getCollectionName(), - aggregatePathExpressionParser.getCollectionRole() - ); - } - q.appendScalarSelectToken( aggregatePathExpressionParser.getWhereColumn() ); - q.addSelectScalar( aggregateType(aggregateFuncTokenList, aggregatePathExpressionParser.getWhereColumnType(), q ) ); - aggregatePathExpressionParser.addAssociation(q); + if (constantToken) { + q.appendScalarSelectToken(token); + } + else { + if ( aggregatePathExpressionParser.isCollectionValued() ) { + q.addCollection( + aggregatePathExpressionParser.getCollectionName(), + aggregatePathExpressionParser.getCollectionRole() + ); + } + q.appendScalarSelectToken( aggregatePathExpressionParser.getWhereColumn() ); + if (aggregateAddSelectScalar) { + q.addSelectScalar( aggregateType(aggregateFuncTokenList, aggregatePathExpressionParser.getWhereColumnType(), q ) ); + aggregateAddSelectScalar = false; + } + aggregatePathExpressionParser.addAssociation(q); + } } else { if (!ready) throw new QueryException(", expected in SELECT"); ===================================================================== --- QueryTranslator_old.java Mon Nov 3 15:59:06 2003 +++ QueryTranslator.java Mon Nov 3 15:59:06 2003 @@ -654,6 +654,12 @@ Object next = iter.next(); if (next instanceof String) { String token = (String) next; + if (StringHelper.OPEN_PAREN.equals(token)) { + isSubselect = true; + } + else if (StringHelper.CLOSE_PAREN.equals(token)) { + isSubselect = superQuery!=null; + } String lc = token.toLowerCase(); if ( lc.equals(StringHelper.COMMA_SPACE) ) { if (nolast) { --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-158 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-158 Summary: Customizable SQL Type: New Feature Status: Unassigned Priority: Major Project: Hibernate2 Components: core Versions: 2.0.1 Assignee: Reporter: TURIN ACCOUNT Created: Tue, 8 Jul 2003 3:38 PM Updated: Tue, 8 Jul 2003 3:38 PM Description: Ability to be able to get the SQL Hibernate would send to the database for a given query, be able to look at it and possibly tweak it (as a String) and then allow Hibernate to continue - sending the SQL on its way to the database. This allows for subtle hints and other database tricks one is often forced to do when you don't "own" the datamodel. --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |