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