From: Kevin W. <kev...@us...> - 2004-12-31 18:22:44
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27954 Modified Files: OrderByParser.cs ParserHelper.cs PreprocessingParser.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: ParserHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/ParserHelper.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ParserHelper.cs 14 Apr 2004 11:35:53 -0000 1.6 --- ParserHelper.cs 31 Dec 2004 18:22:33 -0000 1.7 *************** *** 1,35 **** - using System; - using NHibernate; using NHibernate.Util; ! namespace NHibernate.Hql { ! public class ParserHelper { ! public const string HqlVariablePrefix = ":"; ! public const string HqlSeparators = " \n\r\f\t,()=<>&|+-=/*'^![]#~\\"; //NOTICE: no " or . since they are part of (compound) identifiers ! public const string PathSeparators = "."; ! public const string Whitespace = " \n\r\f\t"; ! ! public static bool IsWhitespace(string str) { ! return Whitespace.IndexOf(str) > - 1; } ! ! private ParserHelper() { } ! ! public static void Parse(IParser p, string text, string seperators, QueryTranslator q) { ! StringTokenizer tokens = new StringTokenizer(text, seperators, true); ! p.Start(q); ! foreach(string token in tokens) { ! p.Token(token, q); } ! p.End(q); } } --- 1,49 ---- using NHibernate.Util; ! namespace NHibernate.Hql { ! /// <summary></summary> ! public class ParserHelper { ! /// <summary></summary> public const string HqlVariablePrefix = ":"; ! /// <summary></summary> ! public const string HqlSeparators = " \n\r\f\t,()=<>&|+-=/*'^![]#~\\"; //NOTICE: no " or . since they are part of (compound) identifiers ! /// <summary></summary> ! public const string PathSeparators = "."; ! /// <summary></summary> ! public const string Whitespace = " \n\r\f\t"; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="str"></param> ! /// <returns></returns> ! public static bool IsWhitespace( string str ) { ! return Whitespace.IndexOf( str ) > - 1; } ! ! private ParserHelper() { } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="p"></param> ! /// <param name="text"></param> ! /// <param name="seperators"></param> ! /// <param name="q"></param> ! public static void Parse( IParser p, string text, string seperators, QueryTranslator q ) { ! StringTokenizer tokens = new StringTokenizer( text, seperators, true ); ! p.Start( q ); ! foreach( string token in tokens ) { ! p.Token( token, q ); } ! p.End( q ); } } Index: PreprocessingParser.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/PreprocessingParser.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PreprocessingParser.cs 4 Dec 2004 22:41:20 -0000 1.5 --- PreprocessingParser.cs 31 Dec 2004 18:22:33 -0000 1.6 *************** *** 1,20 **** - using System; using System.Collections; using System.Text; - using Iesi.Collections; - using NHibernate.Util; ! namespace NHibernate.Hql { ! /// <summary> ! /// </summary> ! public class PreprocessingParser : IParser { private static ISet operators; private static IDictionary collectionProps; ! static PreprocessingParser() { operators = new HashedSet(); --- 1,17 ---- using System.Collections; using System.Text; using Iesi.Collections; using NHibernate.Util; ! namespace NHibernate.Hql { ! /// <summary></summary> ! public class PreprocessingParser : IParser { private static ISet operators; private static IDictionary collectionProps; ! /// <summary></summary> ! static PreprocessingParser() { operators = new HashedSet(); *************** *** 34,48 **** operators.Add( "not between" ); operators.Add( "not exists" ); ! collectionProps = new Hashtable(); ! collectionProps.Add("elements", "elements"); ! collectionProps.Add("indices", "indices"); ! collectionProps.Add("size", "size"); ! collectionProps.Add("maxindex", "maxIndex"); ! collectionProps.Add("minindex", "minIndex"); ! collectionProps.Add("maxelement", "maxElement"); ! collectionProps.Add("minelement", "minElement"); } ! private IDictionary replacements; private bool quoted; --- 31,45 ---- operators.Add( "not between" ); operators.Add( "not exists" ); ! collectionProps = new Hashtable(); ! collectionProps.Add( "elements", "elements" ); ! collectionProps.Add( "indices", "indices" ); ! collectionProps.Add( "size", "size" ); ! collectionProps.Add( "maxindex", "maxIndex" ); ! collectionProps.Add( "minindex", "minIndex" ); ! collectionProps.Add( "maxelement", "maxElement" ); ! collectionProps.Add( "minelement", "minElement" ); } ! private IDictionary replacements; private bool quoted; *************** *** 51,152 **** private string lastToken; private string currentCollectionProp; ! ! ! public PreprocessingParser(IDictionary replacements) { this.replacements = replacements; } ! ! public void Token(string token, QueryTranslator q) { - //handle quoted strings ! if (quoted) { ! quotedString.Append(token); } ! if ("'".Equals(token)) { ! if (quoted) { token = quotedString.ToString(); ! } ! else { ! quotedString = new StringBuilder(20).Append(token); } quoted = !quoted; } ! if (quoted) return; ! //ignore whitespace ! if (ParserHelper.IsWhitespace(token)) return; ! //do replacements ! string substoken = (string) replacements[token]; ! token = (substoken == null) ? token : substoken; ! //handle HQL2 collection syntax ! if (currentCollectionProp != null) { ! if (StringHelper.OpenParen.Equals(token)) { return; ! } ! else if (StringHelper.ClosedParen.Equals(token)) { currentCollectionProp = null; ! return ; ! } ! else { token += StringHelper.Dot + currentCollectionProp; } } ! else { ! string prop = (string) collectionProps[token.ToLower()]; ! if (prop != null) { currentCollectionProp = prop; ! return ; } } ! ! //handle <=, >=, !=, is not, not between, not in ! if (lastToken == null) { lastToken = token; ! } ! else { ! string doubleToken = (token.Length > 1)? ! lastToken + ' ' + token : lastToken + token; ! if (operators.Contains(doubleToken.ToLower())) { ! parser.Token(doubleToken, q); lastToken = null; ! } ! else { ! parser.Token(lastToken, q); lastToken = token; } } ! } ! ! public virtual void Start(QueryTranslator q) { quoted = false; ! parser.Start(q); } ! ! public virtual void End(QueryTranslator q) { ! if (lastToken != null) parser.Token(lastToken, q); ! parser.End(q); lastToken = null; currentCollectionProp = null; --- 48,173 ---- private string lastToken; private string currentCollectionProp; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="replacements"></param> ! public PreprocessingParser( IDictionary replacements ) { this.replacements = replacements; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="token"></param> ! /// <param name="q"></param> ! public void Token( string token, QueryTranslator q ) { //handle quoted strings ! if( quoted ) { ! quotedString.Append( token ); } ! if( "'".Equals( token ) ) { ! if( quoted ) { token = quotedString.ToString(); ! } ! else { ! quotedString = new StringBuilder( 20 ).Append( token ); } quoted = !quoted; } ! if( quoted ) ! { ! return; ! } ! //ignore whitespace ! if( ParserHelper.IsWhitespace( token ) ) ! { ! return; ! } ! //do replacements ! string substoken = ( string ) replacements[ token ]; ! token = ( substoken == null ) ? token : substoken; ! //handle HQL2 collection syntax ! if( currentCollectionProp != null ) { ! if( StringHelper.OpenParen.Equals( token ) ) { return; ! } ! else if( StringHelper.ClosedParen.Equals( token ) ) { currentCollectionProp = null; ! return; ! } ! else { token += StringHelper.Dot + currentCollectionProp; } } ! else { ! string prop = ( string ) collectionProps[ token.ToLower() ]; ! if( prop != null ) { currentCollectionProp = prop; ! return; } } ! ! //handle <=, >=, !=, is not, not between, not in ! if( lastToken == null ) { lastToken = token; ! } ! else { ! string doubleToken = ( token.Length > 1 ) ? ! lastToken + ' ' + token : lastToken + token; ! if( operators.Contains( doubleToken.ToLower() ) ) { ! parser.Token( doubleToken, q ); lastToken = null; ! } ! else { ! parser.Token( lastToken, q ); lastToken = token; } } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public virtual void Start( QueryTranslator q ) { quoted = false; ! parser.Start( q ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="q"></param> ! public virtual void End( QueryTranslator q ) { ! if( lastToken != null ) ! { ! parser.Token( lastToken, q ); ! } ! parser.End( q ); lastToken = null; currentCollectionProp = null; Index: OrderByParser.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/OrderByParser.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OrderByParser.cs 30 Apr 2004 08:57:59 -0000 1.5 --- OrderByParser.cs 31 Dec 2004 18:22:33 -0000 1.6 *************** *** 1,45 **** - using System; - using System.Collections; using NHibernate.Util; ! namespace NHibernate.Hql ! { /// <summary> /// Parses the ORDER BY clause of a query /// </summary> ! public class OrderByParser : IParser { // 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 ! // 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.AppendOrderByToken(pathExpressionParser.WhereColumn); ! pathExpressionParser.AddAssociation(q); ! } ! else { ! q.AppendOrderByToken(token); } } ! ! public void Start(QueryTranslator q) { } ! ! public void End(QueryTranslator q) { } public OrderByParser() { --- 1,57 ---- using NHibernate.Util; ! namespace NHibernate.Hql ! { /// <summary> /// Parses the ORDER BY clause of a query /// </summary> ! public class OrderByParser : IParser { // 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 ! // 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.AppendOrderByToken( pathExpressionParser.WhereColumn ); ! pathExpressionParser.AddAssociation( q ); ! } ! else { ! q.AppendOrderByToken( 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 OrderByParser() { |