From: <ste...@us...> - 2009-05-14 11:35:40
|
Revision: 4299 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4299&view=rev Author: steverstrong Date: 2009-05-14 11:35:34 +0000 (Thu, 14 May 2009) Log Message: ----------- Another minor clean up within AST parser, and a fix for NH-1773 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectExpressionList.cs trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs trunk/nhibernate/src/NHibernate/Persister/Collection/CollectionPropertyMapping.cs trunk/nhibernate/src/NHibernate/Persister/Collection/ElementPropertyMapping.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs trunk/nhibernate/src/NHibernate/Persister/Entity/IPropertyMapping.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -847,15 +847,11 @@ if ( fromElements.Count == 1 ) { FromElement fromElement = (FromElement) fromElements[0]; - try - { - log.Info( "attempting to resolve property [" + identText + "] as a non-qualified ref" ); - return fromElement.GetPropertyMapping(identText).ToType(identText) != null; - } - catch( QueryException ) - { - // Should mean that no such property was found - } + + log.Info( "attempting to resolve property [" + identText + "] as a non-qualified ref" ); + + IType type; + return fromElement.GetPropertyMapping(identText).TryToType(identText, out type); } return false; Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -136,6 +136,16 @@ //sqlResultTypeList.addAll( constructorArgumentTypeList ); queryReturnTypeList.AddRange(constructorArgumentTypeList ); _scalarSelect = true; + + for (int j = 1; j < _constructorNode.ChildCount; j++) + { + ISelectExpression se = _constructorNode.GetChild(j) as ISelectExpression; + + if (se != null && IsReturnableEntity(se)) + { + _fromElementsForLoad.Add(se.FromElement); + } + } } else { @@ -227,7 +237,7 @@ // generate id select fragment and then property select fragment for // each expression, just like generateSelectFragments(). - RenderNonScalarSelects( CollectSelectExpressions(), fromClause ); + RenderNonScalarSelects( CollectSelectExpressions(true), fromClause ); } if ( _scalarSelect || Walker.IsShallowQuery ) Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectExpressionList.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectExpressionList.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectExpressionList.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -20,8 +20,16 @@ /// <summary> /// Returns an array of SelectExpressions gathered from the children of the given parent AST node. /// </summary> - public ISelectExpression[] CollectSelectExpressions() + public ISelectExpression[] CollectSelectExpressions() { + return CollectSelectExpressions(false); + } + + /// <summary> + /// Returns an array of SelectExpressions gathered from the children of the given parent AST node. + /// </summary> + public ISelectExpression[] CollectSelectExpressions(bool recurse) + { // Get the first child to be considered. Sub-classes may do this differently in order to skip nodes that // are not select expressions (e.g. DISTINCT). IASTNode firstChild = GetFirstSelectExpression(); @@ -30,14 +38,47 @@ for (IASTNode n = firstChild; n != null; n = n.NextSibling) { - var se = n as ISelectExpression; - if (se != null) + if (recurse) { - list.Add(se); + var ctor = n as ConstructorNode; + + if (ctor != null) + { + for (IASTNode cn = ctor.GetChild(1); cn != null; cn = cn.NextSibling) + { + var se = cn as ISelectExpression; + if (se != null) + { + list.Add(se); + } + } + } + else + { + var se = n as ISelectExpression; + if (se != null) + { + list.Add(se); + } + else + { + throw new InvalidOperationException("Unexpected AST: " + n.GetType().FullName + " " + + new ASTPrinter().ShowAsString(n, "")); + } + } } else { - throw new InvalidOperationException("Unexpected AST: " + n.GetType().FullName + " " + new ASTPrinter().ShowAsString(n, "")); + var se = n as ISelectExpression; + if (se != null) + { + list.Add(se); + } + else + { + throw new InvalidOperationException("Unexpected AST: " + n.GetType().FullName + " " + + new ASTPrinter().ShowAsString(n, "")); + } } } Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -1304,6 +1304,19 @@ return elementPropertyMapping.ToType(propertyName); } + public bool TryToType(string propertyName, out IType type) + { + if ("index".Equals(propertyName)) + { + type = indexType; + return true; + } + else + { + return elementPropertyMapping.TryToType(propertyName, out type); + } + } + public string GetManyToManyFilterFragment(string alias, IDictionary<string, IFilter> enabledFilters) { StringBuilder buffer = new StringBuilder(); Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/CollectionPropertyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/CollectionPropertyMapping.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/CollectionPropertyMapping.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -1,3 +1,4 @@ +using System; using NHibernate.Persister.Entity; using NHibernate.Type; @@ -42,6 +43,20 @@ } } + public bool TryToType(string propertyName, out IType type) + { + try + { + type = ToType(propertyName); + return true; + } + catch (Exception) + { + type = null; + return false; + } + } + public string[] ToColumns(string alias, string propertyName) { string[] cols; Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/ElementPropertyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/ElementPropertyMapping.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/ElementPropertyMapping.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -1,3 +1,4 @@ +using System; using NHibernate.Persister.Entity; using NHibernate.Type; using NHibernate.Util; @@ -32,6 +33,20 @@ } } + public bool TryToType(string propertyName, out IType outType) + { + try + { + outType = ToType(propertyName); + return true; + } + catch (Exception) + { + outType = null; + return false; + } + } + public string[] ToColumns(string alias, string propertyName) { if (propertyName == null || "id".Equals(propertyName)) Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -1720,6 +1720,11 @@ return propertyMapping.ToType(propertyName); } + public bool TryToType(string propertyName, out IType type) + { + return propertyMapping.TryToType(propertyName, out type); + } + public string[] GetPropertyColumnNames(string propertyName) { return propertyMapping.GetColumnNames(propertyName); Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -43,6 +43,11 @@ } } + public bool TryToType(string propertyName, out IType type) + { + return typesByPropertyPath.TryGetValue(propertyName, out type); + } + public virtual string[] ToColumns(string alias, string propertyName) { //TODO: *two* hashmap lookups here is one too many... Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/IPropertyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/IPropertyMapping.cs 2009-05-14 06:41:09 UTC (rev 4298) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/IPropertyMapping.cs 2009-05-14 11:35:34 UTC (rev 4299) @@ -22,6 +22,14 @@ IType ToType(string propertyName); /// <summary> + /// Given a component path expression, get the type of the property. + /// </summary> + /// <param name="propertyName"></param> + /// <param name="type"></param> + /// <returns>true if a type was found, false if not</returns> + bool TryToType(string propertyName, out IType type); + + /// <summary> /// Given a query alias and a property path, return the qualified column name /// </summary> /// <param name="alias"></param> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |