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. |