Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql In directory sc8-pr-cvs1:/tmp/cvs-serv14211/src/net/sf/hibernate/hql Modified Files: ClauseParser.java FilterTranslator.java FromParser.java GroupByParser.java HavingParser.java OrderByParser.java Parser.java ParserHelper.java PathExpressionParser.java PreprocessingParser.java QueryTranslator.java SelectParser.java SelectPathExpressionParser.java WhereParser.java Log Message: reformatted code with beautiful, shiny, happy TABS! improved an exception Index: ClauseParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/ClauseParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ClauseParser.java 1 Jan 2003 13:54:23 -0000 1.1.1.1 --- ClauseParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 22,29 **** String lcToken = token.toLowerCase(); ! if ( byExpected && !lcToken.equals("by") ) ! throw new QueryException("BY expected after GROUP or ORDER: " + token); - if ( !enableSubselect && lcToken.equals("select") ) { selectTokens = new ArrayList(); --- 22,29 ---- String lcToken = token.toLowerCase(); ! if ( byExpected && !lcToken.equals("by") ) ! throw new QueryException("BY expected after GROUP or ORDER: " + token); ! if ( !enableSubselect && lcToken.equals("select") ) { selectTokens = new ArrayList(); *************** *** 57,61 **** byExpected = true; } ! else if ( lcToken.equals("by") ) { if ( !byExpected ) throw new QueryException("GROUP or ORDER expected before BY"); child.start(q); --- 57,61 ---- byExpected = true; } ! else if ( lcToken.equals("by") ) { if ( !byExpected ) throw new QueryException("GROUP or ORDER expected before BY"); child.start(q); *************** *** 78,93 **** private void endChild(QueryTranslator q) throws QueryException { ! if (child==null) { //null child could occur for no from clause in a filter cacheSelectTokens = false; } else { ! child.end(q); } } ! public void start(QueryTranslator q) { } ! public void end(QueryTranslator q) throws QueryException { endChild(q); --- 78,93 ---- private void endChild(QueryTranslator q) throws QueryException { ! if (child==null) { //null child could occur for no from clause in a filter cacheSelectTokens = false; } else { ! child.end(q); } } ! public void start(QueryTranslator q) { } ! public void end(QueryTranslator q) throws QueryException { endChild(q); *************** *** 105,109 **** cacheSelectTokens = false; } ! } --- 105,112 ---- cacheSelectTokens = false; } ! } + + + Index: FilterTranslator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/FilterTranslator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** FilterTranslator.java 1 Jan 2003 13:54:23 -0000 1.1.1.1 --- FilterTranslator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 17,30 **** * times. Subsequent invocations are no-ops. */ ! public synchronized void compile(String collectionRole, SessionFactoryImplementor factory, String queryString, Map replacements, boolean scalar) ! throws QueryException, MappingException { if (!compiled) { this.factory = factory; // yick! addFromCollection("this", collectionRole); ! super.compile(factory, queryString, replacements, scalar); } } - } --- 17,33 ---- * times. Subsequent invocations are no-ops. */ ! public synchronized void compile(String collectionRole, SessionFactoryImplementor factory, String queryString, Map replacements, boolean scalar) ! throws QueryException, MappingException { if (!compiled) { this.factory = factory; // yick! addFromCollection("this", collectionRole); ! super.compile(factory, queryString, replacements, scalar); } } + + + } + Index: FromParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/FromParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** FromParser.java 1 Jan 2003 13:54:24 -0000 1.1.1.1 --- FromParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 10,22 **** public class FromParser implements Parser { ! private boolean expectingIn; ! private boolean expectingComma; private boolean fromClass; private String name; private PathExpressionParser peParser = new PathExpressionParser(); - - public void token(String token, QueryTranslator q) throws QueryException { String lcToken = token.toLowerCase(); if ( lcToken.equals("class") ) { --- 10,22 ---- public class FromParser implements Parser { ! private boolean expectingIn; ! private boolean expectingComma; private boolean fromClass; private String name; private PathExpressionParser peParser = new PathExpressionParser(); + public void token(String token, QueryTranslator q) throws QueryException { + String lcToken = token.toLowerCase(); if ( lcToken.equals("class") ) { *************** *** 58,72 **** } } ! public void start(QueryTranslator q) { expectingIn = false; ! expectingComma = false; name = null; fromClass = false; } ! public void end(QueryTranslator q) { } ! } --- 58,75 ---- } } ! public void start(QueryTranslator q) { expectingIn = false; ! expectingComma = false; name = null; fromClass = false; } ! public void end(QueryTranslator q) { } ! } + + + Index: GroupByParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/GroupByParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GroupByParser.java 1 Jan 2003 13:54:24 -0000 1.1.1.1 --- GroupByParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 13,17 **** // This uses a PathExpressionParser but notice that compound paths are not valid, ! // only bare names and simple paths: // SELECT p FROM p IN CLASS eg.Person GROUP BY p.Name, p.Address, p --- 13,17 ---- // This uses a PathExpressionParser but notice that compound paths are not valid, ! // only bare names and simple paths: // SELECT p FROM p IN CLASS eg.Person GROUP BY p.Name, p.Address, p *************** *** 21,29 **** private PathExpressionParser pathExpressionParser = new PathExpressionParser(); - - public void token(String token, QueryTranslator q) throws QueryException { if ( q.isName( StringHelper.root(token) ) ) { ! ParserHelper.parse(pathExpressionParser, token, ParserHelper.PATH_SEPERATORS, q); q.appendGroupByToken( pathExpressionParser.getWhereColumn() ); q.addJoin( pathExpressionParser.getWhereJoin() ); --- 21,29 ---- private PathExpressionParser pathExpressionParser = new PathExpressionParser(); + public void token(String token, QueryTranslator q) throws QueryException { + if ( q.isName( StringHelper.root(token) ) ) { ! ParserHelper.parse(pathExpressionParser, token, ParserHelper.PATH_SEPERATORS, q); q.appendGroupByToken( pathExpressionParser.getWhereColumn() ); q.addJoin( pathExpressionParser.getWhereJoin() ); *************** *** 33,43 **** } } ! public void start(QueryTranslator q) throws QueryException { } ! public void end(QueryTranslator q) throws QueryException { } - } \ No newline at end of file --- 33,45 ---- } } ! public void start(QueryTranslator q) throws QueryException { } ! public void end(QueryTranslator q) throws QueryException { } + + + } Index: HavingParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/HavingParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HavingParser.java 1 Jan 2003 13:54:24 -0000 1.1.1.1 --- HavingParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 7,14 **** */ public class HavingParser extends WhereParser { ! void appendToken(QueryTranslator q, String token) { q.appendHavingToken(token); } ! } --- 7,17 ---- */ public class HavingParser extends WhereParser { ! void appendToken(QueryTranslator q, String token) { q.appendHavingToken(token); } ! } + + + Index: OrderByParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/OrderByParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OrderByParser.java 1 Jan 2003 13:54:24 -0000 1.1.1.1 --- OrderByParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 12,16 **** // This uses a PathExpressionParser but notice that compound paths are not valid, ! // only bare names and simple paths: // SELECT p FROM p IN CLASS eg.Person ORDER BY p.Name, p.Address, p --- 12,16 ---- // This uses a PathExpressionParser but notice that compound paths are not valid, ! // only bare names and simple paths: // SELECT p FROM p IN CLASS eg.Person ORDER BY p.Name, p.Address, p *************** *** 20,28 **** private PathExpressionParser pathExpressionParser = new PathExpressionParser(); - - public void token(String token, QueryTranslator q) throws QueryException { if ( q.isName( StringHelper.root(token) ) ) { ! ParserHelper.parse(pathExpressionParser, token, ParserHelper.PATH_SEPERATORS, q); q.appendOrderByToken( pathExpressionParser.getWhereColumn() ); q.addJoin( pathExpressionParser.getWhereJoin() ); --- 20,28 ---- private PathExpressionParser pathExpressionParser = new PathExpressionParser(); + public void token(String token, QueryTranslator q) throws QueryException { + if ( q.isName( StringHelper.root(token) ) ) { ! ParserHelper.parse(pathExpressionParser, token, ParserHelper.PATH_SEPERATORS, q); q.appendOrderByToken( pathExpressionParser.getWhereColumn() ); q.addJoin( pathExpressionParser.getWhereJoin() ); *************** *** 32,42 **** } } ! public void start(QueryTranslator q) throws QueryException { } ! public void end(QueryTranslator q) throws QueryException { } ! } --- 32,45 ---- } } ! public void start(QueryTranslator q) throws QueryException { } ! public void end(QueryTranslator q) throws QueryException { } ! } + + + Index: Parser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/Parser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Parser.java 1 Jan 2003 13:54:24 -0000 1.1.1.1 --- Parser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 17,18 **** --- 17,21 ---- } + + + Index: ParserHelper.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/ParserHelper.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ParserHelper.java 1 Jan 2003 13:54:30 -0000 1.1.1.1 --- ParserHelper.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 9,15 **** public static final String HQL_VARIABLE_PREFIX = ":"; ! ! public static final String HQL_SEPERATORS = " \n\r\f\t,()=<>&|+-=/*'^![]#~"; ! //NOTICE: no " or . since they are part of (compound) identifiers public static final String PATH_SEPERATORS = "."; --- 9,15 ---- public static final String HQL_VARIABLE_PREFIX = ":"; ! ! public static final String HQL_SEPERATORS = " \n\r\f\t,()=<>&|+-=/*'^![]#~"; ! //NOTICE: no " or . since they are part of (compound) identifiers public static final String PATH_SEPERATORS = "."; *************** *** 19,23 **** return whitespace.indexOf(str) > -1; } ! private ParserHelper() { //cannot instantiate --- 19,23 ---- return whitespace.indexOf(str) > -1; } ! private ParserHelper() { //cannot instantiate *************** *** 32,33 **** --- 32,36 ---- } + + + Index: PathExpressionParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/PathExpressionParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PathExpressionParser.java 3 Jan 2003 13:36:00 -0000 1.2 --- PathExpressionParser.java 4 Jan 2003 11:15:28 -0000 1.3 *************** *** 29,33 **** public static final String COLLECTION_MAX_ELEMENT = "maxElement"; public static final String COLLECTION_MIN_ELEMENT = "minElement"; ! private int dotcount; protected String currentName; --- 29,33 ---- public static final String COLLECTION_MAX_ELEMENT = "maxElement"; public static final String COLLECTION_MIN_ELEMENT = "minElement"; ! private int dotcount; protected String currentName; *************** *** 45,63 **** private boolean skippedId; private boolean continuation; ! private void addJoin(String name, String[] rhsCols, QueryTranslator q) throws QueryException { String[] lhsCols = currentColumns(q); for ( int i=0; i<rhsCols.length; i++) { join.append(" and ") ! .append( lhsCols[i] ) ! .append('=') ! .append(name) ! .append('.') ! .append( rhsCols[i] ); } } public String continueFromManyToMany(Class clazz, String[] joinColumns, QueryTranslator q) throws QueryException { ! start(q); continuation=true; currentName = q.createNameFor(clazz); --- 45,63 ---- private boolean skippedId; private boolean continuation; ! private void addJoin(String name, String[] rhsCols, QueryTranslator q) throws QueryException { String[] lhsCols = currentColumns(q); for ( int i=0; i<rhsCols.length; i++) { join.append(" and ") ! .append( lhsCols[i] ) ! .append('=') ! .append(name) ! .append('.') ! .append( rhsCols[i] ); } } public String continueFromManyToMany(Class clazz, String[] joinColumns, QueryTranslator q) throws QueryException { ! start(q); continuation=true; currentName = q.createNameFor(clazz); *************** *** 66,74 **** for ( int i=0; i<joinColumns.length; i++ ) { join.append(" and ") ! .append( joinColumns[i] ) ! .append('=') ! .append(currentName) ! .append('.') ! .append( q.getPersister(clazz).getIdentifierColumnNames()[i] ); } return currentName; --- 66,74 ---- for ( int i=0; i<joinColumns.length; i++ ) { join.append(" and ") ! .append( joinColumns[i] ) ! .append('=') ! .append(currentName) ! .append('.') ! .append( q.getPersister(clazz).getIdentifierColumnNames()[i] ); } return currentName; *************** *** 76,80 **** public String continueFromSubcollection(String role, String[] joinColumns, QueryTranslator q) throws QueryException { ! start(q); continuation=true; collectionName = q.createNameForCollection(role); --- 76,80 ---- public String continueFromSubcollection(String role, String[] joinColumns, QueryTranslator q) throws QueryException { ! start(q); continuation=true; collectionName = q.createNameForCollection(role); *************** *** 84,99 **** CollectionPersister p = q.getCollectionPersister(role); collectionTable = p.getQualifiedTableName(); ! for ( int i=0; i<joinColumns.length; i++ ) { join.append(" and ") ! .append( joinColumns[i] ) ! .append('=') ! .append(collectionName) ! .append('.') ! .append( p.getKeyColumnNames()[i] ); } return collectionName; } ! public void token(String token, QueryTranslator q) throws QueryException { --- 84,99 ---- CollectionPersister p = q.getCollectionPersister(role); collectionTable = p.getQualifiedTableName(); ! for ( int i=0; i<joinColumns.length; i++ ) { join.append(" and ") ! .append( joinColumns[i] ) ! .append('=') ! .append(collectionName) ! .append('.') ! .append( p.getKeyColumnNames()[i] ); } return collectionName; } ! public void token(String token, QueryTranslator q) throws QueryException { *************** *** 112,119 **** else { if ( dotcount==0 ) { ! if (!continuation) { ! if ( !q.isName(token) ) throw new QueryException("undefined alias: " + token); ! currentName=token; ! } } else if (dotcount==1) { --- 112,119 ---- else { if ( dotcount==0 ) { ! if (!continuation) { ! if ( !q.isName(token) ) throw new QueryException("undefined alias: " + token); ! currentName=token; ! } } else if (dotcount==1) { *************** *** 134,138 **** // Do the corresponding RHS Type propertyType = getPropertyType(q); ! if (propertyType==null) { throw new QueryException("unresolved property: " + currentProperty); --- 134,138 ---- // Do the corresponding RHS Type propertyType = getPropertyType(q); ! if (propertyType==null) { throw new QueryException("unresolved property: " + currentProperty); *************** *** 148,161 **** } else { ! if ( propertyType.isEntityType() ) { Class memberClass = ( (EntityType) propertyType ).getPersistentClass(); Queryable memberPersister = q.getPersister(memberClass); ! if ( // if its "id" ! ENTITY_ID.equals(token) || ( //or its the id property name ! memberPersister.hasIdentifierProperty() && ! memberPersister.getIdentifierPropertyName().equals(token) ) ) { --- 148,161 ---- } else { ! if ( propertyType.isEntityType() ) { Class memberClass = ( (EntityType) propertyType ).getPersistentClass(); Queryable memberPersister = q.getPersister(memberClass); ! if ( // if its "id" ! ENTITY_ID.equals(token) || ( //or its the id property name ! memberPersister.hasIdentifierProperty() && ! memberPersister.getIdentifierPropertyName().equals(token) ) ) { *************** *** 194,198 **** else { if (token!=null) throw new QueryException( ! "dereferenced: " + currentProperty ); --- 194,198 ---- else { if (token!=null) throw new QueryException( ! "dereferenced: " + currentProperty ); *************** *** 200,204 **** } ! } } --- 200,204 ---- } ! } } *************** *** 210,216 **** } else { ! return currentProperty + ! ( skippedId ? '.' + ENTITY_ID : "" ) + ! ( (componentPath==null) ? "" : '.' + componentPath ); } } --- 210,216 ---- } else { ! return currentProperty + ! ( skippedId ? '.' + ENTITY_ID : "" ) + ! ( (componentPath==null) ? "" : '.' + componentPath ); } } *************** *** 259,263 **** } } ! public void end(QueryTranslator q) throws QueryException { if ( isCollectionValued() ) { --- 259,263 ---- } } ! public void end(QueryTranslator q) throws QueryException { if ( isCollectionValued() ) { *************** *** 278,282 **** CollectionPersister memberPersister = q.getCollectionPersister(collectionRole); if ( !memberPersister.hasIndex() ) throw new QueryException("unindexed collection before []"); ! String[] keyCols = memberPersister.getKeyColumnNames(); --- 278,282 ---- CollectionPersister memberPersister = q.getCollectionPersister(collectionRole); if ( !memberPersister.hasIndex() ) throw new QueryException("unindexed collection before []"); ! String[] keyCols = memberPersister.getKeyColumnNames(); *************** *** 286,298 **** if ( indexCols.length!=1 ) throw new QueryException("composite-index appears in []"); join.append(" and ") ! .append(collectionName) ! .append('.') ! .append( indexCols[0] ) ! .append("="); String[] eltCols = memberPersister.getElementColumnNames(); //if ( eltCols.length!=1 ) throw new QueryException("composite-id collection element []"); ! CollectionElement elem = new CollectionElement(); elem.elementColumns = StringHelper.prefix( eltCols, collectionName + '.' ); elem.type = memberPersister.getElementType(); --- 286,298 ---- if ( indexCols.length!=1 ) throw new QueryException("composite-index appears in []"); join.append(" and ") ! .append(collectionName) ! .append('.') ! .append( indexCols[0] ) ! .append("="); String[] eltCols = memberPersister.getElementColumnNames(); //if ( eltCols.length!=1 ) throw new QueryException("composite-id collection element []"); ! CollectionElement elem = new CollectionElement(); elem.elementColumns = StringHelper.prefix( eltCols, collectionName + '.' ); elem.type = memberPersister.getElementType(); *************** *** 309,318 **** setType(q); } ! } //important!! continuation=false; ! } --- 309,318 ---- setType(q); } ! } //important!! continuation=false; ! } *************** *** 356,369 **** return type; } ! public String getCollectionSubquery(String extraJoin) throws QueryException { if (extraJoin!=null) join.append(extraJoin); return new StringBuffer( "SELECT " ) ! .append( StringHelper.join( ", ", collectionElementColumns ) ) ! .append(" FROM ").append(collectionTable).append(' ').append(collectionName) ! .append(" WHERE ").append( join.substring(5).toString() ) // remove initial " and " ! .toString(); } ! public boolean isCollectionValued() { return collectionElementColumns!=null; --- 356,369 ---- return type; } ! public String getCollectionSubquery(String extraJoin) throws QueryException { if (extraJoin!=null) join.append(extraJoin); return new StringBuffer( "SELECT " ) ! .append( StringHelper.join( ", ", collectionElementColumns ) ) ! .append(" FROM ").append(collectionTable).append(' ').append(collectionName) ! .append(" WHERE ").append( join.substring(5).toString() ) // remove initial " and " ! .toString(); } ! public boolean isCollectionValued() { return collectionElementColumns!=null; *************** *** 371,375 **** public void addFromCollection(QueryTranslator q, String elementName) throws QueryException { ! if ( !collectionElementType.isEntityType() ) throw new QueryException( "collection of values in from clause: " + elementName --- 371,375 ---- public void addFromCollection(QueryTranslator q, String elementName) throws QueryException { ! if ( !collectionElementType.isEntityType() ) throw new QueryException( "collection of values in from clause: " + elementName *************** *** 379,383 **** CollectionPersister persister = q.getCollectionPersister(collectionRole); ! if ( persister.isOneToMany() ) { q.addJoin( StringHelper.replace( join.toString(), collectionName, elementName ) ); } --- 379,383 ---- CollectionPersister persister = q.getCollectionPersister(collectionRole); ! if ( persister.isOneToMany() ) { q.addJoin( StringHelper.replace( join.toString(), collectionName, elementName ) ); } *************** *** 388,396 **** for ( int i=0; i<keyColumnNames.length; i++ ) { join.append(" and ") ! .append( collectionElementColumns[i] ) //already qualified ! .append('=') ! .append(elementName) ! .append('.') ! .append( keyColumnNames[i] ); } q.addJoin( join.toString() ); --- 388,396 ---- for ( int i=0; i<keyColumnNames.length; i++ ) { join.append(" and ") ! .append( collectionElementColumns[i] ) //already qualified ! .append('=') ! .append(elementName) ! .append('.') ! .append( keyColumnNames[i] ); } q.addJoin( join.toString() ); *************** *** 454,458 **** } } ! } --- 454,461 ---- } } ! } + + + Index: PreprocessingParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/PreprocessingParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PreprocessingParser.java 1 Jan 2003 13:54:33 -0000 1.1.1.1 --- PreprocessingParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 9,13 **** /** ! * */ public class PreprocessingParser implements Parser { --- 9,13 ---- /** ! * */ public class PreprocessingParser implements Parser { *************** *** 42,46 **** this.replacements=replacements; } ! /** * @see net.sf.hibernate.query.Parser#token(String, QueryTranslator) --- 42,46 ---- this.replacements=replacements; } ! /** * @see net.sf.hibernate.query.Parser#token(String, QueryTranslator) *************** *** 76,81 **** else { String doubleToken = (token.length()>1) ? ! lastToken + ' ' + token : ! lastToken + token; if ( operators.contains( doubleToken.toLowerCase() ) ) { parser.token(doubleToken, q); --- 76,81 ---- else { String doubleToken = (token.length()>1) ? ! lastToken + ' ' + token : ! lastToken + token; if ( operators.contains( doubleToken.toLowerCase() ) ) { parser.token(doubleToken, q); *************** *** 89,93 **** } ! /** * @see net.sf.hibernate.query.Parser#start(QueryTranslator) --- 89,93 ---- } ! /** * @see net.sf.hibernate.query.Parser#start(QueryTranslator) *************** *** 97,101 **** parser.start(q); } ! /** * @see net.sf.hibernate.query.Parser#end(QueryTranslator) --- 97,101 ---- parser.start(q); } ! /** * @see net.sf.hibernate.query.Parser#end(QueryTranslator) *************** *** 105,108 **** parser.end(q); } ! } --- 105,111 ---- parser.end(q); } ! } + + + Index: QueryTranslator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/QueryTranslator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** QueryTranslator.java 3 Jan 2003 13:36:00 -0000 1.2 --- QueryTranslator.java 4 Jan 2003 11:15:28 -0000 1.3 *************** *** 46,50 **** public class QueryTranslator extends Loader { ! private static final HashSet dontSpace = new HashSet(); static { --- 46,50 ---- public class QueryTranslator extends Loader { ! private static final HashSet dontSpace = new HashSet(); static { *************** *** 90,94 **** private final List groupByTokens = new ArrayList(); private final Set identifierSpaces = new HashSet(); ! private Queryable[] persisters; private Type[] types; --- 90,94 ---- private final List groupByTokens = new ArrayList(); private final Set identifierSpaces = new HashSet(); ! private Queryable[] persisters; private Type[] types; *************** *** 109,113 **** private String[] suffixes; ! private static final Log log = LogFactory.getLog(QueryTranslator.class); --- 109,113 ---- private String[] suffixes; ! private static final Log log = LogFactory.getLog(QueryTranslator.class); *************** *** 128,138 **** compile(queryString); } ! ! /** * Compile a "normal" query. This method may be called multiple * times. Subsequent invocations are no-ops. */ ! public synchronized void compile(SessionFactoryImplementor factory, String queryString, Map replacements, boolean scalar) throws QueryException, MappingException { if (!compiled) { this.factory = factory; --- 128,138 ---- compile(queryString); } ! ! /** * Compile a "normal" query. This method may be called multiple * times. Subsequent invocations are no-ops. */ ! public synchronized void compile(SessionFactoryImplementor factory, String queryString, Map replacements, boolean scalar) throws QueryException, MappingException { if (!compiled) { this.factory = factory; *************** *** 142,146 **** } } ! /** * Compile the query (generate the SQL). --- 142,146 ---- } } ! /** * Compile the query (generate the SQL). *************** *** 149,153 **** this.queryString = queryString; ! log.trace("compiling query"); try { --- 149,153 ---- this.queryString = queryString; ! log.trace("compiling query"); try { *************** *** 210,220 **** protected String getSQLString() { String result = new StringBuffer(50) ! .append(selectPropertiesString) ! .append(fromWhereString) ! .toString(); logQuery(queryString, result); return result; } ! /** * Return the SQL for an <tt>iterate()</tt> style query. --- 210,220 ---- protected String getSQLString() { String result = new StringBuffer(50) ! .append(selectPropertiesString) ! .append(fromWhereString) ! .toString(); logQuery(queryString, result); return result; } ! /** * Return the SQL for an <tt>iterate()</tt> style query. *************** *** 223,233 **** protected String getScalarSelectSQL() { String result= new StringBuffer(50) ! .append(scalarSelectString) ! .append(fromWhereString) ! .toString(); logQuery(queryString, result); return result; } ! private String prefix(String s) { if ( s.length()>3 ) { --- 223,233 ---- protected String getScalarSelectSQL() { String result= new StringBuffer(50) ! .append(scalarSelectString) ! .append(fromWhereString) ! .toString(); logQuery(queryString, result); return result; } ! private String prefix(String s) { if ( s.length()>3 ) { *************** *** 432,439 **** String selectPerhapsDistinct = "SELECT "; ! if (distinct) selectPerhapsDistinct += "DISTINCT "; String selectScalars = renderScalarSelect(); scalarSelectString = selectPerhapsDistinct + selectScalars; ! String selectIdentifiers = renderIdentifierSelect(); selectPropertiesString = selectPerhapsDistinct + selectIdentifiers + renderPropertiesSelect(); //TODO: for some dialiects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings --- 432,439 ---- String selectPerhapsDistinct = "SELECT "; ! if (distinct) selectPerhapsDistinct += "DISTINCT "; String selectScalars = renderScalarSelect(); scalarSelectString = selectPerhapsDistinct + selectScalars; ! String selectIdentifiers = renderIdentifierSelect(); selectPropertiesString = selectPerhapsDistinct + selectIdentifiers + renderPropertiesSelect(); //TODO: for some dialiects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings *************** *** 444,448 **** selectPropertiesString += selectScalars; } ! int scalarSize = scalarTypes.size(); types = new Type[scalarSize]; --- 444,448 ---- selectPropertiesString += selectScalars; } ! int scalarSize = scalarTypes.size(); types = new Type[scalarSize]; *************** *** 450,454 **** types[i] = (Type) scalarTypes.get(i); } ! scalarColumnNames = generateColumnNames(types, factory); --- 450,454 ---- types[i] = (Type) scalarTypes.get(i); } ! scalarColumnNames = generateColumnNames(types, factory); *************** *** 464,468 **** addIdentifierSpace( p.getIdentifierSpace() ); } ! } --- 464,468 ---- addIdentifierSpace( p.getIdentifierSpace() ); } ! } *************** *** 483,492 **** private String renderOrderByPropertiesSelect() { StringBuffer buf = new StringBuffer(10); ! //add the columns we are ordering by to the select ID select clause Iterator iter = orderByTokens.iterator(); while ( iter.hasNext() ) { String token = (String) iter.next(); ! if ( token.lastIndexOf(".") > 0 ) { //ie. it is of form "foo.bar", not of form "asc" or "desc" buf.append(", ").append(token); --- 483,492 ---- private String renderOrderByPropertiesSelect() { StringBuffer buf = new StringBuffer(10); ! //add the columns we are ordering by to the select ID select clause Iterator iter = orderByTokens.iterator(); while ( iter.hasNext() ) { String token = (String) iter.next(); ! if ( token.lastIndexOf(".") > 0 ) { //ie. it is of form "foo.bar", not of form "asc" or "desc" buf.append(", ").append(token); *************** *** 521,525 **** int size = returnTypes.size(); for ( int k=0; k<size; k++ ) { ! scalarTypes.add( Hibernate.association( persisters[k].getMappedClass() --- 521,525 ---- int size = returnTypes.size(); for ( int k=0; k<size; k++ ) { ! scalarTypes.add( Hibernate.association( persisters[k].getMappedClass() *************** *** 571,575 **** } if (!isSubselect && !nolast) buf.append(" as ").append( scalarName(c++, 0) ); ! } --- 571,575 ---- } if (!isSubselect && !nolast) buf.append(" as ").append( scalarName(c++, 0) ); ! } *************** *** 580,584 **** //FROM StringBuffer buf = new StringBuffer(120) ! .append(" FROM"); Iterator iter = typeMap.keySet().iterator(); while ( iter.hasNext() ) { --- 580,584 ---- //FROM StringBuffer buf = new StringBuffer(120) ! .append(" FROM"); Iterator iter = typeMap.keySet().iterator(); while ( iter.hasNext() ) { *************** *** 587,591 **** Queryable p = getPersisterForName(name); buf.append(' ') ! .append( p.fromClauseFragment(name, true) ); if ( iter.hasNext() || collections.size()!=0 ) buf.append(','); } --- 587,591 ---- Queryable p = getPersisterForName(name); buf.append(' ') ! .append( p.fromClauseFragment(name, true) ); if ( iter.hasNext() || collections.size()!=0 ) buf.append(','); } *************** *** 606,610 **** private String renderWhereClause() throws QueryException, MappingException { ! Iterator iter = typeMap.keySet().iterator(); StringBuffer inClassWheres = new StringBuffer(50); --- 606,610 ---- private String renderWhereClause() throws QueryException, MappingException { ! Iterator iter = typeMap.keySet().iterator(); StringBuffer inClassWheres = new StringBuffer(50); *************** *** 615,619 **** Queryable p = getPersisterForName(name); addIdentifierSpace( p.getIdentifierSpace() ); ! //render the " and foo.class in ( 'Foo', 'Bar' ) " bit String where = p.getQueryWhereClause(name); --- 615,619 ---- Queryable p = getPersisterForName(name); addIdentifierSpace( p.getIdentifierSpace() ); ! //render the " and foo.class in ( 'Foo', 'Bar' ) " bit String where = p.getQueryWhereClause(name); *************** *** 660,664 **** appendTokens( buf, havingTokens.iterator() ); } ! if ( orderByTokens.size()!=0 ) { //ORDER BY --- 660,664 ---- appendTokens( buf, havingTokens.iterator() ); } ! if ( orderByTokens.size()!=0 ) { //ORDER BY *************** *** 680,688 **** } } ! public Set getQuerySpaces() { return identifierSpaces; } ! public boolean isShallowQuery() { return shallowQuery; --- 680,688 ---- } } ! public Set getQuerySpaces() { return identifierSpaces; } ! public boolean isShallowQuery() { return shallowQuery; *************** *** 697,701 **** this.distinct = distinct; } ! protected CollectionPersister getCollectionPersister() { return null; --- 697,701 ---- this.distinct = distinct; } ! protected CollectionPersister getCollectionPersister() { return null; *************** *** 705,710 **** return suffixes; } ! ! protected void addFromCollection(final String elementName, final String collectionRole) throws QueryException { //q.addCollection(collectionName, collectionRole); --- 705,710 ---- return suffixes; } ! ! protected void addFromCollection(final String elementName, final String collectionRole) throws QueryException { //q.addCollection(collectionName, collectionRole); *************** *** 723,731 **** join.append(" and "); // all conditions must begin with " and " ! if ( persister.isOneToMany() ) { join.append(elementName) ! .append('.') ! .append( keyColumnNames[0] ) ! .append(" = ?"); } else { //many-to-many --- 723,731 ---- join.append(" and "); // all conditions must begin with " and " ! if ( persister.isOneToMany() ) { join.append(elementName) ! .append('.') ! .append( keyColumnNames[0] ) ! .append(" = ?"); } else { //many-to-many *************** *** 733,739 **** addCollection(collectionName, collectionRole); join.append(collectionName) ! .append('.') ! .append( keyColumnNames[0] ) ! .append(" = ?"); String[] idColumnNames = getPersisterForName(elementName).getIdentifierColumnNames(); --- 733,739 ---- addCollection(collectionName, collectionRole); join.append(collectionName) ! .append('.') ! .append( keyColumnNames[0] ) ! .append(" = ?"); String[] idColumnNames = getPersisterForName(elementName).getIdentifierColumnNames(); *************** *** 741,751 **** for ( int i=0; i<idColumnNames.length; i++ ) { join.append(" and ") ! .append(collectionName) ! .append('.') ! .append( eltColumnNames[i] ) ! .append('=') ! .append(elementName) ! .append('.') ! .append( idColumnNames[i] ); } } --- 741,751 ---- for ( int i=0; i<idColumnNames.length; i++ ) { join.append(" and ") ! .append(collectionName) ! .append('.') ! .append( eltColumnNames[i] ) ! .append('=') ! .append(elementName) ! .append('.') ! .append( idColumnNames[i] ); } } *************** *** 768,773 **** pathJoins.put(path, join); } ! ! protected void bindNamedParameters(PreparedStatement ps, Map namedParams, SessionImplementor session) throws SQLException, HibernateException { if (namedParams!=null) { --- 768,773 ---- pathJoins.put(path, join); } ! ! protected void bindNamedParameters(PreparedStatement ps, Map namedParams, SessionImplementor session) throws SQLException, HibernateException { if (namedParams!=null) { *************** *** 780,784 **** for ( int i=0; i<locs.length; i++ ) { typedval.getType().nullSafeSet( ps, typedval.getValue(), locs[i], session ); ! } } } --- 780,784 ---- for ( int i=0; i<locs.length; i++ ) { typedval.getType().nullSafeSet( ps, typedval.getValue(), locs[i], session ); ! } } } *************** *** 786,790 **** public Iterator iterate(Object[] values, Type[] types, RowSelection selection, Map namedParams, SessionImplementor session) throws HibernateException, SQLException { ! PreparedStatement st = prepareQueryStatement( getScalarSelectSQL(), values, types, selection, false, session ); try { --- 786,790 ---- public Iterator iterate(Object[] values, Type[] types, RowSelection selection, Map namedParams, SessionImplementor session) throws HibernateException, SQLException { ! PreparedStatement st = prepareQueryStatement( getScalarSelectSQL(), values, types, selection, false, session ); try { *************** *** 803,807 **** public ScrollableResults scroll(Object[] values, Type[] types, RowSelection selection, Map namedParams, SessionImplementor session) throws HibernateException, SQLException { ! PreparedStatement st = prepareQueryStatement( getScalarSelectSQL(), values, types, selection, true, session ); try { --- 803,807 ---- public ScrollableResults scroll(Object[] values, Type[] types, RowSelection selection, Map namedParams, SessionImplementor session) throws HibernateException, SQLException { ! PreparedStatement st = prepareQueryStatement( getScalarSelectSQL(), values, types, selection, true, session ); try { *************** *** 818,822 **** } } ! public static String[] concreteQueries(String query, SessionFactoryImplementor factory) { StringTokenizer tokens = new StringTokenizer(query, ", "); --- 818,822 ---- } } ! public static String[] concreteQueries(String query, SessionFactoryImplementor factory) { StringTokenizer tokens = new StringTokenizer(query, ", "); *************** *** 875,877 **** --- 875,880 ---- } } + + + Index: SelectParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/SelectParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SelectParser.java 1 Jan 2003 13:54:37 -0000 1.1.1.1 --- SelectParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 27,39 **** countArguments.add("*"); } ! private boolean ready; private boolean aggregate; private boolean count; private boolean first; ! private SelectPathExpressionParser pathExpressionParser = new SelectPathExpressionParser(); private PathExpressionParser aggregatePathExpressionParser = new PathExpressionParser(); ! public void token(String token, QueryTranslator q) throws QueryException { --- 27,39 ---- countArguments.add("*"); } ! private boolean ready; private boolean aggregate; private boolean count; private boolean first; ! private SelectPathExpressionParser pathExpressionParser = new SelectPathExpressionParser(); private PathExpressionParser aggregatePathExpressionParser = new PathExpressionParser(); ! public void token(String token, QueryTranslator q) throws QueryException { *************** *** 99,105 **** if ( aggregatePathExpressionParser.isCollectionValued() ) { ! q.addCollection( ! aggregatePathExpressionParser.getCollectionName(), ! aggregatePathExpressionParser.getCollectionRole() ); } --- 99,105 ---- if ( aggregatePathExpressionParser.isCollectionValued() ) { ! q.addCollection( ! aggregatePathExpressionParser.getCollectionName(), ! aggregatePathExpressionParser.getCollectionRole() ); } *************** *** 111,119 **** if (!ready) throw new QueryException(", expected in SELECT"); ! ParserHelper.parse(pathExpressionParser, token, ParserHelper.PATH_SEPERATORS, q); if ( pathExpressionParser.isCollectionValued() ) { ! q.addCollection( ! pathExpressionParser.getCollectionName(), ! pathExpressionParser.getCollectionRole() ); } --- 111,119 ---- if (!ready) throw new QueryException(", expected in SELECT"); ! ParserHelper.parse(pathExpressionParser, token, ParserHelper.PATH_SEPERATORS, q); if ( pathExpressionParser.isCollectionValued() ) { ! q.addCollection( ! pathExpressionParser.getCollectionName(), ! pathExpressionParser.getCollectionRole() ); } *************** *** 128,132 **** } } ! public void start(QueryTranslator q) { ready=true; --- 128,132 ---- } } ! public void start(QueryTranslator q) { ready=true; *************** *** 135,142 **** count = false; } ! public void end(QueryTranslator q) { } ! } --- 135,145 ---- count = false; } ! public void end(QueryTranslator q) { } ! } + + + Index: SelectPathExpressionParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/SelectPathExpressionParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SelectPathExpressionParser.java 1 Jan 2003 13:54:37 -0000 1.1.1.1 --- SelectPathExpressionParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 23,27 **** throw new QueryException("expecting .elements or .indices after collection path expression in select"); } ! public String getSelectName() { --- 23,27 ---- throw new QueryException("expecting .elements or .indices after collection path expression in select"); } ! public String getSelectName() { *************** *** 29,31 **** --- 29,34 ---- } } + + + Index: WhereParser.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/hql/WhereParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** WhereParser.java 1 Jan 2003 13:54:39 -0000 1.1.1.1 --- WhereParser.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 38,42 **** private PathExpressionParser pathExpressionParser = new PathExpressionParser(); ! private static final Set expressionTerminators = new HashSet(); //tokens that close a sub expression private static final Set expressionOpeners = new HashSet(); //tokens that open a sub expression --- 38,42 ---- private PathExpressionParser pathExpressionParser = new PathExpressionParser(); ! private static final Set expressionTerminators = new HashSet(); //tokens that close a sub expression private static final Set expressionOpeners = new HashSet(); //tokens that open a sub expression *************** *** 199,203 **** PathExpressionParser.CollectionElement element = pathExpressionParser.lastCollectionElement(); ! if ( token.startsWith(".") ) { // the path expression continues after a ] doPathExpression( getElementName(element, q) + token, q ); // careful with this! --- 199,203 ---- PathExpressionParser.CollectionElement element = pathExpressionParser.lastCollectionElement(); ! if ( token.startsWith(".") ) { // the path expression continues after a ] doPathExpression( getElementName(element, q) + token, q ); // careful with this! *************** *** 222,226 **** } ! //Cope with a subselect --- 222,226 ---- } ! //Cope with a subselect *************** *** 247,251 **** } if (inSubselect) { ! if ( token.equals("(") ) bracketsSinceSelect++; subselect.append(token).append(' '); return; --- 247,251 ---- } if (inSubselect) { ! if ( token.equals("(") ) bracketsSinceSelect++; subselect.append(token).append(' '); return; *************** *** 265,279 **** if ( booleanOperators.contains(lcToken) ) { ! booleanTests.removeLast(); ! booleanTests.addLast(Boolean.TRUE); } if ( lcToken.equals("not") ) { ! nots.addLast( ! new Boolean( !( (Boolean) nots.removeLast() ).booleanValue() ) ); negated = !negated; return; //NOTE: early return ! } //process a token, mapping OO path expressions to SQL expressions --- 265,279 ---- if ( booleanOperators.contains(lcToken) ) { ! booleanTests.removeLast(); ! booleanTests.addLast(Boolean.TRUE); } if ( lcToken.equals("not") ) { ! nots.addLast( ! new Boolean( !( (Boolean) nots.removeLast() ).booleanValue() ) ); negated = !negated; return; //NOTE: early return ! } //process a token, mapping OO path expressions to SQL expressions *************** *** 295,303 **** } ! public void start(QueryTranslator q) throws QueryException { token("(", q); } ! public void end(QueryTranslator q) throws QueryException { if (expectingPathContinuation) { --- 295,303 ---- } ! public void start(QueryTranslator q) throws QueryException { token("(", q); } ! public void end(QueryTranslator q) throws QueryException { if (expectingPathContinuation) { *************** *** 317,333 **** if ( booleanTests.size()>0 ) { // the next one up must also be ! booleanTests.removeLast(); ! booleanTests.addLast(Boolean.TRUE); } ! // Add any joins appendToken(q, ( (StringBuffer) joins.removeLast() ).toString() ); ! // finish off any unary operations /*int count = ( (Integer) unaryCounts.removeLast() ).intValue(); for ( int i=0; i<count; i++ ) { //to allow not not, not not not, etc... appendToken(q, ")"); }*/ ! } else { --- 317,333 ---- if ( booleanTests.size()>0 ) { // the next one up must also be ! booleanTests.removeLast(); ! booleanTests.addLast(Boolean.TRUE); } ! // Add any joins appendToken(q, ( (StringBuffer) joins.removeLast() ).toString() ); ! // finish off any unary operations /*int count = ( (Integer) unaryCounts.removeLast() ).intValue(); for ( int i=0; i<count; i++ ) { //to allow not not, not not not, etc... appendToken(q, ")"); }*/ ! } else { *************** *** 341,345 **** if ( !")".equals(lcToken) ) appendToken(q, ")"); } ! private void openExpression(QueryTranslator q, String lcToken) { //unaryCounts.addLast( new Integer(0) ); --- 341,345 ---- if ( !")".equals(lcToken) ) appendToken(q, ")"); } ! private void openExpression(QueryTranslator q, String lcToken) { //unaryCounts.addLast( new Integer(0) ); *************** *** 381,385 **** } } ! private void doToken(String token, QueryTranslator q) throws QueryException { if ( q.isName( StringHelper.root(token) ) ) { //path expression --- 381,385 ---- } } ! private void doToken(String token, QueryTranslator q) throws QueryException { if ( q.isName( StringHelper.root(token) ) ) { //path expression *************** *** 397,403 **** else { Object constant; ! if ( ! token.indexOf('.')>-1 && ! ( constant=ReflectHelper.getConstantValue(token) )!=null ) { Type type; --- 397,403 ---- else { Object constant; ! if ( ! token.indexOf('.')>-1 && ! ( constant=ReflectHelper.getConstantValue(token) )!=null ) { Type type; *************** *** 455,457 **** --- 455,460 ---- } } + + + |