From: <ric...@us...> - 2010-08-29 17:17:45
|
Revision: 5169 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5169&view=rev Author: ricbrown Date: 2010-08-29 17:17:39 +0000 (Sun, 29 Aug 2010) Log Message: ----------- NHibernate.Test.Legacy.FumTest.CompositeIDQuery: corrected parameter positions for positional parameters (not working with Oracle) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2010-08-25 12:23:28 UTC (rev 5168) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2010-08-29 17:17:39 UTC (rev 5169) @@ -105,11 +105,6 @@ _collectionKeys = collectionKeys; _readOnly = readOnly; _resultTransformer = transformer; - - if (_positionalParameterLocations == null) - { - CreatePositionalParameterLocations(); - } } public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, @@ -196,15 +191,15 @@ set { _lockModes = value; } } - private void CreatePositionalParameterLocations() + private void CreatePositionalParameterLocations(ISessionFactoryImplementor factory) { - if (_positionalParameterTypes != null) + _positionalParameterLocations = new int[_positionalParameterTypes.Length]; + int location = 0; + for (int i = 0; i < _positionalParameterLocations.Length; i++) { - _positionalParameterLocations = new int[_positionalParameterTypes.Length]; - for (int i = 0; i < _positionalParameterLocations.Length; i++) - { - _positionalParameterLocations[i] = i; - } + var span = _positionalParameterTypes[i].GetColumnSpan(factory); + _positionalParameterLocations[i] = location; + location += span; } } @@ -460,6 +455,8 @@ int parameterIndex = 0; int totalSpan = 0; + CreatePositionalParameterLocations(factory); + IList<Parameter> sqlParameters = FindParametersIn(sqlString); for (int index = 0; index < PositionalParameterTypes.Length; index++) @@ -470,7 +467,7 @@ int location = PositionalParameterLocations[index]; location = FindAdjustedParameterLocation(location); int span = type.GetColumnSpan(factory); - SetParameterLocation(sqlParameters, startParameterIndex + parameterIndex, location, span); + SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span); totalSpan += span; parameterIndex++; @@ -483,7 +480,7 @@ int location = FilteredParameterLocations[index]; int span = type.GetColumnSpan(factory); - SetParameterLocation(sqlParameters, startParameterIndex + parameterIndex, location, span); + SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span); totalSpan += span; parameterIndex++; @@ -510,7 +507,7 @@ while ((location < sqlParameters.Count) && (sqlParameters[location].ParameterPosition != null)) location++; - SetParameterLocation(sqlParameters, startParameterIndex + parameterIndex, location, span); + SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span); } totalSpan += span; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 17:00:06
|
Revision: 5937 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5937&view=rev Author: fabiomaulo Date: 2011-06-16 16:59:59 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Removed no more needed code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:51:52 UTC (rev 5936) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:59:59 UTC (rev 5937) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using NHibernate.Impl; using NHibernate.Param; using NHibernate.SqlCommand; @@ -22,12 +23,8 @@ private IType[] _positionalParameterTypes; private object[] _positionalParameterValues; - private int[] _positionalParameterLocations; private IDictionary<string, TypedValue> _namedParameters; private IDictionary<string, LockMode> _lockModes; - private IList<IType> filteredParameterTypes; - private IList<object> filteredParameterValues; - private IList<int> filteredParameterLocations; private RowSelection _rowSelection; private bool _cacheable; private string _cacheRegion; @@ -118,11 +115,6 @@ set { _positionalParameterTypes = value; } } - public int[] PositionalParameterLocations - { - get { return _positionalParameterLocations; } - } - /// <summary> /// Gets or sets an array of <see cref="object"/> objects that is stored at the index /// of the Parameter. @@ -284,11 +276,8 @@ var copy = new QueryParameters(_positionalParameterTypes, _positionalParameterValues, _namedParameters, _lockModes, selection, _isReadOnlyInitialized, _readOnly, _cacheable, _cacheRegion, _comment, _collectionKeys, _optionalObject, _optionalEntityName, _optionalId, _resultTransformer); - copy._positionalParameterLocations = _positionalParameterLocations; copy.processedSQL = processedSQL; - copy.filteredParameterTypes = filteredParameterTypes; - copy.filteredParameterValues = filteredParameterValues; - copy.filteredParameterLocations = filteredParameterLocations; + copy.ProcessedSqlParameters = ProcessedSqlParameters.ToList(); return copy; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 17:20:24
|
Revision: 5938 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5938&view=rev Author: fabiomaulo Date: 2011-06-16 17:20:18 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Minor refactoring Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 16:59:59 UTC (rev 5937) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 17:20:18 UTC (rev 5938) @@ -72,9 +72,9 @@ 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, object[] collectionKeys, IResultTransformer transformer) { - _positionalParameterTypes = positionalParameterTypes; - _positionalParameterValues = positionalParameterValues; - _namedParameters = namedParameters; + _positionalParameterTypes = positionalParameterTypes ?? new IType[0]; + _positionalParameterValues = positionalParameterValues ?? new IType[0]; + _namedParameters = namedParameters ?? new Dictionary<string, TypedValue>(1); _lockModes = lockModes; _rowSelection = rowSelection; _cacheable = cacheable; @@ -102,7 +102,7 @@ public IDictionary<string, TypedValue> NamedParameters { get { return _namedParameters; } - set { _namedParameters = value; } + internal set { _namedParameters = value; } } /// <summary> @@ -150,15 +150,6 @@ get { return _isReadOnlyInitialized; } } - private int SafeLength(Array array) - { - if (array == null) - { - return 0; - } - return array.Length; - } - public void LogParameters(ISessionFactoryImplementor factory) { var print = new Printer(factory); @@ -200,8 +191,8 @@ /// </exception> public void ValidateParameters() { - int typesLength = SafeLength(PositionalParameterTypes); - int valuesLength = SafeLength(PositionalParameterValues); + int typesLength = PositionalParameterTypes.Length; + int valuesLength = PositionalParameterValues.Length; if (typesLength != valuesLength) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-06-16 17:32:31
|
Revision: 5939 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5939&view=rev Author: fabiomaulo Date: 2011-06-16 17:32:25 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Minor reformatting/refactoring (now it does not scare) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 17:20:18 UTC (rev 5938) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2011-06-16 17:32:25 UTC (rev 5939) @@ -17,35 +17,18 @@ [Serializable] public sealed class QueryParameters { - public delegate int[] GetNamedParameterLocations(string parameterName); - private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof (QueryParameters)); - private IType[] _positionalParameterTypes; - private object[] _positionalParameterValues; - private IDictionary<string, TypedValue> _namedParameters; - private IDictionary<string, LockMode> _lockModes; - private RowSelection _rowSelection; - private bool _cacheable; - private string _cacheRegion; - private object[] _collectionKeys; - private object _optionalObject; - private string _optionalEntityName; - private object _optionalId; - private bool _isReadOnlyInitialized; - private string _comment; - private bool _readOnly; - private SqlString processedSQL; - private readonly IResultTransformer _resultTransformer; - + private bool readOnly; + public QueryParameters() : this(ArrayHelper.EmptyTypeArray, ArrayHelper.EmptyObjectArray) {} public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, object optionalObject, string optionalEntityName, object optionalObjectId) : this(positionalParameterTypes, postionalParameterValues) { - _optionalObject = optionalObject; - _optionalId = optionalObjectId; - _optionalEntityName = optionalEntityName; + OptionalObject = optionalObject; + OptionalId = optionalObjectId; + OptionalEntityName = optionalEntityName; } public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues) @@ -57,224 +40,180 @@ 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) + 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; } - 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) + 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; } - 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, object[] collectionKeys, IResultTransformer transformer) + 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, object[] collectionKeys, IResultTransformer transformer) { - _positionalParameterTypes = positionalParameterTypes ?? new IType[0]; - _positionalParameterValues = positionalParameterValues ?? new IType[0]; - _namedParameters = namedParameters ?? new Dictionary<string, TypedValue>(1); - _lockModes = lockModes; - _rowSelection = rowSelection; - _cacheable = cacheable; - _cacheRegion = cacheRegion; - _comment = comment; - _collectionKeys = collectionKeys; - _isReadOnlyInitialized = isReadOnlyInitialized; - _readOnly = readOnly; - _resultTransformer = transformer; + PositionalParameterTypes = positionalParameterTypes ?? new IType[0]; + PositionalParameterValues = positionalParameterValues ?? new IType[0]; + NamedParameters = namedParameters ?? new Dictionary<string, TypedValue>(1); + LockModes = lockModes; + RowSelection = rowSelection; + Cacheable = cacheable; + CacheRegion = cacheRegion; + Comment = comment; + CollectionKeys = collectionKeys; + IsReadOnlyInitialized = isReadOnlyInitialized; + this.readOnly = readOnly; + ResultTransformer = transformer; } - 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, object[] collectionKeys, object optionalObject, string optionalEntityName, object optionalId, IResultTransformer transformer) - : this(positionalParameterTypes, positionalParameterValues, namedParameters, lockModes, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, collectionKeys, transformer) + 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, object[] collectionKeys, object optionalObject, string optionalEntityName, object optionalId, IResultTransformer transformer) + : this( + positionalParameterTypes, positionalParameterValues, namedParameters, lockModes, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, collectionKeys, + transformer) { - _optionalEntityName = optionalEntityName; - _optionalId = optionalId; - _optionalObject = optionalObject; + OptionalEntityName = optionalEntityName; + OptionalId = optionalId; + OptionalObject = optionalObject; } public bool HasRowSelection { - get { return _rowSelection != null; } + get { return RowSelection != null; } } - public IDictionary<string, TypedValue> NamedParameters - { - get { return _namedParameters; } - internal set { _namedParameters = value; } - } + public IDictionary<string, TypedValue> NamedParameters { get; internal set; } /// <summary> /// Gets or sets an array of <see cref="IType"/> objects that is stored at the index /// of the Parameter. /// </summary> - public IType[] PositionalParameterTypes - { - get { return _positionalParameterTypes; } - set { _positionalParameterTypes = value; } - } + public IType[] PositionalParameterTypes { get; set; } /// <summary> /// Gets or sets an array of <see cref="object"/> objects that is stored at the index /// of the Parameter. /// </summary> - public object[] PositionalParameterValues - { - get { return _positionalParameterValues; } - set { _positionalParameterValues = value; } - } + public object[] PositionalParameterValues { get; set; } /// <summary> /// Gets or sets the <see cref="RowSelection"/> for the Query. /// </summary> - public RowSelection RowSelection - { - get { return _rowSelection; } - set { _rowSelection = value; } - } + public RowSelection RowSelection { get; set; } /// <summary> /// Gets or sets an <see cref="IDictionary"/> that contains the alias name of the /// object from hql as the key and the <see cref="LockMode"/> as the value. /// </summary> /// <value>An <see cref="IDictionary"/> of lock modes.</value> - public IDictionary<string, LockMode> LockModes - { - get { return _lockModes; } - set { _lockModes = value; } - } + public IDictionary<string, LockMode> LockModes { get; set; } - public bool IsReadOnlyInitialized - { - get { return _isReadOnlyInitialized; } - } + public bool IsReadOnlyInitialized { get; private set; } - public void LogParameters(ISessionFactoryImplementor factory) - { - var print = new Printer(factory); - if (_positionalParameterValues.Length != 0) - { - log.Debug("parameters: " + print.ToString(_positionalParameterTypes, _positionalParameterValues)); - } + public bool Cacheable { get; set; } - if (_namedParameters != null) - { - log.Debug("named parameters: " + print.ToString(_namedParameters)); - } - } + public string CacheRegion { get; set; } - public bool Cacheable - { - get { return _cacheable; } - set { _cacheable = value; } - } + public string Comment { get; set; } - public string CacheRegion - { - get { return _cacheRegion; } - set { _cacheRegion = value; } - } - - public string Comment - { - get { return _comment; } - set { _comment = value; } - } - - /// <summary> - /// Ensure the Types and Values are the same length. - /// </summary> - /// <exception cref="QueryException"> - /// If the Lengths of <see cref="PositionalParameterTypes"/> and - /// <see cref="PositionalParameterValues"/> are not equal. - /// </exception> - public void ValidateParameters() - { - int typesLength = PositionalParameterTypes.Length; - int valuesLength = PositionalParameterValues.Length; - - if (typesLength != valuesLength) - { - throw new QueryException("Number of positional parameter types (" + typesLength - + ") does not match number of positional parameter values (" + valuesLength + ")"); - } - } - public bool ForceCacheRefresh { get; set; } - public string OptionalEntityName - { - get { return _optionalEntityName; } - set { _optionalEntityName = value; } - } + public string OptionalEntityName { get; set; } - public object OptionalId - { - get { return _optionalId; } - set { _optionalId = value; } - } + public object OptionalId { get; set; } - public object OptionalObject - { - get { return _optionalObject; } - set { _optionalObject = value; } - } + public object OptionalObject { get; set; } - public object[] CollectionKeys - { - get { return _collectionKeys; } - set { _collectionKeys = value; } - } + public object[] CollectionKeys { get; set; } public bool Callable { get; set; } - + public bool ReadOnly { get { - if (!_isReadOnlyInitialized) + if (!IsReadOnlyInitialized) + { throw new InvalidOperationException("cannot call ReadOnly when IsReadOnlyInitialized returns false"); + } - return _readOnly; + return readOnly; } set { - _readOnly = value; - _isReadOnlyInitialized = true; + readOnly = value; + IsReadOnlyInitialized = true; } } - public SqlString ProcessedSql - { - get { return processedSQL; } - internal set { processedSQL = value; } - } + public SqlString ProcessedSql { get; internal set; } public IEnumerable<IParameterSpecification> ProcessedSqlParameters { get; internal set; } public bool NaturalKeyLookup { get; set; } - public IResultTransformer ResultTransformer + public IResultTransformer ResultTransformer { get; private set; } + + public bool HasAutoDiscoverScalarTypes { get; set; } + + public void LogParameters(ISessionFactoryImplementor factory) { - get { return _resultTransformer; } + var print = new Printer(factory); + if (PositionalParameterValues.Length != 0) + { + log.Debug("parameters: " + print.ToString(PositionalParameterTypes, PositionalParameterValues)); + } + + if (NamedParameters != null) + { + log.Debug("named parameters: " + print.ToString(NamedParameters)); + } } - public bool HasAutoDiscoverScalarTypes { get; set; } + /// <summary> + /// Ensure the Types and Values are the same length. + /// </summary> + /// <exception cref="QueryException"> + /// If the Lengths of <see cref="PositionalParameterTypes"/> and + /// <see cref="PositionalParameterValues"/> are not equal. + /// </exception> + public void ValidateParameters() + { + int typesLength = PositionalParameterTypes == null ? 0 : PositionalParameterTypes.Length; + int valuesLength = PositionalParameterValues == null ? 0 : PositionalParameterValues.Length; + if (typesLength != valuesLength) + { + throw new QueryException("Number of positional parameter types (" + typesLength + + ") does not match number of positional parameter values (" + valuesLength + ")"); + } + } + public QueryParameters CreateCopyUsing(RowSelection selection) { - var copy = new QueryParameters(_positionalParameterTypes, _positionalParameterValues, _namedParameters, _lockModes, - selection, _isReadOnlyInitialized, _readOnly, _cacheable, _cacheRegion, _comment, _collectionKeys, - _optionalObject, _optionalEntityName, _optionalId, _resultTransformer); - copy.processedSQL = processedSQL; - copy.ProcessedSqlParameters = ProcessedSqlParameters.ToList(); + var copy = new QueryParameters(PositionalParameterTypes, PositionalParameterValues, NamedParameters, LockModes, + selection, IsReadOnlyInitialized, readOnly, Cacheable, CacheRegion, Comment, CollectionKeys, + OptionalObject, OptionalEntityName, OptionalId, ResultTransformer) + { + ProcessedSql = ProcessedSql, + ProcessedSqlParameters = ProcessedSqlParameters.ToList() + }; return copy; } - + public bool IsReadOnly(ISessionImplementor session) { - return _isReadOnlyInitialized ? this.ReadOnly : session.PersistenceContext.DefaultReadOnly; + return IsReadOnlyInitialized ? ReadOnly : session.PersistenceContext.DefaultReadOnly; } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |