Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql In directory sc8-pr-cvs1:/tmp/cvs-serv2323/sf/hibernate/hql Modified Files: FromParser.java PathExpressionParser.java PreprocessingParser.java QueryTranslator.java SelectParser.java WhereParser.java Log Message: major refactoring to create SQL Generation layer more efficient queries against normalized mappings Index: FromParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/FromParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FromParser.java 5 Jan 2003 02:11:21 -0000 1.3 --- FromParser.java 20 Jan 2003 12:48:10 -0000 1.4 *************** *** 3,6 **** --- 3,7 ---- import net.sf.hibernate.QueryException; + import net.sf.hibernate.util.StringHelper; /** *************** *** 32,36 **** } else if (expectingComma) { ! if ( token.equals(",") ) { expectingComma = false; fromClass = false; --- 33,37 ---- } else if (expectingComma) { ! if ( token.equals(StringHelper.COMMA) ) { expectingComma = false; fromClass = false; Index: PathExpressionParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/PathExpressionParser.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PathExpressionParser.java 12 Jan 2003 15:04:51 -0000 1.5 --- PathExpressionParser.java 20 Jan 2003 12:48:10 -0000 1.6 *************** *** 53,57 **** .append('=') .append(name) ! .append('.') .append( rhsCols[i] ); } --- 53,57 ---- .append('=') .append(name) ! .append(StringHelper.DOT) .append( rhsCols[i] ); } *************** *** 69,73 **** .append('=') .append(currentName) ! .append('.') .append( q.getPersister(clazz).getIdentifierColumnNames()[i] ); } --- 69,73 ---- .append('=') .append(currentName) ! .append(StringHelper.DOT) .append( q.getPersister(clazz).getIdentifierColumnNames()[i] ); } *************** *** 90,94 **** .append('=') .append(collectionName) ! .append('.') .append( p.getKeyColumnNames()[i] ); } --- 90,94 ---- .append('=') .append(collectionName) ! .append(StringHelper.DOT) .append( p.getKeyColumnNames()[i] ); } *************** *** 144,148 **** } else { ! componentPath+= '.' + token; } } --- 144,148 ---- } else { ! componentPath+= StringHelper.DOT + token; } } *************** *** 172,176 **** currentName = name; currentProperty = token; ! q.addPathAliasAndJoin( path.substring( 0, path.lastIndexOf('.') ), name, join.toString() ); } --- 172,176 ---- currentName = name; currentProperty = token; ! q.addPathAliasAndJoin( path.substring( 0, path.lastIndexOf(StringHelper.DOT) ), name, join.toString() ); } *************** *** 207,216 **** private String getPropertyPath() { if (currentProperty==null) { ! return "id"; } else { return currentProperty + ! ( skippedId ? '.' + ENTITY_ID : "" ) + ! ( (componentPath==null) ? "" : '.' + componentPath ); } } --- 207,216 ---- private String getPropertyPath() { if (currentProperty==null) { ! return ENTITY_ID; } else { return currentProperty + ! ( skippedId ? StringHelper.DOT + ENTITY_ID : StringHelper.EMPTY_STRING ) + ! ( (componentPath==null) ? StringHelper.EMPTY_STRING : StringHelper.DOT + componentPath ); } } *************** *** 256,260 **** if (!continuation) { reset(); ! path = ""; } } --- 256,260 ---- if (!continuation) { reset(); ! path = StringHelper.EMPTY_STRING; } } *************** *** 287,291 **** join.append(" and ") .append(collectionName) ! .append('.') .append( indexCols[0] ) .append("="); --- 287,291 ---- join.append(" and ") .append(collectionName) ! .append(StringHelper.DOT) .append( indexCols[0] ) .append("="); *************** *** 295,299 **** CollectionElement elem = new CollectionElement(); ! elem.elementColumns = StringHelper.prefix( eltCols, collectionName + '.' ); elem.type = memberPersister.getElementType(); elem.isOneToMany = memberPersister.isOneToMany(); --- 295,299 ---- CollectionElement elem = new CollectionElement(); ! elem.elementColumns = StringHelper.prefix( eltCols, collectionName + StringHelper.DOT ); elem.type = memberPersister.getElementType(); elem.isOneToMany = memberPersister.isOneToMany(); *************** *** 393,397 **** .append('=') .append(elementName) ! .append('.') .append( keyColumnNames[i] ); } --- 393,397 ---- .append('=') .append(elementName) ! .append(StringHelper.DOT) .append( keyColumnNames[i] ); } *************** *** 413,417 **** if ( token.equals(COLLECTION_ELEMENTS) ) { String[] cols = memberPersister.getElementColumnNames(); ! collectionElementColumns = StringHelper.prefix( cols, name + '.'); collectionElementType = memberPersister.getElementType(); } --- 413,417 ---- if ( token.equals(COLLECTION_ELEMENTS) ) { String[] cols = memberPersister.getElementColumnNames(); ! collectionElementColumns = StringHelper.prefix( cols, name + StringHelper.DOT); collectionElementType = memberPersister.getElementType(); } *************** *** 419,423 **** if ( !memberPersister.hasIndex() ) throw new QueryException("unindexed collection before .indices"); String[] cols = memberPersister.getIndexColumnNames(); ! collectionElementColumns = StringHelper.prefix(cols, name + '.'); collectionElementType = memberPersister.getIndexType(); } --- 419,423 ---- if ( !memberPersister.hasIndex() ) throw new QueryException("unindexed collection before .indices"); String[] cols = memberPersister.getIndexColumnNames(); ! collectionElementColumns = StringHelper.prefix(cols, name + StringHelper.DOT); collectionElementType = memberPersister.getIndexType(); } *************** *** 430,434 **** String[] cols = memberPersister.getIndexColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection index in maxIndex"); ! collectionElementColumns = new String[] { "max(" + cols[0] + ")" }; collectionElementType = memberPersister.getIndexType(); } --- 430,434 ---- String[] cols = memberPersister.getIndexColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection index in maxIndex"); ! collectionElementColumns = new String[] { "max(" + cols[0] + StringHelper.CLOSE_PAREN }; collectionElementType = memberPersister.getIndexType(); } *************** *** 437,441 **** String[] cols = memberPersister.getIndexColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection index in minIndex"); ! collectionElementColumns = new String[] { "min(" + cols[0] + ")" }; collectionElementType = memberPersister.getIndexType(); } --- 437,441 ---- String[] cols = memberPersister.getIndexColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection index in minIndex"); ! collectionElementColumns = new String[] { "min(" + cols[0] + StringHelper.CLOSE_PAREN }; collectionElementType = memberPersister.getIndexType(); } *************** *** 443,447 **** String[] cols = memberPersister.getElementColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection element in maxElement"); ! collectionElementColumns = new String[] { "max(" + cols[0] + ")" }; collectionElementType = memberPersister.getElementType(); } --- 443,447 ---- String[] cols = memberPersister.getElementColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection element in maxElement"); ! collectionElementColumns = new String[] { "max(" + cols[0] + StringHelper.CLOSE_PAREN }; collectionElementType = memberPersister.getElementType(); } *************** *** 449,457 **** String[] cols = memberPersister.getElementColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection element in minElement"); ! collectionElementColumns = new String[] { "min(" + cols[0] + ")" }; collectionElementType = memberPersister.getElementType(); } else { ! throw new QueryException("expecting 'elements' or 'indices' after " + currentProperty + '.'); } } --- 449,457 ---- String[] cols = memberPersister.getElementColumnNames(); if ( cols.length!=1 ) throw new QueryException("composite collection element in minElement"); ! collectionElementColumns = new String[] { "min(" + cols[0] + StringHelper.CLOSE_PAREN }; collectionElementType = memberPersister.getElementType(); } else { ! throw new QueryException("expecting 'elements' or 'indices' after " + currentProperty + StringHelper.DOT); } } Index: PreprocessingParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/PreprocessingParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PreprocessingParser.java 12 Jan 2003 14:22:09 -0000 1.6 --- PreprocessingParser.java 20 Jan 2003 12:48:10 -0000 1.7 *************** *** 8,11 **** --- 8,12 ---- import net.sf.hibernate.QueryException; + import net.sf.hibernate.util.StringHelper; /** *************** *** 84,96 **** //handle HQL2 collection syntax if ( currentCollectionProp!=null ) { ! if ( "(".equals(token) ) { return; } ! else if ( ")".equals(token) ) { currentCollectionProp=null; return; } else { ! token+='.'+currentCollectionProp; } } --- 85,97 ---- //handle HQL2 collection syntax if ( currentCollectionProp!=null ) { ! if ( StringHelper.OPEN_PAREN.equals(token) ) { return; } ! else if ( StringHelper.CLOSE_PAREN.equals(token) ) { currentCollectionProp=null; return; } else { ! token+=StringHelper.DOT+currentCollectionProp; } } Index: QueryTranslator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/QueryTranslator.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** QueryTranslator.java 18 Jan 2003 09:57:36 -0000 1.7 --- QueryTranslator.java 20 Jan 2003 12:48:10 -0000 1.8 *************** *** 30,36 **** import net.sf.hibernate.loader.Loader; import net.sf.hibernate.loader.OuterJoinLoader; ! import net.sf.hibernate.loader.OuterJoinLoader.OuterJoinableAssociation; import net.sf.hibernate.persister.Loadable; import net.sf.hibernate.persister.Queryable; import net.sf.hibernate.type.EntityType; import net.sf.hibernate.type.Type; --- 30,38 ---- import net.sf.hibernate.loader.Loader; import net.sf.hibernate.loader.OuterJoinLoader; ! //import net.sf.hibernate.loader.OuterJoinLoader; ! //import net.sf.hibernate.loader.OuterJoinLoader.OuterJoinableAssociation; import net.sf.hibernate.persister.Loadable; import net.sf.hibernate.persister.Queryable; + import net.sf.hibernate.sql.OuterJoinFragment; import net.sf.hibernate.type.EntityType; import net.sf.hibernate.type.Type; *************** *** 74,79 **** dontSpace.add("!<"); dontSpace.add("!>"); ! dontSpace.add("("); //for MySQL ! dontSpace.add(")"); } private final HashMap typeMap = new HashMap(); --- 76,81 ---- dontSpace.add("!<"); dontSpace.add("!>"); ! dontSpace.add(StringHelper.OPEN_PAREN); //for MySQL ! dontSpace.add(StringHelper.CLOSE_PAREN); } private final HashMap typeMap = new HashMap(); *************** *** 253,261 **** String createNameFor(Class type) { String typeName = type.getName(); ! return prefix( StringHelper.unqualify(typeName) ) + nextCount() + '_'; } String createNameForCollection(String role) { ! return prefix( StringHelper.unqualify(role, "/") ) + nextCount() + '_'; } --- 255,263 ---- String createNameFor(Class type) { String typeName = type.getName(); ! return prefix( StringHelper.unqualify(typeName) ) + nextCount() + StringHelper.UNDERSCORE; } String createNameForCollection(String role) { ! return prefix( StringHelper.unqualify(role, "/") ) + nextCount() + StringHelper.UNDERSCORE; } *************** *** 298,302 **** for ( int i=0; i<imports.length; i++ ) { try { ! return (Queryable) factory.getPersister(imports[i] + '.' + className); } catch (Exception ex) {} --- 300,304 ---- for ( int i=0; i<imports.length; i++ ) { try { ! return (Queryable) factory.getPersister(imports[i] + StringHelper.DOT + className); } catch (Exception ex) {} *************** *** 419,423 **** public static String scalarName(int x, int y) { ! return new StringBuffer().append('x').append(x).append('_').append(y).append('_').toString(); } --- 421,431 ---- public static String scalarName(int x, int y) { ! return new StringBuffer() ! .append('x') ! .append(x) ! .append(StringHelper.UNDERSCORE) ! .append(y) ! .append(StringHelper.UNDERSCORE) ! .toString(); } *************** *** 433,441 **** String outerJoinedProperties=null; ! String outerJoinsAfterFrom=null; ! String outerJoinsAfterWhere=null; String selectProperties; String selectIdentifiers; ! if ( !isShallowQuery() && returnTypes.size()==1 && typeMap.size()==1 && collections.size()==0 ) { OuterJoinLoader ojl = new OuterJoinLoader( factory.getDialect() ); String name = (String) returnTypes.get(0); --- 441,448 ---- String outerJoinedProperties=null; ! OuterJoinFragment outerjoin=null; String selectProperties; String selectIdentifiers; ! if ( !isShallowQuery() && returnTypes.size()==1 && typeMap.size()==1 ) { OuterJoinLoader ojl = new OuterJoinLoader( factory.getDialect() ); String name = (String) returnTypes.get(0); *************** *** 446,462 **** String[] ojsuffixes = new String[joins]; ojl.setSuffixed(ojsuffixes); ! for ( int i=0; i<joins; i++ ) ojsuffixes[i] = Integer.toString(i) + '_'; ! selectProperties = persister.propertySelectClauseFragment(name, ""); ! selectIdentifiers = persister.selectIdentifierString(name, ""); outerJoinedProperties = ojl.selectString(associations); ! outerJoinsAfterFrom = ojl.outerJoinsAfterFrom(associations); ! outerJoinsAfterWhere = ojl.outerJoinsAfterWhere(associations); persisters = new Queryable[joins+1]; suffixes = new String[joins+1]; persisters[joins] = persister; ! suffixes[joins] = ""; for ( int i=0; i<joins; i++ ) { ! suffixes[i] = Integer.toString(i) + '_'; ! persisters[i] = (Queryable) ( (OuterJoinableAssociation) associations.get(i) ).subpersister; //TODO: dont like the typecast to Queryable } } --- 453,468 ---- String[] ojsuffixes = new String[joins]; ojl.setSuffixed(ojsuffixes); ! for ( int i=0; i<joins; i++ ) ojsuffixes[i] = Integer.toString(i) + StringHelper.UNDERSCORE; ! selectProperties = persister.propertySelectClauseFragment(name, StringHelper.EMPTY_STRING); ! selectIdentifiers = persister.identifierSelectClauseFragment(name, StringHelper.EMPTY_STRING); outerJoinedProperties = ojl.selectString(associations); ! outerjoin = ojl.outerJoins(associations); persisters = new Queryable[joins+1]; suffixes = new String[joins+1]; persisters[joins] = persister; ! suffixes[joins] = StringHelper.EMPTY_STRING; for ( int i=0; i<joins; i++ ) { ! suffixes[i] = Integer.toString(i) + StringHelper.UNDERSCORE; ! persisters[i] = (Queryable) ( (OuterJoinLoader.OuterJoinableAssociation) associations.get(i) ).subpersister; //TODO: dont like the typecast to Queryable } } *************** *** 468,472 **** if ( !isName(name) ) throw new QueryException("unknown type: " + name); persisters[i] = getPersisterForName(name); ! suffixes[i] = (size==1) ? "" : Integer.toString(i) + '_'; } selectProperties = renderPropertiesSelect(); --- 474,478 ---- if ( !isName(name) ) throw new QueryException("unknown type: " + name); persisters[i] = getPersisterForName(name); ! suffixes[i] = (size==1) ? StringHelper.EMPTY_STRING : Integer.toString(i) + StringHelper.UNDERSCORE; } selectProperties = renderPropertiesSelect(); *************** *** 481,488 **** if ( outerJoinedProperties!=null && outerJoinedProperties.length() > 0 ) selectPropertiesString += ", " + outerJoinedProperties; //TODO: for some dialiects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings ! fromWhereString = renderFromClause(); ! if (outerJoinsAfterFrom!=null) fromWhereString += outerJoinsAfterFrom; ! if (outerJoinsAfterWhere!=null) fromWhereString += outerJoinsAfterWhere; ! fromWhereString += renderWhereClause(); if ( scalarTypes.size()!=size ) { --- 487,491 ---- if ( outerJoinedProperties!=null && outerJoinedProperties.length() > 0 ) selectPropertiesString += ", " + outerJoinedProperties; //TODO: for some dialiects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings ! fromWhereString = renderFromClause(outerjoin) + renderWhereClause(outerjoin); if ( scalarTypes.size()!=size ) { *************** *** 523,529 **** for ( int k=0; k<size; k++ ) { String name = (String) returnTypes.get(k); ! String suffix = size==1 ? "" : Integer.toString(k) + '_'; ! buf.append( persisters[k].selectIdentifierString(name, suffix) ); ! if ( k!=size-1 ) buf.append(", "); } --- 526,532 ---- for ( int k=0; k<size; k++ ) { String name = (String) returnTypes.get(k); ! String suffix = size==1 ? StringHelper.EMPTY_STRING : Integer.toString(k) + StringHelper.UNDERSCORE; ! buf.append( persisters[k].identifierSelectClauseFragment(name, suffix) ); ! if ( k!=size-1 ) buf.append(StringHelper.COMMA_SPACE); } *************** *** 540,544 **** if ( token.lastIndexOf(".") > 0 ) { //ie. it is of form "foo.bar", not of form "asc" or "desc" ! buf.append(", ").append(token); } } --- 543,547 ---- if ( token.lastIndexOf(".") > 0 ) { //ie. it is of form "foo.bar", not of form "asc" or "desc" ! buf.append(StringHelper.COMMA_SPACE).append(token); } } *************** *** 551,555 **** int size = returnTypes.size(); for ( int k=0; k<size; k++ ) { ! String suffix = (size==1) ? "" : Integer.toString(k) + '_'; String name = (String) returnTypes.get(k) ; buf.append( persisters[k].propertySelectClauseFragment(name, suffix) ); --- 554,558 ---- int size = returnTypes.size(); for ( int k=0; k<size; k++ ) { ! String suffix = (size==1) ? StringHelper.EMPTY_STRING : Integer.toString(k) + StringHelper.UNDERSCORE; String name = (String) returnTypes.get(k) ; buf.append( persisters[k].propertySelectClauseFragment(name, suffix) ); *************** *** 578,584 **** String[] names = persisters[k].getIdentifierColumnNames(); for (int i=0; i<names.length; i++) { ! buf.append( returnTypes.get(k) ).append('.').append( names[i] ); if (!isSubselect) buf.append(" as ").append( scalarName(k, i) ); ! if (i!=names.length-1 || k!=size-1 ) buf.append(", "); } --- 581,587 ---- String[] names = persisters[k].getIdentifierColumnNames(); for (int i=0; i<names.length; i++) { ! buf.append( returnTypes.get(k) ).append(StringHelper.DOT).append( names[i] ); if (!isSubselect) buf.append(" as ").append( scalarName(k, i) ); ! if (i!=names.length-1 || k!=size-1 ) buf.append(StringHelper.COMMA_SPACE); } *************** *** 596,600 **** String token = (String) next; String lc = token.toLowerCase(); ! if ( lc.equals(", ") ) { if (nolast) { nolast=false; --- 599,603 ---- String token = (String) next; String lc = token.toLowerCase(); ! if ( lc.equals(StringHelper.COMMA_SPACE) ) { if (nolast) { nolast=false; *************** *** 615,619 **** buf.append(tokens[i]); if (!isSubselect) buf.append(" as ").append( scalarName(c, i) ); ! if (i!=tokens.length-1) buf.append(", "); } c++; --- 618,622 ---- buf.append(tokens[i]); if (!isSubselect) buf.append(" as ").append( scalarName(c, i) ); ! if (i!=tokens.length-1) buf.append(StringHelper.COMMA_SPACE); } c++; *************** *** 627,631 **** } ! private String renderFromClause() throws QueryException, MappingException { //FROM StringBuffer buf = new StringBuffer(120) --- 630,634 ---- } ! private String renderFromClause(OuterJoinFragment outerjoin) throws QueryException, MappingException { //FROM StringBuffer buf = new StringBuffer(120) *************** *** 637,644 **** Queryable p = getPersisterForName(name); buf.append(' ') ! .append( p.fromClauseFragment(name, true) ); if ( iter.hasNext() || collections.size()!=0 ) buf.append(','); } iter = collections.entrySet().iterator(); while ( iter.hasNext() ) { --- 640,649 ---- Queryable p = getPersisterForName(name); buf.append(' ') ! .append( p.fromClauseFragment( name, true, returnTypes.contains(name) && !isShallowQuery() ) ); if ( iter.hasNext() || collections.size()!=0 ) buf.append(','); } + if (outerjoin!=null) buf.append( outerjoin.toFromFragmentString() ); + iter = collections.entrySet().iterator(); while ( iter.hasNext() ) { *************** *** 655,659 **** } ! private String renderWhereClause() throws QueryException, MappingException { Iterator iter = typeMap.keySet().iterator(); --- 660,664 ---- } ! private String renderWhereClause(OuterJoinFragment outerjoin) throws QueryException, MappingException { Iterator iter = typeMap.keySet().iterator(); *************** *** 667,671 **** //render the " and foo.class in ( 'Foo', 'Bar' ) " bit ! String where = p.getQueryWhereClause(name); if ( where!=null ) { if (!first) inClassWheres.append(" AND "); --- 672,676 ---- //render the " and foo.class in ( 'Foo', 'Bar' ) " bit ! String where = p.getQueryWhereClause( name, returnTypes.contains(name) && !isShallowQuery() ); if ( where!=null ) { if (!first) inClassWheres.append(" AND "); *************** *** 735,738 **** --- 740,747 ---- } + /** + * Is this query called by scroll() or iterate()? + * @return true if it is, false if it is called by find() or list() + */ public boolean isShallowQuery() { return shallowQuery; *************** *** 775,779 **** if ( persister.isOneToMany() ) { join.append(elementName) ! .append('.') .append( keyColumnNames[0] ) .append(" = ?"); --- 784,788 ---- if ( persister.isOneToMany() ) { join.append(elementName) ! .append(StringHelper.DOT) .append( keyColumnNames[0] ) .append(" = ?"); *************** *** 783,787 **** addCollection(collectionName, collectionRole); join.append(collectionName) ! .append('.') .append( keyColumnNames[0] ) .append(" = ?"); --- 792,796 ---- addCollection(collectionName, collectionRole); join.append(collectionName) ! .append(StringHelper.DOT) .append( keyColumnNames[0] ) .append(" = ?"); *************** *** 792,800 **** join.append(" and ") .append(collectionName) ! .append('.') .append( eltColumnNames[i] ) .append('=') .append(elementName) ! .append('.') .append( idColumnNames[i] ); } --- 801,809 ---- join.append(" and ") .append(collectionName) ! .append(StringHelper.DOT) .append( eltColumnNames[i] ) .append('=') .append(elementName) ! .append(StringHelper.DOT) .append( idColumnNames[i] ); } *************** *** 870,874 **** public static String[] concreteQueries(String query, SessionFactoryImplementor factory) { ! StringTokenizer tokens = new StringTokenizer(query, ", "); ArrayList placeholders = new ArrayList(); ArrayList replacements = new ArrayList(); --- 879,883 ---- public static String[] concreteQueries(String query, SessionFactoryImplementor factory) { ! StringTokenizer tokens = new StringTokenizer(query, StringHelper.COMMA_SPACE); ArrayList placeholders = new ArrayList(); ArrayList replacements = new ArrayList(); *************** *** 905,909 **** for (int i=0; i<imports.length; i++) { try { ! return ReflectHelper.classForName( imports[i] + '.' + name ); } catch (Exception ex) {} --- 914,918 ---- for (int i=0; i<imports.length; i++) { try { ! return ReflectHelper.classForName( imports[i] + StringHelper.DOT + name ); } catch (Exception ex) {} Index: SelectParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/SelectParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SelectParser.java 5 Jan 2003 02:11:21 -0000 1.3 --- SelectParser.java 20 Jan 2003 12:48:11 -0000 1.4 *************** *** 7,10 **** --- 7,11 ---- import net.sf.hibernate.Hibernate; import net.sf.hibernate.QueryException; + import net.sf.hibernate.util.StringHelper; /** *************** *** 52,61 **** } ! if ( token.equals(",") ) { if (ready) throw new QueryException("alias or expression expected in SELECT"); ! q.appendScalarSelectToken(", "); ready=true; } ! else if ( "(".equals(token) ) { if (aggregate) { q.appendScalarSelectToken(token); --- 53,62 ---- } ! if ( token.equals(StringHelper.COMMA) ) { if (ready) throw new QueryException("alias or expression expected in SELECT"); ! q.appendScalarSelectToken(StringHelper.COMMA_SPACE); ready=true; } ! else if ( StringHelper.OPEN_PAREN.equals(token) ) { if (aggregate) { q.appendScalarSelectToken(token); *************** *** 66,70 **** ready = true; } ! else if ( ")".equals(token) ) { if (aggregate && ready) { q.appendScalarSelectToken(token); --- 67,71 ---- ready = true; } ! else if ( StringHelper.CLOSE_PAREN.equals(token) ) { if (aggregate && ready) { q.appendScalarSelectToken(token); Index: WhereParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/WhereParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WhereParser.java 5 Jan 2003 02:11:21 -0000 1.3 --- WhereParser.java 20 Jan 2003 12:48:11 -0000 1.4 *************** *** 47,56 **** expressionTerminators.add("and"); expressionTerminators.add("or"); ! expressionTerminators.add(")"); //expressionTerminators.add(","); // deliberately excluded expressionOpeners.add("and"); expressionOpeners.add("or"); ! expressionOpeners.add("("); //expressionOpeners.add(","); // deliberately excluded --- 47,56 ---- expressionTerminators.add("and"); expressionTerminators.add("or"); ! expressionTerminators.add(StringHelper.CLOSE_PAREN); //expressionTerminators.add(","); // deliberately excluded expressionOpeners.add("and"); expressionOpeners.add("or"); ! expressionOpeners.add(StringHelper.OPEN_PAREN); //expressionOpeners.add(","); // deliberately excluded *************** *** 230,234 **** subselect = new StringBuffer(20); } ! if ( inSubselect && token.equals(")") ) { bracketsSinceSelect--; --- 230,234 ---- subselect = new StringBuffer(20); } ! if ( inSubselect && token.equals(StringHelper.CLOSE_PAREN) ) { bracketsSinceSelect--; *************** *** 247,251 **** } if (inSubselect) { ! if ( token.equals("(") ) bracketsSinceSelect++; subselect.append(token).append(' '); return; --- 247,251 ---- } if (inSubselect) { ! if ( token.equals(StringHelper.OPEN_PAREN) ) bracketsSinceSelect++; subselect.append(token).append(' '); return; *************** *** 297,301 **** public void start(QueryTranslator q) throws QueryException { ! token("(", q); } --- 297,301 ---- public void start(QueryTranslator q) throws QueryException { ! token(StringHelper.OPEN_PAREN, q); } *************** *** 309,313 **** addToCurrentJoin( element.indexValue.toString() ); } ! token(")", q); } --- 309,313 ---- addToCurrentJoin( element.indexValue.toString() ); } ! token(StringHelper.CLOSE_PAREN, q); } *************** *** 327,331 **** /*int count = ( (Integer) unaryCounts.removeLast() ).intValue(); for ( int i=0; i<count; i++ ) { //to allow not not, not not not, etc... ! appendToken(q, ")"); }*/ --- 327,331 ---- /*int count = ( (Integer) unaryCounts.removeLast() ).intValue(); for ( int i=0; i<count; i++ ) { //to allow not not, not not not, etc... ! appendToken(q, StringHelper.CLOSE); }*/ *************** *** 339,343 **** if ( ( (Boolean) nots.removeLast() ).booleanValue() ) negated = !negated; ! if ( !")".equals(lcToken) ) appendToken(q, ")"); } --- 339,343 ---- if ( ( (Boolean) nots.removeLast() ).booleanValue() ) negated = !negated; ! if ( !StringHelper.CLOSE_PAREN.equals(lcToken) ) appendToken(q, StringHelper.CLOSE_PAREN); } *************** *** 347,351 **** booleanTests.addLast(Boolean.FALSE); joins.addLast( new StringBuffer() ); ! if ( !"(".equals(lcToken) ) appendToken(q, "("); } --- 347,351 ---- booleanTests.addLast(Boolean.FALSE); joins.addLast( new StringBuffer() ); ! if ( !StringHelper.OPEN_PAREN.equals(lcToken) ) appendToken(q, StringHelper.OPEN_PAREN); } *************** *** 354,358 **** Integer count = new Integer( ( (Integer) unaryCounts.removeLast() ).intValue() + 1 ); unaryCounts.addLast(count); ! appendToken(q, "("); }*/ --- 354,358 ---- Integer count = new Integer( ( (Integer) unaryCounts.removeLast() ).intValue() + 1 ); unaryCounts.addLast(count); ! appendToken(q, StringHelper.OPEN); }*/ *************** *** 365,372 **** pathExpressionParser.end(q); if ( pathExpressionParser.isCollectionValued() ) { ! openExpression(q, ""); appendToken( q, pathExpressionParser.getCollectionSubquery(collectionJoin) ); q.addIdentifierSpace( pathExpressionParser.getCollectionTable() ); ! closeExpression(q, ""); collectionJoin = null; } --- 365,372 ---- pathExpressionParser.end(q); if ( pathExpressionParser.isCollectionValued() ) { ! openExpression(q, StringHelper.EMPTY_STRING); appendToken( q, pathExpressionParser.getCollectionSubquery(collectionJoin) ); q.addIdentifierSpace( pathExpressionParser.getCollectionTable() ); ! closeExpression(q, StringHelper.EMPTY_STRING); collectionJoin = null; } *************** *** 398,402 **** Object constant; if ( ! token.indexOf('.')>-1 && ( constant=ReflectHelper.getConstantValue(token) )!=null ) { --- 398,402 ---- Object constant; if ( ! token.indexOf(StringHelper.DOT)>-1 && ( constant=ReflectHelper.getConstantValue(token) )!=null ) { |