From: <fab...@us...> - 2011-06-14 14:00:54
|
Revision: 5925 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5925&view=rev Author: fabiomaulo Date: 2011-06-14 14:00:44 +0000 (Tue, 14 Jun 2011) Log Message: ----------- Classic QueryTranslator using parameter specifications Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Classic/GroupByParser.cs trunk/nhibernate/src/NHibernate/Hql/Classic/OrderByParser.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs trunk/nhibernate/src/NHibernate/SqlCommand/SqlString.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/GroupByParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/GroupByParser.cs 2011-06-13 16:01:13 UTC (rev 5924) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/GroupByParser.cs 2011-06-14 14:00:44 UTC (rev 5925) @@ -27,9 +27,13 @@ q.AppendGroupByToken(pathExpressionParser.WhereColumn); pathExpressionParser.AddAssociation(q); } - else if (token.StartsWith(ParserHelper.HqlVariablePrefix)) + else if (token.StartsWith(ParserHelper.HqlVariablePrefix)) //named query parameter { - q.AddNamedParameter(token.Substring(1)); + var name = token.Substring(1); + q.AppendGroupByParameter(name); + } + else if (token.Equals(StringHelper.SqlParameter)) + { q.AppendGroupByParameter(); } else Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/OrderByParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/OrderByParser.cs 2011-06-13 16:01:13 UTC (rev 5924) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/OrderByParser.cs 2011-06-14 14:00:44 UTC (rev 5925) @@ -27,7 +27,11 @@ } else if (token.StartsWith(ParserHelper.HqlVariablePrefix)) { - q.AddNamedParameter(token.Substring(1)); + var name = token.Substring(1); + q.AppendOrderByParameter(name); + } + else if (StringHelper.SqlParameter.Equals(token)) + { q.AppendOrderByParameter(); } else Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-13 16:01:13 UTC (rev 5924) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-14 14:00:44 UTC (rev 5925) @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections; using System.Data; using System.Diagnostics; @@ -11,9 +12,9 @@ using NHibernate.Engine; using NHibernate.Engine.Query; using NHibernate.Event; -using NHibernate.Hql.Util; using NHibernate.Impl; using NHibernate.Loader; +using NHibernate.Param; using NHibernate.Persister.Collection; using NHibernate.Persister.Entity; using NHibernate.SqlCommand; @@ -21,8 +22,8 @@ using NHibernate.Type; using NHibernate.Util; using NHibernate.Dialect.Function; -using System.Collections.Specialized; using System.Collections.Generic; +using IQueryable = NHibernate.Persister.Entity.IQueryable; namespace NHibernate.Hql.Classic { @@ -79,6 +80,8 @@ private bool hasScalars; private bool shallowQuery; private QueryTranslator superQuery; + private IList<IParameterSpecification> collectedParameters = new List<IParameterSpecification>(); + private int positionalParameterFound; private class FetchedCollections { @@ -268,7 +271,108 @@ Compile(); } + private int GetPositionalParameterPosition() + { + return superQuery != null ? superQuery.GetPositionalParameterPosition() : positionalParameterFound++; + } + + public SqlString GetNamedParameter(string name) + { + var parameterSpecification = new NamedParameterSpecification(1, 0, name); + var parameter = Parameter.Placeholder; + parameter.BackTrack = parameterSpecification.GetIdsForBackTrack(Factory).First(); + + AddNamedParameter(name); + collectedParameters.Add(parameterSpecification); + return new SqlString(parameter); + } + + public SqlString GetPositionalParameter() + { + var parameterSpecification = new PositionalParameterSpecification(1, 0, GetPositionalParameterPosition()); + var parameter = Parameter.Placeholder; + parameter.BackTrack = parameterSpecification.GetIdsForBackTrack(Factory).First(); + collectedParameters.Add(parameterSpecification); + return new SqlString(parameter); + } + + public IEnumerable<IParameterSpecification> CollectedParameterSpecifications + { + get { return ((superQuery != null) ? superQuery.CollectedParameterSpecifications:Enumerable.Empty<IParameterSpecification>()).Concat(collectedParameters); } + } + + public override ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) + { + // A distinct-copy of parameter specifications collected during query construction + var parameterSpecs = new HashSet<IParameterSpecification>(CollectedParameterSpecifications); + SqlString sql = SqlString.Copy(); + + // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it + sql = ExpandDynamicFilterParameters(sql, parameterSpecs, session); + AdjustQueryParametersForSubSelectFetching(sql, parameterSpecs, session, queryParameters); // NOTE: see TODO below + + sql = AddLimitsParametersIfNeeded(sql, parameterSpecs, queryParameters, session); + // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries + + // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) + sql = PreprocessSQL(sql, queryParameters, session.Factory.Dialect); + + // After the last modification to the SqlString we can collect all parameters types. + parameterSpecs.ResetEffectiveExpectedType(queryParameters); + + return new SqlCommandImpl(sql, parameterSpecs, queryParameters, session.Factory); + } + /// <summary> + /// Obtain an <c>IDbCommand</c> with all parameters pre-bound. Bind positional parameters, + /// named parameters, and limit parameters. + /// </summary> + /// <remarks> + /// Creates an IDbCommand object and populates it with the values necessary to execute it against the + /// database to Load an Entity. + /// </remarks> + /// <param name="queryParameters">The <see cref="QueryParameters"/> to use for the IDbCommand.</param> + /// <param name="scroll">TODO: find out where this is used...</param> + /// <param name="session">The SessionImpl this Command is being prepared in.</param> + /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> + protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) + { + var sqlCommand = (SqlCommandImpl)CreateSqlCommand(queryParameters, session); + var parameterSpecs = sqlCommand.Specifications; + var query = sqlCommand.Query; + var sqlQueryParametersList = sqlCommand.SqlQueryParametersList; + + parameterSpecs.SetQueryParameterLocations(sqlQueryParametersList, session.Factory); + + IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, query, sqlCommand.ParameterTypes); + + try + { + RowSelection selection = queryParameters.RowSelection; + if (selection != null && selection.Timeout != RowSelection.NoValue) + { + command.CommandTimeout = selection.Timeout; + } + + sqlCommand.Bind(command, sqlQueryParametersList, 0, session); + + session.Batcher.ExpandQueryParameters(command, query); + } + catch (HibernateException) + { + session.Batcher.CloseCommand(command, null); + throw; + } + catch (Exception sqle) + { + session.Batcher.CloseCommand(command, null); + ADOExceptionReporter.LogExceptions(sqle); + throw; + } + return command; + } + + /// <summary> /// Compile a "normal" query. This method may be called multiple /// times. Subsequent invocations are no-ops. /// </summary> @@ -672,15 +776,17 @@ internal void AppendOrderByToken(string token) { - if (StringHelper.SqlParameter.Equals(token)) - orderByTokens.Add(SqlString.Parameter); - else - orderByTokens.Add(new SqlString(token)); + orderByTokens.Add(new SqlString(token)); } + internal void AppendOrderByParameter(string name) + { + orderByTokens.Add(GetNamedParameter(name)); + } + internal void AppendOrderByParameter() { - orderByTokens.Add(SqlString.Parameter); + orderByTokens.Add(GetPositionalParameter()); } internal void AppendGroupByToken(string token) @@ -688,9 +794,14 @@ groupByTokens.Add(new SqlString(token)); } + internal void AppendGroupByParameter(string name) + { + groupByTokens.Add(GetNamedParameter(name)); + } + internal void AppendGroupByParameter() { - groupByTokens.Add(SqlString.Parameter); + groupByTokens.Add(GetPositionalParameter()); } internal void AppendScalarSelectToken(string token) @@ -703,9 +814,14 @@ scalarSelectTokens.Add(new SqlString(tokens)); } + internal void AppendScalarSelectParameter(string name) + { + scalarSelectTokens.Add(GetNamedParameter(name)); + } + internal void AppendScalarSelectParameter() { - scalarSelectTokens.Add(SqlString.Parameter); + scalarSelectTokens.Add(GetPositionalParameter()); } internal void AddJoin(string name, JoinSequence joinSequence) @@ -1087,10 +1203,21 @@ int parenCount = 1; for (; tokenIdx < tokens.Count && parenCount > 0; tokenIdx++) { - if (tokens[tokenIdx].StartsWithCaseInsensitive(ParserHelper.HqlVariablePrefix) || tokens[tokenIdx].ToString().Equals(StringHelper.SqlParameter)) + if (tokens[tokenIdx].Parts.Count == 1 && (tokens[tokenIdx].Parts.First() is Parameter)) { - functionTokens.Add(SqlString.Parameter); + // the parameter was processed + functionTokens.Add(tokens[tokenIdx]); + continue; } + if (tokens[tokenIdx].StartsWithCaseInsensitive(ParserHelper.HqlVariablePrefix)) + { + string name = tokens[tokenIdx].Substring(1).ToString(); + functionTokens.Add(GetNamedParameter(name)); + } + else if (StringHelper.SqlParameter.Equals(tokens[tokenIdx].ToString())) + { + functionTokens.Add(GetPositionalParameter()); + } else { functionTokens.Add(tokens[tokenIdx]); Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs 2011-06-13 16:01:13 UTC (rev 5924) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs 2011-06-14 14:00:44 UTC (rev 5925) @@ -170,7 +170,11 @@ if (token.StartsWith(ParserHelper.HqlVariablePrefix)) { - q.AddNamedParameter(token.Substring(1)); + string name = token.Substring(1); + q.AppendScalarSelectParameter(name); + } + else if (token.Equals(StringHelper.SqlParameter)) + { q.AppendScalarSelectParameter(); } else if (constantToken) @@ -237,7 +241,11 @@ } else if (token.StartsWith(ParserHelper.HqlVariablePrefix)) { - q.AddNamedParameter(token.Substring(1)); + string name = token.Substring(1); + q.AppendScalarSelectParameter(name); + } + else if (token.Equals(StringHelper.SqlParameter)) + { q.AppendScalarSelectParameter(); } else Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs 2011-06-13 16:01:13 UTC (rev 5924) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs 2011-06-14 14:00:44 UTC (rev 5925) @@ -470,17 +470,17 @@ } else if (token.StartsWith(ParserHelper.HqlVariablePrefix)) //named query parameter { - q.AddNamedParameter(token.Substring(1)); + var name = token.Substring(1); // this is only a temporary parameter to help with the parsing of hql - // when the type becomes known then this will be converted to its real // parameter type. - AppendToken(q, SqlString.Parameter); + AppendToken(q, q.GetNamedParameter(name)); } else if (token.Equals(StringHelper.SqlParameter)) { //if the token is a "?" then we have a Parameter so convert it to a SqlCommand.Parameter // instead of appending a "?" to the WhereTokens - AppendToken(q, SqlString.Parameter); + AppendToken(q, q.GetPositionalParameter()); } else { Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SqlString.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SqlString.cs 2011-06-13 16:01:13 UTC (rev 5924) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SqlString.cs 2011-06-14 14:00:44 UTC (rev 5925) @@ -26,11 +26,6 @@ public static readonly SqlString Empty = new SqlString(new object[0]); - public static SqlString Parameter - { - get { return new SqlString(SqlCommand.Parameter.Placeholder); } - } - public SqlString(string sqlPart) { if (StringHelper.IsNotEmpty(sqlPart)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2011-06-14 15:18:08
|
Revision: 5926 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5926&view=rev Author: julian-maughan Date: 2011-06-14 15:18:00 +0000 (Tue, 14 Jun 2011) Log Message: ----------- Adds grammar support for Linq queries that have orderby on collection count (NH-2760) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.g trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2760/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2760/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2760/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2760/Model.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs 2011-06-14 14:00:44 UTC (rev 5925) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs 2011-06-14 15:18:00 UTC (rev 5926) @@ -1,4 +1,4 @@ -// $ANTLR 3.2 Sep 23, 2009 12:02:23 HqlSqlWalker.g 2011-05-22 07:45:51 +// $ANTLR 3.2 Sep 23, 2009 12:02:23 HqlSqlWalker.g 2011-06-14 20:28:08 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 168, 219 @@ -681,16 +681,16 @@ // AST REWRITE - // elements: f, u, w, s + // elements: w, f, s, u // token labels: u - // rule labels: w, f, retval, s + // rule labels: f, w, retval, s // token list labels: // rule list labels: // wildcard labels: retval.Tree = root_0; RewriteRuleNodeStream stream_u = new RewriteRuleNodeStream(adaptor, "token u", u); + RewriteRuleSubtreeStream stream_f = new RewriteRuleSubtreeStream(adaptor, "rule f", f!=null ? f.Tree : null); RewriteRuleSubtreeStream stream_w = new RewriteRuleSubtreeStream(adaptor, "rule w", w!=null ? w.Tree : null); - RewriteRuleSubtreeStream stream_f = new RewriteRuleSubtreeStream(adaptor, "rule f", f!=null ? f.Tree : null); RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null); RewriteRuleSubtreeStream stream_s = new RewriteRuleSubtreeStream(adaptor, "rule s", s!=null ? s.Tree : null); @@ -1845,17 +1845,17 @@ // AST REWRITE - // elements: w, o, f, s, g, tk, sk, h + // elements: sk, o, h, g, s, tk, w, f // token labels: - // rule labels: f, w, sk, g, retval, s, o, tk, h + // rule labels: f, w, g, sk, retval, s, o, tk, h // token list labels: // rule list labels: // wildcard labels: retval.Tree = root_0; RewriteRuleSubtreeStream stream_f = new RewriteRuleSubtreeStream(adaptor, "rule f", f!=null ? f.Tree : null); RewriteRuleSubtreeStream stream_w = new RewriteRuleSubtreeStream(adaptor, "rule w", w!=null ? w.Tree : null); + RewriteRuleSubtreeStream stream_g = new RewriteRuleSubtreeStream(adaptor, "rule g", g!=null ? g.Tree : null); RewriteRuleSubtreeStream stream_sk = new RewriteRuleSubtreeStream(adaptor, "rule sk", sk!=null ? sk.Tree : null); - RewriteRuleSubtreeStream stream_g = new RewriteRuleSubtreeStream(adaptor, "rule g", g!=null ? g.Tree : null); RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null); RewriteRuleSubtreeStream stream_s = new RewriteRuleSubtreeStream(adaptor, "rule s", s!=null ? s.Tree : null); RewriteRuleSubtreeStream stream_o = new RewriteRuleSubtreeStream(adaptor, "rule o", o!=null ? o.Tree : null); @@ -1961,7 +1961,7 @@ }; // $ANTLR start "orderClause" - // HqlSqlWalker.g:142:1: orderClause : ^( ORDER orderExprs ) ; + // HqlSqlWalker.g:142:1: orderClause : ^( ORDER ( orderExprs | query ( ASCENDING | DESCENDING )? ) ) ; public HqlSqlWalker.orderClause_return orderClause() // throws RecognitionException [1] { HqlSqlWalker.orderClause_return retval = new HqlSqlWalker.orderClause_return(); @@ -1973,15 +1973,19 @@ IASTNode _last = null; IASTNode ORDER27 = null; + IASTNode set30 = null; HqlSqlWalker.orderExprs_return orderExprs28 = default(HqlSqlWalker.orderExprs_return); + HqlSqlWalker.query_return query29 = default(HqlSqlWalker.query_return); + IASTNode ORDER27_tree=null; + IASTNode set30_tree=null; try { - // HqlSqlWalker.g:143:2: ( ^( ORDER orderExprs ) ) - // HqlSqlWalker.g:143:4: ^( ORDER orderExprs ) + // HqlSqlWalker.g:143:2: ( ^( ORDER ( orderExprs | query ( ASCENDING | DESCENDING )? ) ) ) + // HqlSqlWalker.g:143:4: ^( ORDER ( orderExprs | query ( ASCENDING | DESCENDING )? ) ) { root_0 = (IASTNode)adaptor.GetNilNode(); @@ -1999,13 +2003,92 @@ HandleClauseStart( ORDER ); Match(input, Token.DOWN, null); - _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_orderExprs_in_orderClause658); - orderExprs28 = orderExprs(); - state.followingStackPointer--; + // HqlSqlWalker.g:143:44: ( orderExprs | query ( ASCENDING | DESCENDING )? ) + int alt17 = 2; + int LA17_0 = input.LA(1); - adaptor.AddChild(root_1, orderExprs28.Tree); + if ( (LA17_0 == COUNT || LA17_0 == DOT || LA17_0 == FALSE || LA17_0 == NULL || LA17_0 == TRUE || LA17_0 == CASE || LA17_0 == AGGREGATE || LA17_0 == CASE2 || LA17_0 == INDEX_OP || LA17_0 == METHOD_CALL || LA17_0 == UNARY_MINUS || (LA17_0 >= VECTOR_EXPR && LA17_0 <= WEIRD_IDENT) || (LA17_0 >= NUM_INT && LA17_0 <= JAVA_CONSTANT) || (LA17_0 >= COLON && LA17_0 <= PARAM) || (LA17_0 >= BNOT && LA17_0 <= DIV) || (LA17_0 >= QUOTED_String && LA17_0 <= IDENT)) ) + { + alt17 = 1; + } + else if ( (LA17_0 == UNION || LA17_0 == QUERY) ) + { + alt17 = 2; + } + else + { + NoViableAltException nvae_d17s0 = + new NoViableAltException("", 17, 0, input); + throw nvae_d17s0; + } + switch (alt17) + { + case 1 : + // HqlSqlWalker.g:143:45: orderExprs + { + _last = (IASTNode)input.LT(1); + PushFollow(FOLLOW_orderExprs_in_orderClause659); + orderExprs28 = orderExprs(); + state.followingStackPointer--; + + adaptor.AddChild(root_1, orderExprs28.Tree); + + } + break; + case 2 : + // HqlSqlWalker.g:143:58: query ( ASCENDING | DESCENDING )? + { + _last = (IASTNode)input.LT(1); + PushFollow(FOLLOW_query_in_orderClause663); + query29 = query(); + state.followingStackPointer--; + + adaptor.AddChild(root_1, query29.Tree); + // HqlSqlWalker.g:143:64: ( ASCENDING | DESCENDING )? + int alt16 = 2; + int LA16_0 = input.LA(1); + + if ( (LA16_0 == ASCENDING || LA16_0 == DESCENDING) ) + { + alt16 = 1; + } + switch (alt16) + { + case 1 : + // HqlSqlWalker.g: + { + _last = (IASTNode)input.LT(1); + set30 = (IASTNode)input.LT(1); + if ( input.LA(1) == ASCENDING || input.LA(1) == DESCENDING ) + { + input.Consume(); + + set30_tree = (IASTNode)adaptor.DupNode(set30); + + adaptor.AddChild(root_1, set30_tree); + + state.errorRecovery = false; + } + else + { + MismatchedSetException mse = new MismatchedSetException(null,input); + throw mse; + } + + + } + break; + + } + + + } + break; + + } + + Match(input, Token.UP, null); adaptor.AddChild(root_0, root_1);_last = _save_last_1; } @@ -2049,13 +2132,13 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode set30 = null; - HqlSqlWalker.expr_return expr29 = default(HqlSqlWalker.expr_return); + IASTNode set32 = null; + HqlSqlWalker.expr_return expr31 = default(HqlSqlWalker.expr_return); - HqlSqlWalker.orderExprs_return orderExprs31 = default(HqlSqlWalker.orderExprs_return); + HqlSqlWalker.orderExprs_return orderExprs33 = default(HqlSqlWalker.orderExprs_return); - IASTNode set30_tree=null; + IASTNode set32_tree=null; try { @@ -2065,33 +2148,33 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_expr_in_orderExprs670); - expr29 = expr(); + PushFollow(FOLLOW_expr_in_orderExprs686); + expr31 = expr(); state.followingStackPointer--; - adaptor.AddChild(root_0, expr29.Tree); + adaptor.AddChild(root_0, expr31.Tree); // HqlSqlWalker.g:147:9: ( ASCENDING | DESCENDING )? - int alt16 = 2; - int LA16_0 = input.LA(1); + int alt18 = 2; + int LA18_0 = input.LA(1); - if ( (LA16_0 == ASCENDING || LA16_0 == DESCENDING) ) + if ( (LA18_0 == ASCENDING || LA18_0 == DESCENDING) ) { - alt16 = 1; + alt18 = 1; } - switch (alt16) + switch (alt18) { case 1 : // HqlSqlWalker.g: { _last = (IASTNode)input.LT(1); - set30 = (IASTNode)input.LT(1); + set32 = (IASTNode)input.LT(1); if ( input.LA(1) == ASCENDING || input.LA(1) == DESCENDING ) { input.Consume(); - set30_tree = (IASTNode)adaptor.DupNode(set30); + set32_tree = (IASTNode)adaptor.DupNode(set32); - adaptor.AddChild(root_0, set30_tree); + adaptor.AddChild(root_0, set32_tree); state.errorRecovery = false; } @@ -2108,24 +2191,24 @@ } // HqlSqlWalker.g:147:37: ( orderExprs )? - int alt17 = 2; - int LA17_0 = input.LA(1); + int alt19 = 2; + int LA19_0 = input.LA(1); - if ( (LA17_0 == COUNT || LA17_0 == DOT || LA17_0 == FALSE || LA17_0 == NULL || LA17_0 == TRUE || LA17_0 == CASE || LA17_0 == AGGREGATE || LA17_0 == CASE2 || LA17_0 == INDEX_OP || LA17_0 == METHOD_CALL || LA17_0 == UNARY_MINUS || (LA17_0 >= VECTOR_EXPR && LA17_0 <= WEIRD_IDENT) || (LA17_0 >= NUM_INT && LA17_0 <= JAVA_CONSTANT) || (LA17_0 >= COLON && LA17_0 <= PARAM) || (LA17_0 >= BNOT && LA17_0 <= DIV) || (LA17_0 >= QUOTED_String && LA17_0 <= IDENT)) ) + if ( (LA19_0 == COUNT || LA19_0 == DOT || LA19_0 == FALSE || LA19_0 == NULL || LA19_0 == TRUE || LA19_0 == CASE || LA19_0 == AGGREGATE || LA19_0 == CASE2 || LA19_0 == INDEX_OP || LA19_0 == METHOD_CALL || LA19_0 == UNARY_MINUS || (LA19_0 >= VECTOR_EXPR && LA19_0 <= WEIRD_IDENT) || (LA19_0 >= NUM_INT && LA19_0 <= JAVA_CONSTANT) || (LA19_0 >= COLON && LA19_0 <= PARAM) || (LA19_0 >= BNOT && LA19_0 <= DIV) || (LA19_0 >= QUOTED_String && LA19_0 <= IDENT)) ) { - alt17 = 1; + alt19 = 1; } - switch (alt17) + switch (alt19) { case 1 : // HqlSqlWalker.g:147:38: orderExprs { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_orderExprs_in_orderExprs684); - orderExprs31 = orderExprs(); + PushFollow(FOLLOW_orderExprs_in_orderExprs700); + orderExprs33 = orderExprs(); state.followingStackPointer--; - adaptor.AddChild(root_0, orderExprs31.Tree); + adaptor.AddChild(root_0, orderExprs33.Tree); } break; @@ -2172,13 +2255,13 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode SKIP32 = null; - IASTNode NUM_INT33 = null; - HqlSqlWalker.parameter_return parameter34 = default(HqlSqlWalker.parameter_return); + IASTNode SKIP34 = null; + IASTNode NUM_INT35 = null; + HqlSqlWalker.parameter_return parameter36 = default(HqlSqlWalker.parameter_return); - IASTNode SKIP32_tree=null; - IASTNode NUM_INT33_tree=null; + IASTNode SKIP34_tree=null; + IASTNode NUM_INT35_tree=null; try { @@ -2192,43 +2275,43 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - SKIP32=(IASTNode)Match(input,SKIP,FOLLOW_SKIP_in_skipClause698); - SKIP32_tree = (IASTNode)adaptor.DupNode(SKIP32); + SKIP34=(IASTNode)Match(input,SKIP,FOLLOW_SKIP_in_skipClause714); + SKIP34_tree = (IASTNode)adaptor.DupNode(SKIP34); - root_1 = (IASTNode)adaptor.BecomeRoot(SKIP32_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(SKIP34_tree, root_1); Match(input, Token.DOWN, null); // HqlSqlWalker.g:151:11: ( NUM_INT | parameter ) - int alt18 = 2; - int LA18_0 = input.LA(1); + int alt20 = 2; + int LA20_0 = input.LA(1); - if ( (LA18_0 == NUM_INT) ) + if ( (LA20_0 == NUM_INT) ) { - alt18 = 1; + alt20 = 1; } - else if ( ((LA18_0 >= COLON && LA18_0 <= PARAM)) ) + else if ( ((LA20_0 >= COLON && LA20_0 <= PARAM)) ) { - alt18 = 2; + alt20 = 2; } else { - NoViableAltException nvae_d18s0 = - new NoViableAltException("", 18, 0, input); + NoViableAltException nvae_d20s0 = + new NoViableAltException("", 20, 0, input); - throw nvae_d18s0; + throw nvae_d20s0; } - switch (alt18) + switch (alt20) { case 1 : // HqlSqlWalker.g:151:12: NUM_INT { _last = (IASTNode)input.LT(1); - NUM_INT33=(IASTNode)Match(input,NUM_INT,FOLLOW_NUM_INT_in_skipClause701); - NUM_INT33_tree = (IASTNode)adaptor.DupNode(NUM_INT33); + NUM_INT35=(IASTNode)Match(input,NUM_INT,FOLLOW_NUM_INT_in_skipClause717); + NUM_INT35_tree = (IASTNode)adaptor.DupNode(NUM_INT35); - adaptor.AddChild(root_1, NUM_INT33_tree); + adaptor.AddChild(root_1, NUM_INT35_tree); } @@ -2237,11 +2320,11 @@ // HqlSqlWalker.g:151:22: parameter { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_parameter_in_skipClause705); - parameter34 = parameter(); + PushFollow(FOLLOW_parameter_in_skipClause721); + parameter36 = parameter(); state.followingStackPointer--; - adaptor.AddChild(root_1, parameter34.Tree); + adaptor.AddChild(root_1, parameter36.Tree); } break; @@ -2292,13 +2375,13 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode TAKE35 = null; - IASTNode NUM_INT36 = null; - HqlSqlWalker.parameter_return parameter37 = default(HqlSqlWalker.parameter_return); + IASTNode TAKE37 = null; + IASTNode NUM_INT38 = null; + HqlSqlWalker.parameter_return parameter39 = default(HqlSqlWalker.parameter_return); - IASTNode TAKE35_tree=null; - IASTNode NUM_INT36_tree=null; + IASTNode TAKE37_tree=null; + IASTNode NUM_INT38_tree=null; try { @@ -2312,43 +2395,43 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - TAKE35=(IASTNode)Match(input,TAKE,FOLLOW_TAKE_in_takeClause719); - TAKE35_tree = (IASTNode)adaptor.DupNode(TAKE35); + TAKE37=(IASTNode)Match(input,TAKE,FOLLOW_TAKE_in_takeClause735); + TAKE37_tree = (IASTNode)adaptor.DupNode(TAKE37); - root_1 = (IASTNode)adaptor.BecomeRoot(TAKE35_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(TAKE37_tree, root_1); Match(input, Token.DOWN, null); // HqlSqlWalker.g:155:11: ( NUM_INT | parameter ) - int alt19 = 2; - int LA19_0 = input.LA(1); + int alt21 = 2; + int LA21_0 = input.LA(1); - if ( (LA19_0 == NUM_INT) ) + if ( (LA21_0 == NUM_INT) ) { - alt19 = 1; + alt21 = 1; } - else if ( ((LA19_0 >= COLON && LA19_0 <= PARAM)) ) + else if ( ((LA21_0 >= COLON && LA21_0 <= PARAM)) ) { - alt19 = 2; + alt21 = 2; } else { - NoViableAltException nvae_d19s0 = - new NoViableAltException("", 19, 0, input); + NoViableAltException nvae_d21s0 = + new NoViableAltException("", 21, 0, input); - throw nvae_d19s0; + throw nvae_d21s0; } - switch (alt19) + switch (alt21) { case 1 : // HqlSqlWalker.g:155:12: NUM_INT { _last = (IASTNode)input.LT(1); - NUM_INT36=(IASTNode)Match(input,NUM_INT,FOLLOW_NUM_INT_in_takeClause722); - NUM_INT36_tree = (IASTNode)adaptor.DupNode(NUM_INT36); + NUM_INT38=(IASTNode)Match(input,NUM_INT,FOLLOW_NUM_INT_in_takeClause738); + NUM_INT38_tree = (IASTNode)adaptor.DupNode(NUM_INT38); - adaptor.AddChild(root_1, NUM_INT36_tree); + adaptor.AddChild(root_1, NUM_INT38_tree); } @@ -2357,11 +2440,11 @@ // HqlSqlWalker.g:155:22: parameter { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_parameter_in_takeClause726); - parameter37 = parameter(); + PushFollow(FOLLOW_parameter_in_takeClause742); + parameter39 = parameter(); state.followingStackPointer--; - adaptor.AddChild(root_1, parameter37.Tree); + adaptor.AddChild(root_1, parameter39.Tree); } break; @@ -2412,11 +2495,11 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode GROUP38 = null; - HqlSqlWalker.expr_return expr39 = default(HqlSqlWalker.expr_return); + IASTNode GROUP40 = null; + HqlSqlWalker.expr_return expr41 = default(HqlSqlWalker.expr_return); - IASTNode GROUP38_tree=null; + IASTNode GROUP40_tree=null; try { @@ -2430,54 +2513,54 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - GROUP38=(IASTNode)Match(input,GROUP,FOLLOW_GROUP_in_groupClause740); - GROUP38_tree = (IASTNode)adaptor.DupNode(GROUP38); + GROUP40=(IASTNode)Match(input,GROUP,FOLLOW_GROUP_in_groupClause756); + GROUP40_tree = (IASTNode)adaptor.DupNode(GROUP40); - root_1 = (IASTNode)adaptor.BecomeRoot(GROUP38_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(GROUP40_tree, root_1); HandleClauseStart( GROUP ); Match(input, Token.DOWN, null); // HqlSqlWalker.g:159:44: ( expr )+ - int cnt20 = 0; + int cnt22 = 0; do { - int alt20 = 2; - int LA20_0 = input.LA(1); + int alt22 = 2; + int LA22_0 = input.LA(1); - if ( (LA20_0 == COUNT || LA20_0 == DOT || LA20_0 == FALSE || LA20_0 == NULL || LA20_0 == TRUE || LA20_0 == CASE || LA20_0 == AGGREGATE || LA20_0 == CASE2 || LA20_0 == INDEX_OP || LA20_0 == METHOD_CALL || LA20_0 == UNARY_MINUS || (LA20_0 >= VECTOR_EXPR && LA20_0 <= WEIRD_IDENT) || (LA20_0 >= NUM_INT && LA20_0 <= JAVA_CONSTANT) || (LA20_0 >= COLON && LA20_0 <= PARAM) || (LA20_0 >= BNOT && LA20_0 <= DIV) || (LA20_0 >= QUOTED_String && LA20_0 <= IDENT)) ) + if ( (LA22_0 == COUNT || LA22_0 == DOT || LA22_0 == FALSE || LA22_0 == NULL || LA22_0 == TRUE || LA22_0 == CASE || LA22_0 == AGGREGATE || LA22_0 == CASE2 || LA22_0 == INDEX_OP || LA22_0 == METHOD_CALL || LA22_0 == UNARY_MINUS || (LA22_0 >= VECTOR_EXPR && LA22_0 <= WEIRD_IDENT) || (LA22_0 >= NUM_INT && LA22_0 <= JAVA_CONSTANT) || (LA22_0 >= COLON && LA22_0 <= PARAM) || (LA22_0 >= BNOT && LA22_0 <= DIV) || (LA22_0 >= QUOTED_String && LA22_0 <= IDENT)) ) { - alt20 = 1; + alt22 = 1; } - switch (alt20) + switch (alt22) { case 1 : // HqlSqlWalker.g:159:45: expr { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_expr_in_groupClause745); - expr39 = expr(); + PushFollow(FOLLOW_expr_in_groupClause761); + expr41 = expr(); state.followingStackPointer--; - adaptor.AddChild(root_1, expr39.Tree); + adaptor.AddChild(root_1, expr41.Tree); } break; default: - if ( cnt20 >= 1 ) goto loop20; - EarlyExitException eee20 = - new EarlyExitException(20, input); - throw eee20; + if ( cnt22 >= 1 ) goto loop22; + EarlyExitException eee22 = + new EarlyExitException(22, input); + throw eee22; } - cnt20++; + cnt22++; } while (true); - loop20: - ; // Stops C# compiler whining that label 'loop20' has no statements + loop22: + ; // Stops C# compiler whining that label 'loop22' has no statements Match(input, Token.UP, null); adaptor.AddChild(root_0, root_1);_last = _save_last_1; @@ -2523,11 +2606,11 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode HAVING40 = null; - HqlSqlWalker.logicalExpr_return logicalExpr41 = default(HqlSqlWalker.logicalExpr_return); + IASTNode HAVING42 = null; + HqlSqlWalker.logicalExpr_return logicalExpr43 = default(HqlSqlWalker.logicalExpr_return); - IASTNode HAVING40_tree=null; + IASTNode HAVING42_tree=null; try { @@ -2541,20 +2624,20 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - HAVING40=(IASTNode)Match(input,HAVING,FOLLOW_HAVING_in_havingClause761); - HAVING40_tree = (IASTNode)adaptor.DupNode(HAVING40); + HAVING42=(IASTNode)Match(input,HAVING,FOLLOW_HAVING_in_havingClause777); + HAVING42_tree = (IASTNode)adaptor.DupNode(HAVING42); - root_1 = (IASTNode)adaptor.BecomeRoot(HAVING40_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(HAVING42_tree, root_1); Match(input, Token.DOWN, null); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_logicalExpr_in_havingClause763); - logicalExpr41 = logicalExpr(); + PushFollow(FOLLOW_logicalExpr_in_havingClause779); + logicalExpr43 = logicalExpr(); state.followingStackPointer--; - adaptor.AddChild(root_1, logicalExpr41.Tree); + adaptor.AddChild(root_1, logicalExpr43.Tree); Match(input, Token.UP, null); adaptor.AddChild(root_0, root_1);_last = _save_last_1; } @@ -2600,12 +2683,12 @@ IASTNode _last = null; IASTNode d = null; - IASTNode SELECT42 = null; + IASTNode SELECT44 = null; HqlSqlWalker.selectExprList_return x = default(HqlSqlWalker.selectExprList_return); IASTNode d_tree=null; - IASTNode SELECT42_tree=null; + IASTNode SELECT44_tree=null; RewriteRuleNodeStream stream_SELECT = new RewriteRuleNodeStream(adaptor,"token SELECT"); RewriteRuleNodeStream stream_DISTINCT = new RewriteRuleNodeStream(adaptor,"token DISTINCT"); RewriteRuleSubtreeStream stream_selectExprList = new RewriteRuleSubtreeStream(adaptor,"rule selectExprList"); @@ -2619,28 +2702,28 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - SELECT42=(IASTNode)Match(input,SELECT,FOLLOW_SELECT_in_selectClause777); - stream_SELECT.Add(SELECT42); + SELECT44=(IASTNode)Match(input,SELECT,FOLLOW_SELECT_in_selectClause793); + stream_SELECT.Add(SELECT44); HandleClauseStart( SELECT ); BeforeSelectClause(); Match(input, Token.DOWN, null); // HqlSqlWalker.g:167:68: (d= DISTINCT )? - int alt21 = 2; - int LA21_0 = input.LA(1); + int alt23 = 2; + int LA23_0 = input.LA(1); - if ( (LA21_0 == DISTINCT) ) + if ( (LA23_0 == DISTINCT) ) { - alt21 = 1; + alt23 = 1; } - switch (alt21) + switch (alt23) { case 1 : // HqlSqlWalker.g:167:69: d= DISTINCT { _last = (IASTNode)input.LT(1); - d=(IASTNode)Match(input,DISTINCT,FOLLOW_DISTINCT_in_selectClause784); + d=(IASTNode)Match(input,DISTINCT,FOLLOW_DISTINCT_in_selectClause800); stream_DISTINCT.Add(d); @@ -2650,7 +2733,7 @@ } _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_selectExprList_in_selectClause790); + PushFollow(FOLLOW_selectExprList_in_selectClause806); x = selectExprList(); state.followingStackPointer--; @@ -2662,7 +2745,7 @@ // AST REWRITE - // elements: d, x + // elements: x, d // token labels: d // rule labels: retval, x // token list labels: @@ -2735,9 +2818,9 @@ IASTNode _first_0 = null; IASTNode _last = null; - HqlSqlWalker.selectExpr_return selectExpr43 = default(HqlSqlWalker.selectExpr_return); + HqlSqlWalker.selectExpr_return selectExpr45 = default(HqlSqlWalker.selectExpr_return); - HqlSqlWalker.aliasedSelectExpr_return aliasedSelectExpr44 = default(HqlSqlWalker.aliasedSelectExpr_return); + HqlSqlWalker.aliasedSelectExpr_return aliasedSelectExpr46 = default(HqlSqlWalker.aliasedSelectExpr_return); @@ -2753,33 +2836,33 @@ root_0 = (IASTNode)adaptor.GetNilNode(); // HqlSqlWalker.g:175:4: ( selectExpr | aliasedSelectExpr )+ - int cnt22 = 0; + int cnt24 = 0; do { - int alt22 = 3; - int LA22_0 = input.LA(1); + int alt24 = 3; + int LA24_0 = input.LA(1); - if ( (LA22_0 == ALL || LA22_0 == COUNT || LA22_0 == DOT || LA22_0 == ELEMENTS || LA22_0 == INDICES || LA22_0 == UNION || LA22_0 == CASE || LA22_0 == OBJECT || LA22_0 == AGGREGATE || (LA22_0 >= CONSTRUCTOR && LA22_0 <= CASE2) || LA22_0 == METHOD_CALL || LA22_0 == QUERY || LA22_0 == UNARY_MINUS || LA22_0 == WEIRD_IDENT || (LA22_0 >= NUM_INT && LA22_0 <= NUM_LONG) || (LA22_0 >= COLON && LA22_0 <= PARAM) || (LA22_0 >= BNOT && LA22_0 <= DIV) || (LA22_0 >= QUOTED_String && LA22_0 <= IDENT)) ) + if ( (LA24_0 == ALL || LA24_0 == COUNT || LA24_0 == DOT || LA24_0 == ELEMENTS || LA24_0 == INDICES || LA24_0 == UNION || LA24_0 == CASE || LA24_0 == OBJECT || LA24_0 == AGGREGATE || (LA24_0 >= CONSTRUCTOR && LA24_0 <= CASE2) || LA24_0 == METHOD_CALL || LA24_0 == QUERY || LA24_0 == UNARY_MINUS || LA24_0 == WEIRD_IDENT || (LA24_0 >= NUM_INT && LA24_0 <= NUM_LONG) || (LA24_0 >= COLON && LA24_0 <= PARAM) || (LA24_0 >= BNOT && LA24_0 <= DIV) || (LA24_0 >= QUOTED_String && LA24_0 <= IDENT)) ) { - alt22 = 1; + alt24 = 1; } - else if ( (LA22_0 == AS) ) + else if ( (LA24_0 == AS) ) { - alt22 = 2; + alt24 = 2; } - switch (alt22) + switch (alt24) { case 1 : // HqlSqlWalker.g:175:6: selectExpr { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_selectExpr_in_selectExprList825); - selectExpr43 = selectExpr(); + PushFollow(FOLLOW_selectExpr_in_selectExprList841); + selectExpr45 = selectExpr(); state.followingStackPointer--; - adaptor.AddChild(root_0, selectExpr43.Tree); + adaptor.AddChild(root_0, selectExpr45.Tree); } break; @@ -2787,26 +2870,26 @@ // HqlSqlWalker.g:175:19: aliasedSelectExpr { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_aliasedSelectExpr_in_selectExprList829); - aliasedSelectExpr44 = aliasedSelectExpr(); + PushFollow(FOLLOW_aliasedSelectExpr_in_selectExprList845); + aliasedSelectExpr46 = aliasedSelectExpr(); state.followingStackPointer--; - adaptor.AddChild(root_0, aliasedSelectExpr44.Tree); + adaptor.AddChild(root_0, aliasedSelectExpr46.Tree); } break; default: - if ( cnt22 >= 1 ) goto loop22; - EarlyExitException eee22 = - new EarlyExitException(22, input); - throw eee22; + if ( cnt24 >= 1 ) goto loop24; + EarlyExitException eee24 = + new EarlyExitException(24, input); + throw eee24; } - cnt22++; + cnt24++; } while (true); - loop22: - ; // Stops C# compiler whining that label 'loop22' has no statements + loop24: + ; // Stops C# compiler whining that label 'loop24' has no statements _inSelect = oldInSelect; @@ -2851,13 +2934,13 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode AS45 = null; + IASTNode AS47 = null; HqlSqlWalker.selectExpr_return se = default(HqlSqlWalker.selectExpr_return); HqlSqlWalker.identifier_return i = default(HqlSqlWalker.identifier_return); - IASTNode AS45_tree=null; + IASTNode AS47_tree=null; try { @@ -2871,22 +2954,22 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - AS45=(IASTNode)Match(input,AS,FOLLOW_AS_in_aliasedSelectExpr853); - AS45_tree = (IASTNode)adaptor.DupNode(AS45); + AS47=(IASTNode)Match(input,AS,FOLLOW_AS_in_aliasedSelectExpr869); + AS47_tree = (IASTNode)adaptor.DupNode(AS47); - root_1 = (IASTNode)adaptor.BecomeRoot(AS45_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(AS47_tree, root_1); Match(input, Token.DOWN, null); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_selectExpr_in_aliasedSelectExpr857); + PushFollow(FOLLOW_selectExpr_in_aliasedSelectExpr873); se = selectExpr(); state.followingStackPointer--; adaptor.AddChild(root_1, se.Tree); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_identifier_in_aliasedSelectExpr861); + PushFollow(FOLLOW_identifier_in_aliasedSelectExpr877); i = identifier(); state.followingStackPointer--; @@ -2939,8 +3022,8 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode ALL46 = null; - IASTNode OBJECT47 = null; + IASTNode ALL48 = null; + IASTNode OBJECT49 = null; HqlSqlWalker.propertyRef_return p = default(HqlSqlWalker.propertyRef_return); HqlSqlWalker.aliasRef_return ar2 = default(HqlSqlWalker.aliasRef_return); @@ -2949,73 +3032,73 @@ HqlSqlWalker.constructor_return con = default(HqlSqlWalker.constructor_return); - HqlSqlWalker.functionCall_return functionCall48 = default(HqlSqlWalker.functionCall_return); + HqlSqlWalker.functionCall_return functionCall50 = default(HqlSqlWalker.functionCall_return); - HqlSqlWalker.parameter_return parameter49 = default(HqlSqlWalker.parameter_return); + HqlSqlWalker.parameter_return parameter51 = default(HqlSqlWalker.parameter_return); - HqlSqlWalker.count_return count50 = default(HqlSqlWalker.count_return); + HqlSqlWalker.count_return count52 = default(HqlSqlWalker.count_return); - HqlSqlWalker.collectionFunction_return collectionFunction51 = default(HqlSqlWalker.collectionFunction_return); + HqlSqlWalker.collectionFunction_return collectionFunction53 = default(HqlSqlWalker.collectionFunction_return); - HqlSqlWalker.literal_return literal52 = default(HqlSqlWalker.literal_return); + HqlSqlWalker.literal_return literal54 = default(HqlSqlWalker.literal_return); - HqlSqlWalker.arithmeticExpr_return arithmeticExpr53 = default(HqlSqlWalker.arithmeticExpr_return); + HqlSqlWalker.arithmeticExpr_return arithmeticExpr55 = default(HqlSqlWalker.arithmeticExpr_return); - HqlSqlWalker.query_return query54 = default(HqlSqlWalker.query_return); + HqlSqlWalker.query_return query56 = default(HqlSqlWalker.query_return); - IASTNode ALL46_tree=null; - IASTNode OBJECT47_tree=null; + IASTNode ALL48_tree=null; + IASTNode OBJECT49_tree=null; try { // HqlSqlWalker.g:189:2: (p= propertyRef | ^( ALL ar2= aliasRef ) | ^( OBJECT ar3= aliasRef ) | con= constructor | functionCall | parameter | count | collectionFunction | literal | arithmeticExpr | query ) - int alt23 = 11; + int alt25 = 11; switch ( input.LA(1) ) { case DOT: case WEIRD_IDENT: case IDENT: { - alt23 = 1; + alt25 = 1; } break; case ALL: { - alt23 = 2; + alt25 = 2; } break; case OBJECT: { - alt23 = 3; + alt25 = 3; } break; case CONSTRUCTOR: { - alt23 = 4; + alt25 = 4; } break; case AGGREGATE: case METHOD_CALL: { - alt23 = 5; + alt25 = 5; } break; case COLON: case PARAM: { - alt23 = 6; + alt25 = 6; } break; case COUNT: { - alt23 = 7; + alt25 = 7; } break; case ELEMENTS: case INDICES: { - alt23 = 8; + alt25 = 8; } break; case NUM_INT: @@ -3025,7 +3108,7 @@ case NUM_LONG: case QUOTED_String: { - alt23 = 9; + alt25 = 9; } break; case CASE: @@ -3040,23 +3123,23 @@ case STAR: case DIV: { - alt23 = 10; + alt25 = 10; } break; case UNION: case QUERY: { - alt23 = 11; + alt25 = 11; } break; default: - NoViableAltException nvae_d23s0 = - new NoViableAltException("", 23, 0, input); + NoViableAltException nvae_d25s0 = + new NoViableAltException("", 25, 0, input); - throw nvae_d23s0; + throw nvae_d25s0; } - switch (alt23) + switch (alt25) { case 1 : // HqlSqlWalker.g:189:4: p= propertyRef @@ -3064,7 +3147,7 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_propertyRef_in_selectExpr876); + PushFollow(FOLLOW_propertyRef_in_selectExpr892); p = propertyRef(); state.followingStackPointer--; @@ -3083,16 +3166,16 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - ALL46=(IASTNode)Match(input,ALL,FOLLOW_ALL_in_selectExpr888); - ALL46_tree = (IASTNode)adaptor.DupNode(ALL46); + ALL48=(IASTNode)Match(input,ALL,FOLLOW_ALL_in_selectExpr904); + ALL48_tree = (IASTNode)adaptor.DupNode(ALL48); - root_1 = (IASTNode)adaptor.BecomeRoot(ALL46_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(ALL48_tree, root_1); Match(input, Token.DOWN, null); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_aliasRef_in_selectExpr892); + PushFollow(FOLLOW_aliasRef_in_selectExpr908); ar2 = aliasRef(); state.followingStackPointer--; @@ -3115,16 +3198,16 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - OBJECT47=(IASTNode)Match(input,OBJECT,FOLLOW_OBJECT_in_selectExpr904); - OBJECT47_tree = (IASTNode)adaptor.DupNode(OBJECT47); + OBJECT49=(IASTNode)Match(input,OBJECT,FOLLOW_OBJECT_in_selectExpr920); + OBJECT49_tree = (IASTNode)adaptor.DupNode(OBJECT49); - root_1 = (IASTNode)adaptor.BecomeRoot(OBJECT47_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(OBJECT49_tree, root_1); Match(input, Token.DOWN, null); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_aliasRef_in_selectExpr908); + PushFollow(FOLLOW_aliasRef_in_selectExpr924); ar3 = aliasRef(); state.followingStackPointer--; @@ -3143,7 +3226,7 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_constructor_in_selectExpr919); + PushFollow(FOLLOW_constructor_in_selectExpr935); con = constructor(); state.followingStackPointer--; @@ -3158,11 +3241,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_functionCall_in_selectExpr930); - functionCall48 = functionCall(); + PushFollow(FOLLOW_functionCall_in_selectExpr946); + functionCall50 = functionCall(); state.followingStackPointer--; - adaptor.AddChild(root_0, functionCall48.Tree); + adaptor.AddChild(root_0, functionCall50.Tree); } break; @@ -3172,11 +3255,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_parameter_in_selectExpr935); - parameter49 = parameter(); + PushFollow(FOLLOW_parameter_in_selectExpr951); + parameter51 = parameter(); state.followingStackPointer--; - adaptor.AddChild(root_0, parameter49.Tree); + adaptor.AddChild(root_0, parameter51.Tree); } break; @@ -3186,11 +3269,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_count_in_selectExpr940); - count50 = count(); + PushFollow(FOLLOW_count_in_selectExpr956); + count52 = count(); state.followingStackPointer--; - adaptor.AddChild(root_0, count50.Tree); + adaptor.AddChild(root_0, count52.Tree); } break; @@ -3200,11 +3283,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_collectionFunction_in_selectExpr945); - collectionFunction51 = collectionFunction(); + PushFollow(FOLLOW_collectionFunction_in_selectExpr961); + collectionFunction53 = collectionFunction(); state.followingStackPointer--; - adaptor.AddChild(root_0, collectionFunction51.Tree); + adaptor.AddChild(root_0, collectionFunction53.Tree); } break; @@ -3214,11 +3297,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_literal_in_selectExpr953); - literal52 = literal(); + PushFollow(FOLLOW_literal_in_selectExpr969); + literal54 = literal(); state.followingStackPointer--; - adaptor.AddChild(root_0, literal52.Tree); + adaptor.AddChild(root_0, literal54.Tree); } break; @@ -3228,11 +3311,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_arithmeticExpr_in_selectExpr958); - arithmeticExpr53 = arithmeticExpr(); + PushFollow(FOLLOW_arithmeticExpr_in_selectExpr974); + arithmeticExpr55 = arithmeticExpr(); state.followingStackPointer--; - adaptor.AddChild(root_0, arithmeticExpr53.Tree); + adaptor.AddChild(root_0, arithmeticExpr55.Tree); } break; @@ -3242,11 +3325,11 @@ root_0 = (IASTNode)adaptor.GetNilNode(); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_query_in_selectExpr963); - query54 = query(); + PushFollow(FOLLOW_query_in_selectExpr979); + query56 = query(); state.followingStackPointer--; - adaptor.AddChild(root_0, query54.Tree); + adaptor.AddChild(root_0, query56.Tree); } break; @@ -3289,15 +3372,15 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode COUNT55 = null; - IASTNode set56 = null; - IASTNode ROW_STAR58 = null; - HqlSqlWalker.aggregateExpr_return aggregateExpr57 = default(HqlSqlWalker.aggregateExpr_return); + IASTNode COUNT57 = null; + IASTNode set58 = null; + IASTNode ROW_STAR60 = null; + HqlSqlWalker.aggregateExpr_return aggregateExpr59 = default(HqlSqlWalker.aggregateExpr_return); - IASTNode COUNT55_tree=null; - IASTNode set56_tree=null; - IASTNode ROW_STAR58_tree=null; + IASTNode COUNT57_tree=null; + IASTNode set58_tree=null; + IASTNode ROW_STAR60_tree=null; try { @@ -3311,36 +3394,36 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - COUNT55=(IASTNode)Match(input,COUNT,FOLLOW_COUNT_in_count975); - COUNT55_tree = (IASTNode)adaptor.DupNode(COUNT55); + COUNT57=(IASTNode)Match(input,COUNT,FOLLOW_COUNT_in_count991); + COUNT57_tree = (IASTNode)adaptor.DupNode(COUNT57); - root_1 = (IASTNode)adaptor.BecomeRoot(COUNT55_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(COUNT57_tree, root_1); Match(input, Token.DOWN, null); // HqlSqlWalker.g:203:12: ( DISTINCT | ALL )? - int alt24 = 2; - int LA24_0 = input.LA(1); + int alt26 = 2; + int LA26_0 = input.LA(1); - if ( (LA24_0 == ALL || LA24_0 == DISTINCT) ) + if ( (LA26_0 == ALL || LA26_0 == DISTINCT) ) { - alt24 = 1; + alt26 = 1; } - switch (alt24) + switch (alt26) { case 1 : // HqlSqlWalker.g: { _last = (IASTNode)input.LT(1); - set56 = (IASTNode)input.LT(1); + set58 = (IASTNode)input.LT(1); if ( input.LA(1) == ALL || input.LA(1) == DISTINCT ) { input.Consume(); - set56_tree = (IASTNode)adaptor.DupNode(set56); + set58_tree = (IASTNode)adaptor.DupNode(set58); - adaptor.AddChild(root_1, set56_tree); + adaptor.AddChild(root_1, set58_tree); state.errorRecovery = false; } @@ -3357,35 +3440,35 @@ } // HqlSqlWalker.g:203:32: ( aggregateExpr | ROW_STAR ) - int alt25 = 2; - int LA25_0 = input.LA(1); + int alt27 = 2; + int LA27_0 = input.LA(1); - if ( (LA25_0 == COUNT || LA25_0 == DOT || LA25_0 == ELEMENTS || LA25_0 == FALSE || LA25_0 == INDICES || LA25_0 == NULL || LA25_0 == TRUE || LA25_0 == CASE || LA25_0 == AGGREGATE || LA25_0 == CASE2 || LA25_0 == INDEX_OP || LA25_0 == METHOD_CALL || LA25_0 == UNARY_MINUS || (LA25_0 >= VECTOR_EXPR && LA25_0 <= WEIRD_IDENT) || (LA25_0 >= NUM_INT && LA25_0 <= JAVA_CONSTANT) || (LA25_0 >= COLON && LA25_0 <= PARAM) || (LA25_0 >= BNOT && LA25_0 <= DIV) || (LA25_0 >= QUOTED_String && LA25_0 <= IDENT)) ) + if ( (LA27_0 == COUNT || LA27_0 == DOT || LA27_0 == ELEMENTS || LA27_0 == FALSE || LA27_0 == INDICES || LA27_0 == NULL || LA27_0 == TRUE || LA27_0 == CASE || LA27_0 == AGGREGATE || LA27_0 == CASE2 || LA27_0 == INDEX_OP || LA27_0 == METHOD_CALL || LA27_0 == UNARY_MINUS || (LA27_0 >= VECTOR_EXPR && LA27_0 <= WEIRD_IDENT) || (LA27_0 >= NUM_INT && LA27_0 <= JAVA_CONSTANT) || (LA27_0 >= COLON && LA27_0 <= PARAM) || (LA27_0 >= BNOT && LA27_0 <= DIV) || (LA27_0 >= QUOTED_String && LA27_0 <= IDENT)) ) { - alt25 = 1; + alt27 = 1; } - else if ( (LA25_0 == ROW_STAR) ) + else if ( (LA27_0 == ROW_STAR) ) { - alt25 = 2; + alt27 = 2; } else { - NoViableAltException nvae_d25s0 = - new NoViableAltException("", 25, 0, input); + NoViableAltException nvae_d27s0 = + new NoViableAltException("", 27, 0, input); - throw nvae_d25s0; + throw nvae_d27s0; } - switch (alt25) + switch (alt27) { case 1 : // HqlSqlWalker.g:203:34: aggregateExpr { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_aggregateExpr_in_count990); - aggregateExpr57 = aggregateExpr(); + PushFollow(FOLLOW_aggregateExpr_in_count1006); + aggregateExpr59 = aggregateExpr(); state.followingStackPointer--; - adaptor.AddChild(root_1, aggregateExpr57.Tree); + adaptor.AddChild(root_1, aggregateExpr59.Tree); } break; @@ -3393,10 +3476,10 @@ // HqlSqlWalker.g:203:50: ROW_STAR { _last = (IASTNode)input.LT(1); - ROW_STAR58=(IASTNode)Match(input,ROW_STAR,FOLLOW_ROW_STAR_in_count994); - ROW_STAR58_tree = (IASTNode)adaptor.DupNode(ROW_STAR58); + ROW_STAR60=(IASTNode)Match(input,ROW_STAR,FOLLOW_ROW_STAR_in_count1010); + ROW_STAR60_tree = (IASTNode)adaptor.DupNode(ROW_STAR60); - adaptor.AddChild(root_1, ROW_STAR58_tree); + adaptor.AddChild(root_1, ROW_STAR60_tree); } @@ -3448,15 +3531,15 @@ IASTNode _first_0 = null; IASTNode _last = null; - IASTNode CONSTRUCTOR59 = null; - HqlSqlWalker.path_return path60 = default(HqlSqlWalker.path_return); + IASTNode CONSTRUCTOR61 = null; + HqlSqlWalker.path_return path62 = default(HqlSqlWalker.path_return); - HqlSqlWalker.selectExpr_return selectExpr61 = default(HqlSqlWalker.selectExpr_return); + HqlSqlWalker.selectExpr_return selectExpr63 = default(HqlSqlWalker.selectExpr_return); - HqlSqlWalker.aliasedSelectExpr_return aliasedSelectExpr62 = default(HqlSqlWalker.aliasedSelectExpr_return); + HqlSqlWalker.aliasedSelectExpr_return aliasedSelectExpr64 = default(HqlSqlWalker.aliasedSelectExpr_return); - IASTNode CONSTRUCTOR59_tree=null; + IASTNode CONSTRUCTOR61_tree=null; try { @@ -3470,47 +3553,47 @@ IASTNode _save_last_1 = _last; IASTNode _first_1 = null; IASTNode root_1 = (IASTNode)adaptor.GetNilNode();_last = (IASTNode)input.LT(1); - CONSTRUCTOR59=(IASTNode)Match(input,CONSTRUCTOR,FOLLOW_CONSTRUCTOR_in_constructor1010); - CONSTRUCTOR59_tree = (IASTNode)adaptor.DupNode(CONSTRUCTOR59); + CONSTRUCTOR61=(IASTNode)Match(input,CONSTRUCTOR,FOLLOW_CONSTRUCTOR_in_constructor1026); + CONSTRUCTOR61_tree = (IASTNode)adaptor.DupNode(CONSTRUCTOR61); - root_1 = (IASTNode)adaptor.BecomeRoot(CONSTRUCTOR59_tree, root_1); + root_1 = (IASTNode)adaptor.BecomeRoot(CONSTRUCTOR61_tree, root_1); Match(input, Token.DOWN, null); _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_path_in_constructor1012); - path60 = path(); + PushFollow(FOLLOW_path_in_constructor1028); + path62 = path(); state.followingStackPointer--; - adaptor.AddChild(root_1, path60.Tree); + adaptor.AddChild(root_1, path62.Tree); // HqlSqlWalker.g:207:23: ( selectExpr | aliasedSelectExpr )* do { - int alt26 = 3; - int LA26_0 = input.LA(1); + int alt28 = 3; + int LA28_0 = input.LA(1); - if ( (LA26_0 == ALL || LA26_0 == COUNT || LA26_0 == DOT || LA26_0 == ELEMENTS || LA26_0 == INDICES || LA26_0 == UNION || LA26_0 == CASE || LA26_0 == OBJECT || LA26_0 == AGGREGATE || (LA26_0 >= CONSTRUCTOR && LA26_0 <= CASE2) || LA26_0 == METHOD_CALL || LA26_0 == QUERY || LA26_0 == UNARY_MINUS || LA26_0 == WEIRD_IDENT || (LA26_0 >= NUM_INT && LA26_0 <= NUM_LONG) || (LA26_0 >= COLON && LA26_0 <= PARAM) || (LA26_0 >= BNOT && LA26_0 <= DIV) || (LA26_0 >= QUOTED_String && LA26_0 <= IDENT)) ) + if ( (LA28_0 == ALL || LA28_0 == COUNT || LA28_0 == DOT || LA28_0 == ELEMENTS || LA28_0 == INDICES || LA28_0 == UNION || LA28_0 == CASE || LA28_0 == OBJECT || LA28_0 == AGGREGATE || (LA28_0 >= CONSTRUCTOR && LA28_0 <= CASE2) || LA28_0 == METHOD_CALL || LA28_0 == QUERY || LA28_0 == UNARY_MINUS || LA28_0 == WEIRD_IDENT || (LA28_0 >= NUM_INT && LA28_0 <= NUM_LONG) || (LA28_0 >= COLON && LA28_0 <= PARAM) || (LA28_0 >= BNOT && LA28_0 <= DIV) || (LA28_0 >= QUOTED_String && LA28_0 <= IDENT)) ) { - alt26 = 1; + alt28 = 1; } - else if ( (LA26_0 == AS) ) + else if ( (LA28_0 == AS) ) { - alt26 = 2; + alt28 = 2; } - switch (alt26) + switch (alt28) { case 1 : // HqlSqlWalker.g:207:25: selectExpr { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_selectExpr_in_constructor1016); - selectExpr61 = selectExpr(); + PushFollow(FOLLOW_selectExpr_in_constructor1032); + selectExpr63 = selectExpr(); state.followingStackPointer--; - adaptor.AddChild(root_1, selectExpr61.Tree); + adaptor.AddChild(root_1, selectExpr63.Tree); } break; @@ -3518,22 +3601,22 @@ // HqlSqlWalker.g:207:38: aliasedSelectExpr { _last = (IASTNode)input.LT(1); - PushFollow(FOLLOW_aliasedSelectExpr_in_constructor1020); - aliasedSelectExpr62 = aliasedSelectExpr(); + PushFollow(FOLLOW_aliasedSelectExpr_in_constructor1036); + aliasedSelectExpr64 = aliasedSelectExpr(); state.followingStackPointer--; - adaptor.AddChild(root_1, aliasedSelectExpr62.Tree); + adaptor.AddChild(root_1, aliasedSelectExpr64.Tree); } break; default: - goto loop26; + goto loop28; } } while (true); - loop26: - ; // Stops C# compiler whining that label 'loop26' has no statements + loop28: + ; // Stops C# compiler whining that label 'loop28' has no statements Match(input, Token.UP, null); adaptor.AddChild(root_0, root_1);_last = _save_last_1; @@ -3579,34 +3662,34 @@ IASTNode _first_0 = null; IASTNode _last = null; - HqlSqlWalker.expr_return expr63 = default(HqlSqlWalker.expr_return); + HqlSqlWalker.expr_return expr65 = default(HqlSqlWalker.expr_return); - HqlSqlWalker.collectionFunction_return collectionFunction64 = default(HqlSqlWalker.collectionFunction_return); + HqlSqlWalker.collectionFunction_return collectionFunction66 = default(HqlSqlWalker.collectionFunction_return); try { // HqlSqlWalker.g:211:2: ( expr | collectionFunction ) - int alt27 = 2; - int LA27_0 = input.LA(1); + int alt29 = 2; + int LA29_0 = input.LA(1); - if ( (LA27_0 == COUNT || LA27_0 == DOT || LA27_0 == FALSE || LA27_0 == NULL || LA27_0 == TRUE || LA27_0 == CASE || LA27_0 == AGGREGATE || LA27_0 == CASE2 || LA27_0 == INDEX_OP || LA27_0 == METHOD_CALL || LA27_0 == UNARY_MINUS || (LA27_0 >= VECTOR_EXPR && LA27_0 <= WEIRD_IDENT) || (LA27_0 >= NUM_INT && LA27_0 <= JAVA_CONSTANT) || (LA27_0 >= COLON && LA27_0 <= PARAM) || (LA27_0 >= BNOT && LA27_0 <= DIV) || (LA27_0 >= QUOTED_String && LA27_0 <= IDENT)) ) + if ( (LA29_0 == COUNT || LA29_0 == DOT || LA29_0 == FALSE || LA29_0 == NULL || LA29_0 == TRUE || LA29_0 == CASE || LA29_0 == AGGREGATE || LA29_0 == CASE2 || LA29_0 == INDEX_OP || LA29_0 == METHOD_CALL || LA29_0 == UNARY_MINUS || (LA29_0 >= VECTOR_EXPR && LA29_0 <= WEIRD_IDENT) |... [truncated message content] |
From: <fab...@us...> - 2011-06-14 21:58:42
|
Revision: 5927 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5927&view=rev Author: fabiomaulo Date: 2011-06-14 21:58:36 +0000 (Tue, 14 Jun 2011) Log Message: ----------- Minor refactoring Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-14 15:18:00 UTC (rev 5926) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-14 21:58:36 UTC (rev 5927) @@ -486,7 +486,7 @@ command.CommandTimeout = selection.Timeout; } - sqlCommand.Bind(command, sqlQueryParametersList, 0, session); + sqlCommand.Bind(command, session); session.Batcher.ExpandQueryParameters(command, sqlString); } Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-14 15:18:00 UTC (rev 5926) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-14 21:58:36 UTC (rev 5927) @@ -354,7 +354,7 @@ command.CommandTimeout = selection.Timeout; } - sqlCommand.Bind(command, sqlQueryParametersList, 0, session); + sqlCommand.Bind(command, session); session.Batcher.ExpandQueryParameters(command, query); } Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-14 15:18:00 UTC (rev 5926) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-14 21:58:36 UTC (rev 5927) @@ -231,7 +231,7 @@ command.CommandTimeout = selection.Timeout; } - sqlCommand.Bind(command, sqlQueryParametersList, 0, session); + sqlCommand.Bind(command, session); session.Batcher.ExpandQueryParameters(command, sqlString); } Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-14 15:18:00 UTC (rev 5926) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-14 21:58:36 UTC (rev 5927) @@ -371,7 +371,7 @@ // After the last modification to the SqlString we can collect all parameters types. parameterSpecs.ResetEffectiveExpectedType(queryParameters); - return new SqlCommand.SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); + return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); } public IType[] ResultTypes Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs 2011-06-14 15:18:00 UTC (rev 5926) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs 2011-06-14 21:58:36 UTC (rev 5927) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -21,6 +22,17 @@ /// <param name="singleSqlParametersOffset">The offset from where start the list of <see cref="IDataParameter"/>, in the given <paramref name="command"/>, for the this <see cref="SqlCommandImpl"/>. </param> /// <param name="session">The session against which the current execution is occuring.</param> void Bind(IDbCommand command, IList<Parameter> commandQueryParametersList, int singleSqlParametersOffset, ISessionImplementor session); + + /// <summary> + /// Bind the appropriate value into the given command. + /// </summary> + /// <param name="command">The command into which the value should be bound.</param> + /// <param name="session">The session against which the current execution is occuring.</param> + /// <remarks> + /// Use this method when the <paramref name="command"/> contains just 'this' instance of <see cref="ISqlCommand"/>. + /// Use the overload <see cref="Bind(IDbCommand, IList{Parameter}, int, ISessionImplementor)"/> when the <paramref name="command"/> contains more instances of <see cref="ISqlCommand"/>. + /// </remarks> + void Bind(IDbCommand command, ISessionImplementor session); } public class SqlCommandImpl : ISqlCommand @@ -79,5 +91,22 @@ parameterSpecification.Bind(command, commandQueryParametersList, singleSqlParametersOffset, SqlQueryParametersList, QueryParameters, session); } } + + /// <summary> + /// Bind the appropriate value into the given command. + /// </summary> + /// <param name="command">The command into which the value should be bound.</param> + /// <param name="session">The session against which the current execution is occuring.</param> + /// <remarks> + /// Use this method when the <paramref name="command"/> contains just 'this' instance of <see cref="ISqlCommand"/>. + /// Use the overload <see cref="Bind(IDbCommand, IList{Parameter}, int, ISessionImplementor)"/> when the <paramref name="command"/> contains more instances of <see cref="ISqlCommand"/>. + /// </remarks> + public void Bind(IDbCommand command, ISessionImplementor session) + { + foreach (IParameterSpecification parameterSpecification in Specifications) + { + parameterSpecification.Bind(command, SqlQueryParametersList, QueryParameters, session); + } + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-15 19:19:52
|
Revision: 5929 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5929&view=rev Author: fabiomaulo Date: 2011-06-15 19:19:46 +0000 (Wed, 15 Jun 2011) Log Message: ----------- Refactoring: moved extension-method in ISqlCommand instance Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Param/ParametersBackTrackExtensions.cs trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-14 23:05:35 UTC (rev 5928) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-15 19:19:46 UTC (rev 5929) @@ -469,13 +469,10 @@ /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) { - var sqlCommand = (SqlCommandImpl)CreateSqlCommand(queryParameters, session); - var parameterSpecs = sqlCommand.Specifications; + var sqlCommand = CreateSqlCommand(queryParameters, session); var sqlString = sqlCommand.Query; - var sqlQueryParametersList = sqlCommand.SqlQueryParametersList; - - parameterSpecs.SetQueryParameterLocations(sqlQueryParametersList, session.Factory); + sqlCommand.ResetParametersIndexesForTheCommand(0); IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlCommand.ParameterTypes); try Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-14 23:05:35 UTC (rev 5928) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-15 19:19:46 UTC (rev 5929) @@ -337,13 +337,10 @@ /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) { - var sqlCommand = (SqlCommandImpl)CreateSqlCommand(queryParameters, session); - var parameterSpecs = sqlCommand.Specifications; + var sqlCommand = CreateSqlCommand(queryParameters, session); var query = sqlCommand.Query; - var sqlQueryParametersList = sqlCommand.SqlQueryParametersList; - parameterSpecs.SetQueryParameterLocations(sqlQueryParametersList, session.Factory); - + sqlCommand.ResetParametersIndexesForTheCommand(0); IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, query, sqlCommand.ParameterTypes); try Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-14 23:05:35 UTC (rev 5928) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-15 19:19:46 UTC (rev 5929) @@ -215,14 +215,12 @@ /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) { - var sqlCommand = (SqlCommandImpl)CreateSqlCommand(queryParameters, session); - var parameterSpecs = sqlCommand.Specifications; + var sqlCommand = CreateSqlCommand(queryParameters, session); var sqlString = sqlCommand.Query; - var sqlQueryParametersList = sqlCommand.SqlQueryParametersList; - parameterSpecs.SetQueryParameterLocations(sqlQueryParametersList, session.Factory); - + sqlCommand.ResetParametersIndexesForTheCommand(0); IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlCommand.ParameterTypes); + try { RowSelection selection = queryParameters.RowSelection; Modified: trunk/nhibernate/src/NHibernate/Param/ParametersBackTrackExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/ParametersBackTrackExtensions.cs 2011-06-14 23:05:35 UTC (rev 5928) +++ trunk/nhibernate/src/NHibernate/Param/ParametersBackTrackExtensions.cs 2011-06-15 19:19:46 UTC (rev 5929) @@ -48,34 +48,5 @@ parameterSpecification.SetEffectiveType(queryParameters); } } - - /// <summary> - /// Influence the final name of the parameter. - /// </summary> - /// <param name="parameterSpecs"></param> - /// <param name="sqlQueryParametersList"></param> - /// <param name="factory"></param> - public static void SetQueryParameterLocations(this IEnumerable<IParameterSpecification> parameterSpecs, List<Parameter> sqlQueryParametersList, ISessionFactoryImplementor factory) - { - // due to IType.NullSafeSet(System.Data.IDbCommand , object, int, ISessionImplementor) the SqlType[] is supposed to be in a certain sequence. - // this mean that found the first location of a parameter for the IType span, the others are in secuence - foreach (IParameterSpecification specification in parameterSpecs) - { - string firstParameterId = specification.GetIdsForBackTrack(factory).First(); - int[] effectiveParameterLocations = sqlQueryParametersList.GetEffectiveParameterLocations(firstParameterId).ToArray(); - if (effectiveParameterLocations.Length > 0) // Parameters previously present might have been removed from the SQL at a later point. - { - int firstParamNameIndex = effectiveParameterLocations.First(); - foreach (int location in effectiveParameterLocations) - { - int parameterSpan = specification.ExpectedType.GetColumnSpan(factory); - for (int j = 0; j < parameterSpan; j++) - { - sqlQueryParametersList[location + j].ParameterPosition = firstParamNameIndex + j; - } - } - } - } - } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs 2011-06-14 23:05:35 UTC (rev 5928) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandImpl.cs 2011-06-15 19:19:46 UTC (rev 5929) @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -15,12 +14,31 @@ QueryParameters QueryParameters { get; } /// <summary> + /// re-set the index of each parameter in the final <see cref="IDbCommand">command</see>. + /// </summary> + /// <param name="singleSqlParametersOffset">The offset from where start the list of <see cref="IDataParameter"/>, in the given command, for the this <see cref="SqlCommandImpl"/>. </param> + /// <remarks> + /// Suppose the final <see cref="IDbCommand">command</see> is composed by two queries. The <paramref name="singleSqlParametersOffset"/> for the first query is zero. + /// If the first query command has 12 parameters (size of its SqlType array) the offset to bind all <see cref="IParameterSpecification"/>s, of the second query in the + /// command, is 12 (for the first query we are using from 0 to 11). + /// <para> + /// This method should be called before call <see cref="IBatcher.PrepareCommand"/>. + /// </para> + /// </remarks> + void ResetParametersIndexesForTheCommand(int singleSqlParametersOffset); // Note: should be included ParameterTypes getter + + /// <summary> /// Bind the appropriate value into the given command. /// </summary> /// <param name="command">The command into which the value should be bound.</param> /// <param name="commandQueryParametersList">The parameter-list of the whole query of the command.</param> /// <param name="singleSqlParametersOffset">The offset from where start the list of <see cref="IDataParameter"/>, in the given <paramref name="command"/>, for the this <see cref="SqlCommandImpl"/>. </param> /// <param name="session">The session against which the current execution is occuring.</param> + /// <remarks> + /// Suppose the <paramref name="command"/> is composed by two queries. The <paramref name="singleSqlParametersOffset"/> for the first query is zero. + /// If the first query in <paramref name="command"/> has 12 parameters (size of its SqlType array) the offset to bind all <see cref="IParameterSpecification"/>s, of the second query in the + /// <paramref name="command"/>, is 12 (for the first query we are using from 0 to 11). + /// </remarks> void Bind(IDbCommand command, IList<Parameter> commandQueryParametersList, int singleSqlParametersOffset, ISessionImplementor session); /// <summary> @@ -77,6 +95,35 @@ get { return queryParameters; } } + public void ResetParametersIndexesForTheCommand(int singleSqlParametersOffset) + { + // a better place could be the Bind of each IParameterSpecification but we have to do it before bind values + // in this way the same parameter of a dynamic-filter will be set with two different parameter-names in the same command (when it is a command-set). + if (singleSqlParametersOffset < 0) + { + throw new AssertionFailure("singleSqlParametersOffset < 0 - this indicate a bug in NHibernate "); + } + // due to IType.NullSafeSet(System.Data.IDbCommand , object, int, ISessionImplementor) the SqlType[] is supposed to be in a certain sequence. + // this mean that found the first location of a parameter for the IType span, the others are in secuence + foreach (IParameterSpecification specification in Specifications) + { + string firstParameterId = specification.GetIdsForBackTrack(factory).First(); + int[] effectiveParameterLocations = SqlQueryParametersList.GetEffectiveParameterLocations(firstParameterId).ToArray(); + if (effectiveParameterLocations.Length > 0) // Parameters previously present might have been removed from the SQL at a later point. + { + int firstParamNameIndex = effectiveParameterLocations.First() + singleSqlParametersOffset; + foreach (int location in effectiveParameterLocations) + { + int parameterSpan = specification.ExpectedType.GetColumnSpan(factory); + for (int j = 0; j < parameterSpan; j++) + { + sqlQueryParametersList[location + j].ParameterPosition = firstParamNameIndex + j; + } + } + } + } + } + /// <summary> /// Bind the appropriate value into the given command. /// </summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-15 20:04:53
|
Revision: 5931 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5931&view=rev Author: fabiomaulo Date: 2011-06-15 20:04:47 +0000 (Wed, 15 Jun 2011) Log Message: ----------- Removed dead constructor Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-15 19:38:45 UTC (rev 5930) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-15 20:04:47 UTC (rev 5931) @@ -52,8 +52,6 @@ public QueryParameters() : this(ArrayHelper.EmptyTypeArray, ArrayHelper.EmptyObjectArray) {} - public QueryParameters(IType type, object value) : this(new[] {type}, new[] {value}) {} - public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, object optionalObject, string optionalEntityName, object optionalObjectId) : this(positionalParameterTypes, postionalParameterValues) { @@ -78,9 +76,10 @@ _tempPagingParameterIndexes = tempPagingParameterIndexes; } - public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool isReadOnlyInitialized, bool readOnly, bool cacheable, string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer) - : this(positionalParameterTypes, positionalParameterValues, namedParameters, lockModes, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, null, transformer) + public QueryParameters(IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool isReadOnlyInitialized, bool readOnly, bool cacheable, string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer) + : this(ArrayHelper.EmptyTypeArray, ArrayHelper.EmptyObjectArray, namedParameters, lockModes, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, null, transformer) { + // used by CriteriaTranslator NaturalKeyLookup = isLookupByNaturalKey; } Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2011-06-15 19:38:45 UTC (rev 5930) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2011-06-15 20:04:47 UTC (rev 5931) @@ -134,8 +134,6 @@ return new QueryParameters( - new IType[0], - new object[0], queryNamedParameters, lockModes, selection, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-15 23:31:24
|
Revision: 5932 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5932&view=rev Author: fabiomaulo Date: 2011-06-15 23:31:17 +0000 (Wed, 15 Jun 2011) Log Message: ----------- Refactoring to have common PrepareQueryCommand (as before) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -454,51 +454,5 @@ return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); } - - /// <summary> - /// Obtain an <c>IDbCommand</c> with all parameters pre-bound. Bind positional parameters, - /// named parameters, and limit parameters. - /// </summary> - /// <remarks> - /// Creates an IDbCommand object and populates it with the values necessary to execute it against the - /// database to Load an Entity. - /// </remarks> - /// <param name="queryParameters">The <see cref="QueryParameters"/> to use for the IDbCommand.</param> - /// <param name="scroll">TODO: find out where this is used...</param> - /// <param name="session">The SessionImpl this Command is being prepared in.</param> - /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> - protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) - { - var sqlCommand = CreateSqlCommand(queryParameters, session); - var sqlString = sqlCommand.Query; - - sqlCommand.ResetParametersIndexesForTheCommand(0); - IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlCommand.ParameterTypes); - - try - { - RowSelection selection = queryParameters.RowSelection; - if (selection != null && selection.Timeout != RowSelection.NoValue) - { - command.CommandTimeout = selection.Timeout; - } - - sqlCommand.Bind(command, session); - - session.Batcher.ExpandQueryParameters(command, sqlString); - } - catch (HibernateException) - { - session.Batcher.CloseCommand(command, null); - throw; - } - catch (Exception sqle) - { - session.Batcher.CloseCommand(command, null); - ADOExceptionReporter.LogExceptions(sqle); - throw; - } - return command; - } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -324,52 +324,6 @@ } /// <summary> - /// Obtain an <c>IDbCommand</c> with all parameters pre-bound. Bind positional parameters, - /// named parameters, and limit parameters. - /// </summary> - /// <remarks> - /// Creates an IDbCommand object and populates it with the values necessary to execute it against the - /// database to Load an Entity. - /// </remarks> - /// <param name="queryParameters">The <see cref="QueryParameters"/> to use for the IDbCommand.</param> - /// <param name="scroll">TODO: find out where this is used...</param> - /// <param name="session">The SessionImpl this Command is being prepared in.</param> - /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> - protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) - { - var sqlCommand = CreateSqlCommand(queryParameters, session); - var query = sqlCommand.Query; - - sqlCommand.ResetParametersIndexesForTheCommand(0); - IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, query, sqlCommand.ParameterTypes); - - try - { - RowSelection selection = queryParameters.RowSelection; - if (selection != null && selection.Timeout != RowSelection.NoValue) - { - command.CommandTimeout = selection.Timeout; - } - - sqlCommand.Bind(command, session); - - session.Batcher.ExpandQueryParameters(command, query); - } - catch (HibernateException) - { - session.Batcher.CloseCommand(command, null); - throw; - } - catch (Exception sqle) - { - session.Batcher.CloseCommand(command, null); - ADOExceptionReporter.LogExceptions(sqle); - throw; - } - return command; - } - - /// <summary> /// Compile a "normal" query. This method may be called multiple /// times. Subsequent invocations are no-ops. /// </summary> Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -865,7 +865,7 @@ var sqlQueryImpl = (SqlQueryImpl) sqlQuery; NativeSQLQuerySpecification sqlQuerySpec = sqlQueryImpl.GenerateQuerySpecification(sqlQueryImpl.NamedParams); var sqlCustomQuery = new SQLCustomQuery(sqlQuerySpec.SqlQueryReturns, sqlQuerySpec.QueryString, sqlQuerySpec.QuerySpaces, sessionFactory); - loader = new CustomLoader(sqlCustomQuery, sqlCustomQuery.CollectedParametersSpecifications, sessionFactory); + loader = new CustomLoader(sqlCustomQuery, sessionFactory); } public IType[] ReturnTypes Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -201,52 +201,6 @@ return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); } - /// <summary> - /// Obtain an <c>IDbCommand</c> with all parameters pre-bound. Bind positional parameters, - /// named parameters, and limit parameters. - /// </summary> - /// <remarks> - /// Creates an IDbCommand object and populates it with the values necessary to execute it against the - /// database to Load an Entity. - /// </remarks> - /// <param name="queryParameters">The <see cref="QueryParameters"/> to use for the IDbCommand.</param> - /// <param name="scroll">TODO: find out where this is used...</param> - /// <param name="session">The SessionImpl this Command is being prepared in.</param> - /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> - protected internal override IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) - { - var sqlCommand = CreateSqlCommand(queryParameters, session); - var sqlString = sqlCommand.Query; - - sqlCommand.ResetParametersIndexesForTheCommand(0); - IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlCommand.ParameterTypes); - - try - { - RowSelection selection = queryParameters.RowSelection; - if (selection != null && selection.Timeout != RowSelection.NoValue) - { - command.CommandTimeout = selection.Timeout; - } - - sqlCommand.Bind(command, session); - - session.Batcher.ExpandQueryParameters(command, sqlString); - } - catch (HibernateException) - { - session.Batcher.CloseCommand(command, null); - throw; - } - catch (Exception sqle) - { - session.Batcher.CloseCommand(command, null); - ADOExceptionReporter.LogExceptions(sqle); - throw; - } - return command; - } - public override int[] GetNamedParameterLocs(string name) { return new int[0]; Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -43,17 +43,12 @@ private IType[] resultTypes; private string[] transformerAliases; - public CustomLoader(ICustomQuery customQuery, IEnumerable<IParameterSpecification> parametersSpecifications, ISessionFactoryImplementor factory) - : this(customQuery, factory) - { - this.parametersSpecifications = parametersSpecifications.ToList(); - } - public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory) : base(factory) { sql = customQuery.SQL; querySpaces.AddAll(customQuery.QuerySpaces); namedParameterBindPoints = customQuery.NamedParameterBindPoints; + this.parametersSpecifications = customQuery.CollectedParametersSpecifications.ToList(); List<IQueryable> entitypersisters = new List<IQueryable>(); List<int> entityowners = new List<int>(); @@ -350,10 +345,6 @@ public override ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) { - if(parametersSpecifications == null) - { - throw new InvalidOperationException("The custom SQL loader was not initialized with Parameters Specifications."); - } // A distinct-copy of parameter specifications collected during query construction var parameterSpecs = new HashSet<IParameterSpecification>(parametersSpecifications); SqlString sqlString = SqlString.Copy(); Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -1,5 +1,6 @@ using System.Collections.Generic; using Iesi.Collections.Generic; +using NHibernate.Param; using NHibernate.SqlCommand; namespace NHibernate.Loader.Custom @@ -42,5 +43,7 @@ /// ADO result set to be expected and how to map this result set. /// </summary> IList<IReturn> CustomQueryReturns { get; } + + IEnumerable<IParameterSpecification> CollectedParametersSpecifications { get; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-15 20:04:47 UTC (rev 5931) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-15 23:31:17 UTC (rev 5932) @@ -1136,83 +1136,25 @@ /// <param name="scroll">TODO: find out where this is used...</param> /// <param name="session">The SessionImpl this Command is being prepared in.</param> /// <returns>A CommandWrapper wrapping an IDbCommand that is ready to be executed.</returns> - protected internal virtual IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, - ISessionImplementor session) + protected internal virtual IDbCommand PrepareQueryCommand(QueryParameters queryParameters, bool scroll, ISessionImplementor session) { - SqlString sqlString = ProcessFilters(queryParameters, session); - Dialect.Dialect dialect = session.Factory.Dialect; + ISqlCommand sqlCommand = CreateSqlCommand(queryParameters, session); + SqlString sqlString = sqlCommand.Query; - RowSelection selection = queryParameters.RowSelection; - bool useLimit = UseLimit(selection, dialect); - bool hasFirstRow = GetFirstRow(selection) > 0; - bool useOffset = hasFirstRow && useLimit && dialect.SupportsLimitOffset; - int startIndex = GetFirstLimitParameterCount(dialect, useLimit, hasFirstRow, useOffset); - // TODO NH bool callable = queryParameters.Callable; + sqlCommand.ResetParametersIndexesForTheCommand(0); + IDbCommand command = session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlCommand.ParameterTypes); - SqlType[] parameterTypes = queryParameters.PrepareParameterTypes(sqlString, Factory, GetNamedParameterLocs, startIndex, useLimit, useOffset); - - if (useLimit) - { - int? offset = GetOffsetUsingDialect(selection, dialect); - int? limit = GetLimitUsingDialect(selection, dialect); - Parameter offsetParameter = queryParameters.OffsetParameterIndex.HasValue ? Parameter.WithIndex(queryParameters.OffsetParameterIndex.Value) : null; - Parameter limitParameter = queryParameters.LimitParameterIndex.HasValue ? Parameter.WithIndex(queryParameters.LimitParameterIndex.Value) : null; - sqlString = - dialect.GetLimitString( - sqlString.Trim(), - useOffset ? offset : null, - limit, - useOffset ? offsetParameter : null, - limitParameter); - } - - sqlString = PreprocessSQL(sqlString, queryParameters, dialect); - - // TODO NH: Callable for SP -> PrepareCallableQueryCommand - IDbCommand command = - session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, parameterTypes); - try { - // Added in NH - not in H2.1 + RowSelection selection = queryParameters.RowSelection; if (selection != null && selection.Timeout != RowSelection.NoValue) { command.CommandTimeout = selection.Timeout; } - int colIndex = 0; + sqlCommand.Bind(command, session); - if (useLimit && dialect.BindLimitParametersFirst) - { - colIndex += BindLimitParameters(command, colIndex, selection, session); - } - // TODO NH - //if (callable) - //{ - // colIndex = dialect.RegisterResultSetOutParameter(command, col); - //} - - colIndex += BindParameterValues(command, queryParameters, colIndex, session); - - if (useLimit && !dialect.BindLimitParametersFirst) - { - BindLimitParameters(command, colIndex, selection, session); - } - session.Batcher.ExpandQueryParameters(command, sqlString); - - if (!useLimit) - { - SetMaxRows(command, selection); - } - if (selection != null) - { - if (selection.Timeout != RowSelection.NoValue) - { - command.CommandTimeout = selection.Timeout; - } - // H2.1 handles FetchSize here - not ported - } } catch (HibernateException) { @@ -1225,7 +1167,6 @@ ADOExceptionReporter.LogExceptions(sqle); throw; } - return command; } @@ -1758,9 +1699,43 @@ public virtual ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) { - throw new NotSupportedException("This loader does not support extraction of single command."); + // The implementation of this method is itended to be used just for "internal" command (not for queries coming from users) + // Internally NH creates various commands, all using just positional-parameters, to then potentially apply dynamic-filters and pagination. + // In practice this method should be overriden by those loaders representing a user-query as CriteriaLoader, QueryLoader, classic QueryTraslator, CustomLoader (for custmon SQL queries). + + // A distinct-copy of parameter specifications collected during query construction + var parameterSpecs = new HashSet<IParameterSpecification>(GetParameterSpecifications(queryParameters, session.Factory)); + SqlString sqlString = SqlString.Copy(); + + // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it + sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); + AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below + + sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); + // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries + + // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) + sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); + + return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); } + protected IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + { + // TODO FM: remove this implementation and put an abstract ParameterSpecifications in the Loader (each concrete implementation have to expose it) => NH1990, SubselectFetchFixture + var positionalSpecifications = queryParameters.PositionalParameterTypes.Select((t, i) => (IParameterSpecification)new PositionalParameterSpecification(1, 0, i) { ExpectedType = t }); + var namedSpecifications = queryParameters.NamedParameters != null ? queryParameters.NamedParameters.Select(np => (IParameterSpecification)new NamedParameterSpecification(1, 0, np.Key) { ExpectedType = np.Value.Type }): Enumerable.Empty<IParameterSpecification>(); + var specifications= positionalSpecifications.Concat(namedSpecifications).ToList(); + var parameters = SqlString.GetParameters().ToArray(); + var sqlParameterPos = 0; + var paramTrackers = specifications.SelectMany(specification => specification.GetIdsForBackTrack(sessionFactory)); + foreach (var paramTracker in paramTrackers) + { + parameters[sqlParameterPos++].BackTrack = paramTracker; + } + return specifications; + } + protected void AdjustQueryParametersForSubSelectFetching(SqlString sqlString, IEnumerable<IParameterSpecification> parameterSpecs, ISessionImplementor session, QueryParameters queryParameters) { // TODO: Remove this when all parameters are managed using IParameterSpecification (QueryParameters does not need to have decomposed values for filters) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 16:29:46
|
Revision: 5933 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5933&view=rev Author: fabiomaulo Date: 2011-06-16 16:29:39 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Added parameter-specifications for sub-select queries Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-15 23:31:17 UTC (rev 5932) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:29:39 UTC (rev 5933) @@ -6,6 +6,7 @@ using NHibernate.Hql.Classic; using NHibernate.Impl; +using NHibernate.Param; using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Transform; @@ -639,12 +640,14 @@ return span; } - internal SqlString ProcessedSql + public SqlString ProcessedSql { get { return processedSQL; } - set { processedSQL = value; } + internal set { processedSQL = value; } } + public IEnumerable<IParameterSpecification> ProcessedSqlParameters { get; internal set; } + public SqlString FilteredSQL { get { return processedSQL; } Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-15 23:31:17 UTC (rev 5932) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-16 16:29:39 UTC (rev 5933) @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Linq; using NHibernate.Engine; +using NHibernate.Param; using NHibernate.Persister.Collection; using NHibernate.SqlCommand; using NHibernate.Type; @@ -14,6 +16,7 @@ private readonly IDictionary<string, TypedValue> namedParameters; private readonly IType[] types; private readonly object[] values; + private readonly List<IParameterSpecification> parametersSpecifications; public SubselectCollectionLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys, QueryParameters queryParameters, IDictionary<string, int[]> namedParameterLocMap, @@ -28,7 +31,9 @@ } namedParameters = queryParameters.NamedParameters; + // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters + parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); types = queryParameters.PositionalParameterTypes; values = queryParameters.PositionalParameterValues; this.namedParameterLocMap = namedParameterLocMap; @@ -43,5 +48,10 @@ { return namedParameterLocMap[name]; } + + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + { + return parametersSpecifications; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-15 23:31:17 UTC (rev 5932) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-16 16:29:39 UTC (rev 5933) @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Linq; using NHibernate.Engine; +using NHibernate.Param; using NHibernate.Persister.Collection; using NHibernate.SqlCommand; using NHibernate.Type; @@ -17,6 +19,7 @@ private readonly IDictionary<string, TypedValue> namedParameters; private readonly IType[] types; private readonly object[] values; + private readonly List<IParameterSpecification> parametersSpecifications; public SubselectOneToManyLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys, QueryParameters queryParameters, IDictionary<string, int[]> namedParameterLocMap, @@ -32,8 +35,9 @@ namedParameters = queryParameters.NamedParameters; // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters - types = new List<IType>(new JoinedEnumerable<IType>(queryParameters.FilteredParameterTypes, queryParameters.PositionalParameterTypes)).ToArray(); - values = new List<object>(new JoinedEnumerable<object>(queryParameters.FilteredParameterValues, queryParameters.PositionalParameterValues)).ToArray(); + parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); + types = queryParameters.PositionalParameterTypes; + values = queryParameters.PositionalParameterValues; this.namedParameterLocMap = namedParameterLocMap; } @@ -46,5 +50,10 @@ { return namedParameterLocMap[name]; } + + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + { + return parametersSpecifications; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-15 23:31:17 UTC (rev 5932) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-16 16:29:39 UTC (rev 5933) @@ -1712,7 +1712,7 @@ AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries + // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); @@ -1720,7 +1720,7 @@ return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); } - protected IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected virtual IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) { // TODO FM: remove this implementation and put an abstract ParameterSpecifications in the Loader (each concrete implementation have to expose it) => NH1990, SubselectFetchFixture var positionalSpecifications = queryParameters.PositionalParameterTypes.Select((t, i) => (IParameterSpecification)new PositionalParameterSpecification(1, 0, i) { ExpectedType = t }); @@ -1763,6 +1763,7 @@ } queryParameters.ProcessedSql = sqlString; + queryParameters.ProcessedSqlParameters = parameterSpecs.ToList(); queryParameters.FilteredParameterLocations = filteredParameterLocations; queryParameters.FilteredParameterTypes = filteredParameterTypes; queryParameters.FilteredParameterValues = filteredParameterValues; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 16:30:16
|
Revision: 5934 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5934&view=rev Author: fabiomaulo Date: 2011-06-16 16:30:10 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Adjusted TODO Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-16 16:29:39 UTC (rev 5933) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-16 16:30:10 UTC (rev 5934) @@ -444,7 +444,7 @@ AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries + // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-16 16:29:39 UTC (rev 5933) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-16 16:30:10 UTC (rev 5934) @@ -193,7 +193,7 @@ AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries + // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-16 16:29:39 UTC (rev 5933) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-16 16:30:10 UTC (rev 5934) @@ -354,7 +354,7 @@ //AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries + // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 16:41:07
|
Revision: 5935 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5935&view=rev Author: fabiomaulo Date: 2011-06-16 16:41:01 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:30:10 UTC (rev 5934) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:41:01 UTC (rev 5935) @@ -1,14 +1,9 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Data; -using System.Linq; - -using NHibernate.Hql.Classic; using NHibernate.Impl; using NHibernate.Param; using NHibernate.SqlCommand; -using NHibernate.SqlTypes; using NHibernate.Transform; using NHibernate.Type; using NHibernate.Util; @@ -43,11 +38,6 @@ private bool _isReadOnlyInitialized; private string _comment; private bool _readOnly; - private int? limitParameterIndex = null; - private int? offsetParameterIndex = null; - private IDictionary<int, int> _adjustedParameterLocations; - private IDictionary<int, int> _tempPagingParameterIndexes; - private IDictionary<int, int> _pagingParameterIndexMap; private SqlString processedSQL; private readonly IResultTransformer _resultTransformer; @@ -62,7 +52,7 @@ } public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues) - : this(positionalParameterTypes, postionalParameterValues, null, null, false, false, false, null, null, false, null, null) {} + : this(positionalParameterTypes, postionalParameterValues, null, null, false, false, false, null, null, false, null) {} public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, object[] collectionKeys) : this(positionalParameterTypes, postionalParameterValues, null, collectionKeys) {} @@ -70,11 +60,10 @@ public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, IDictionary<string, TypedValue> namedParameters, object[] collectionKeys) : this(positionalParameterTypes, postionalParameterValues, namedParameters, null, null, false, false, false, null, null, collectionKeys, null) {} - public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool isReadOnlyInitialized, bool readOnly, bool cacheable, string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer, IDictionary<int,int> tempPagingParameterIndexes) + public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool isReadOnlyInitialized, bool readOnly, bool cacheable, string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer) : this(positionalParameterTypes, positionalParameterValues, null, lockModes, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, null, transformer) { NaturalKeyLookup = isLookupByNaturalKey; - _tempPagingParameterIndexes = tempPagingParameterIndexes; } public QueryParameters(IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool isReadOnlyInitialized, bool readOnly, bool cacheable, string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer) @@ -113,16 +102,6 @@ get { return _rowSelection != null; } } - public int? LimitParameterIndex - { - get { return limitParameterIndex; } - } - - public int? OffsetParameterIndex - { - get { return offsetParameterIndex; } - } - public IDictionary<string, TypedValue> NamedParameters { get { return _namedParameters; } @@ -178,18 +157,6 @@ { get { return _isReadOnlyInitialized; } } - - private void CreatePositionalParameterLocations(ISessionFactoryImplementor factory) - { - _positionalParameterLocations = new int[_positionalParameterTypes.Length]; - int location = 0; - for (int i = 0; i < _positionalParameterLocations.Length; i++) - { - var span = _positionalParameterTypes[i].GetColumnSpan(factory); - _positionalParameterLocations[i] = location; - location += span; - } - } private int SafeLength(Array array) { @@ -295,351 +262,6 @@ } } - /************** Filters ********************************/ - - public int FindAdjustedParameterLocation(int parameterIndex) - { - if (_adjustedParameterLocations == null) - return parameterIndex; - - return _adjustedParameterLocations[parameterIndex]; - } - - public void ProcessFilters(SqlString sql, ISessionImplementor session) - { - filteredParameterValues = new List<object>(); - filteredParameterTypes = new List<IType>(); - filteredParameterLocations = new List<int>(); - - if (session.EnabledFilters.Count == 0 || sql.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0) - { - processedSQL = sql.Copy(); - return; - } - - Dialect.Dialect dialect = session.Factory.Dialect; - string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote; - - var result = new SqlStringBuilder(); - - int originalParameterIndex = 0; // keep track of the positional parameter - int newParameterIndex = 0; - _adjustedParameterLocations = new Dictionary<int, int>(); - - foreach (var part in sql.Parts) - { - if (part is Parameter) - { - result.Add(((Parameter)part).Clone()); - - // (?) can be a position parameter or a named parameter (already substituted by (?), - // but only the positional parameters are available at this point. Adding them in the - // order of appearance is best that can be done at this point of time, but if they - // are mixed with named parameters, the order is still wrong, because values and - // types for the named parameters are added later to the end of the list. - // see test fixture NH-1098 - - _adjustedParameterLocations[originalParameterIndex] = newParameterIndex; - originalParameterIndex++; - newParameterIndex++; - continue; - } - - var tokenizer = new StringTokenizer((string) part, symbols, true); - - foreach (var token in tokenizer) - { - if (token.StartsWith(ParserHelper.HqlVariablePrefix)) - { - string filterParameterName = token.Substring(1); - object value = session.GetFilterParameterValue(filterParameterName); - IType type = session.GetFilterParameterType(filterParameterName); - - // If the value is not a value of the type but a collection of values... - if (value != null && !type.ReturnedClass.IsAssignableFrom(value.GetType()) && // Added to fix NH-882 - typeof (ICollection).IsAssignableFrom(value.GetType())) - { - var coll = (ICollection) value; - int i = 0; - foreach (var elementValue in coll) - { - i++; - int span = type.GetColumnSpan(session.Factory); - if (span > 0) - { - result.AddParameter(); - filteredParameterTypes.Add(type); - filteredParameterValues.Add(elementValue); - filteredParameterLocations.Add(newParameterIndex); - newParameterIndex++; - if (i < coll.Count) - { - result.Add(", "); - } - } - } - } - else - { - int span = type.GetColumnSpan(session.Factory); - if (span > 0) - { - result.AddParameter(); - filteredParameterTypes.Add(type); - filteredParameterValues.Add(value); - filteredParameterLocations.Add(newParameterIndex); - newParameterIndex++; - } - } - } - else - { - result.Add(token); - } - } - } - - processedSQL = result.ToSqlString(); - } - - private IList<Parameter> FindParametersIn(SqlString sqlString) - { - IList<Parameter> sqlParameters = new List<Parameter>(); - - foreach (object sqlParameter in sqlString.Parts) - { - if (sqlParameter is Parameter) - { - var parameter = (Parameter) sqlParameter; - if (!parameter.ParameterPosition.HasValue || (parameter.ParameterPosition >= 0)) - { - sqlParameters.Add(parameter); - } - } - } - - return sqlParameters; - } - - private void SetParameterLocation(IList<Parameter> sqlParameters, int parameterIndex, int sqlLocation, int span) - { - int i = 0; - while (i < span) - { - sqlParameters[sqlLocation + i].ParameterPosition = parameterIndex + i; - i++; - } - } - - private SqlType[] ConvertITypesToSqlTypes(List<IType> nhTypes, ISessionFactoryImplementor factory, int totalSpan) - { - SqlType[] result = new SqlType[totalSpan]; - - int index = 0; - foreach (IType type in nhTypes) - { - int span = type.SqlTypes(factory).Length; - Array.Copy(type.SqlTypes(factory), 0, result, index, span); - index += span; - } - - return result; - } - - public SqlType[] PrepareParameterTypes(SqlString sqlString, ISessionFactoryImplementor factory, GetNamedParameterLocations getNamedParameterLocations, int startParameterIndex, bool addLimit, bool addOffset) - { - List<IType> paramTypeList = new List<IType>(); - int parameterIndex = 0; - int totalSpan = 0; - - CreatePositionalParameterLocations(factory); - - IList<Parameter> sqlParameters = FindParametersIn(sqlString); - - for (int index = 0; index < PositionalParameterTypes.Length; index++) - { - IType type = PositionalParameterTypes[index]; - ArrayHelper.SafeSetValue(paramTypeList, parameterIndex, type); - - int location = PositionalParameterLocations[index]; - location = FindAdjustedParameterLocation(location); - int span = type.GetColumnSpan(factory); - SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span); - - totalSpan += span; - parameterIndex++; - } - - for (int index = 0; index < FilteredParameterTypes.Count; index++) - { - IType type = FilteredParameterTypes[index]; - ArrayHelper.SafeSetValue(paramTypeList, parameterIndex, type); - - int location = FilteredParameterLocations[index]; - int span = type.GetColumnSpan(factory); - SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span); - - totalSpan += span; - parameterIndex++; - } - - if (NamedParameters != null && NamedParameters.Count > 0) - { - // convert the named parameters to an array of types - foreach (KeyValuePair<string, TypedValue> namedParameter in NamedParameters) - { - TypedValue typedval = namedParameter.Value; - ArrayHelper.SafeSetValue(paramTypeList, parameterIndex, typedval.Type); - - int span = typedval.Type.GetColumnSpan(factory); - string name = namedParameter.Key; - int[] locs = getNamedParameterLocations(name); - for (int i = 0; i < locs.Length; i++) - { - int location = locs[i]; - location = FindAdjustedParameterLocation(location); - - // can still clash with positional parameters - // could consider throwing an exception to locate problem (NH-1098) - while ((location < sqlParameters.Count) && (sqlParameters[location].ParameterPosition != null)) - location++; - - SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span); - } - - totalSpan += span; - parameterIndex++; - } - } - - if (_tempPagingParameterIndexes != null) - { - _pagingParameterIndexMap = new Dictionary<int, int>(); - - var pagingParameters = - sqlString.Parts - .Cast<object>() - .Where(p => p is Parameter) - .Cast<Parameter>() - .Where(p => p.ParameterPosition.HasValue && p.ParameterPosition < 0) - .ToList(); - - foreach (Parameter pagingParameter in pagingParameters) - { - int pagingValue = _tempPagingParameterIndexes[pagingParameter.ParameterPosition.Value]; - int position = parameterIndex + startParameterIndex; - _pagingParameterIndexMap.Add(position, pagingValue); - pagingParameter.ParameterPosition = position; - paramTypeList.Add(NHibernateUtil.Int32); - parameterIndex++; - totalSpan++; - } - } - - if (addLimit && factory.Dialect.SupportsVariableLimit) - { - if (factory.Dialect.BindLimitParametersFirst) - { - paramTypeList.Insert(0, NHibernateUtil.Int32); - limitParameterIndex = startParameterIndex - 1; - if (addOffset) - { - paramTypeList.Insert(0, NHibernateUtil.Int32); - offsetParameterIndex = startParameterIndex - 2; - } - } - else - { - paramTypeList.Add(NHibernateUtil.Int32); - limitParameterIndex = startParameterIndex + totalSpan; - if (addOffset) - { - paramTypeList.Add(NHibernateUtil.Int32); - offsetParameterIndex = startParameterIndex + totalSpan; - limitParameterIndex = startParameterIndex + totalSpan + 1; - } - } - - if (addOffset && factory.Dialect.BindLimitParametersInReverseOrder) - { - int? temp = limitParameterIndex; - limitParameterIndex = offsetParameterIndex; - offsetParameterIndex = temp; - } - - totalSpan += addOffset ? 2 : 1; - } - - return ConvertITypesToSqlTypes(paramTypeList, factory, totalSpan); - } - - public int BindParameters(IDbCommand command, int start, ISessionImplementor session) - { - int location = start; - var values = new List<object>(); - var types = new List<IType>(); - var sources = new List<string>(); - - for (int i = 0; i < _positionalParameterLocations.Length; i++) - { - object value = _positionalParameterValues[i]; - IType type = _positionalParameterTypes[i]; - ArrayHelper.SafeSetValue(values, location, value); - ArrayHelper.SafeSetValue(types, location, type); - ArrayHelper.SafeSetValue(sources, location, "Positional" + i); - location++; - } - - for (int i = 0; i < filteredParameterLocations.Count; i++) - { - object value = filteredParameterValues[i]; - IType type = filteredParameterTypes[i]; - ArrayHelper.SafeSetValue(values, location, value); - ArrayHelper.SafeSetValue(types, location, type); - ArrayHelper.SafeSetValue(sources, location, "Filter" + i); - location++; - } - - if ((_namedParameters != null) && (_namedParameters.Count > 0)) - { - foreach (var namedParameter in _namedParameters) - { - string name = namedParameter.Key; - TypedValue typedval = namedParameter.Value; - ArrayHelper.SafeSetValue(values, location, typedval.Value); - ArrayHelper.SafeSetValue(types, location, typedval.Type); - ArrayHelper.SafeSetValue(sources, location, "name_" + name); - location++; - } - } - - if (_pagingParameterIndexMap != null) - { - foreach (int pagingParameterIndex in _pagingParameterIndexMap.Keys) - { - ArrayHelper.SafeSetValue(values, pagingParameterIndex, _pagingParameterIndexMap[pagingParameterIndex]); - ArrayHelper.SafeSetValue(types, pagingParameterIndex, NHibernateUtil.Int32); - ArrayHelper.SafeSetValue(sources, pagingParameterIndex, "limit_" + pagingParameterIndex); - } - } - - int span = 0; - for (int i = start; i < values.Count; i++) - { - IType type = types[i]; - object value = values[i]; - string source = sources[i]; - if (log.IsDebugEnabled) - { - log.Debug(string.Format("BindParameters({0}:{1}) {2} -> [{3}]", source, type, value, i)); - } - type.NullSafeSet(command, value, start + span, session); - span += type.GetColumnSpan(session.Factory); - } - - return span; - } - public SqlString ProcessedSql { get { return processedSQL; } Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-16 16:30:10 UTC (rev 5934) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-16 16:41:01 UTC (rev 5935) @@ -1170,12 +1170,6 @@ return command; } - protected virtual SqlString ProcessFilters(QueryParameters parameters, ISessionImplementor session) - { - parameters.ProcessFilters(SqlString, session); - return parameters.FilteredSQL; - } - /// <summary> /// Some dialect-specific LIMIT clauses require the maximium last row number /// (aka, first_row_number + total_row_count), while others require the maximum @@ -1246,23 +1240,6 @@ //} } - /// <summary> - /// Bind all parameter values into the prepared statement in preparation for execution. - /// </summary> - /// <param name="statement">The ADO prepared statement </param> - /// <param name="queryParameters">The encapsulation of the parameter values to be bound. </param> - /// <param name="startIndex">The position from which to start binding parameter values. </param> - /// <param name="session">The originating session. </param> - /// <returns> The number of ADO bind positions actually bound during this method execution. </returns> - protected virtual int BindParameterValues(IDbCommand statement, QueryParameters queryParameters, - int startIndex, ISessionImplementor session) - { - // NH Different behavior: - // The responsibility of parameter binding was entirely moved to QueryParameters - // to deal with positionslParameter+NamedParameter+ParameterOfFilters - return queryParameters.BindParameters(statement, startIndex, session); - } - public virtual int[] GetNamedParameterLocs(string name) { throw new AssertionFailure("no named parameters"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 16:51:58
|
Revision: 5936 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5936&view=rev Author: fabiomaulo Date: 2011-06-16 16:51:52 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:41:01 UTC (rev 5935) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:51:52 UTC (rev 5936) @@ -270,29 +270,6 @@ public IEnumerable<IParameterSpecification> ProcessedSqlParameters { get; internal set; } - public SqlString FilteredSQL - { - get { return processedSQL; } - } - - public IList<IType> FilteredParameterTypes - { - get { return filteredParameterTypes; } - internal set { filteredParameterTypes = value; } - } - - public IList<object> FilteredParameterValues - { - get { return filteredParameterValues; } - internal set { filteredParameterValues = value; } - } - - public IList<int> FilteredParameterLocations - { - get { return filteredParameterLocations; } - internal set { filteredParameterLocations = value; } - } - public bool NaturalKeyLookup { get; set; } public IResultTransformer ResultTransformer Modified: trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs 2011-06-16 16:41:01 UTC (rev 5935) +++ trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs 2011-06-16 16:51:52 UTC (rev 5936) @@ -24,7 +24,7 @@ this.loadable = loadable; this.alias = alias; - queryString = queryParameters.FilteredSQL.GetSubselectString(); + queryString = queryParameters.ProcessedSql.GetSubselectString(); } public QueryParameters QueryParameters Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-16 16:41:01 UTC (rev 5935) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-16 16:51:52 UTC (rev 5936) @@ -441,7 +441,7 @@ // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below + AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-16 16:41:01 UTC (rev 5935) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-16 16:51:52 UTC (rev 5936) @@ -309,7 +309,7 @@ // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it sql = ExpandDynamicFilterParameters(sql, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sql, parameterSpecs, session, queryParameters); // NOTE: see TODO below + AdjustQueryParametersForSubSelectFetching(sql, parameterSpecs, queryParameters); // NOTE: see TODO below sql = AddLimitsParametersIfNeeded(sql, parameterSpecs, queryParameters, session); // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-16 16:41:01 UTC (rev 5935) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-16 16:51:52 UTC (rev 5936) @@ -190,7 +190,7 @@ // dynamic-filter parameters: during the Criteria parsing, filters can be added as string. sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below + AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-16 16:41:01 UTC (rev 5935) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-16 16:51:52 UTC (rev 5936) @@ -1686,7 +1686,7 @@ // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below + AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor @@ -1713,37 +1713,11 @@ return specifications; } - protected void AdjustQueryParametersForSubSelectFetching(SqlString sqlString, IEnumerable<IParameterSpecification> parameterSpecs, ISessionImplementor session, QueryParameters queryParameters) + protected void AdjustQueryParametersForSubSelectFetching(SqlString sqlString, IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) { // TODO: Remove this when all parameters are managed using IParameterSpecification (QueryParameters does not need to have decomposed values for filters) - - var dynamicFilterParameterSpecifications = parameterSpecs.OfType<DynamicFilterParameterSpecification>().ToList(); - var filteredParameterValues = new List<object>(); - var filteredParameterTypes = new List<IType>(); - var filteredParameterLocations = new List<int>(); - - if (dynamicFilterParameterSpecifications.Count != 0) - { - var sqlQueryParametersList = sqlString.GetParameters().ToList(); - foreach (DynamicFilterParameterSpecification specification in dynamicFilterParameterSpecifications) - { - string backTrackId = specification.GetIdsForBackTrack(session.Factory).First(); - object value = session.GetFilterParameterValue(specification.FilterParameterFullName); - var elementType = specification.ExpectedType; - foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId)) - { - filteredParameterValues.Add(value); - filteredParameterTypes.Add(elementType); - filteredParameterLocations.Add(position); - } - } - } - queryParameters.ProcessedSql = sqlString; queryParameters.ProcessedSqlParameters = parameterSpecs.ToList(); - queryParameters.FilteredParameterLocations = filteredParameterLocations; - queryParameters.FilteredParameterTypes = filteredParameterTypes; - queryParameters.FilteredParameterValues = filteredParameterValues; } protected SqlString ExpandDynamicFilterParameters(SqlString sqlString, ICollection<IParameterSpecification> parameterSpecs, ISessionImplementor session) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-17 12:06:02
|
Revision: 5941 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5941&view=rev Author: fabiomaulo Date: 2011-06-17 12:05:56 +0000 (Fri, 17 Jun 2011) Log Message: ----------- Fix NH-2770 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs 2011-06-17 12:03:42 UTC (rev 5940) +++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs 2011-06-17 12:05:56 UTC (rev 5941) @@ -304,7 +304,7 @@ set { configuration.SetProperty(Environment.ShowSql, value.ToString().ToLowerInvariant()); } } - public bool LogFormatedSql + public bool LogFormattedSql { set { configuration.SetProperty(Environment.FormatSql, value.ToString().ToLowerInvariant()); } } Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs 2011-06-17 12:03:42 UTC (rev 5940) +++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs 2011-06-17 12:05:56 UTC (rev 5941) @@ -36,7 +36,7 @@ void Dialect<TDialect>() where TDialect : Dialect.Dialect; Hbm2DDLKeyWords KeywordsAutoImport { set; } bool LogSqlInConsole { set; } - bool LogFormatedSql { set; } + bool LogFormattedSql { set; } void ConnectionProvider<TProvider>() where TProvider : IConnectionProvider; void Driver<TDriver>() where TDriver : IDriver; Modified: trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-06-17 12:03:42 UTC (rev 5940) +++ trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-06-17 12:05:56 UTC (rev 5941) @@ -24,7 +24,7 @@ protected override void Configure(Cfg.Configuration configuration) { - configuration.DataBaseIntegration(x=> x.LogFormatedSql = false); + configuration.DataBaseIntegration(x=> x.LogFormattedSql = false); } protected override void OnSetUp() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-17 17:44:00
|
Revision: 5945 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5945&view=rev Author: fabiomaulo Date: 2011-06-17 17:43:54 +0000 (Fri, 17 Jun 2011) Log Message: ----------- Refactoring (DRY) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate/Loader/Entity/AbstractEntityLoader.cs trunk/nhibernate/src/NHibernate/Loader/Entity/CollectionElementLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs trunk/nhibernate/src/NHibernate/Loader/OuterJoinLoader.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -433,26 +433,14 @@ return result; } - public override ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) + protected override void ResetEffectiveExpectedType(IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) { - // A distinct-copy of parameter specifications collected during query construction - var parameterSpecs = new HashSet<IParameterSpecification>(_queryTranslator.CollectedParameterSpecifications); - SqlString sqlString = SqlString.Copy(); - - // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it - sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below - - sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor - - // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) - sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); - - // After the last modification to the SqlString we can collect all parameters types. parameterSpecs.ResetEffectiveExpectedType(queryParameters); + } - return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() + { + return _queryTranslator.CollectedParameterSpecifications; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -301,26 +301,14 @@ get { return ((superQuery != null) ? superQuery.CollectedParameterSpecifications:Enumerable.Empty<IParameterSpecification>()).Concat(collectedParameters); } } - public override ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) + protected override void ResetEffectiveExpectedType(IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) { - // A distinct-copy of parameter specifications collected during query construction - var parameterSpecs = new HashSet<IParameterSpecification>(CollectedParameterSpecifications); - SqlString sql = SqlString.Copy(); - - // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it - sql = ExpandDynamicFilterParameters(sql, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sql, parameterSpecs, queryParameters); // NOTE: see TODO below - - sql = AddLimitsParametersIfNeeded(sql, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries - - // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) - sql = PreprocessSQL(sql, queryParameters, session.Factory.Dialect); - - // After the last modification to the SqlString we can collect all parameters types. parameterSpecs.ResetEffectiveExpectedType(queryParameters); + } - return new SqlCommandImpl(sql, parameterSpecs, queryParameters, session.Factory); + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() + { + return CollectedParameterSpecifications; } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -63,7 +63,7 @@ return specifications; } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications ?? (parametersSpecifications = CreateParameterSpecificationsAndAssignBackTrack(SqlString.GetParameters()).ToArray()); } Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -30,10 +30,9 @@ keys[i++] = entityKey.Identifier; } - namedParameters = queryParameters.NamedParameters; - // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); + namedParameters = queryParameters.NamedParameters; types = queryParameters.PositionalParameterTypes; values = queryParameters.PositionalParameterValues; this.namedParameterLocMap = namedParameterLocMap; @@ -49,7 +48,7 @@ return namedParameterLocMap[name]; } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications; } Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -33,9 +33,9 @@ keys[i++] = entityKey.Identifier; } - namedParameters = queryParameters.NamedParameters; // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); + namedParameters = queryParameters.NamedParameters; types = queryParameters.PositionalParameterTypes; values = queryParameters.PositionalParameterValues; this.namedParameterLocMap = namedParameterLocMap; @@ -51,7 +51,7 @@ return namedParameterLocMap[name]; } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications; } Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -182,23 +182,9 @@ return customResultTransformer.TransformList(results); } - public override ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { - // A distinct-copy of parameter specifications collected during query construction - var parameterSpecs = new HashSet<IParameterSpecification>(translator.CollectedParameterSpecifications); - SqlString sqlString = SqlString.Copy(); - - // dynamic-filter parameters: during the Criteria parsing, filters can be added as string. - sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below - - sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor - - // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) - sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); - - return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); + return translator.CollectedParameterSpecifications; } public override int[] GetNamedParameterLocs(string name) Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -343,26 +343,14 @@ transformerAliases = aliases.ToArray(); } - public override ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) + protected override void ResetEffectiveExpectedType(IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) { - // A distinct-copy of parameter specifications collected during query construction - var parameterSpecs = new HashSet<IParameterSpecification>(parametersSpecifications); - SqlString sqlString = SqlString.Copy(); - - // dynamic-filter parameters ? - //sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - //AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, session, queryParameters); // NOTE: see TODO below - - sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor - - // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) - sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); - - // After the last modification to the SqlString we can collect all parameters types. parameterSpecs.ResetEffectiveExpectedType(queryParameters); + } - return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() + { + return parametersSpecifications; } public IType[] ResultTypes Modified: trunk/nhibernate/src/NHibernate/Loader/Entity/AbstractEntityLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Entity/AbstractEntityLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Entity/AbstractEntityLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -92,7 +92,7 @@ return specifications; } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications ?? (parametersSpecifications = CreateParameterSpecificationsAndAssignBackTrack(SqlString.GetParameters()).ToArray()); } Modified: trunk/nhibernate/src/NHibernate/Loader/Entity/CollectionElementLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Entity/CollectionElementLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Entity/CollectionElementLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -59,7 +59,7 @@ return specifications; } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications ?? (parametersSpecifications = CreateParameterSpecificationsAndAssignBackTrack(SqlString.GetParameters()).ToArray()); } Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -1641,15 +1641,11 @@ public virtual ISqlCommand CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session) { - // The implementation of this method is itended to be used just for "internal" command (not for queries coming from users) - // Internally NH creates various commands, all using just positional-parameters, to then potentially apply dynamic-filters and pagination. - // In practice this method should be overriden by those loaders representing a user-query as CriteriaLoader, QueryLoader, classic QueryTraslator, CustomLoader (for custmon SQL queries). - // A distinct-copy of parameter specifications collected during query construction - var parameterSpecs = new HashSet<IParameterSpecification>(GetParameterSpecifications(queryParameters, session.Factory)); + var parameterSpecs = new HashSet<IParameterSpecification>(GetParameterSpecifications()); SqlString sqlString = SqlString.Copy(); - // dynamic-filter parameters: during the HQL->SQL parsing, filters can be added as SQL_TOKEN/string and the SqlGenerator will not find it + // dynamic-filter parameters: during the createion of the SqlString of allLoader implementation, filters can be added as SQL_TOKEN/string for this reason we have to re-parse the SQL. sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below @@ -1659,25 +1655,19 @@ // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); + // After the last modification to the SqlString we can collect all parameters types (there are cases where we can't infer the type during the creation of the query) + ResetEffectiveExpectedType(parameterSpecs, queryParameters); + return new SqlCommandImpl(sqlString, parameterSpecs, queryParameters, session.Factory); } - protected virtual IEnumerable<IParameterSpecification> GetParameterSpecifications(QueryParameters queryParameters, ISessionFactoryImplementor sessionFactory) + protected virtual void ResetEffectiveExpectedType(IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) { - // TODO FM: remove this implementation and put an abstract ParameterSpecifications in the Loader (each concrete implementation have to expose it) => NH1990, SubselectFetchFixture - var positionalSpecifications = queryParameters.PositionalParameterTypes.Select((t, i) => (IParameterSpecification)new PositionalParameterSpecification(1, 0, i) { ExpectedType = t }); - var namedSpecifications = queryParameters.NamedParameters != null ? queryParameters.NamedParameters.Select(np => (IParameterSpecification)new NamedParameterSpecification(1, 0, np.Key) { ExpectedType = np.Value.Type }): Enumerable.Empty<IParameterSpecification>(); - var specifications= positionalSpecifications.Concat(namedSpecifications).ToList(); - var parameters = SqlString.GetParameters().ToArray(); - var sqlParameterPos = 0; - var paramTrackers = specifications.SelectMany(specification => specification.GetIdsForBackTrack(sessionFactory)); - foreach (var paramTracker in paramTrackers) - { - parameters[sqlParameterPos++].BackTrack = paramTracker; - } - return specifications; + // Have to be overridden just by those loaders that can't infer the type during the parse process } + protected abstract IEnumerable<IParameterSpecification> GetParameterSpecifications(); + protected void AdjustQueryParametersForSubSelectFetching(SqlString sqlString, IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) { queryParameters.ProcessedSql = sqlString; Modified: trunk/nhibernate/src/NHibernate/Loader/OuterJoinLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/OuterJoinLoader.cs 2011-06-17 16:48:39 UTC (rev 5944) +++ trunk/nhibernate/src/NHibernate/Loader/OuterJoinLoader.cs 2011-06-17 17:43:54 UTC (rev 5945) @@ -14,7 +14,7 @@ /// Generates an SQL select string containing all properties of those classes. /// Tablse are joined using an ANSI-style left outer join. /// </remarks> - public class OuterJoinLoader : BasicLoader + public abstract class OuterJoinLoader : BasicLoader { // Having these fields as protected prevents CLS compliance, so they are // private in NHibernate, and setters are created for the relevant @@ -32,7 +32,7 @@ private readonly IDictionary<string, IFilter> enabledFilters; - public OuterJoinLoader(ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) + protected OuterJoinLoader(ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(factory) { this.enabledFilters = enabledFilters; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-17 18:09:25
|
Revision: 5946 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5946&view=rev Author: fabiomaulo Date: 2011-06-17 18:09:19 +0000 (Fri, 17 Jun 2011) Log Message: ----------- Removed dead code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Engine/Query/QueryMetadata.cs Deleted: trunk/nhibernate/src/NHibernate/Engine/Query/QueryMetadata.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/QueryMetadata.cs 2011-06-17 17:43:54 UTC (rev 5945) +++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryMetadata.cs 2011-06-17 18:09:19 UTC (rev 5946) @@ -1,56 +0,0 @@ -using System; -using Iesi.Collections.Generic; -using NHibernate.Type; - -namespace NHibernate.Engine.Query -{ - /// <summary> Defines metadata regarding a translated HQL or native-SQL query. </summary> - [Serializable] - public class QueryMetadata - { - private readonly string sourceQuery; - private readonly ParameterMetadata parameterMetadata; - private readonly string[] returnAliases; - private readonly IType[] returnTypes; - private readonly ISet<string> querySpaces; - - public QueryMetadata(string sourceQuery, ParameterMetadata parameterMetadata, - string[] returnAliases, IType[] returnTypes, ISet<string> querySpaces) - { - this.sourceQuery = sourceQuery; - this.parameterMetadata = parameterMetadata; - this.returnAliases = returnAliases; - this.returnTypes = returnTypes; - this.querySpaces = querySpaces; - } - - /// <summary> Get the source HQL or native-SQL query. </summary> - public string SourceQuery - { - get { return sourceQuery; } - } - - public ParameterMetadata ParameterMetadata - { - get { return parameterMetadata; } - } - - /// <summary> Return source query select clause aliases (if any) </summary> - public string[] ReturnAliases - { - get { return returnAliases; } - } - - /// <summary> An array of types describing the returns of the source query. </summary> - public IType[] ReturnTypes - { - get { return returnTypes; } - } - - /// <summary> The set of query spaces affected by this source query. </summary> - public ISet<string> QuerySpaces - { - get { return querySpaces; } - } - } -} Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-06-17 17:43:54 UTC (rev 5945) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-06-17 18:09:19 UTC (rev 5946) @@ -1293,7 +1293,6 @@ <Compile Include="Engine\Query\OrdinalParameterDescriptor.cs" /> <Compile Include="Engine\Query\ParameterMetadata.cs" /> <Compile Include="Engine\Query\ParamLocationRecognizer.cs" /> - <Compile Include="Engine\Query\QueryMetadata.cs" /> <Compile Include="Engine\Query\QueryPlanCache.cs" /> <Compile Include="Engine\Query\ReturnMetadata.cs" /> <Compile Include="Engine\Query\FilterQueryPlan.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 12:59:32
|
Revision: 5947 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5947&view=rev Author: fabiomaulo Date: 2011-06-18 12:59:25 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Fix NH-2296 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs trunk/nhibernate/src/NHibernate/SqlCommand/SubselectClauseExtractor.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/src/NHibernate.Test/SubselectFetchTest/ParentChild.hbm.xml Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Model.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -157,8 +157,8 @@ } public SqlString ProcessedSql { get; internal set; } - public IEnumerable<IParameterSpecification> ProcessedSqlParameters { get; internal set; } + public RowSelection ProcessedRowSelection { get; internal set; } public bool NaturalKeyLookup { get; set; } Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionLoader.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -30,6 +30,11 @@ ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(collectionPersister, factory, enabledFilters) { + InitializeFromWalker(collectionPersister, subquery, batchSize, enabledFilters, factory); + } + + protected virtual void InitializeFromWalker(IQueryableCollection collectionPersister, SqlString subquery, int batchSize, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + { JoinWalker walker = new BasicCollectionJoinWalker(collectionPersister, batchSize, subquery, factory, enabledFilters); InitFromWalker(walker); Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -67,5 +67,48 @@ { return parametersSpecifications ?? (parametersSpecifications = CreateParameterSpecificationsAndAssignBackTrack(SqlString.GetParameters()).ToArray()); } + + protected SqlString GetSubSelectWithLimits(SqlString subquery, ICollection<IParameterSpecification> parameterSpecs, RowSelection processedRowSelection, IDictionary<string, TypedValue> parameters, IDictionary<string, int[]> namedParameterLocMap) + { + ISessionFactoryImplementor sessionFactory = Factory; + Dialect.Dialect dialect = sessionFactory.Dialect; + + RowSelection selection = processedRowSelection; + bool useLimit = UseLimit(selection, dialect); + if (useLimit) + { + bool hasFirstRow = GetFirstRow(selection) > 0; + bool useOffset = hasFirstRow && dialect.SupportsLimitOffset; + int max = GetMaxOrLimit(dialect, selection); + int? skip = useOffset ? (int?) dialect.GetOffsetValue(GetFirstRow(selection)) : null; + int? take = max != int.MaxValue ? (int?) max : null; + + Parameter skipSqlParameter = null; + Parameter takeSqlParameter = null; + if (skip.HasValue) + { + string skipParameterName = "nhsubselectskip"; + var skipParameter = new NamedParameterSpecification(1, 0, skipParameterName) {ExpectedType = NHibernateUtil.Int32}; + skipSqlParameter = Parameter.Placeholder; + skipSqlParameter.BackTrack = skipParameter.GetIdsForBackTrack(sessionFactory).First(); + parameters.Add(skipParameterName, new TypedValue(skipParameter.ExpectedType, skip.Value, EntityMode.Poco)); + namedParameterLocMap.Add(skipParameterName, new int[0]); + parameterSpecs.Add(skipParameter); + } + if (take.HasValue) + { + string takeParameterName = "nhsubselecttake"; + var takeParameter = new NamedParameterSpecification(1, 0, takeParameterName) {ExpectedType = NHibernateUtil.Int32}; + takeSqlParameter = Parameter.Placeholder; + takeSqlParameter.BackTrack = takeParameter.GetIdsForBackTrack(sessionFactory).First(); + parameters.Add(takeParameterName, new TypedValue(takeParameter.ExpectedType, take.Value, EntityMode.Poco)); + namedParameterLocMap.Add(takeParameterName, new int[0]); + parameterSpecs.Add(takeParameter); + } + // The dialect can move the given parameters where he need, what it can't do is generates new parameters loosing the BackTrack. + return dialect.GetLimitString(subquery, skip, take, skipSqlParameter, takeSqlParameter); + } + return subquery; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyLoader.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -30,6 +30,11 @@ ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(oneToManyPersister, factory, enabledFilters) { + InitializeFromWalker(oneToManyPersister, subquery, batchSize, enabledFilters, factory); + } + + protected virtual void InitializeFromWalker(IQueryableCollection oneToManyPersister, SqlString subquery, int batchSize, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + { JoinWalker walker = new OneToManyJoinWalker(oneToManyPersister, batchSize, subquery, factory, enabledFilters); InitFromWalker(walker); Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -11,6 +11,7 @@ /// <summary> Implements subselect fetching for a collection</summary> public class SubselectCollectionLoader : BasicCollectionLoader { + private const int BatchSizeForSubselectFetching = 1; private readonly object[] keys; private readonly IDictionary<string, int[]> namedParameterLocMap; private readonly IDictionary<string, TypedValue> namedParameters; @@ -21,7 +22,7 @@ public SubselectCollectionLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys, QueryParameters queryParameters, IDictionary<string, int[]> namedParameterLocMap, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) - : base(persister, 1, subquery, factory, enabledFilters) + : base(persister, BatchSizeForSubselectFetching, factory, enabledFilters) { keys = new object[entityKeys.Count]; int i = 0; @@ -29,13 +30,23 @@ { keys[i++] = entityKey.Identifier; } - + // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters + namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters); + this.namedParameterLocMap = new Dictionary<string, int[]>(namedParameterLocMap); parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); - namedParameters = queryParameters.NamedParameters; + var processedRowSelection = queryParameters.ProcessedRowSelection; + SqlString finalSubquery = subquery; + if (queryParameters.ProcessedRowSelection != null && !SubselectClauseExtractor.HasOrderBy(queryParameters.ProcessedSql)) + { + // when the original query has an "ORDER BY" we can't re-apply the pagination + // this is a simplification, we should actually check which is the "ORDER BY" clause because when the "ORDER BY" is just for the PK we can re-apply "ORDER BY" and pagination. + finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters, this.namedParameterLocMap); + } + InitializeFromWalker(persister, finalSubquery, BatchSizeForSubselectFetching, enabledFilters, factory); + types = queryParameters.PositionalParameterTypes; values = queryParameters.PositionalParameterValues; - this.namedParameterLocMap = namedParameterLocMap; } public override void Initialize(object id, ISessionImplementor session) Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -5,7 +5,6 @@ using NHibernate.Persister.Collection; using NHibernate.SqlCommand; using NHibernate.Type; -using NHibernate.Util; namespace NHibernate.Loader.Collection { @@ -14,6 +13,7 @@ /// </summary> public class SubselectOneToManyLoader : OneToManyLoader { + private const int BatchSizeForSubselectFetching = 1; private readonly object[] keys; private readonly IDictionary<string, int[]> namedParameterLocMap; private readonly IDictionary<string, TypedValue> namedParameters; @@ -24,7 +24,7 @@ public SubselectOneToManyLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys, QueryParameters queryParameters, IDictionary<string, int[]> namedParameterLocMap, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) - : base(persister, 1, subquery, factory, enabledFilters) + : base(persister, BatchSizeForSubselectFetching, factory, enabledFilters) { keys = new object[entityKeys.Count]; int i = 0; @@ -34,11 +34,21 @@ } // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters + namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters); + this.namedParameterLocMap = new Dictionary<string, int[]>(namedParameterLocMap); parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); - namedParameters = queryParameters.NamedParameters; + var processedRowSelection = queryParameters.ProcessedRowSelection; + SqlString finalSubquery = subquery; + if (queryParameters.ProcessedRowSelection != null && !SubselectClauseExtractor.HasOrderBy(queryParameters.ProcessedSql)) + { + // when the original query has an "ORDER BY" we can't re-apply the pagination. + // This is a simplification, we should actually check which is the "ORDER BY" clause because when the "ORDER BY" is just for the PK we can re-apply "ORDER BY" and pagination. + finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters, this.namedParameterLocMap); + } + InitializeFromWalker(persister, finalSubquery, BatchSizeForSubselectFetching, enabledFilters, factory); + types = queryParameters.PositionalParameterTypes; values = queryParameters.PositionalParameterValues; - this.namedParameterLocMap = namedParameterLocMap; } public override void Initialize(object id, ISessionImplementor session) Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -1647,10 +1647,10 @@ // dynamic-filter parameters: during the createion of the SqlString of allLoader implementation, filters can be added as SQL_TOKEN/string for this reason we have to re-parse the SQL. sqlString = ExpandDynamicFilterParameters(sqlString, parameterSpecs, session); - AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); // NOTE: see TODO below + AdjustQueryParametersForSubSelectFetching(sqlString, parameterSpecs, queryParameters); + // Add limits sqlString = AddLimitsParametersIfNeeded(sqlString, parameterSpecs, queryParameters, session); - // TODO: for sub-select fetching we have to try to assign the QueryParameter.ProcessedSQL here (with limits) but only after use IParameterSpecification for any kind of queries and taking care about the work done by SubselectClauseExtractor // The PreprocessSQL method can modify the SqlString but should never add parameters (or we have to override it) sqlString = PreprocessSQL(sqlString, queryParameters, session.Factory.Dialect); @@ -1668,10 +1668,14 @@ protected abstract IEnumerable<IParameterSpecification> GetParameterSpecifications(); - protected void AdjustQueryParametersForSubSelectFetching(SqlString sqlString, IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters) + protected void AdjustQueryParametersForSubSelectFetching(SqlString filteredSqlString, IEnumerable<IParameterSpecification> parameterSpecsWithFilters, QueryParameters queryParameters) { - queryParameters.ProcessedSql = sqlString; - queryParameters.ProcessedSqlParameters = parameterSpecs.ToList(); + queryParameters.ProcessedSql = filteredSqlString; + queryParameters.ProcessedSqlParameters = parameterSpecsWithFilters.ToList(); + if (queryParameters.RowSelection != null) + { + queryParameters.ProcessedRowSelection = new RowSelection { FirstRow = queryParameters.RowSelection.FirstRow, MaxRows = queryParameters.RowSelection.MaxRows }; + } } protected SqlString ExpandDynamicFilterParameters(SqlString sqlString, ICollection<IParameterSpecification> parameterSpecs, ISessionImplementor session) Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SubselectClauseExtractor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SubselectClauseExtractor.cs 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SubselectClauseExtractor.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -11,6 +11,11 @@ /// </summary> public class SubselectClauseExtractor { + /* + * NH TODO: this implementation will break, for MsSQL2005Dialect, a when the query is an HQL with skip/take because the last "ORDER BY" is there for pagination. + * Because HQL skip/take are new features, we hope nobody will use it in conjuction with subselect fetching at least until MS-SQL will release a more modern + * syntax for pagination. + */ private const string FromClauseToken = " from "; private const string OrderByToken = "order by"; @@ -94,6 +99,13 @@ return builder.ToSqlString(); } + public static bool HasOrderBy(SqlString subselect) + { + var extractor = new SubselectClauseExtractor((object[])subselect.Parts); + extractor.GetSqlString(); + return extractor.lastOrderByPartIndex >= 0; + } + private int FindFromClauseInPart(string part) { int afterLastClosingParenIndex = 0; Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Fixture.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -0,0 +1,67 @@ +using System.Linq; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2296 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + + using (var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + var o = new Order() { AccountName = "Acct1" }; + o.Products.Add(new Product() { StatusReason = "Success", Order = o }); + o.Products.Add(new Product() { StatusReason = "Failure", Order = o }); + s.Save(o); + + o = new Order() { AccountName = "Acct2" }; + s.Save(o); + + o = new Order() { AccountName = "Acct3" }; + o.Products.Add(new Product() { StatusReason = "Success", Order = o }); + o.Products.Add(new Product() { StatusReason = "Failure", Order = o }); + s.Save(o); + + tx.Commit(); + } + } + + protected override void OnTearDown() + { + using (var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + s.Delete("from Product"); + s.Delete("from Order"); + tx.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public void Test() + { + using (var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + var orders = s.CreateQuery("select o from Order o") + .SetMaxResults(2) + .List<Order>(); + + // trigger lazy-loading of products, using subselect fetch. + string sr = orders[0].Products[0].StatusReason; + + // count of entities we want: + int ourEntities = orders.Count + orders.Sum(o => o.Products.Count); + + s.Statistics.EntityCount.Should().Be(ourEntities); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Mappings.hbm.xml 2011-06-18 12:59:25 UTC (rev 5947) @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + default-access="property" + auto-import="true" + default-cascade="none" + default-lazy="true" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2296"> + + <class mutable="true" name="Order" table="`Order`"> + + <id name="Id" type="System.Int32"> + <column name="Id" /> + <generator class="identity" /> + </id> + + <bag cascade="all-delete-orphan" fetch="subselect" inverse="true" name="Products" mutable="true"> + <key> + <column name="Order_id" /> + </key> + <one-to-many class="Product" /> + </bag> + + <property name="AccountName" type="System.String"> + <column name="AccountName" /> + </property> + + </class> + + <class mutable="true" name="Product" table="`Product`"> + + <id name="Id" type="System.Int32"> + <column name="Id" /> + <generator class="identity" /> + </id> + + <property name="StatusReason" type="System.String"> + <column name="StatusReason" /> + </property> + + <many-to-one class="Order" name="Order"> + <column name="Order_id" /> + </many-to-one> + + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2296/Model.cs 2011-06-18 12:59:25 UTC (rev 5947) @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2296 +{ + public class Order + { + public virtual int Id { get; set; } + public virtual string AccountName { get; set; } + public virtual IList<Product> Products { get; set; } + + public Order() + { + this.Products = new List<Product>(); + } + } + + public class Product + { + public virtual int Id { get; set; } + public virtual string StatusReason { get; set; } + public virtual Order Order { get; set; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-18 12:59:25 UTC (rev 5947) @@ -723,6 +723,8 @@ <Compile Include="NHSpecificTest\NH2288\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2293\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2294\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2296\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2296\Model.cs" /> <Compile Include="NHSpecificTest\NH2302\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2302\StringLengthEntity.cs" /> <Compile Include="NHSpecificTest\NH2303\Fixture.cs" /> @@ -2716,6 +2718,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2296\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2760\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2662\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2703\Mappings.hbm.xml" /> Modified: trunk/nhibernate/src/NHibernate.Test/SubselectFetchTest/ParentChild.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/SubselectFetchTest/ParentChild.hbm.xml 2011-06-17 18:09:19 UTC (rev 5946) +++ trunk/nhibernate/src/NHibernate.Test/SubselectFetchTest/ParentChild.hbm.xml 2011-06-18 12:59:25 UTC (rev 5947) @@ -8,7 +8,7 @@ <generator class="assigned" /> </id> <bag name="Friends" fetch="subselect" table="ChildChild"> - <key column="childName1" /><!-- H3 has not-null="true" --> + <key column="childName1" not-null="true" /> <many-to-many class="Child" column="childName2"/> </bag> </class> @@ -18,12 +18,12 @@ <generator class="assigned" /> </id> <list name="Children" fetch="subselect" cascade="all"> - <key column="parentName" /><!-- H3 has not-null="true" --> + <key column="parentName" not-null="true"/> <index column="loc"/> <one-to-many class="Child"/> </list> <list name="MoreChildren" table="ParentChild" fetch="subselect"> - <key column="parentName" /><!-- H3 has not-null="true" --> + <key column="parentName" not-null="true"/> <index column="loc"/> <many-to-many class="Child" column="childName"/> </list> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 13:14:52
|
Revision: 5948 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5948&view=rev Author: fabiomaulo Date: 2011-06-18 13:14:46 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs trunk/nhibernate/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs Modified: trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Engine/SubselectFetch.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Iesi.Collections.Generic; using NHibernate.Persister.Entity; using NHibernate.SqlCommand; @@ -10,17 +9,15 @@ { private readonly string alias; private readonly ILoadable loadable; - private readonly IDictionary<string, int[]> namedParameterLocMap; private readonly QueryParameters queryParameters; private readonly SqlString queryString; private readonly ISet<EntityKey> resultingEntityKeys; public SubselectFetch(string alias, ILoadable loadable, QueryParameters queryParameters, - ISet<EntityKey> resultingEntityKeys, IDictionary<string, int[]> namedParameterLocMap) + ISet<EntityKey> resultingEntityKeys) { this.resultingEntityKeys = resultingEntityKeys; this.queryParameters = queryParameters; - this.namedParameterLocMap = namedParameterLocMap; this.loadable = loadable; this.alias = alias; @@ -37,11 +34,6 @@ get { return resultingEntityKeys; } } - public IDictionary<string, int[]> NamedParameterLocMap - { - get { return namedParameterLocMap; } - } - public SqlString ToSubselectString(string ukname) { string[] joinColumns = ukname == null Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/CollectionLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -68,7 +68,7 @@ return parametersSpecifications ?? (parametersSpecifications = CreateParameterSpecificationsAndAssignBackTrack(SqlString.GetParameters()).ToArray()); } - protected SqlString GetSubSelectWithLimits(SqlString subquery, ICollection<IParameterSpecification> parameterSpecs, RowSelection processedRowSelection, IDictionary<string, TypedValue> parameters, IDictionary<string, int[]> namedParameterLocMap) + protected SqlString GetSubSelectWithLimits(SqlString subquery, ICollection<IParameterSpecification> parameterSpecs, RowSelection processedRowSelection, IDictionary<string, TypedValue> parameters) { ISessionFactoryImplementor sessionFactory = Factory; Dialect.Dialect dialect = sessionFactory.Dialect; @@ -92,7 +92,6 @@ skipSqlParameter = Parameter.Placeholder; skipSqlParameter.BackTrack = skipParameter.GetIdsForBackTrack(sessionFactory).First(); parameters.Add(skipParameterName, new TypedValue(skipParameter.ExpectedType, skip.Value, EntityMode.Poco)); - namedParameterLocMap.Add(skipParameterName, new int[0]); parameterSpecs.Add(skipParameter); } if (take.HasValue) @@ -102,7 +101,6 @@ takeSqlParameter = Parameter.Placeholder; takeSqlParameter.BackTrack = takeParameter.GetIdsForBackTrack(sessionFactory).First(); parameters.Add(takeParameterName, new TypedValue(takeParameter.ExpectedType, take.Value, EntityMode.Poco)); - namedParameterLocMap.Add(takeParameterName, new int[0]); parameterSpecs.Add(takeParameter); } // The dialect can move the given parameters where he need, what it can't do is generates new parameters loosing the BackTrack. Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -13,14 +13,13 @@ { private const int BatchSizeForSubselectFetching = 1; private readonly object[] keys; - private readonly IDictionary<string, int[]> namedParameterLocMap; private readonly IDictionary<string, TypedValue> namedParameters; private readonly IType[] types; private readonly object[] values; private readonly List<IParameterSpecification> parametersSpecifications; public SubselectCollectionLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys, - QueryParameters queryParameters, IDictionary<string, int[]> namedParameterLocMap, + QueryParameters queryParameters, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(persister, BatchSizeForSubselectFetching, factory, enabledFilters) { @@ -33,7 +32,6 @@ // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters); - this.namedParameterLocMap = new Dictionary<string, int[]>(namedParameterLocMap); parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); var processedRowSelection = queryParameters.ProcessedRowSelection; SqlString finalSubquery = subquery; @@ -41,7 +39,7 @@ { // when the original query has an "ORDER BY" we can't re-apply the pagination // this is a simplification, we should actually check which is the "ORDER BY" clause because when the "ORDER BY" is just for the PK we can re-apply "ORDER BY" and pagination. - finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters, this.namedParameterLocMap); + finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters); } InitializeFromWalker(persister, finalSubquery, BatchSizeForSubselectFetching, enabledFilters, factory); @@ -56,7 +54,7 @@ public override int[] GetNamedParameterLocs(string name) { - return namedParameterLocMap[name]; + return new int[0]; } protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -15,14 +15,13 @@ { private const int BatchSizeForSubselectFetching = 1; private readonly object[] keys; - private readonly IDictionary<string, int[]> namedParameterLocMap; private readonly IDictionary<string, TypedValue> namedParameters; private readonly IType[] types; private readonly object[] values; private readonly List<IParameterSpecification> parametersSpecifications; public SubselectOneToManyLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys, - QueryParameters queryParameters, IDictionary<string, int[]> namedParameterLocMap, + QueryParameters queryParameters, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(persister, BatchSizeForSubselectFetching, factory, enabledFilters) { @@ -35,7 +34,6 @@ // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters); - this.namedParameterLocMap = new Dictionary<string, int[]>(namedParameterLocMap); parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList(); var processedRowSelection = queryParameters.ProcessedRowSelection; SqlString finalSubquery = subquery; @@ -43,7 +41,7 @@ { // when the original query has an "ORDER BY" we can't re-apply the pagination. // This is a simplification, we should actually check which is the "ORDER BY" clause because when the "ORDER BY" is just for the PK we can re-apply "ORDER BY" and pagination. - finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters, this.namedParameterLocMap); + finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters); } InitializeFromWalker(persister, finalSubquery, BatchSizeForSubselectFetching, enabledFilters, factory); @@ -58,7 +56,7 @@ public override int[] GetNamedParameterLocs(string name) { - return namedParameterLocMap[name]; + return new int[0]; } protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -521,8 +521,6 @@ ISet<EntityKey>[] keySets = Transpose(keys); - IDictionary<string, int[]> namedParameterLocMap = BuildNamedParameterLocMap(queryParameters); - ILoadable[] loadables = EntityPersisters; string[] aliases = Aliases; @@ -533,7 +531,7 @@ if (rowKeys[i] != null && loadables[i].HasSubselectLoadableCollections) { SubselectFetch subselectFetch = - new SubselectFetch(aliases[i], loadables[i], queryParameters, keySets[i], namedParameterLocMap); + new SubselectFetch(aliases[i], loadables[i], queryParameters, keySets[i]); session.PersistenceContext.BatchFetchQueue.AddSubselect(rowKeys[i], subselectFetch); } @@ -542,23 +540,6 @@ } } - private IDictionary<string, int[]> BuildNamedParameterLocMap(QueryParameters queryParameters) - { - if (queryParameters.NamedParameters != null) - { - IDictionary<string, int[]> namedParameterLocMap = new Dictionary<string, int[]>(); - foreach (string name in queryParameters.NamedParameters.Keys) - { - namedParameterLocMap[name] = GetNamedParameterLocs(name); - } - return namedParameterLocMap; - } - else - { - return null; - } - } - internal void InitializeEntitiesAndCollections(IList hydratedObjects, object resultSetId, ISessionImplementor session, bool readOnly) { ICollectionPersister[] collectionPersisters = CollectionPersisters; Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -300,7 +300,7 @@ { return new SubselectCollectionLoader(this, subselect.ToSubselectString(CollectionType.LHSPropertyName), subselect.Result, - subselect.QueryParameters, subselect.NamedParameterLocMap, session.Factory, + subselect.QueryParameters, session.Factory, session.EnabledFilters); } Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs 2011-06-18 12:59:25 UTC (rev 5947) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs 2011-06-18 13:14:46 UTC (rev 5948) @@ -382,7 +382,7 @@ { return new SubselectOneToManyLoader(this, subselect.ToSubselectString(CollectionType.LHSPropertyName), subselect.Result, - subselect.QueryParameters, subselect.NamedParameterLocMap, session.Factory, + subselect.QueryParameters, session.Factory, session.EnabledFilters); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 13:30:45
|
Revision: 5949 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5949&view=rev Author: fabiomaulo Date: 2011-06-18 13:30:39 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/Query/NamedParameterDescriptor.cs trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSkip.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessTake.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs Modified: trunk/nhibernate/src/NHibernate/Engine/Query/NamedParameterDescriptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/NamedParameterDescriptor.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Engine/Query/NamedParameterDescriptor.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -9,14 +9,12 @@ { private readonly string name; private readonly IType expectedType; - private readonly int[] sourceLocations; private readonly bool jpaStyle; - public NamedParameterDescriptor(string name, IType expectedType, int[] sourceLocations, bool jpaStyle) + public NamedParameterDescriptor(string name, IType expectedType, bool jpaStyle) { this.name = name; this.expectedType = expectedType; - this.sourceLocations = sourceLocations; this.jpaStyle = jpaStyle; } @@ -30,11 +28,6 @@ get { return expectedType; } } - public int[] SourceLocations - { - get { return sourceLocations; } - } - /// <summary> /// Not supported yet (AST parse needed) /// </summary> Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -76,11 +76,5 @@ { return GetNamedParameterDescriptor(name).ExpectedType; } - - public int[] GetNamedParameterSourceLocations(string name) - { - return GetNamedParameterDescriptor(name).SourceLocations; - } - } } Modified: trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -168,7 +168,7 @@ string name = entry.Key; ParamLocationRecognizer.NamedParameterDescription description = entry.Value; namedParamDescriptorMap[name] = - new NamedParameterDescriptor(name, null, description.BuildPositionsArray(), description.JpaStyle); + new NamedParameterDescriptor(name, null, description.JpaStyle); } return new ParameterMetadata(ordinalDescriptors, namedParamDescriptorMap); Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -137,16 +137,6 @@ } /// <summary> - /// Returns the locations of all occurrences of the named parameter. - /// </summary> - /// <param name="name"></param> - /// <returns></returns> - public override int[] GetNamedParameterLocs(string name) - { - return _queryTranslator.GetParameterTranslations().GetNamedParameterSqlLocations(name); - } - - /// <summary> /// /// </summary> /// <param name="lockModes">a collection of lock modes specified dynamically via the Query interface</param> Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -200,8 +200,7 @@ foreach (var name in parameterTranslations.GetNamedParameterNames()) { namedDescriptorMap[name] = - new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), - parameterTranslations.GetNamedParameterSqlLocations(name), false);// description.JpaStyle); + new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), false);// description.JpaStyle); } Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -448,8 +448,7 @@ string name = entry.Key; ParamLocationRecognizer.NamedParameterDescription description = entry.Value; namedParamDescriptorMap[name] = - new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), - description.BuildPositionsArray(), description.JpaStyle); + new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), description.JpaStyle); } return new ParameterMetadata(ordinalParamDescriptors, namedParamDescriptorMap); @@ -794,18 +793,6 @@ } } - public override int[] GetNamedParameterLocs(string name) - { - List<int> o; - if (!namedParameters.TryGetValue(name, out o)) - { - QueryException qe = new QueryException("Named parameter does not appear in Query: " + name); - qe.QueryString = queryString; - throw qe; - } - return o.ToArray(); - } - public static string ScalarName(int x, int y) { return new StringBuilder() @@ -1834,7 +1821,7 @@ public int[] GetNamedParameterSqlLocations(string name) { - return queryTraslator.GetNamedParameterLocs(name); + return new int[0]; } public IType GetNamedParameterExpectedType(string name) Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -332,7 +332,7 @@ NamedParameter namedParameter; if (_parameters.ConstantToParameterMap.TryGetValue(operandEx, out namedParameter)) { - _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, new[] { _parameters.RequiredHqlParameters.Count + 1 }, false)); + _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false)); return _hqlTreeBuilder.Parameter(namedParameter.Name).AsExpression(); } @@ -402,7 +402,7 @@ if (_parameters.ConstantToParameterMap.TryGetValue(expression, out namedParameter)) { - _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, new[] { _parameters.RequiredHqlParameters.Count + 1 }, false)); + _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false)); if (namedParameter.Value is bool) { Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSkip.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSkip.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSkip.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -16,7 +16,7 @@ if (parameters.ConstantToParameterMap.TryGetValue(resultOperator.Count as ConstantExpression, out namedParameter)) { - parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, new[] {parameters.RequiredHqlParameters.Count + 1}, false)); + parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false)); tree.AddSkipClause(tree.TreeBuilder.Parameter(namedParameter.Name)); } else Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessTake.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessTake.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessTake.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -16,7 +16,7 @@ if (parameters.ConstantToParameterMap.TryGetValue(resultOperator.Count as ConstantExpression, out namedParameter)) { - parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, new[] {parameters.RequiredHqlParameters.Count + 1}, false)); + parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false)); tree.AddTakeClause(tree.TreeBuilder.Parameter(namedParameter.Name)); } else Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -52,11 +52,6 @@ LoadCollectionSubselect(session, keys, values, types, namedParameters, KeyType); } - public override int[] GetNamedParameterLocs(string name) - { - return new int[0]; - } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications; Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -54,11 +54,6 @@ LoadCollectionSubselect(session, keys, values, types, namedParameters, KeyType); } - public override int[] GetNamedParameterLocs(string name) - { - return new int[0]; - } - protected override IEnumerable<IParameterSpecification> GetParameterSpecifications() { return parametersSpecifications; Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -186,10 +186,5 @@ { return translator.CollectedParameterSpecifications; } - - public override int[] GetNamedParameterLocs(string name) - { - return new int[0]; - } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -308,24 +308,6 @@ } } - public override int[] GetNamedParameterLocs(string name) - { - object loc = namedParameterBindPoints[name]; - if (loc == null) - { - throw new QueryException("Named parameter does not appear in Query: " + name, sql.ToString()); - } - - if (loc is int) - { - return new int[] {(int) loc}; - } - else - { - return ArrayHelper.ToIntArray((IList) loc); - } - } - protected override void AutoDiscoverTypes(IDataReader rs) { MetaData metadata = new MetaData(rs); Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-18 13:14:46 UTC (rev 5948) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2011-06-18 13:30:39 UTC (rev 5949) @@ -1186,11 +1186,6 @@ //} } - public virtual int[] GetNamedParameterLocs(string name) - { - throw new AssertionFailure("no named parameters"); - } - /// <summary> /// Fetch a <c>IDbCommand</c>, call <c>SetMaxRows</c> and then execute it, /// advance to the first result and return an SQL <c>IDataReader</c> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 13:38:13
|
Revision: 5950 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5950&view=rev Author: fabiomaulo Date: 2011-06-18 13:38:07 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 13:30:39 UTC (rev 5949) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 13:38:07 UTC (rev 5950) @@ -1819,11 +1819,6 @@ return queryTraslator.namedParameters.Keys; } - public int[] GetNamedParameterSqlLocations(string name) - { - return new int[0]; - } - public IType GetNamedParameterExpectedType(string name) { return null; Modified: trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs 2011-06-18 13:30:39 UTC (rev 5949) +++ trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs 2011-06-18 13:38:07 UTC (rev 5950) @@ -15,8 +15,6 @@ IEnumerable<string> GetNamedParameterNames(); - int[] GetNamedParameterSqlLocations(string name); - IType GetNamedParameterExpectedType(string name); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2011-06-18 13:30:39 UTC (rev 5949) +++ trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2011-06-18 13:38:07 UTC (rev 5950) @@ -82,11 +82,6 @@ return _namedParameters.Keys; } - public int[] GetNamedParameterSqlLocations(string name) - { - return GetNamedParameterInfo(name).SqlLocations; - } - public IType GetNamedParameterExpectedType(string name) { return GetNamedParameterInfo(name).ExpectedType; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 18:52:35
|
Revision: 5956 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5956&view=rev Author: fabiomaulo Date: 2011-06-18 18:52:29 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Removed dead code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/Query/OrdinalParameterDescriptor.cs trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs Modified: trunk/nhibernate/src/NHibernate/Engine/Query/OrdinalParameterDescriptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/OrdinalParameterDescriptor.cs 2011-06-18 18:44:52 UTC (rev 5955) +++ trunk/nhibernate/src/NHibernate/Engine/Query/OrdinalParameterDescriptor.cs 2011-06-18 18:52:29 UTC (rev 5956) @@ -8,13 +8,11 @@ { private readonly int ordinalPosition; private readonly IType expectedType; - private readonly int sourceLocation; - public OrdinalParameterDescriptor(int ordinalPosition, IType expectedType, int sourceLocation) + public OrdinalParameterDescriptor(int ordinalPosition, IType expectedType) { this.ordinalPosition = ordinalPosition; this.expectedType = expectedType; - this.sourceLocation = sourceLocation; } public int OrdinalPosition @@ -26,10 +24,5 @@ { get { return expectedType; } } - - public int SourceLocation - { - get { return sourceLocation; } - } } } Modified: trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2011-06-18 18:44:52 UTC (rev 5955) +++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2011-06-18 18:52:29 UTC (rev 5956) @@ -158,7 +158,7 @@ for (int i = 0; i < recognizer.OrdinalParameterLocationList.Count; i++) { int position = recognizer.OrdinalParameterLocationList[i]; - ordinalDescriptors[i] = new OrdinalParameterDescriptor(i, null, position); + ordinalDescriptors[i] = new OrdinalParameterDescriptor(i, null); } IDictionary<string, NamedParameterDescriptor> namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 18:44:52 UTC (rev 5955) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 18:52:29 UTC (rev 5956) @@ -193,7 +193,7 @@ new OrdinalParameterDescriptor(i, parameterTranslations.SupportsOrdinalParameterMetadata ? parameterTranslations.GetOrdinalParameterExpectedType(i) - : null, parameterTranslations.GetOrdinalParameterSqlLocation(i)); + : null); } var namedDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 18:44:52 UTC (rev 5955) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 18:52:29 UTC (rev 5956) @@ -439,7 +439,7 @@ new OrdinalParameterDescriptor(i, parameterTranslations.SupportsOrdinalParameterMetadata ? parameterTranslations.GetOrdinalParameterExpectedType(i) - : null, locations[i - 1]); + : null); } Dictionary<string, NamedParameterDescriptor> namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 19:58:07
|
Revision: 5957 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5957&view=rev Author: fabiomaulo Date: 2011-06-18 19:58:00 +0000 (Sat, 18 Jun 2011) Log Message: ----------- BuildParameterMetadata refactoring with parameter specifications fix Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Param/DynamicFilterParameterSpecification.cs trunk/nhibernate/src/NHibernate/Param/NamedParameterSpecification.cs trunk/nhibernate/src/NHibernate/Param/PositionalParameterSpecification.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Parameters/ trunk/nhibernate/src/NHibernate.Test/Parameters/NamedParameterSpecificationTest.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 18:52:29 UTC (rev 5956) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 19:58:00 UTC (rev 5957) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using Antlr.Runtime; using Antlr.Runtime.Tree; using Iesi.Collections.Generic; @@ -17,6 +18,7 @@ using NHibernate.SqlCommand; using NHibernate.Type; using NHibernate.Util; +using IQueryable = NHibernate.Persister.Entity.IQueryable; namespace NHibernate.Hql.Ast.ANTLR { @@ -183,28 +185,14 @@ public ParameterMetadata BuildParameterMetadata() { - var parameterTranslations = GetParameterTranslations(); - - var ordinalDescriptors = new OrdinalParameterDescriptor[parameterTranslations.OrdinalParameterCount]; - - for (var i = 1; i <= ordinalDescriptors.Length; i++) - { - ordinalDescriptors[i - 1] = - new OrdinalParameterDescriptor(i, - parameterTranslations.SupportsOrdinalParameterMetadata - ? parameterTranslations.GetOrdinalParameterExpectedType(i) - : null); - } - - var namedDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); - foreach (var name in parameterTranslations.GetNamedParameterNames()) - { - namedDescriptorMap[name] = - new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), false);// description.JpaStyle); - - } - - return new ParameterMetadata(ordinalDescriptors, namedDescriptorMap); + IList<IParameterSpecification> specifications = _sqlAst.Walker.Parameters; + IEnumerable<OrdinalParameterDescriptor> ordinals = + specifications.OfType<PositionalParameterSpecification>().Select(op => new OrdinalParameterDescriptor(op.HqlPosition, op.ExpectedType)); + Dictionary<string, NamedParameterDescriptor> nameds = specifications.OfType<NamedParameterSpecification>() + .Distinct() + .Select(np => new {np.Name, Descriptor = new NamedParameterDescriptor(np.Name, np.ExpectedType, false)}) + .ToDictionary(ep => ep.Name, ep => ep.Descriptor); + return new ParameterMetadata(ordinals, nameds); } public string[][] GetColumnNames() Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 18:52:29 UTC (rev 5956) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2011-06-18 19:58:00 UTC (rev 5957) @@ -410,51 +410,19 @@ get { return actualReturnTypes; } } - public ParameterMetadata BuildParameterMetadata() - { - return BuildParameterMetadata(GetParameterTranslations(), queryString); - } + public ParameterMetadata BuildParameterMetadata() + { + IEnumerable<IParameterSpecification> specifications = CollectedParameterSpecifications; + IEnumerable<OrdinalParameterDescriptor> ordinals = + specifications.OfType<PositionalParameterSpecification>().Select(op => new OrdinalParameterDescriptor(op.HqlPosition, op.ExpectedType)); + Dictionary<string, NamedParameterDescriptor> nameds = specifications.OfType<NamedParameterSpecification>() + .Distinct() + .Select(np => new { np.Name, Descriptor = new NamedParameterDescriptor(np.Name, np.ExpectedType, false) }) + .ToDictionary(ep => ep.Name, ep => ep.Descriptor); + return new ParameterMetadata(ordinals, nameds); + } - private static ParameterMetadata BuildParameterMetadata(IParameterTranslations parameterTranslations, string hql) - { - long start = DateTime.Now.Ticks; - ParamLocationRecognizer recognizer = ParamLocationRecognizer.ParseLocations(hql); - long end = DateTime.Now.Ticks; - if (log.IsDebugEnabled) - { - log.Debug("HQL param location recognition took " + (end - start) + " mills (" + hql + ")"); - } - - int ordinalParamCount = parameterTranslations.OrdinalParameterCount; - int[] locations = recognizer.OrdinalParameterLocationList.ToArray(); - if (parameterTranslations.SupportsOrdinalParameterMetadata && locations.Length != ordinalParamCount) - { - throw new HibernateException("ordinal parameter mismatch"); - } - ordinalParamCount = locations.Length; - OrdinalParameterDescriptor[] ordinalParamDescriptors = new OrdinalParameterDescriptor[ordinalParamCount]; - for (int i = 1; i <= ordinalParamCount; i++) - { - ordinalParamDescriptors[i - 1] = - new OrdinalParameterDescriptor(i, - parameterTranslations.SupportsOrdinalParameterMetadata - ? parameterTranslations.GetOrdinalParameterExpectedType(i) - : null); - } - - Dictionary<string, NamedParameterDescriptor> namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); - foreach (KeyValuePair<string, ParamLocationRecognizer.NamedParameterDescription> entry in recognizer.NamedParameterDescriptionMap) - { - string name = entry.Key; - ParamLocationRecognizer.NamedParameterDescription description = entry.Value; - namedParamDescriptorMap[name] = - new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), description.JpaStyle); - - } - return new ParameterMetadata(ordinalParamDescriptors, namedParamDescriptorMap); - } - - public virtual string[][] ScalarColumnNames + public virtual string[][] ScalarColumnNames { get { return scalarColumnNames; } } Modified: trunk/nhibernate/src/NHibernate/Param/DynamicFilterParameterSpecification.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/DynamicFilterParameterSpecification.cs 2011-06-18 18:52:29 UTC (rev 5956) +++ trunk/nhibernate/src/NHibernate/Param/DynamicFilterParameterSpecification.cs 2011-06-18 19:58:00 UTC (rev 5957) @@ -90,7 +90,7 @@ public override bool Equals(object obj) { - return base.Equals(obj); + return Equals(obj as DynamicFilterParameterSpecification); } [Serializable] Modified: trunk/nhibernate/src/NHibernate/Param/NamedParameterSpecification.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/NamedParameterSpecification.cs 2011-06-18 18:52:29 UTC (rev 5956) +++ trunk/nhibernate/src/NHibernate/Param/NamedParameterSpecification.cs 2011-06-18 19:58:00 UTC (rev 5957) @@ -72,7 +72,7 @@ public override bool Equals(object obj) { - return base.Equals(obj as NamedParameterSpecification); + return Equals(obj as NamedParameterSpecification); } public bool Equals(NamedParameterSpecification other) Modified: trunk/nhibernate/src/NHibernate/Param/PositionalParameterSpecification.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/PositionalParameterSpecification.cs 2011-06-18 18:52:29 UTC (rev 5956) +++ trunk/nhibernate/src/NHibernate/Param/PositionalParameterSpecification.cs 2011-06-18 19:58:00 UTC (rev 5957) @@ -75,7 +75,7 @@ public override bool Equals(object obj) { - return base.Equals(obj as PositionalParameterSpecification); + return Equals(obj as PositionalParameterSpecification); } public bool Equals(PositionalParameterSpecification other) Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-18 18:52:29 UTC (rev 5956) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-18 19:58:00 UTC (rev 5957) @@ -883,6 +883,7 @@ <Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\Fixture.cs" /> <Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\Model.cs" /> <Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\SqlConverter.cs" /> + <Compile Include="Parameters\NamedParameterSpecificationTest.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="PropertyTest\FieldCamelCaseMUnderscoreFixture.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/Parameters/NamedParameterSpecificationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Parameters/NamedParameterSpecificationTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Parameters/NamedParameterSpecificationTest.cs 2011-06-18 19:58:00 UTC (rev 5957) @@ -0,0 +1,37 @@ +using NHibernate.Param; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.Parameters +{ + public class NamedParameterSpecificationTest + { + [Test] + public void WhenHasSameNameThenSameHashCode() + { + var expected = (new NamedParameterSpecification(1, 0, "nhlist")).GetHashCode(); + (new NamedParameterSpecification(1, 0, "nhlist")).GetHashCode().Should().Be.EqualTo(expected); + } + + [Test] + public void WhenHasNoSameNameThenNoSameHashCode() + { + var expected = (new NamedParameterSpecification(1, 0, "nHlist")).GetHashCode(); + (new NamedParameterSpecification(1, 0, "nhlist")).GetHashCode().Should().Not.Be.EqualTo(expected); + } + + [Test] + public void WhenHasSameNameThenAreEquals() + { + var expected = (new NamedParameterSpecification(1, 0, "nhlist")); + (new NamedParameterSpecification(1, 0, "nhlist")).Should().Be.EqualTo(expected); + } + + [Test] + public void WhenHasNoSameNameThenAreNotEquals() + { + var expected = (new NamedParameterSpecification(1, 0, "nHlist")); + (new NamedParameterSpecification(1, 0, "nhlist")).Should().Not.Be.EqualTo(expected); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-18 23:03:25
|
Revision: 5959 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5959&view=rev Author: fabiomaulo Date: 2011-06-18 23:03:18 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLCustomQuery.cs trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -37,7 +37,6 @@ private QueryLoader _queryLoader; private IStatementExecutor _statementExecutor; private IStatement _sqlAst; - private ParameterTranslationsImpl _paramTranslations; private IDictionary<string, string> _tokenReplacements; private HqlSqlGenerator _generator; Deleted: trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Hql/IParameterTranslations.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using NHibernate.Type; - -namespace NHibernate.Hql -{ - public interface IParameterTranslations - { - bool SupportsOrdinalParameterMetadata { get; } - - int OrdinalParameterCount { get; } - - int GetOrdinalParameterSqlLocation(int ordinalPosition); - - IType GetOrdinalParameterExpectedType(int ordinalPosition); - - IEnumerable<string> GetNamedParameterNames(); - - IType GetNamedParameterExpectedType(string name); - } -} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -26,7 +26,6 @@ private readonly SqlString sql; private readonly ISet<string> querySpaces = new HashedSet<string>(); - private readonly IDictionary<string, object> namedParameterBindPoints; private List<IParameterSpecification> parametersSpecifications; private readonly IQueryable[] entityPersisters; @@ -47,8 +46,7 @@ { sql = customQuery.SQL; querySpaces.AddAll(customQuery.QuerySpaces); - namedParameterBindPoints = customQuery.NamedParameterBindPoints; - this.parametersSpecifications = customQuery.CollectedParametersSpecifications.ToList(); + parametersSpecifications = customQuery.CollectedParametersSpecifications.ToList(); List<IQueryable> entitypersisters = new List<IQueryable>(); List<int> entityowners = new List<int>(); @@ -347,7 +345,7 @@ public IEnumerable<string> NamedParameters { - get { return namedParameterBindPoints.Keys; } + get { return parametersSpecifications.OfType<NamedParameterSpecification>().Select(np=> np.Name ); } } public class ResultRowProcessor Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/ICustomQuery.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -22,22 +22,6 @@ /// </summary> ISet<string> QuerySpaces { get; } - /// <summary> - /// A map representing positions within the supplied <see cref="SQL"/> query to - /// which we need to bind named parameters. - /// </summary> - /// <remarks> - /// Optional, may return null if no named parameters. - /// The structure of the returned map (if one) as follows: - /// <ol> - /// <li>The keys into the map are the named parameter names</li> - /// <li>The corresponding value is either an if the - /// parameter occurs only once in the query; or a List of int if the - /// parameter occurs more than once</li> - /// </ol> - /// </remarks> - IDictionary<string, object> NamedParameterBindPoints { get; } - /// <summary> /// A collection of <see cref="IReturn"/> descriptors describing the /// ADO result set to be expected and how to map this result set. Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLCustomQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLCustomQuery.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLCustomQuery.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -19,7 +19,6 @@ private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof (SQLCustomQuery)); private readonly List<IReturn> customQueryReturns = new List<IReturn>(); - private readonly Dictionary<string, object> namedParameterBindPoints = new Dictionary<string, object>(); private readonly ISet<string> querySpaces = new HashedSet<string>(); private readonly SqlString sql; private List<IParameterSpecification> parametersSpecifications; @@ -33,7 +32,6 @@ SQLQueryParser parser = new SQLQueryParser(factory, sqlQuery, new ParserContext(aliasContext)); sql = parser.Process(); - ArrayHelper.AddAll(namedParameterBindPoints, parser.NamedParameters); ArrayHelper.AddAll(customQueryReturns, processor.GenerateCustomReturns(parser.QueryHasAliases)); parametersSpecifications = parser.CollectedParametersSpecifications.ToList(); @@ -55,11 +53,6 @@ get { return sql; } } - public IDictionary<string, object> NamedParameterBindPoints - { - get { return namedParameterBindPoints; } - } - public ISet<string> QuerySpaces { get { return querySpaces; } Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -28,8 +28,6 @@ private readonly string originalQueryString; private readonly IParserContext context; - private readonly Dictionary<string, object> namedParameters = new Dictionary<string, object>(); - private long aliasesFound; private IEnumerable<IParameterSpecification> parametersSpecifications; @@ -40,11 +38,6 @@ this.context = context; } - public IDictionary<string, object> NamedParameters - { - get { return namedParameters; } - } - public bool QueryHasAliases { get { return aliasesFound > 0; } @@ -253,11 +246,6 @@ var recognizer = new ParameterSubstitutionRecognizer(factory); ParameterParser.Parse(sqlString, recognizer); parametersSpecifications = recognizer.ParametersSpecifications.ToList(); - namedParameters.Clear(); - foreach (KeyValuePair<string, object> de in recognizer.namedParameterBindPoints) - { - namedParameters.Add(de.Key, de.Value); - } return recognizer.result.ToSqlString(); } @@ -266,7 +254,6 @@ { private readonly ISessionFactoryImplementor factory; internal SqlStringBuilder result = new SqlStringBuilder(); - internal Dictionary<string, object> namedParameterBindPoints = new Dictionary<string, object>(); internal int parameterCount = 0; private readonly List<IParameterSpecification> parametersSpecifications = new List<IParameterSpecification>(); private int positionalParameterCount; @@ -301,7 +288,6 @@ public void NamedParameter(string name, int position) { - AddNamedParameter(name); var paramSpec = new NamedParameterSpecification(1, position, name); var parameter = Parameter.Placeholder; parameter.BackTrack = paramSpec.GetIdsForBackTrack(factory).First(); @@ -323,27 +309,6 @@ { result.Add(sqlPart); } - - private void AddNamedParameter(string name) - { - int loc = parameterCount++; - object o; - if (!namedParameterBindPoints.TryGetValue(name, out o)) - { - namedParameterBindPoints[name] = loc; - } - else if (o is int) - { - List<int> list = new List<int>(4); - list.Add((int) o); - list.Add(loc); - namedParameterBindPoints[name] = list; - } - else - { - ((IList) o).Add(loc); - } - } } } } Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-06-18 23:03:18 UTC (rev 5959) @@ -1007,7 +1007,6 @@ <Compile Include="Param\IExplicitParameterSpecification.cs" /> <Compile Include="Param\IParameterSpecification.cs" /> <Compile Include="Param\NamedParameterSpecification.cs" /> - <Compile Include="Param\ParameterTranslationsImpl.cs" /> <Compile Include="Param\PositionalParameterSpecification.cs" /> <Compile Include="Hql\Ast\ANTLR\QuerySyntaxException.cs" /> <Compile Include="Hql\Ast\ANTLR\QueryTranslatorImpl.cs" /> @@ -1520,7 +1519,6 @@ <Compile Include="Criterion\IsNotEmptyExpression.cs" /> <Compile Include="Hql\HolderInstantiator.cs" /> <Compile Include="Hql\IFilterTranslator.cs" /> - <Compile Include="Hql\IParameterTranslations.cs" /> <Compile Include="Hql\IQueryTranslator.cs" /> <Compile Include="Hql\IQueryTranslatorFactory.cs" /> <Compile Include="Hql\NameGenerator.cs" /> Deleted: trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2011-06-18 20:05:26 UTC (rev 5958) +++ trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2011-06-18 23:03:18 UTC (rev 5959) @@ -1,143 +0,0 @@ -using System; -using System.Collections.Generic; -using NHibernate.Engine; -using NHibernate.Hql; -using NHibernate.Type; -using NHibernate.Util; - -namespace NHibernate.Param -{ - /// <summary> - /// Defines the information available for parameters encountered during - /// query translation through the antlr-based parser. - /// Author: Steve Ebersole - /// Ported by: Steve Strong - /// </summary> - public class ParameterTranslationsImpl : IParameterTranslations - { - private readonly Dictionary<string, ParameterInfo> _namedParameters; - private readonly ParameterInfo[] _ordinalParameters; - - public ParameterTranslationsImpl(IEnumerable<IParameterSpecification> parameterSpecifications) - { - List<ParameterInfo> ordinalParameterList = new List<ParameterInfo>(); - NullableDictionary<string, NamedParamTempHolder> namedParameterMap = new NullableDictionary<string, NamedParamTempHolder>(); - - int i = 0; - foreach (IParameterSpecification spec in parameterSpecifications) - { - if ( spec is PositionalParameterSpecification) - { - PositionalParameterSpecification ordinalSpec = ( PositionalParameterSpecification ) spec; - ordinalParameterList.Add( new ParameterInfo( i, ordinalSpec.ExpectedType) ); - } - else if ( spec is NamedParameterSpecification ) - { - NamedParameterSpecification namedSpec = ( NamedParameterSpecification ) spec; - NamedParamTempHolder paramHolder = namedParameterMap[namedSpec.Name]; - if ( paramHolder == null ) { - paramHolder = new NamedParamTempHolder(); - paramHolder.name = namedSpec.Name; - paramHolder.type = namedSpec.ExpectedType; - namedParameterMap.Add( namedSpec.Name, paramHolder ); - } - paramHolder.positions.Add( i ); - } - else { - // don't care about other param types here, just those explicitly user-defined... - - // Steve Strong Note: The original Java does not do this decrement; it increments i for - // every parameter type. However, within the Loader.GetParameterTypes() method, this introduces - // nulls into the paramTypeList array, which in turn causes Loader.ConvertITypesToSqlTypes() to crash - // with a null dereference. An alternative fix is to change the Loader to handle the null. I'm - // not sure which fix is the most appropriate. - // Legacy.FumTest.CompositeIDQuery() shows the bug if you remove the decrement below... - i--; - } - - i++; - } - - _ordinalParameters = ordinalParameterList.ToArray(); - _namedParameters = new Dictionary<string, ParameterInfo>(); - - foreach (NamedParamTempHolder holder in namedParameterMap.Values) - { - _namedParameters.Add(holder.name, new ParameterInfo( ArrayHelper.ToIntArray( holder.positions ), holder.type )); - } - } - - public int GetOrdinalParameterSqlLocation(int ordinalPosition) - { - return GetOrdinalParameterInfo(ordinalPosition).SqlLocations[0]; - } - - public IType GetOrdinalParameterExpectedType(int ordinalPosition) - { - return GetOrdinalParameterInfo(ordinalPosition).ExpectedType; - } - - public IEnumerable<string> GetNamedParameterNames() - { - return _namedParameters.Keys; - } - - public IType GetNamedParameterExpectedType(string name) - { - return GetNamedParameterInfo(name).ExpectedType; - } - - public bool SupportsOrdinalParameterMetadata - { - get { return true; } - } - - public int OrdinalParameterCount - { - get { return _ordinalParameters.Length; } - } - - private ParameterInfo GetOrdinalParameterInfo(int ordinalPosition) - { - // remember that ordinal parameters numbers are 1-based!!! - return _ordinalParameters[ordinalPosition - 1]; - } - - private ParameterInfo GetNamedParameterInfo(String name) - { - return _namedParameters[name]; - } - - class NamedParamTempHolder - { - internal String name; - internal IType type; - internal readonly List<int> positions = new List<int>(); - } - } - - [Serializable] - public class ParameterInfo - { - private readonly int[] sqlLocations; - - public ParameterInfo(int[] sqlPositions, IType expectedType) - { - sqlLocations = sqlPositions; - ExpectedType = expectedType; - } - - public ParameterInfo(int sqlPosition, IType expectedType) - { - sqlLocations = new[] { sqlPosition }; - ExpectedType = expectedType; - } - - public int[] SqlLocations - { - get { return sqlLocations; } - } - - public IType ExpectedType { get; private set; } - } -} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-21 14:22:34
|
Revision: 5967 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5967&view=rev Author: fabiomaulo Date: 2011-06-21 14:22:28 +0000 (Tue, 21 Jun 2011) Log Message: ----------- Fix NH-2773 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/ProxyCache.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Model.cs Modified: trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/ProxyCache.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/ProxyCache.cs 2011-06-21 12:35:12 UTC (rev 5966) +++ trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/ProxyCache.cs 2011-06-21 14:22:28 UTC (rev 5967) @@ -6,7 +6,6 @@ #endregion -using System; using System.Collections.Generic; using NHibernate.Util; @@ -14,8 +13,7 @@ { public class ProxyCache : IProxyCache { - private readonly IDictionary<ProxyCacheEntry, System.Type> cache = new ThreadSafeDictionary<ProxyCacheEntry, System.Type>(new Dictionary<ProxyCacheEntry, System.Type>()); - private readonly object syncObject = new object(); + private static readonly IDictionary<ProxyCacheEntry, System.Type> cache = new ThreadSafeDictionary<ProxyCacheEntry, System.Type>(new Dictionary<ProxyCacheEntry, System.Type>()); #region IProxyCache Members @@ -32,20 +30,14 @@ public System.Type GetProxyType(System.Type baseType, params System.Type[] baseInterfaces) { - lock (syncObject) - { - var entry = new ProxyCacheEntry(baseType, baseInterfaces); - return cache[entry]; - } + var entry = new ProxyCacheEntry(baseType, baseInterfaces); + return cache[entry]; } public void StoreProxyType(System.Type result, System.Type baseType, params System.Type[] baseInterfaces) { - lock (syncObject) - { - var entry = new ProxyCacheEntry(baseType, baseInterfaces); - cache[entry] = result; - } + var entry = new ProxyCacheEntry(baseType, baseInterfaces); + cache[entry] = result; } #endregion Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) @@ -0,0 +1,72 @@ +using System; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2773 { + public class Fixture : BugTestCase { + private Guid _entityGuid; + + protected override void OnSetUp() { + using (ISession session = OpenSession()) { + using (ITransaction tx = session.BeginTransaction()) { + var entity = new MyEntity(); + var entity2 = new MyEntity(); + entity.OtherEntity = entity2; + + session.Save(entity); + session.Save(entity2); + + _entityGuid = entity.Id; + + tx.Commit(); + } + } + } + + protected override void OnTearDown() { + base.OnTearDown(); + + using (ISession session = OpenSession()) { + using (ITransaction tx = session.BeginTransaction()) { + session.Delete("from MyEntity"); + tx.Commit(); + } + } + } + + [Test] + public void DeserializedSession_ProxyType_ShouldBeEqualToOriginalProxyType() { + System.Type originalProxyType = null; + System.Type deserializedProxyType = null; + ISession deserializedSession = null; + + using (ISession session = OpenSession()) { + using (ITransaction tx = session.BeginTransaction()) { + var entity = session.Get<MyEntity>(_entityGuid); + originalProxyType = entity.OtherEntity.GetType(); + tx.Commit(); + } + + + using (MemoryStream sessionMemoryStream = new MemoryStream()) { + BinaryFormatter formatter = new BinaryFormatter(); + formatter.Serialize(sessionMemoryStream, session); + + sessionMemoryStream.Seek(0, SeekOrigin.Begin); + deserializedSession = (ISession)formatter.Deserialize(sessionMemoryStream); + } + } + + using (ITransaction tx = deserializedSession.BeginTransaction()) { + var entity = deserializedSession.Get<MyEntity>(_entityGuid); + deserializedProxyType = entity.OtherEntity.GetType(); + tx.Commit(); + } + + deserializedSession.Dispose(); + + Assert.AreEqual(originalProxyType, deserializedProxyType); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Mappings.hbm.xml 2011-06-21 14:22:28 UTC (rev 5967) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2773"> + <class name="MyEntity"> + <id name="Id" column="id"> + <generator class="guid" /> + </id> + <many-to-one name="OtherEntity" /> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2773/Model.cs 2011-06-21 14:22:28 UTC (rev 5967) @@ -0,0 +1,9 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2773 { + [Serializable] + public class MyEntity { + public virtual Guid Id { get; set; } + public virtual MyEntity OtherEntity { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-21 12:35:12 UTC (rev 5966) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-21 14:22:28 UTC (rev 5967) @@ -880,6 +880,8 @@ <Compile Include="NHSpecificTest\NH2746\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2760\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2760\Model.cs" /> + <Compile Include="NHSpecificTest\NH2773\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2773\Model.cs" /> <Compile Include="NHSpecificTest\NH941\Domain.cs" /> <Compile Include="NHSpecificTest\NH941\Fixture.cs" /> <Compile Include="NHSpecificTest\NH941\FixtureUsingList.cs" /> @@ -2726,6 +2728,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2773\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2693\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2746\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2700\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2011-06-21 16:31:44
|
Revision: 5968 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5968&view=rev Author: julian-maughan Date: 2011-06-21 16:31:37 +0000 (Tue, 21 Jun 2011) Log Message: ----------- Fixed grammatical error in ModelMapper method names Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsAccessorTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NestedComponetsTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/IntegrationTests/NH2738/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1270/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1965/ReattachWithCollectionTest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2510/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2587/CachingWithLinq.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/FixtureUsingList.cs trunk/nhibernate/src/NHibernate.Test/Stateless/FetchingLazyCollections/LazyCollectionFetchTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -1766,12 +1766,12 @@ } } - public HbmMapping CompileMappingForAllExplicitAddedEntities() + public HbmMapping CompileMappingForAllExplicitlyAddedEntities() { return CompileMappingFor(customizerHolder.GetAllCustomizedEntities()); } - public IEnumerable<HbmMapping> CompileMappingForEachExplicitAddedEntity() + public IEnumerable<HbmMapping> CompileMappingForEachExplicitlyAddedEntity() { return CompileMappingForEach(customizerHolder.GetAllCustomizedEntities()); } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsAccessorTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsAccessorTests.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsAccessorTests.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -34,7 +34,7 @@ { x.Property(c => c.Something); }); - return mapper.CompileMappingForAllExplicitAddedEntities(); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); } [Test] Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -57,7 +57,7 @@ x.Component(c => c.Owner); x.Property(c => c.Something); }); - return mapper.CompileMappingForAllExplicitAddedEntities(); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); } [Test] Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -140,7 +140,7 @@ y.Property(c => c.Something); }); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); var hbmClass = mappings.RootClasses[0]; var hbmJoinedSubclass = mappings.JoinedSubclasses[0]; hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo"); @@ -179,7 +179,7 @@ }); mapper.Class<Inherited>(mc =>{}); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); var hbmClass = mappings.RootClasses[0]; mappings.JoinedSubclasses.Should().Be.Empty(); hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo"); @@ -212,7 +212,7 @@ y.Property(c => c.Something); }); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); var hbmClass = mappings.RootClasses[0]; var hbmJoinedSubclass = mappings.JoinedSubclasses[0]; hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo"); @@ -251,7 +251,7 @@ }); mapper.Class<Inherited>(mc => { }); - HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + HbmMapping mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); HbmClass hbmClass = mappings.RootClasses[0]; mappings.JoinedSubclasses.Should().Be.Empty(); hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -109,7 +109,7 @@ }); ca.Property(x => x.Something, map => map.Length(150)); }); - var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities(); + var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); ModelIsWellFormed(hbmMapping); } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -49,7 +49,7 @@ cm.Component(person => person.Address, comp => { }); }); - var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities(); + var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); var hbmClass = hbmMapping.RootClasses[0]; Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -81,7 +81,7 @@ { var mapper = new ModelMapper(); mapper.AddMapping(typeof(MyClassMap)); - var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities(); + var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); ModelIsWellFormed(hbmMapping); } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NestedComponetsTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NestedComponetsTests.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NestedComponetsTests.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -47,7 +47,7 @@ x.Component(c => c.Owner); x.Property(c => c.Something); }); - return mapper.CompileMappingForAllExplicitAddedEntities(); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); } private HbmMapping GetMappingWithParentInCompo() @@ -69,7 +69,7 @@ x.Component(c => c.Owner); x.Property(c => c.Something); }); - return mapper.CompileMappingForAllExplicitAddedEntities(); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); } [Test] Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/IntegrationTests/NH2738/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/IntegrationTests/NH2738/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/IntegrationTests/NH2738/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -25,7 +25,7 @@ rc.Id(x => x.Id); rc.Property(x => x.MyEmptyEnum); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); var conf = TestConfigurationHelper.GetDefaultConfiguration(); conf.AddMapping(mappings); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1270/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1270/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1270/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -42,7 +42,7 @@ mm.ForeignKey("FK_UserInRole"); })); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -21,7 +21,7 @@ map.Cascade(Mapping.ByCode.Cascade.All.Include(Mapping.ByCode.Cascade.DeleteOrphans)); }, rel => rel.OneToMany()); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1965/ReattachWithCollectionTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1965/ReattachWithCollectionTest.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1965/ReattachWithCollectionTest.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -28,7 +28,7 @@ cm.Id(x => x.Id, map => map.Generator(Generators.Identity)); cm.Bag(x => x.Children, map => map.Cascade(Mapping.ByCode.Cascade.All.Include(Mapping.ByCode.Cascade.DeleteOrphans)), rel => rel.OneToMany()); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2510/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2510/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2510/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -23,7 +23,7 @@ rc.Id(x=> x.Id); rc.Property(x => x.Data, map=> map.Lazy(true)); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -32,7 +32,7 @@ rm.Id(x => x.Id); rm.Bag(x => x.Relateds, am => am.Persister<MyCollectionPersister>(), rel=> rel.OneToMany()); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -28,7 +28,7 @@ }); var conf = new Configuration(); conf.DataBaseIntegration(x=> x.Dialect<MsSql2008Dialect>()); - conf.AddDeserializedMapping(mapper.CompileMappingForAllExplicitAddedEntities(), "wholeDomain"); + conf.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "wholeDomain"); var mappings = conf.CreateMappings(Dialect.Dialect.GetDialect()); var pc = mappings.GetClass(typeof(MyClass).FullName); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2587/CachingWithLinq.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2587/CachingWithLinq.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2587/CachingWithLinq.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -51,7 +51,7 @@ mc.Id(x => x.Id); mc.ManyToOne(x=> x.Foo, map=> map.Column("FooId")); }); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -38,7 +38,7 @@ cm.Property(x => x.Date); cm.ManyToOne(x => x.Customer, map => map.Column("CUSTOMERID")); }); - return mapper.CompileMappingForAllExplicitAddedEntities(); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); } protected override void Configure(Cfg.Configuration configuration) Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -20,7 +20,7 @@ }, rel => rel.OneToMany()); }); mapper.Class<Related>(rc => rc.Id(x => x.Id, map => map.Generator(Generators.HighLow))); - HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + HbmMapping mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/FixtureUsingList.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/FixtureUsingList.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/FixtureUsingList.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -21,7 +21,7 @@ }, rel => rel.OneToMany()); }); mapper.Class<Related>(rc => rc.Id(x => x.Id, map => map.Generator(Generators.HighLow))); - HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + HbmMapping mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } Modified: trunk/nhibernate/src/NHibernate.Test/Stateless/FetchingLazyCollections/LazyCollectionFetchTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Stateless/FetchingLazyCollections/LazyCollectionFetchTests.cs 2011-06-21 14:22:28 UTC (rev 5967) +++ trunk/nhibernate/src/NHibernate.Test/Stateless/FetchingLazyCollections/LazyCollectionFetchTests.cs 2011-06-21 16:31:37 UTC (rev 5968) @@ -30,7 +30,7 @@ }); mapper.AddMapping<FamilyMap<Reptile>>(); mapper.AddMapping<FamilyMap<Human>>(); - var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mappings; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-06-27 00:59:54
|
Revision: 5969 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5969&view=rev Author: patearl Date: 2011-06-27 00:59:46 +0000 (Mon, 27 Jun 2011) Log Message: ----------- Linq: Improved join detection in linq where clauses. Uses an easier to understand algorithm that corrects many cases. Also added some related tests. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetector.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Linq/Visitors/PossibleValueSet.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/InnerJoinFixture.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetectorDesignNotes.txt Added: trunk/nhibernate/src/NHibernate/Linq/Visitors/PossibleValueSet.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/PossibleValueSet.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/PossibleValueSet.cs 2011-06-27 00:59:46 UTC (rev 5969) @@ -0,0 +1,370 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Linq.Visitors +{ + /// <summary> + /// Represents a possible set of values for a computation. For example, an expression may + /// be null, it may be a non-null value, or we may even have a constant value that is known + /// precisely. This class contains operators that know how to combine these values with + /// each other. This class is intended to be used to provide static analysis of expressions + /// before we hit the database. As an example for future improvement, we could handle + /// ranges of numeric values. We can also improve this by handling operators such as the + /// comparison operators and arithmetic operators. They are currently handled by naive + /// null checks. + /// </summary> + public class PossibleValueSet + { + private System.Type ExpressionType { get; set; } + private bool ContainsNull { get; set; } + private bool ContainsAllNonNullValues { get; set; } + private List<object> DistinctValues + { + get + { + if (_DistinctValues == null) + _DistinctValues = new List<object>(); + return _DistinctValues; + } + } + private List<object> _DistinctValues; + + private bool ContainsAnyNonNullValues + { + get { return ContainsAllNonNullValues || DistinctValues.Any(); } + } + + private PossibleValueSet(System.Type expressionType) + { + ExpressionType = expressionType; + } + + public bool Contains(object obj) + { + if (obj == null) + return ContainsNull; + + if (obj.GetType() != ExpressionType) + return false; + + if (ContainsAllNonNullValues) + return true; + + return DistinctValues.Contains(obj); + } + + #region Operations + + public PossibleValueSet Add(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet Divide(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet Modulo(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet Multiply(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet Power(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet Subtract(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet And(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet Or(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet ExclusiveOr(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet LeftShift(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + public PossibleValueSet RightShift(PossibleValueSet pvs, System.Type resultType) + { + return MathOperation(pvs, resultType); + } + + private PossibleValueSet MathOperation(PossibleValueSet pvs, System.Type resultType) + { + // If either side is only null, the result will be null. + if (!ContainsAnyNonNullValues || !pvs.ContainsAnyNonNullValues) + return CreateNull(resultType); + + // If neither side is null, the result cannot be null. + if (!ContainsNull && !pvs.ContainsNull) + return CreateAllNonNullValues(resultType); + + // Otherwise, the result can be anything. + return CreateAllValues(resultType); + } + + public PossibleValueSet AndAlso(PossibleValueSet pvs) + { + /* + * T && T == T + * T && F == F + * T && N == N + * F && T == F + * F && F == F + * F && N == F + * N && T == N + * N && F == F + * N && N == N + */ + + CheckType<bool>(); + pvs.CheckType<bool>(); + PossibleValueSet result = new PossibleValueSet(typeof(bool)); + + if (Contains(true) && pvs.Contains(true) && !result.Contains(true)) result.DistinctValues.Add(true); + if (Contains(true) && pvs.Contains(false) && !result.Contains(false)) result.DistinctValues.Add(false); + if (Contains(true) && pvs.Contains(null)) result.ContainsNull = true; + if (Contains(false) && pvs.Contains(true) && !result.Contains(false)) result.DistinctValues.Add(false); + if (Contains(false) && pvs.Contains(false) && !result.Contains(false)) result.DistinctValues.Add(false); + if (Contains(false) && pvs.Contains(null) && !result.Contains(false)) result.DistinctValues.Add(false); + if (Contains(null) && pvs.Contains(true)) result.ContainsNull = true; + if (Contains(null) && pvs.Contains(false) && !result.Contains(false)) result.DistinctValues.Add(false); + if (Contains(null) && pvs.Contains(null)) result.ContainsNull = true; + + return result; + } + + public PossibleValueSet OrElse(PossibleValueSet pvs) + { + /* + * T || T == T + * T || F == T + * T || N == T + * F || T == T + * F || F == F + * F || N == N + * N || T == T + * N || F == N + * N || N == N + */ + + CheckType<bool>(); + pvs.CheckType<bool>(); + + PossibleValueSet result = new PossibleValueSet(typeof(bool)); + + if (Contains(true) && pvs.Contains(true) && !result.Contains(true)) result.DistinctValues.Add(true); + if (Contains(true) && pvs.Contains(false) && !result.Contains(true)) result.DistinctValues.Add(true); + if (Contains(true) && pvs.Contains(null) && !result.Contains(true)) result.DistinctValues.Add(true); + if (Contains(false) && pvs.Contains(true) && !result.Contains(true)) result.DistinctValues.Add(true); + if (Contains(false) && pvs.Contains(false) && !result.Contains(false)) result.DistinctValues.Add(false); + if (Contains(false) && pvs.Contains(null)) result.ContainsNull = true; + if (Contains(null) && pvs.Contains(true) && !result.Contains(true)) result.DistinctValues.Add(true); + if (Contains(null) && pvs.Contains(false)) result.ContainsNull = true; + if (Contains(null) && pvs.Contains(null)) result.ContainsNull = true; + + return result; + } + + public PossibleValueSet Equal(PossibleValueSet pvs) + { + return ComparisonOperation(pvs); + } + + public PossibleValueSet NotEqual(PossibleValueSet pvs) + { + return ComparisonOperation(pvs); + } + + public PossibleValueSet GreaterThanOrEqual(PossibleValueSet pvs) + { + return ComparisonOperation(pvs); + } + + public PossibleValueSet GreaterThan(PossibleValueSet pvs) + { + return ComparisonOperation(pvs); + } + + public PossibleValueSet LessThan(PossibleValueSet pvs) + { + return ComparisonOperation(pvs); + } + + public PossibleValueSet LessThanOrEqual(PossibleValueSet pvs) + { + return ComparisonOperation(pvs); + } + + private PossibleValueSet ComparisonOperation(PossibleValueSet pvs) + { + return MathOperation(pvs, typeof (bool)); + } + + public PossibleValueSet Coalesce(PossibleValueSet pvs) + { + if (!ContainsNull) + return this; + + PossibleValueSet result = new PossibleValueSet(ExpressionType); + result.DistinctValues.AddRange(DistinctValues); + result.ContainsAllNonNullValues = ContainsAllNonNullValues; + + result.ContainsNull = pvs.ContainsNull; + result.ContainsAllNonNullValues |= pvs.ContainsAllNonNullValues; + result.DistinctValues.AddRange(pvs.DistinctValues.Except(result.DistinctValues)); + + return result; + } + + // Unary Operators + + public PossibleValueSet Not() + { + CheckType<bool>(); + + PossibleValueSet result = new PossibleValueSet(typeof(bool)); + result.ContainsNull = ContainsNull; + result.DistinctValues.AddRange(DistinctValues.Cast<bool>().Select(v => !v).Cast<object>()); + return result; + } + + public PossibleValueSet BitwiseNot(System.Type resultType) + { + return UnaryMathOperation(resultType); + } + + public PossibleValueSet ArrayLength(System.Type resultType) + { + return CreateAllNonNullValues(typeof (int)); + } + + public PossibleValueSet Convert(System.Type resultType) + { + return UnaryMathOperation(resultType); + } + + public PossibleValueSet Negate(System.Type resultType) + { + return UnaryMathOperation(resultType); + } + + public PossibleValueSet UnaryPlus(System.Type resultType) + { + return this; + } + + private PossibleValueSet UnaryMathOperation(System.Type resultType) + { + return + !ContainsAnyNonNullValues ? CreateNull(resultType) : + !ContainsNull ? CreateAllNonNullValues(resultType) : + CreateAllValues(resultType); + } + + // Special Operators + + public PossibleValueSet IsNull() + { + PossibleValueSet result = new PossibleValueSet(typeof(bool)); + if (ContainsNull) + result.DistinctValues.Add(true); + if (ContainsAllNonNullValues || DistinctValues.Any()) + result.DistinctValues.Add(false); + return result; + } + + public PossibleValueSet IsNotNull() + { + PossibleValueSet result = new PossibleValueSet(typeof(bool)); + if (ContainsNull) + result.DistinctValues.Add(false); + if (ContainsAllNonNullValues || DistinctValues.Any()) + result.DistinctValues.Add(true); + return result; + } + + public PossibleValueSet MemberAccess(System.Type resultType) + { + // If instance is null, member will be null too. + if (!ContainsAnyNonNullValues) + return CreateNull(resultType); + + // Otherwise, value could be anything due to value of member. + return CreateAllValues(resultType); + } + + #endregion + + private void CheckType<T>() + { + if (ExpressionType != typeof(T)) + throw new AssertionFailure("Cannot perform desired possible value set operation on expression of type: " + ExpressionType); + } + + public static PossibleValueSet CreateNull(System.Type expressionType) + { + return new PossibleValueSet(expressionType) {ContainsNull = true}; + } + + public static PossibleValueSet CreateAllNonNullValues(System.Type expressionType) + { + PossibleValueSet result = new PossibleValueSet(expressionType); + if (expressionType == typeof(bool)) + { + result.DistinctValues.Add(true); + result.DistinctValues.Add(false); + } + else + { + result.ContainsAllNonNullValues = true; + } + return result; + } + + public static PossibleValueSet CreateAllValues(System.Type expressionType) + { + PossibleValueSet result = CreateAllNonNullValues(expressionType); + result.ContainsNull = true; + return result; + } + + public static PossibleValueSet Create(System.Type expressionType, params object[] values) + { + PossibleValueSet result = new PossibleValueSet(expressionType); + foreach (var v in values) + { + if (v == null) + result.ContainsNull = true; + else if (v.GetType() == expressionType && !result.DistinctValues.Contains(v)) + result.DistinctValues.Add(v); + else + throw new AssertionFailure("Don't know how to add value to possible value set of type " + expressionType + ": " + v); + } + return result; + } + } +} Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetector.cs 2011-06-21 16:31:37 UTC (rev 5968) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetector.cs 2011-06-27 00:59:46 UTC (rev 5969) @@ -1,126 +1,69 @@ -// FIXME - Are there other things that can convert N into T? What about the ?: operator? using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using NHibernate.Linq.ReWriters; using Remotion.Linq.Clauses.Expressions; -using Remotion.Linq.Utilities; namespace NHibernate.Linq.Visitors { /// <summary> /// The WhereJoinDetector creates the joins for the where clause, including - /// optimizations for inner joins. The algorithms are explained in - /// the accompanying text file. + /// optimizations for inner joins. + /// + /// The detector asks the following question: + /// Can an empty outer join ever return a record (ie. produce true in the where clause)? + /// If not, it's equivalent to an inner join since empty joins that can't produce true + /// never appear in the result set. + /// + /// A record (object) will be in the result if the evaluation of the condition in 3-value SQL + /// logic will return true; it will not be in the result if the result is either logical-null + /// or false. The difference between outer joining and inner joining is that with the latter, + /// objects are missing from the set on which the condition is checked. Thus, inner joins + /// "emulates" a result that is logical-null or false. And therefore, we can replace an outer + /// join with an inner join only if the resulting condition was not true on the outer join in + /// the first place when there was an "empty outer join" - i.e., the outer join had to add + /// nulls because there was no joinable record. These nulls can appear even for a column + /// that is not nullable. + /// + /// For example: + /// a.B.C == 1 could never produce true if B didn't match any rows, so it's safe to inner join. + /// a.B.C == null could produce true even if B didn't match any rows, so we can't inner join. + /// a.B.C == 1 && a.D.E == 1 can be inner joined. + /// a.B.C == 1 || a.D.E == 1 must be outer joined. + /// + /// By default we outer join via the code in VisitExpression. The use of inner joins is only + /// an optimization hint to the database. + /// + /// More examples: + /// a.B.C == 1 || a.B.C == null + /// We don't need multiple joins for this. When we reach the ||, we ask the value sets + /// on either side if they have a value for when a.B.C is emptily outer joined. Both of + /// them do, so those values are combined. + /// a.B.C == 1 || a.D.E == 1 + /// In this case, there is no value for a.B.C on the right side, so we use the possible + /// values for the entire expression, ignoring specific members. We only test for the + /// empty outer joining of one member expression at a time, since we can't guarantee that + /// they will all be emptily outer joined at the same time. + /// a.B.C ?? a.D.E + /// Even though each side is null when emptily outer joined, we can't promise that a.D.E + /// will be emptily outer joined when a.B.C is. Therefore, despite both sides being + /// null, the result may not be. + /// + /// There was significant discussion on the developers mailing list regarding this topic. See also NH-2583. + /// + /// The code here is based on the excellent work started by Harald Mueller. /// </summary> internal class WhereJoinDetector : AbstractJoinDetector { - // Possible results of a condition when emptily outer joined. - private const int T = 1; - private const int N = 2; - private const int TN = T | N; - private const int F = 4; - private const int TF = T | F; - private const int NF = N | F; - private const int TNF = T | N | F; + // TODO: There are a number of types of expressions that we didn't handle here due to time constraints. For example, the ?: operator could be checked easily. - // Composition rules for possible results when emptily outer joined - // for &&, ||, !. - private static readonly int[,] AND = new int[8, 8]; - private static readonly int[,] OR = new int[8, 8]; - private static readonly int[] NOT = new int[8]; - private static readonly int[] ISNULL = new int[8]; - private static readonly int[] ISNOTNULL = new int[8]; + private Stack<bool> _handled = new Stack<bool>(); + + // Stack of result values of each expression. After an expression has processed itself, it adds itself to the stack. + private Stack<ExpressionValues> _values = new Stack<ExpressionValues>(); - /// <summary> - /// Setup of <see cref="AND"/>, <see cref="OR"/>, <see cref="NOT"/>. - /// </summary> - static WhereJoinDetector() - { - // Setup of simple values according to SQL 3-valued logic. - NOT[T] = F; - NOT[N] = N; - NOT[F] = T; - ISNULL[T] = F; - ISNULL[N] = T; - ISNULL[F] = F; - ISNOTNULL[T] = T; - ISNOTNULL[N] = F; - ISNOTNULL[F] = T; - - foreach (var p in new[] { T, N, F }) - { - OR[p, p] = AND[p, p] = p; - AND[p, F] = AND[F, p] = F; - OR[p, T] = OR[T, p] = T; - } - AND[T, N] = AND[N, T] = N; - OR[F, N] = OR[N, F] = N; - - // Setup of compound values. Idea: Split each - // compound value to simple values, compute results - // for simple values and or them together. - var allValues = new[] { T, N, TN, F, TF, NF, TNF }; - - // How compound values are split up into simple values. - var split = new int[8][]; - split[T] = new[] { T }; - split[N] = new[] { N }; - split[TN] = new[] { T, N }; - split[F] = new[] { F }; - split[TF] = new[] { T, F }; - split[NF] = new[] { N, F }; - split[TNF] = new[] { T, N, F }; - - foreach (var p in allValues) - { - int[] splitP = split[p]; - // We only need to compute unary operations for compound values. - if (splitP.Length > 1) - { - int notResult = 0; - int isNullResult = 0; - int isNotNullResult = 0; - foreach (var p0 in splitP) - { - notResult |= NOT[p0]; - isNullResult |= ISNULL[p0]; - isNotNullResult |= ISNOTNULL[p0]; - } - NOT[p] = notResult; - ISNULL[p] = isNullResult; - ISNOTNULL[p] = isNotNullResult; - } - foreach (var q in allValues) - { - int[] splitQ = split[q]; - // We must compute AND and OR if both values are compound, - // *but also* if one is compound and the other is simple - // (e.g. T and TNF). - if (splitP.Length > 1 || splitQ.Length > 1) - { - int andResult = 0; - int orResult = 0; - foreach (var p0 in splitP) - { - foreach (var q0 in splitQ) - { - andResult |= AND[p0, q0]; - orResult |= OR[p0, q0]; - } - } - AND[p, q] = andResult; - OR[p, q] = orResult; - } - } - } - } - - // The following is used for all *condition* traversal (but not *expressions* that are not conditions). - // This is the "mapping" described in the text at NH-2583. - private Stack<Dictionary<string, int>> _memberExpressionMappings = new Stack<Dictionary<string, int>>(); - - // The following two are used for member expressions traversal. + // The following is used for member expressions traversal. private int _memberExpressionDepth = 0; internal @@ -133,221 +76,327 @@ { WhereJoinDetector f = new WhereJoinDetector(nameGenerator, isEntityDecider, joins, expressionMap); - f._memberExpressionMappings.Push(new Dictionary<string, int>()); - f.VisitExpression(expression); - foreach (var mapping in f._memberExpressionMappings.Pop()) + ExpressionValues values = f._values.Pop(); + + foreach (var memberExpression in values.MemberExpressions) { // If outer join can never produce true, we can safely inner join. - if ((mapping.Value & T) == 0) + if (!values.GetValues(memberExpression).Contains(true)) { - f.MakeInnerIfJoined(mapping.Key); + f.MakeInnerIfJoined(memberExpression); } } } - protected override Expression VisitBinaryExpression(BinaryExpression expression) + public override Expression VisitExpression(Expression expression) { - ArgumentUtility.CheckNotNull("expression", expression); + if (expression == null) + return null; - Expression baseResult = expression; - if (expression.NodeType == ExpressionType.AndAlso && expression.Type == typeof(bool)) + // To ensure safety in situations we don't understand, we default to "all possible values" + // if we can't process any expression in a known way. The SetResultValues() method is used + // to indicate that the expression has been processed, and what the results are. + + _handled.Push(false); + int originalCount = _values.Count; + + Expression result = base.VisitExpression(expression); + + if (!_handled.Pop()) { - // Case (a) from the text at NH-2583. - _memberExpressionMappings.Push(new Dictionary<string, int>()); - var newLeft = VisitExpression(expression.Left); - var leftMapping = _memberExpressionMappings.Pop(); + // If this expression was not handled in a known way, we throw away any values that might + // have been returned and we return "all values" for this expression, since we don't know + // what the expresson might result in. + while (_values.Count > originalCount) + _values.Pop(); + _values.Push(new ExpressionValues(PossibleValueSet.CreateAllValues(expression.Type))); + } - _memberExpressionMappings.Push(new Dictionary<string, int>()); - var newRight = VisitExpression(expression.Right); - var rightMapping = _memberExpressionMappings.Pop(); + return result; + } - BinaryMapping(leftMapping, rightMapping, AND); + protected override Expression VisitBinaryExpression(BinaryExpression expression) + { + var result = base.VisitBinaryExpression(expression); - // The following is copy-pasted from Relinq's visitor, as I had to split the code above. - var newConversion = (LambdaExpression)VisitExpression(expression.Conversion); - if (newLeft != expression.Left || newRight != expression.Right || newConversion != expression.Conversion) - baseResult = Expression.MakeBinary(expression.NodeType, newLeft, newRight, expression.IsLiftedToNull, expression.Method, newConversion); + if (expression.NodeType == ExpressionType.AndAlso) + { + HandleBinaryOperation((a, b) => a.AndAlso(b)); } - else if (expression.NodeType == ExpressionType.OrElse && expression.Type == typeof(bool)) + else if (expression.NodeType == ExpressionType.OrElse) { - // Case (b) - _memberExpressionMappings.Push(new Dictionary<string, int>()); - var newLeft = VisitExpression(expression.Left); - var leftMapping = _memberExpressionMappings.Pop(); + HandleBinaryOperation((a, b) => a.OrElse(b)); + } + else if (expression.NodeType == ExpressionType.NotEqual && IsNullConstantExpression(expression.Right)) + { + // Discard result from right null. Left is visited first, so it's below right on the stack. + _values.Pop(); - _memberExpressionMappings.Push(new Dictionary<string, int>()); - var newRight = VisitExpression(expression.Right); - var rightMapping = _memberExpressionMappings.Pop(); + HandleUnaryOperation(pvs => pvs.IsNotNull()); + } + else if (expression.NodeType == ExpressionType.NotEqual && IsNullConstantExpression(expression.Left)) + { + // Discard result from left null. + var right = _values.Pop(); + _values.Pop(); // Discard left. + _values.Push(right); - BinaryMapping(leftMapping, rightMapping, OR); + HandleUnaryOperation(pvs => pvs.IsNotNull()); + } + else if (expression.NodeType == ExpressionType.Equal && IsNullConstantExpression(expression.Right)) + { + // Discard result from right null. Left is visited first, so it's below right on the stack. + _values.Pop(); - // Again, the following is copy-pasted from Relinq's visitor, as I had to split the code above. - var newConversion = (LambdaExpression)VisitExpression(expression.Conversion); - if (newLeft != expression.Left || newRight != expression.Right || newConversion != expression.Conversion) - baseResult = Expression.MakeBinary(expression.NodeType, newLeft, newRight, expression.IsLiftedToNull, expression.Method, newConversion); + HandleUnaryOperation(pvs => pvs.IsNull()); } - else if (expression.Type == typeof(bool) - && expression.NodeType == ExpressionType.NotEqual - && (IsNullConstantExpression(expression.Right) || IsNullConstantExpression(expression.Left))) + else if (expression.NodeType == ExpressionType.Equal && IsNullConstantExpression(expression.Left)) { - // Case (h) - _memberExpressionMappings.Push(new Dictionary<string, int>()); - baseResult = base.VisitBinaryExpression(expression); - UnaryMapping(_memberExpressionMappings.Pop(), ISNOTNULL); + // Discard result from left null. + var right = _values.Pop(); + _values.Pop(); // Discard left. + _values.Push(right); + + HandleUnaryOperation(pvs => pvs.IsNull()); } - else if (expression.Type == typeof(bool) - && expression.NodeType == ExpressionType.Equal - && (IsNullConstantExpression(expression.Right) || IsNullConstantExpression(expression.Left))) + else if (expression.NodeType == ExpressionType.Coalesce) { - // Case (i) - _memberExpressionMappings.Push(new Dictionary<string, int>()); - baseResult = base.VisitBinaryExpression(expression); - UnaryMapping(_memberExpressionMappings.Pop(), ISNULL); + HandleBinaryOperation((a, b) => a.Coalesce(b)); } - else // +, * etc. + else if (expression.NodeType == ExpressionType.Add || expression.NodeType == ExpressionType.AddChecked) { - // Case (j) - baseResult = base.VisitBinaryExpression(expression); + HandleBinaryOperation((a, b) => a.Add(b, expression.Type)); } - return baseResult; + else if (expression.NodeType == ExpressionType.Divide) + { + HandleBinaryOperation((a, b) => a.Divide(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.Modulo) + { + HandleBinaryOperation((a, b) => a.Modulo(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.Multiply || expression.NodeType == ExpressionType.MultiplyChecked) + { + HandleBinaryOperation((a, b) => a.Multiply(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.Power) + { + HandleBinaryOperation((a, b) => a.Power(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.Subtract || expression.NodeType == ExpressionType.SubtractChecked) + { + HandleBinaryOperation((a, b) => a.Subtract(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.And) + { + HandleBinaryOperation((a, b) => a.And(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.Or) + { + HandleBinaryOperation((a, b) => a.Or(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.ExclusiveOr) + { + HandleBinaryOperation((a, b) => a.ExclusiveOr(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.LeftShift) + { + HandleBinaryOperation((a, b) => a.LeftShift(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.RightShift) + { + HandleBinaryOperation((a, b) => a.RightShift(b, expression.Type)); + } + else if (expression.NodeType == ExpressionType.Equal) + { + HandleBinaryOperation((a, b) => a.Equal(b)); + } + else if (expression.NodeType == ExpressionType.NotEqual) + { + HandleBinaryOperation((a, b) => a.NotEqual(b)); + } + else if (expression.NodeType == ExpressionType.GreaterThanOrEqual) + { + HandleBinaryOperation((a, b) => a.GreaterThanOrEqual(b)); + } + else if (expression.NodeType == ExpressionType.GreaterThan) + { + HandleBinaryOperation((a, b) => a.GreaterThan(b)); + } + else if (expression.NodeType == ExpressionType.LessThan) + { + HandleBinaryOperation((a, b) => a.LessThan(b)); + } + else if (expression.NodeType == ExpressionType.LessThanOrEqual) + { + HandleBinaryOperation((a, b) => a.LessThanOrEqual(b)); + } + + return result; } protected override Expression VisitUnaryExpression(UnaryExpression expression) { - ArgumentUtility.CheckNotNull("expression", expression); + Expression result = base.VisitUnaryExpression(expression); - Expression baseResult; if (expression.NodeType == ExpressionType.Not && expression.Type == typeof(bool)) { - // Case (c) from text at NH-2583. - _memberExpressionMappings.Push(new Dictionary<string, int>()); - baseResult = VisitExpression(expression.Operand); - UnaryMapping(_memberExpressionMappings.Pop(), NOT); + HandleUnaryOperation(pvs => pvs.Not()); } - else + else if (expression.NodeType == ExpressionType.Not) { - baseResult = base.VisitUnaryExpression(expression); + HandleUnaryOperation(pvs => pvs.BitwiseNot(expression.Type)); } - return baseResult; + else if (expression.NodeType == ExpressionType.ArrayLength) + { + HandleUnaryOperation(pvs => pvs.ArrayLength(expression.Type)); + } + else if (expression.NodeType == ExpressionType.Convert || expression.NodeType == ExpressionType.ConvertChecked) + { + HandleUnaryOperation(pvs => pvs.Convert(expression.Type)); + } + else if (expression.NodeType == ExpressionType.Negate || expression.NodeType == ExpressionType.NegateChecked) + { + HandleUnaryOperation(pvs => pvs.Negate(expression.Type)); + } + else if (expression.NodeType == ExpressionType.UnaryPlus) + { + HandleUnaryOperation(pvs => pvs.UnaryPlus(expression.Type)); + } + + return result; } - //protected override Expression VisitConditionalExpression(ConditionalExpression expression) + // We would usually get NULL if one of our inner member expresions was null. + // However, it's possible a method call will convert the null value from the failed join into a non-null value. + // This could be optimized by actually checking what the method does. For example StartsWith("s") would leave null as null and would still allow us to inner join. + //protected override Expression VisitMethodCallExpression(MethodCallExpression expression) //{ - // ArgumentUtility.CheckNotNull("expression", expression); - - // VisitExpression(expression.Test); - // // If the ?: returns bool, it is (most probably ...) a condition which may require outer joins. - // // TODO: Check check whether HQL accepts ?: conditions; if not, should be rewritten it as (a && b || !a && c). - // if (expression.Type == typeof(bool)) - // { - // ... - // } - // return expression; + // Expression result = base.VisitMethodCallExpression(expression); + // return result; //} - protected override Expression VisitMethodCallExpression(MethodCallExpression expression) - { - _memberExpressionMappings.Push(new Dictionary<string, int>()); - Expression result = base.VisitMethodCallExpression(expression); - // We would usually get NULL if one of our inner member expresions was null. (Mapped to N) - // However, it's possible a method call will convert the null value from the failed join into any one of True, False, or Null. (Mapped to TNF) - // This could be optimized by actually checking what the method does. For example StartsWith("s") would leave null as null and would still allow us to inner join. - FixedMapping(_memberExpressionMappings.Pop(), TNF); - return result; - } - protected override Expression VisitMemberExpression(MemberExpression expression) { - ArgumentUtility.CheckNotNull("expression", expression); + // The member expression we're visiting might be on the end of a variety of things, such as: + // a.B + // a.B.C + // (a.B ?? a.C).D + // I'm not sure what processing re-linq does to strange member expressions. + // TODO: I suspect this code doesn't add the right joins for the last case. - Expression newExpression; - try - { - _memberExpressionDepth++; - newExpression = base.VisitExpression(expression.Expression); - } - finally - { - _memberExpressionDepth--; - } - bool isEntity = _isEntityDecider.IsEntity(expression.Type); + _memberExpressionDepth++; + var result = base.VisitMemberExpression(expression); + _memberExpressionDepth--; - if (isEntity) + ExpressionValues values = _values.Pop().Operation(pvs => pvs.MemberAccess(expression.Type)); + if (_isEntityDecider.IsEntity(expression.Type)) { - // See (h) why we do not check for _memberExpressionDepth here! - AddPossibility(ExpressionKeyVisitor.Visit(expression, null), N); + // Don't add joins for things like a.B == a.C where B and C are entities. + // We only need to join B when there's something like a.B.D. + // TODO: Add an exception for the Id property. + if (_memberExpressionDepth > 0) + AddJoin(expression); + + string key = ExpressionKeyVisitor.Visit(expression, null); + values.MemberExpressionValuesIfEmptyOuterJoined[key] = PossibleValueSet.CreateNull(expression.Type); } + SetResultValues(values); - if (_memberExpressionDepth > 0 && isEntity) + return result; + } + + private static bool IsNullConstantExpression(Expression expression) + { + if (expression is ConstantExpression) { - return AddJoin(expression); + var constant = (ConstantExpression)expression; + return constant.Value == null; } else { - if (newExpression != expression.Expression) - return Expression.MakeMemberAccess(newExpression, expression.Member); - return expression; + return false; } } - private void FixedMapping(Dictionary<string, int> sourceMapping, int value) + private void SetResultValues(ExpressionValues values) { - foreach (var me in sourceMapping.Keys) - { - AddPossibility(me, value); - } + _handled.Pop(); + _handled.Push(true); + _values.Push(values); } - private void BinaryMapping(Dictionary<string, int> leftMapping, Dictionary<string, int> rightMapping, int[,] op) + private void HandleBinaryOperation(Func<PossibleValueSet, PossibleValueSet, PossibleValueSet> operation) { - // Compute mapping for all member expressions in leftMapping. If the member expression is missing - // in rightMapping, use TNF as a "pessimistic approximation" instead (inside the ?: operator). See - // the text for an explanation of this. - foreach (var lhs in leftMapping) + var right = _values.Pop(); + var left = _values.Pop(); + SetResultValues(left.Operation(right, operation)); + } + + private void HandleUnaryOperation(Func<PossibleValueSet, PossibleValueSet> operation) + { + SetResultValues(_values.Pop().Operation(operation)); + } + + private class ExpressionValues + { + public ExpressionValues(PossibleValueSet valuesIfUnknownMemberExpression) { - AddPossibility(lhs.Key, op[lhs.Value, rightMapping.ContainsKey(lhs.Key) ? rightMapping[lhs.Key] : TNF]); + Values = valuesIfUnknownMemberExpression; + MemberExpressionValuesIfEmptyOuterJoined = new Dictionary<string, PossibleValueSet>(); } - // Compute mapping for all member expressions *only* in rightMapping (we did the common ones above). - // Again, use TNF as pessimistic approximation to result of left subcondition. - foreach (var rhs in rightMapping) + + /// <summary> + /// Possible values of expression if there's set of values for the requested member expression. + /// For example, if we have an expression "3" and we request the state for "a.B.C", we'll + /// use "3" from Values since it won't exist in MemberExpressionValuesIfEmptyOuterJoined. + /// </summary> + private PossibleValueSet Values { get; set; } + + /// <summary> + /// Stores the possible values of an expression that would result if the given member expression + /// string was emptily outer joined. For example a.B.C would result in "null" if we try to + /// outer join to B and there are no rows. Even if an expression tree does contain a particular + /// member experssion, it may not appear in this list. In that case, the emptily outer joined + /// value set for that member expression will be whatever's in Values instead. + /// </summary> + public Dictionary<string, PossibleValueSet> MemberExpressionValuesIfEmptyOuterJoined { get; private set; } + + public PossibleValueSet GetValues(string memberExpression) { - if (!leftMapping.ContainsKey(rhs.Key)) - { - AddPossibility(rhs.Key, op[rhs.Value, TNF]); - } + if (MemberExpressionValuesIfEmptyOuterJoined.ContainsKey(memberExpression)) + return MemberExpressionValuesIfEmptyOuterJoined[memberExpression]; + return Values; } - } - private void UnaryMapping(Dictionary<string, int> sourceMapping, int[] op) - { - foreach (var item in sourceMapping) + public IEnumerable<string> MemberExpressions { - AddPossibility(item.Key, op[item.Value]); + get { return MemberExpressionValuesIfEmptyOuterJoined.Keys; } } - } - private static bool IsNullConstantExpression(Expression expression) - { - if (expression is ConstantExpression) + public ExpressionValues Operation(ExpressionValues mergeWith, Func<PossibleValueSet, PossibleValueSet, PossibleValueSet> operation) { - var constant = (ConstantExpression)expression; - return constant.Value == null; + ExpressionValues result = new ExpressionValues(operation(Values, mergeWith.Values)); + foreach (string memberExpression in MemberExpressions.Union(mergeWith.MemberExpressions)) + { + var left = GetValues(memberExpression); + var right = mergeWith.GetValues(memberExpression); + result.MemberExpressionValuesIfEmptyOuterJoined.Add(memberExpression, operation(left, right)); + } + return result; } - else + + public ExpressionValues Operation(Func<PossibleValueSet, PossibleValueSet> operation) { - return false; + ExpressionValues result = new ExpressionValues(operation(Values)); + foreach (string memberExpression in MemberExpressions) + { + result.MemberExpressionValuesIfEmptyOuterJoined.Add(memberExpression, operation(GetValues(memberExpression))); + } + return result; } } - - private void AddPossibility(string memberPath, int value) - { - Dictionary<string, int> mapping = _memberExpressionMappings.Peek(); - if (mapping.ContainsKey(memberPath)) - mapping[memberPath] |= value; - else - mapping[memberPath] = value; - } } } Deleted: trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetectorDesignNotes.txt =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetectorDesignNotes.txt 2011-06-21 16:31:37 UTC (rev 5968) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/WhereJoinDetectorDesignNotes.txt 2011-06-27 00:59:46 UTC (rev 5969) @@ -1,309 +0,0 @@ -[Commiter's Notes: As with the code, this design document was contributed by Harald Mueller. - By default in Linq, a member expression such as a.B.C is converted into left outer joins so if we have something like a => (a.B.C == 1 || a.D.E == 2) we don't lose records due to the join where B or D is null. - This document describes how we optimize to inner joins when outer joins are not required, such as in the simple case of a => a.B.C == 1. - There was significant discussion on the developers mailing list regarding this topic. See also NH-2583.] - -Optimization of outer joins to inner joins for (||-4) semantics -=============================================================== - -It is interesting - and for some databases an advantage - to replace outer joins with inner joins if the outer joins are not necessary. "Not necessary" here means that the result must not be different whether using outer joins or inner joins. The question, obviously, is: For which joinable member expressions can we replace an outer join with an inner join without creating wrong results? - -It took me a few hours to find this out. Here is the result. - -A record (object) will be in the result if the evaluation of the condition in 3-value SQL logic will return true; it will not be in the result if the result is either logical-null or false. The difference between outer joining and inner joining is that with the latter, objects are missing from the set on which the condition is checked. Thus, inner joins "emulates" a result that is logical-null or false. And therefore, we can replace an outer join with an inner join only if the resulting condition was not true on the outer join in the first place when there was an "empty outer join" - i.e., the outer join had to add nulls because there was no joinable record. - -By the way, I will in the following call the nulls added by "dangling outer joins" "oj-nulls". They have to be distinguished from the two other sorts of nulls in SQL: -* "value-null" - a NULL in a column of a table -* "logical-null" - a NULL resulting from the evaluation of certain conditions on certain values (in SQL, at least one of these values must be a value-null or oj-null). -In contrast to value-nulls, oj-nulls have the peculiar property that they can exist even for non-nullable columns. - -If we look at the evaluation tree of a condition, we can assign to each node and for each joinable member expression one of the following small sets: - - t definitely makes the node true when the member expression is emptily outer-joined (i.e., joining it creates oj-nulls for all the simple properties) - n definitely makes the node logical-null when emptily outer-joined - f definitely makes the node false when emptily outer-joined - tn maybe makes it true, maybe logical-null when emptily outer-joined - tf maybe makes it true, maybe false when emptily outer-joined - nf maybe makes it logical-null, maybe false when emptily outer-joined - tnf maybe makes it true, maybe logical-null, maybe false when emptily outer-joined - -(An eighth set, the empty one, could only be assigned to a contradiction. We ignore such conditions in most of the following discussion). - -When we know these values at the top condition, we can then safely use inner joins for all member expressions for which the value does not contain t. -The reasoning is as follows: If for some result record, the empty outer join of a joinable member expression has made the top where condition logical-null or false, this record will be dropped from the result set - this is just the definition of how a query handles logical-null and false results. But an inner join cannot "do more harm" - it will also just drop the record from the result. Therefore, we can safely replace outer joins to such joinable member expressions with inner joins. - -In the following, we assemble the rules for computing the member expressions mappings introduced above. After a few examples, we look at the rules, and then more examples. - -(Remark: I use C# notation in the following, with the following semantics: -* Generally, the semantics for condition evaluation is 3-valued SQL semantics with condition results of true, logical-null, or false -* == null has the semantics of "is null" -* != null the semantics of "is not null" -* the final result contains objects where the condition evaluation yields true, but not logical-null or false - this is the standard mapping of 3-valued-semantics to 2-valued-semantics). - -As a first example, the condition - - x.A.B == 4 - -is logical-null when emptily outer-joining x.A, but never true or false. Thus, we have { x.A -> n }. Inner joining x.A (which drops records that are emptily joined) therefore yields the same 2-valued-logic result. - -On the other hand, the condition - - x.A.B == null && x.E == null - -can be made true or false by emptily outer-joining x.A, but never logical-null (resaon: The right side can only be true or false; and the left side also; so the complete condition is either true or false - depending on x.E's value). So, { x.A -> tf }, and therefore we cannot inner join x.A (there is a t in the mapping!). By direct reasoning, we see that inner joining x.A will drop all the non-joinable records, hence inner and outer joining are different for records where x.E is null, and will yield a different 2-valued-logic result. - -Finally, the condition - - x.A.B == null || x.E == null - -is always true when emptily outer-joining x.A, so { x.A -> t }. Hence, the result is always different from inner joining, where the empty join drops such records from the result. - -How can we compute the mapping from member expressions to possible values? First, we note that we can compute this mapping with different "preciseness". For example, one correct way would be to just collect all joinable member expressions into a set M, and then set { mE -> tnf } for all member expressions mE in M. Obviously, this prevents any inner joins. On the other hand, we can in principle quite precisely check condition like the following - the question is whether this is worth the effort: - - x.A.B == null x.A -> ... - !(x.A.B != null) x.A -> ... - (x.A.B ?? 4) == 4 x.A -> ... - !((x.A.B ?? 4) != 4) x.A -> ... - (x.A.B ?? x.E) == 4 x.A -> ... - (x.A.B ?? x.C.D) == 4 x.A -> ..., x.C -> ... - -In the following, I'll first give the rules for the 4 logical operators &&, ||, !, and ?!; then I'll give practical rules (I think) for common simple conditions; finally, I'll look at some more complex simple conditions. - -(a) && operator: - - && t n f tn tf nf tnf - - t t n f tn tf nf tnf tnf - n n f n nf nf nf nf - f f f f f f f - tn tn tnf nf tnf tnf - tf tf nf tnf tnf - nf nf nf nf - tnf tnf tnf - - - - -The single letters are easy: They follow the 3-valued SQL logic. E.g., if emptily joining a member expression will definitely return true for condition A and logical-null for condition B, it will definitely return (true && logical-null) = logical-null for A && B. -For the multiple values, we have to compute the union of the values in the small sets. For example, tn && tf is { t && t, t && f, n && t, n && f } = { t,f,n,f } = tnf. -If the member expression is missing on one side, we must assume any value for that side. After all, the condition on the other side could e.g. be 0 == 0, 0 == null, or 0 == 1. Therefore, the result is the same as if we would get tnf from the other side. See examples (ex.4) and (ex.5) below for some more thoughts on this. -The values below the diagonal are symmetric to the upper ones. - -(b) || operator: - - || t n f tn tf nf tnf - - t t t t t t t t t - n n n tn tn n tn tn - f f tn tf nf tnf tnf - tn tn tn tn tn tn - tf tf tnf tnf tnf - nf nf tnf tnf - tnf tnf tnf - - - - -The resoning is similar to &&. -Again, the values below the diagonal are symmetric to the upper ones. - -(c) ! operator: - - ! t n f tn tf nf tnf - f n t nf tf tn tnf - -The resoning is similar to &&. - -(d) Logical ?: operator: - -A ? B : C is equivalent to A && B || !A && C. From this, one can compute the mappings (I would need a three-dimensional "cube matrix" for their presentation, which is hard in text ... ok, a tree also would work ...). - -Now let us look at simple conditions. The following are *possible* member expression mappings. As said above, one can also assign the values more crudely - e.g., always assign tnf to all member expressions. However, the assignments below are reasonable precise - i.e., they assign the minimal sets for practical values (if I did not make a mistake). - -(e) mE*.P <op> <constant(s)> (where <constant(s)> are not value-nulls) - -mE* here is a symbol for a "nested sequence of member expressions" mE1, mE2, ..., .P is the final property. E.g. in - - a.B.C.D.E == 4 - -the member expressions are mE1=a.B, mE2=a.B.C, and mE3=a.B.C.D; the final property is E. In this case, we get { mE -> n } for all member expressions mE. Reason: Emptily outer joining any member expression will yield oj-null for P; but oj-null <op> <constant> is always logical-null. - -(f) mE*.P [<op>s <constant>s] == me'*.Q [<op>s <constant>s] - -The result depends on the definition of ==: We can either use the Linq definition where null == null is true (which requires an SQL translation of ... = ... OR ... IS NULL AND ... IS NULL); or the SQL definition where null == null is logical-null. - -In the first case, we reason as follows: - - - When one side (e.g. the left one) does empty outer-joining and yields oj-null for P, but the right side has non-oj-null values, the SQL - oj-null = value OR oj-null IS NULL AND value IS NULL - evaluates as logical-null OR true AND false, which is logical-null OR true, which is true. - - When both sides do empty outer-joining, we get - oj-null = oj-null OR oj-null IS NULL AND oj-null IS NULL - which is logical-null OR true AND true, which is true. - -So, empty outer joining will always yield true, and hence we get { mE -> t } for all member expressions mE. - -For the SQL definition of equality, we get the following: - - - When one side (e.g. the left one) does empty outer-joining and yields oj-null for P, but the right side has non-oj-null values, the SQL - oj-null = value - evaluates as logical-null. - - When both sides do empty outer-joining, we get - oj-null = oj-null - which is logical-null. - -So, empty outer joining will always yield logical-null, and hence we get { mE -> n } for all member expressions mE. - -(g) mE*.P [<op>s <constant>s] != me'*.Q [<op>s <constant>s] - -Again, the result depends on the definition of ==: We can either use the Linq definition where null != null is false (which requires an SQL translation of ... <> ... OR ... IS NULL AND ... IS NOT NULL OR ... IS NOT NULL AND ... IS NULL); or the SQL definition where null != null is logical-null. - -In the first case, we reason as follows: - - - When one side (e.g. the left one) does empty outer-joining and yields oj-null for P, but the right side has non-oj-null values, the SQL - oj-null <> value OR oj-null IS NULL AND value IS NOT NULL OR oj-null IS NOT NULL AND value IS NULL - evaluates as logical-null OR true AND true OR false AND false, which is true. - - When both sides do empty outer-joining, we get - oj-null <> oj-null OR oj-null IS NULL AND oj-null IS NOT NULL OR oj-null IS NOT NULL AND oj-null IS NULL - which is logical-null OR false OR false, which is logical-null. - -So, empty outer joining will yield true or logical-null, and hence we get { mE -> tn } for all member expressions mE. - -For the SQL definition of equality, we get the following: - - - When one side (e.g. the left one) does empty outer-joining and yields oj-null for P, but the right side has non-oj-null values, the SQL - oj-null <> value - evaluates as logical-null. - - When both sides do empty outer-joining, we get - oj-null <> oj-null - which is also logical-null. - -So, empty outer joining will always yield logical-null, and hence we get { mE -> n } for all member expressions mE. - -(h) mE*.P != null - -Here is a first attempt: Empty outer joining can only yield false, hence we get { mE -> f } for all member expressions mE. - -There is a small problem with this definition: If P itself is a pointer to a mapped entity, we would *not* record that P is guaranteed to point to a valid object. This hurts in the following query: - - x.A != null && x.A.B != 4 - -According to (e), the right side will create the mapping { x.A -> n }. The left side does not have a joinable member expression (x.A is not joined! it is just evaluated on x's table), so the mapping is { }. According to (a), we get for the whole condition { x.A -> nf }. Actually, we know that the result should be { x.A -> f }: An empty outer join of x.A will yield "false" fo... [truncated message content] |
From: <pa...@us...> - 2011-06-27 03:45:00
|
Revision: 5971 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5971&view=rev Author: patearl Date: 2011-06-27 03:44:53 +0000 (Mon, 27 Jun 2011) Log Message: ----------- Linq: Support for % operator. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Linq/OperatorTests.cs Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2011-06-27 01:40:52 UTC (rev 5970) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2011-06-27 03:44:53 UTC (rev 5971) @@ -291,6 +291,9 @@ case ExpressionType.Divide: return _hqlTreeBuilder.Divide(lhs, rhs); + case ExpressionType.Modulo: + return _hqlTreeBuilder.MethodCall("mod", lhs, rhs); + case ExpressionType.LessThan: return _hqlTreeBuilder.LessThan(lhs, rhs); Added: trunk/nhibernate/src/NHibernate.Test/Linq/OperatorTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/OperatorTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Linq/OperatorTests.cs 2011-06-27 03:44:53 UTC (rev 5971) @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NHibernate.DomainModel.Northwind.Entities; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.Linq +{ + [TestFixture] + public class OperatorTests : LinqTestCase + { + [Test] + public void Mod() + { + Assert.AreEqual(2, session.Query<TimesheetEntry>().Where(a => a.NumberOfHours % 7 == 0).Count()); + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-27 01:40:52 UTC (rev 5970) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-06-27 03:44:53 UTC (rev 5971) @@ -502,6 +502,7 @@ <Compile Include="Linq\NullComparisonTests.cs" /> <Compile Include="Linq\ObjectDumper.cs" /> <Compile Include="Linq\ByMethod\OrderByTests.cs" /> + <Compile Include="Linq\OperatorTests.cs" /> <Compile Include="Linq\PagingTests.cs" /> <Compile Include="Linq\ParameterisedQueries.cs" /> <Compile Include="Linq\PatientTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-06-28 05:47:15
|
Revision: 5973 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5973&view=rev Author: patearl Date: 2011-06-28 05:47:09 +0000 (Tue, 28 Jun 2011) Log Message: ----------- Linq: Support basic non-aggregating group-by. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/GroupBy/NonAggregatingGroupByRewriter.cs trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs Modified: trunk/nhibernate/src/NHibernate/Linq/GroupBy/NonAggregatingGroupByRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/GroupBy/NonAggregatingGroupByRewriter.cs 2011-06-27 04:19:03 UTC (rev 5972) +++ trunk/nhibernate/src/NHibernate/Linq/GroupBy/NonAggregatingGroupByRewriter.cs 2011-06-28 05:47:09 UTC (rev 5973) @@ -18,6 +18,17 @@ public static void ReWrite(QueryModel queryModel) { + if (queryModel.ResultOperators.Count == 1 && + queryModel.ResultOperators[0] is GroupResultOperator && + IsNonAggregatingGroupBy(queryModel)) + { + GroupResultOperator resultOperator = (GroupResultOperator)queryModel.ResultOperators[0]; + queryModel.ResultOperators.Clear(); + queryModel.ResultOperators.Add(new NonAggregatingGroupBy(resultOperator)); + + return; + } + var subQueryExpression = queryModel.MainFromClause.FromExpression as SubQueryExpression; if ((subQueryExpression != null) && Modified: trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs 2011-06-27 04:19:03 UTC (rev 5972) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs 2011-06-28 05:47:09 UTC (rev 5973) @@ -28,20 +28,20 @@ } [Test] - [Ignore("Not working yet.")] public void SingleKeyGrouping() { var orders = db.Orders.GroupBy(o => o.Customer).ToList(); - Assert.That(orders.Count, Is.EqualTo(830)); + Assert.That(orders.Count(), Is.EqualTo(89)); + Assert.That(orders.Sum(o => o.Count()), Is.EqualTo(830)); CheckGrouping(orders, o => o.Customer); } [Test] - [Ignore("Not working yet.")] public void MultipleKeyGrouping() { var orders = db.Orders.GroupBy(o => new { o.Customer, o.Employee }).ToList(); - Assert.That(orders.Count, Is.EqualTo(830)); + Assert.That(orders.Count(), Is.EqualTo(464)); + Assert.That(orders.Sum(o => o.Count()), Is.EqualTo(830)); CheckGrouping( orders.Select(g => new TupGrouping<Customer, Employee, Order>(g.Key.Customer, g.Key.Employee, g)), @@ -69,10 +69,8 @@ HashSet<object> used = new HashSet<object>(); foreach (IGrouping<Tup<TKey1, TKey2>, TElement> group in groupedItems) { - Assert.IsFalse(used.Contains(group.Key.Item1)); - used.Add(group.Key.Item1); - Assert.IsFalse(used.Contains(group.Key.Item2)); - used.Add(group.Key.Item2); + Assert.IsFalse(used.Contains(group.Key)); + used.Add(group.Key); foreach (var item in group) { @@ -115,6 +113,24 @@ Item1 = item1; Item2 = item2; } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + if (obj.GetType() != GetType()) + return false; + + Tup<T1, T2> other = (Tup<T1, T2>) obj; + + return Equals(Item1, other.Item1) && Equals(Item2, other.Item2); + } + + public override int GetHashCode() + { + return Item1.GetHashCode() ^ Item2.GetHashCode(); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |