From: Kevin W. <kev...@us...> - 2004-12-31 18:23:31
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28087 Modified Files: FromParser.cs FromPathExpressionParser.cs GroupByParser.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: GroupByParser.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/GroupByParser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GroupByParser.cs 14 Apr 2004 11:35:53 -0000 1.4 --- GroupByParser.cs 31 Dec 2004 18:23:05 -0000 1.5 *************** *** 1,50 **** - using System; - using System.Collections; - using NHibernate; using NHibernate.Util; ! namespace NHibernate.Hql { - /// <summary> /// Parses the GROUP BY clause of an aggregate query /// </summary> ! public class GroupByParser : IParser { //this is basically a copy/paste of OrderByParser ... might be worth refactoring ! // 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 ! // The reason for this is SQL doesn't let you sort by an expression you are // not returning in the result set. ! private PathExpressionParser pathExpressionParser = new PathExpressionParser(); ! ! public void Token(string token, QueryTranslator q) { ! ! if (q.IsName(StringHelper.Root(token))) { ! ParserHelper.Parse(pathExpressionParser, q.Unalias(token), ParserHelper.PathSeparators, q); ! q.AppendGroupByToken(pathExpressionParser.WhereColumn); ! pathExpressionParser.AddAssociation(q); ! } ! else { ! q.AppendGroupByToken(token); } } ! ! public void Start(QueryTranslator q) { } ! ! public void End(QueryTranslator q) { } public GroupByParser() { --- 1,59 ---- using NHibernate.Util; ! namespace NHibernate.Hql { /// <summary> /// Parses the GROUP BY clause of an aggregate query /// </summary> ! public class GroupByParser : IParser { //this is basically a copy/paste of OrderByParser ... might be worth refactoring ! // 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 ! // The reason for this is SQL doesn't let you sort by an expression you are // not returning in the result set. ! private PathExpressionParser pathExpressionParser = new PathExpressionParser(); ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="token"></param> ! /// <param name="q"></param> ! public void Token( string token, QueryTranslator q ) { ! if( q.IsName( StringHelper.Root( token ) ) ) { ! ParserHelper.Parse( pathExpressionParser, q.Unalias( token ), ParserHelper.PathSeparators, q ); ! q.AppendGroupByToken( pathExpressionParser.WhereColumn ); ! pathExpressionParser.AddAssociation( q ); ! } ! else { ! q.AppendGroupByToken( token ); } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public void Start( QueryTranslator q ) { } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public void End( QueryTranslator q ) { } + /// <summary></summary> public GroupByParser() { Index: FromParser.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/FromParser.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** FromParser.cs 20 Aug 2004 17:39:02 -0000 1.11 --- FromParser.cs 31 Dec 2004 18:23:05 -0000 1.12 *************** *** 1,17 **** - using System; using System.Collections; - - using NHibernate; using NHibernate.Persister; using NHibernate.SqlCommand; using NHibernate.Util; ! namespace NHibernate.Hql { ! /// <summary> /// Parses the from clause of a hibernate query, looking for tables and /// aliases for the SQL query. /// </summary> ! public class FromParser : IParser { private PathExpressionParser peParser = new FromPathExpressionParser(); private string entityName; --- 1,15 ---- using System.Collections; using NHibernate.Persister; using NHibernate.SqlCommand; using NHibernate.Util; ! namespace NHibernate.Hql ! { /// <summary> /// Parses the from clause of a hibernate query, looking for tables and /// aliases for the SQL query. /// </summary> ! public class FromParser : IParser ! { private PathExpressionParser peParser = new FromPathExpressionParser(); private string entityName; *************** *** 25,115 **** private bool afterJoinType; private bool afterFetch; ! private SqlCommand.JoinType joinType = SqlCommand.JoinType.None; private static IDictionary joinTypes = new Hashtable(); ! static FromParser() { ! joinTypes.Add( "left", SqlCommand.JoinType.LeftOuterJoin ); ! joinTypes.Add( "right", SqlCommand.JoinType.RightOuterJoin ); ! joinTypes.Add( "full", SqlCommand.JoinType.FullJoin ); ! joinTypes.Add( "inner", SqlCommand.JoinType.InnerJoin ); } ! ! public void Token(string token, QueryTranslator q) { ! // start by looking for HQL keywords.... string lcToken = token.ToLower(); ! if ( lcToken.Equals(StringHelper.Comma) ) { ! if ( !(expectingJoin|expectingAs) ) throw new QueryException("unexpected token: ,"); expectingJoin = false; expectingAs = false; ! } ! else if ( lcToken.Equals("join") ) { ! if (!afterJoinType) { ! if ( !(expectingJoin|expectingAs) ) throw new QueryException("unexpected token: join"); // inner joings can be abbreviated to 'join' joinType = JoinType.InnerJoin; expectingJoin = false; expectingAs = false; ! } ! else { afterJoinType = false; } ! } ! else if ( lcToken.Equals("fetch") ) { ! if ( q.IsShallowQuery ) throw new QueryException("fetch may not be used with scroll() or iterate()"); ! if (joinType==JoinType.None) throw new QueryException("unexpected token: fetch"); ! if (joinType==JoinType.FullJoin || joinType==JoinType.RightOuterJoin) ! throw new QueryException("fetch may only be used with inner join or left outer join"); afterFetch = true; } ! else if ( lcToken.Equals("outer") ) { // 'outer' is optional and is ignored) ! if ( !afterJoinType || (joinType!=JoinType.LeftOuterJoin && joinType!=JoinType.RightOuterJoin) ) { ! throw new QueryException("unexpected token: outer"); } ! } ! else if ( joinTypes.Contains(lcToken) ) { ! if ( !(expectingJoin|expectingAs) ) throw new QueryException("unexpected token: " + token); ! joinType = (JoinType) joinTypes[lcToken]; afterJoinType = true; expectingJoin = false; expectingAs = false; ! } ! else if (lcToken.Equals("class")) { ! if (!afterIn) throw new QueryException("unexpected token: class"); ! if (joinType!=JoinType.None) throw new QueryException("outer or full join must be followed by path expression"); afterClass = true; ! } ! else if ( lcToken.Equals("in") ) { ! if (!expectingIn) throw new QueryException("unexpected token: in"); afterIn = true; expectingIn = false; ! } ! else if ( lcToken.Equals("as") ) { ! if (!expectingAs) throw new QueryException("unexpected token: as"); afterAs = true; expectingAs = false; ! } ! else { ! if (afterJoinType) throw new QueryException("join expected: " + token); ! if (expectingJoin) throw new QueryException("unexpected token: " + token); ! if (expectingIn) throw new QueryException("in expected: " + token); // now anything that is not a HQL keyword ! if ( afterAs || expectingAs ) { // (AS is always optional, for consistentcy with SQL/OQL --- 23,158 ---- private bool afterJoinType; private bool afterFetch; ! private JoinType joinType = JoinType.None; private static IDictionary joinTypes = new Hashtable(); ! /// <summary></summary> ! static FromParser() ! { ! joinTypes.Add( "left", JoinType.LeftOuterJoin ); ! joinTypes.Add( "right", JoinType.RightOuterJoin ); ! joinTypes.Add( "full", JoinType.FullJoin ); ! joinTypes.Add( "inner", JoinType.InnerJoin ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="token"></param> ! /// <param name="q"></param> ! public void Token( string token, QueryTranslator q ) ! { // start by looking for HQL keywords.... string lcToken = token.ToLower(); ! if( lcToken.Equals( StringHelper.Comma ) ) { ! if( !( expectingJoin | expectingAs ) ) ! { ! throw new QueryException( "unexpected token: ," ); ! } expectingJoin = false; expectingAs = false; ! } ! else if( lcToken.Equals( "join" ) ) { ! if( !afterJoinType ) { ! if( !( expectingJoin | expectingAs ) ) ! { ! throw new QueryException( "unexpected token: join" ); ! } // inner joings can be abbreviated to 'join' joinType = JoinType.InnerJoin; expectingJoin = false; expectingAs = false; ! } ! else { afterJoinType = false; } ! } ! else if( lcToken.Equals( "fetch" ) ) { ! if( q.IsShallowQuery ) ! { ! throw new QueryException( "fetch may not be used with scroll() or iterate()" ); ! } ! if( joinType == JoinType.None ) ! { ! throw new QueryException( "unexpected token: fetch" ); ! } ! if( joinType == JoinType.FullJoin || joinType == JoinType.RightOuterJoin ) ! { ! throw new QueryException( "fetch may only be used with inner join or left outer join" ); ! } afterFetch = true; } ! else if( lcToken.Equals( "outer" ) ) { // 'outer' is optional and is ignored) ! if( !afterJoinType || ( joinType != JoinType.LeftOuterJoin && joinType != JoinType.RightOuterJoin ) ) { ! throw new QueryException( "unexpected token: outer" ); } ! } ! else if( joinTypes.Contains( lcToken ) ) { ! if( !( expectingJoin | expectingAs ) ) ! { ! throw new QueryException( "unexpected token: " + token ); ! } ! joinType = ( JoinType ) joinTypes[ lcToken ]; afterJoinType = true; expectingJoin = false; expectingAs = false; ! } ! else if( lcToken.Equals( "class" ) ) { ! if( !afterIn ) ! { ! throw new QueryException( "unexpected token: class" ); ! } ! if( joinType != JoinType.None ) ! { ! throw new QueryException( "outer or full join must be followed by path expression" ); ! } afterClass = true; ! } ! else if( lcToken.Equals( "in" ) ) { ! if( !expectingIn ) ! { ! throw new QueryException( "unexpected token: in" ); ! } afterIn = true; expectingIn = false; ! } ! else if( lcToken.Equals( "as" ) ) { ! if( !expectingAs ) ! { ! throw new QueryException( "unexpected token: as" ); ! } afterAs = true; expectingAs = false; ! } ! else { ! if( afterJoinType ) ! { ! throw new QueryException( "join expected: " + token ); ! } ! if( expectingJoin ) ! { ! throw new QueryException( "unexpected token: " + token ); ! } ! if( expectingIn ) ! { ! throw new QueryException( "in expected: " + token ); ! } // now anything that is not a HQL keyword ! if( afterAs || expectingAs ) { // (AS is always optional, for consistentcy with SQL/OQL *************** *** 119,129 **** // AS construction ! if (entityName!=null) { ! q.SetAliasName(token, entityName); ! } ! else { ! throw new QueryException("unexpected: as " + token); } afterAs = false; --- 162,172 ---- // AS construction ! if( entityName != null ) { ! q.SetAliasName( token, entityName ); ! } ! else { ! throw new QueryException( "unexpected: as " + token ); } afterAs = false; *************** *** 131,160 **** expectingAs = false; entityName = null; ! } ! else if (afterIn) { // process the "old" HQL style where aliases appear _first // ie using the IN or IN CLASS constructions ! if (alias==null) throw new QueryException("alias not specified for: " + token); ! if (joinType!=JoinType.None) throw new QueryException("outer or full join must be followed by path expressions"); ! if (afterClass) { // treat it as a classname ! IQueryable p = q.GetPersisterUsingImports(token); ! if (p==null) throw new QueryException("persister not found: " + token); ! q.AddFromClass(alias, p); ! } ! else { // treat it as a path expression peParser.JoinType = JoinType.InnerJoin; peParser.UseThetaStyleJoin = true; ! ParserHelper.Parse(peParser, q.Unalias(token), ParserHelper.PathSeparators, q); ! if ( !peParser.IsCollectionValued ) throw new QueryException("pathe expression did not resolve to collection: " + token); ! string nm = peParser.AddFromCollection(q); ! q.SetAliasName(alias, nm); } --- 174,215 ---- expectingAs = false; entityName = null; ! } ! else if( afterIn ) { // process the "old" HQL style where aliases appear _first // ie using the IN or IN CLASS constructions ! if( alias == null ) ! { ! throw new QueryException( "alias not specified for: " + token ); ! } ! if( joinType != JoinType.None ) ! { ! throw new QueryException( "outer or full join must be followed by path expressions" ); ! } ! if( afterClass ) { // treat it as a classname ! IQueryable p = q.GetPersisterUsingImports( token ); ! if( p == null ) ! { ! throw new QueryException( "persister not found: " + token ); ! } ! q.AddFromClass( alias, p ); ! } ! else { // treat it as a path expression peParser.JoinType = JoinType.InnerJoin; peParser.UseThetaStyleJoin = true; ! ParserHelper.Parse( peParser, q.Unalias( token ), ParserHelper.PathSeparators, q ); ! if( !peParser.IsCollectionValued ) ! { ! throw new QueryException( "pathe expression did not resolve to collection: " + token ); ! } ! string nm = peParser.AddFromCollection( q ); ! q.SetAliasName( alias, nm ); } *************** *** 163,182 **** afterClass = false; expectingJoin = true; ! } ! else { // handle a path expression or class name that appears // at the start, in the "new" HQL style or an alias that // appears at the start in the "old HQL stype ! IQueryable p = q.GetPersisterUsingImports(token); ! if (p!=null) { // starts with the name of a mapped class (new style) ! if (joinType!=JoinType.None) throw new QueryException("outer or full join must be followed by path expression"); entityName = q.CreateNameFor( p.MappedClass ); q.AddFromClass( entityName, p ); expectingAs = true; ! } ! else if ( token.IndexOf('.') < 0 ) { // starts with an alias (old style) --- 218,240 ---- afterClass = false; expectingJoin = true; ! } ! else { // handle a path expression or class name that appears // at the start, in the "new" HQL style or an alias that // appears at the start in the "old HQL stype ! IQueryable p = q.GetPersisterUsingImports( token ); ! if( p != null ) { // starts with the name of a mapped class (new style) ! if( joinType != JoinType.None ) ! { ! throw new QueryException( "outer or full join must be followed by path expression" ); ! } entityName = q.CreateNameFor( p.MappedClass ); q.AddFromClass( entityName, p ); expectingAs = true; ! } ! else if( token.IndexOf( '.' ) < 0 ) { // starts with an alias (old style) *************** *** 184,189 **** alias = token; expectingIn = true; ! } ! else { // starts with a path expression (new style) --- 242,247 ---- alias = token; expectingIn = true; ! } ! else { // starts with a path expression (new style) *************** *** 191,197 **** // force HQL style: from Person p inner join p.cars c //if (joinType==JoinType.None) throw new QueryException("path expression must be preceded by full, left, right or inner join"); ! //allow ODMG OQL style: from Person p, p.cars c ! if (joinType!=JoinType.None) { peParser.JoinType = joinType; --- 249,255 ---- // force HQL style: from Person p inner join p.cars c //if (joinType==JoinType.None) throw new QueryException("path expression must be preceded by full, left, right or inner join"); ! //allow ODMG OQL style: from Person p, p.cars c ! if( joinType != JoinType.None ) { peParser.JoinType = joinType; *************** *** 203,227 **** peParser.UseThetaStyleJoin = q.IsSubquery; ! ParserHelper.Parse(peParser, q.Unalias(token), ParserHelper.PathSeparators, q); ! if ( peParser.IsCollectionValued ) { ! entityName = peParser.AddFromCollection(q); ! } ! else { ! entityName = peParser.AddFromAssociation(q); } joinType = JoinType.None; peParser.JoinType = JoinType.InnerJoin; ! if (afterFetch) { ! ! if ( peParser.IsCollectionValued ) { q.SetCollectionToFetch( peParser.CollectionRole, peParser.CollectionName, peParser.CollectionOwnerName ); } ! q.AddEntityToFetch(entityName); ! afterFetch = false; } --- 261,284 ---- peParser.UseThetaStyleJoin = q.IsSubquery; ! ParserHelper.Parse( peParser, q.Unalias( token ), ParserHelper.PathSeparators, q ); ! if( peParser.IsCollectionValued ) { ! entityName = peParser.AddFromCollection( q ); ! } ! else { ! entityName = peParser.AddFromAssociation( q ); } joinType = JoinType.None; peParser.JoinType = JoinType.InnerJoin; ! if( afterFetch ) { ! if( peParser.IsCollectionValued ) { q.SetCollectionToFetch( peParser.CollectionRole, peParser.CollectionName, peParser.CollectionOwnerName ); } ! q.AddEntityToFetch( entityName ); ! afterFetch = false; } *************** *** 232,237 **** } } ! ! public virtual void Start(QueryTranslator q) { entityName = null; --- 289,298 ---- } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public virtual void Start( QueryTranslator q ) { entityName = null; *************** *** 245,250 **** joinType = JoinType.None; } ! ! public virtual void End(QueryTranslator q) { } --- 306,315 ---- joinType = JoinType.None; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public virtual void End( QueryTranslator q ) { } Index: FromPathExpressionParser.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/FromPathExpressionParser.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FromPathExpressionParser.cs 20 Aug 2004 17:39:02 -0000 1.5 --- FromPathExpressionParser.cs 31 Dec 2004 18:23:05 -0000 1.6 *************** *** 1,38 **** - using System; - using NHibernate.Type; ! namespace NHibernate.Hql { /// <summary> /// FromPathExpressionParser /// </summary> ! public class FromPathExpressionParser : PathExpressionParser { ! ! public override void End(QueryTranslator q) { ! if ( !IsCollectionValued ) { ! IType type = GetPropertyType(q); ! if ( type.IsEntityType ) { // "finish off" the join ! Token(".", q); ! Token(null, q); } ! else if ( type.IsPersistentCollectionType ) { // default to element set if no elements() specified ! Token(".", q); ! Token(CollectionElements, q); } } ! base.End(q); } ! ! protected override void SetExpectingCollectionIndex() { ! throw new QueryException("expecting .elements or .indices after collection path expression in from"); } } --- 1,40 ---- using NHibernate.Type; ! namespace NHibernate.Hql { /// <summary> /// FromPathExpressionParser /// </summary> ! public class FromPathExpressionParser : PathExpressionParser { ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public override void End( QueryTranslator q ) { ! if( !IsCollectionValued ) { ! IType type = GetPropertyType( q ); ! if( type.IsEntityType ) { // "finish off" the join ! Token( ".", q ); ! Token( null, q ); } ! else if( type.IsPersistentCollectionType ) { // default to element set if no elements() specified ! Token( ".", q ); ! Token( CollectionElements, q ); } } ! base.End( q ); } ! ! /// <summary></summary> ! protected override void SetExpectingCollectionIndex() { ! throw new QueryException( "expecting .elements or .indices after collection path expression in from" ); } } |