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