From: <fab...@us...> - 2008-07-22 18:55:10
|
Revision: 3645 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3645&view=rev Author: fabiomaulo Date: 2008-07-22 18:55:18 +0000 (Tue, 22 Jul 2008) Log Message: ----------- Fix NH-1253 (thanks to Jakob Andersen) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/IMultiQuery.cs trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs trunk/nhibernate/src/NHibernate/Util/StringHelper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-3.5.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Car.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/IMultiQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IMultiQuery.cs 2008-07-21 15:21:34 UTC (rev 3644) +++ trunk/nhibernate/src/NHibernate/IMultiQuery.cs 2008-07-22 18:55:18 UTC (rev 3645) @@ -61,9 +61,9 @@ IMultiQuery SetCacheable(bool cacheable); /// Set the name of the cache region. - /// <param name="cacheRegion">The name of a query cache region, or <see langword="null" /> + /// <param name="region">The name of a query cache region, or <see langword="null" /> /// for the default query cache</param> - IMultiQuery SetCacheRegion(string cacheRegion); + IMultiQuery SetCacheRegion(string region); /// Should the query force a refresh of the specified query cache region? /// This is particularly useful in cases where underlying data may have been @@ -261,7 +261,7 @@ /// <summary> /// Override the current session flush mode, just for this query. /// </summary> - IMultiQuery SetFlushMode(FlushMode flushMode); + IMultiQuery SetFlushMode(FlushMode mode); /// <summary> /// Set a strategy for handling the query results. This can be used to change Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2008-07-21 15:21:34 UTC (rev 3644) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2008-07-22 18:55:18 UTC (rev 3645) @@ -267,12 +267,12 @@ if (i > 0) list.Append(StringHelper.CommaSpace); - string alias = (isJpaPositionalParam ? 'x' + name : name) + i++ + StringHelper.Underscore; + string alias = (isJpaPositionalParam ? 'x' + name : name + StringHelper.Underscore) + i++ + StringHelper.Underscore; namedParamsCopy[alias] = new TypedValue(type, obj, session.EntityMode); list.Append(ParserHelper.HqlVariablePrefix).Append(alias); } string paramPrefix = isJpaPositionalParam ? StringHelper.SqlParameter : ParserHelper.HqlVariablePrefix; - return StringHelper.Replace(query, paramPrefix + name, list.ToString()); + return StringHelper.Replace(query, paramPrefix + name, list.ToString(), true); } #region Parameters Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2008-07-21 15:21:34 UTC (rev 3644) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2008-07-22 18:55:18 UTC (rev 3645) @@ -26,21 +26,21 @@ private readonly List<QueryTranslator> translators = new List<QueryTranslator>(); private readonly List<QueryParameters> parameters = new List<QueryParameters>(); private IList criteriaResults; - private Dictionary<string, int> criteriaResultPositions = new Dictionary<string, int>(); + private readonly Dictionary<string, int> criteriaResultPositions = new Dictionary<string, int>(); private string cacheRegion; private int commandTimeout = RowSelection.NoValue; - private bool isCacheable = false; + private bool isCacheable; private readonly ISessionImplementor session; private IResultTransformer resultTransformer; private readonly List<SqlType> types = new List<SqlType>(); - private SqlString sqlString = null; + private SqlString sqlString; private readonly Dialect.Dialect dialect; private bool forceCacheRefresh; private QueryParameters combinedParameters; private readonly List<string> namedParametersThatAreSafeToDuplicate = new List<string>(); private FlushMode flushMode = FlushMode.Unspecified; private FlushMode sessionFlushMode = FlushMode.Unspecified; - private static readonly Regex parseParameterListOrignialName = new Regex(@"(.*?)\d+_", RegexOptions.Compiled); + private static readonly Regex parseParameterListOrignialName = new Regex(@"(?<orgname>.*?)_\d+_", RegexOptions.Compiled); public MultiQueryImpl(ISessionImplementor session) { @@ -334,9 +334,9 @@ return this; } - public IMultiQuery SetCacheRegion(string cacheRegion) + public IMultiQuery SetCacheRegion(string region) { - this.cacheRegion = cacheRegion; + cacheRegion = region; return this; } @@ -361,14 +361,7 @@ { Before(); - if (cacheable) - { - criteriaResults = ListUsingQueryCache(); - } - else - { - criteriaResults = ListIgnoreQueryCache(); - } + criteriaResults = cacheable ? ListUsingQueryCache() : ListIgnoreQueryCache(); return criteriaResults; } finally @@ -377,9 +370,9 @@ } } - public IMultiQuery SetFlushMode(FlushMode flushMode) + public IMultiQuery SetFlushMode(FlushMode mode) { - this.flushMode = flushMode; + flushMode = mode; return this; } @@ -757,7 +750,7 @@ Match match = parseParameterListOrignialName.Match(name); if (match != null) { - string originalName = match.Groups[1].Value; + string originalName = match.Groups["orgname"].Value; return namedParametersThatAreSafeToDuplicate.Contains(originalName); } return false; Modified: trunk/nhibernate/src/NHibernate/Util/StringHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/StringHelper.cs 2008-07-21 15:21:34 UTC (rev 3644) +++ trunk/nhibernate/src/NHibernate/Util/StringHelper.cs 2008-07-22 18:55:18 UTC (rev 3645) @@ -109,15 +109,13 @@ return buf.ToString(); } - /// <summary> - /// - /// </summary> - /// <param name="template"></param> - /// <param name="placeholder"></param> - /// <param name="replacement"></param> - /// <returns></returns> public static string Replace(string template, string placeholder, string replacement) { + return Replace(template, placeholder, replacement, false); + } + + public static string Replace(string template, string placeholder, string replacement, bool wholeWords) + { // sometimes a null value will get passed in here -> SqlWhereStrings are a good example if (template == null) { @@ -131,13 +129,22 @@ } else { - return new StringBuilder(template.Substring(0, loc)) - .Append(replacement) - .Append(Replace( - template.Substring(loc + placeholder.Length), - placeholder, - replacement - )).ToString(); + // NH different implementation (NH-1253) + string replaceWith = replacement; + if(loc + placeholder.Length < template.Length) + { + string afterPlaceholder = template[loc + placeholder.Length].ToString(); + //After a token in HQL there can be whitespace, closedparen or comma.. + if(wholeWords && !(WhiteSpace.Contains(afterPlaceholder) || ClosedParen.Equals(afterPlaceholder) || Comma.Equals(afterPlaceholder))) + { + //If this is not a full token we don't want to touch it + replaceWith = placeholder; + } + } + + return + new StringBuilder(template.Substring(0, loc)).Append(replaceWith).Append( + Replace(template.Substring(loc + placeholder.Length), placeholder, replacement, wholeWords)).ToString(); } } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Car.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Car.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Car.cs 2008-07-22 18:55:18 UTC (rev 3645) @@ -0,0 +1,27 @@ +namespace NHibernate.Test.NHSpecificTest.NH1253 +{ + public class Car + { + private int _Id; + private string _Make; + private string _Model; + + public virtual int Id + { + get { return _Id; } + set { _Id = value; } + } + + public virtual string Model + { + get { return _Model; } + set { _Model = value; } + } + + public virtual string Make + { + get { return _Make; } + set { _Make = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Fixture.cs 2008-07-22 18:55:18 UTC (rev 3645) @@ -0,0 +1,82 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1253 +{ + [TestFixture] + public class Fixture : BugTestCase + { + // The test only check that there are no lost parameter set (no exception) + [Test] + public void TestParametersWithTrailingNumbersSingleInList() + { + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + IQuery q = s.CreateQuery("from Car c where c.Make in (:param1) or c.Model in (:param11)"); + q.SetParameterList("param11", new string[] { "Model1", "Model2" }); + q.SetParameterList("param1", new string[] { "Make1", "Make2" }); + IList<Car> cars = q.List<Car>(); + + tx.Commit(); + } + } + } + + [Test] + public void TestParametersWithTrailingNumbersSingleInListReverse() + { + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + IQuery q = s.CreateQuery("from Car c where c.Make in (:param1) or c.Model in (:param11)"); + q.SetParameterList("param1", new string[] { "Model1", "Model2" }); + q.SetParameterList("param11", new string[] { "Make1", "Make2" }); + IList<Car> cars = q.List<Car>(); + + tx.Commit(); + } + } + } + + [Test] + public void TestParametersWithTrailingNumbersMultipleInList() + { + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + IQuery q = s.CreateQuery("from Car c where c.Make in (:param11) or c.Model in (:param1)"); + q.SetParameterList("param11", new string[] { "One", "Two" }); + q.SetParameterList("param1", new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve" }); + IList cars = q.List(); + + tx.Commit(); + } + } + } + + [Test] + public void MultiQuerySingleInList() + { + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + IList results = s.CreateMultiQuery() + .Add("from Car c where c.Make in (:param1) or c.Model in (:param11)") + .Add("from Car c where c.Make in (:param1) or c.Model in (:param11)") + .SetParameterList("param11",new string[]{"Model1", "Model2"}) + .SetParameterList("param1", new string[] {"Make1", "Make2"}) + .List(); + + tx.Commit(); + } + } + } + + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1253/Mappings.hbm.xml 2008-07-22 18:55:18 UTC (rev 3645) @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate.Test.NHSpecificTest.NH1253" assembly="NHibernate.Test"> + <class name="Car" table="Cars"> + <id name="Id" column="CarID" type="Int32"> + <generator class="native" /> + </id> + <property name="Make" type="string" /> + <property name="Model" type="string" /> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj 2008-07-21 15:21:34 UTC (rev 3644) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj 2008-07-22 18:55:18 UTC (rev 3645) @@ -355,6 +355,8 @@ <Compile Include="NHSpecificTest\NH1230\PreSaveDoVeto.cs" /> <Compile Include="NHSpecificTest\NH1250\Model.cs" /> <Compile Include="NHSpecificTest\NH1250\PolymorphicJoinFetchFixture.cs" /> + <Compile Include="NHSpecificTest\NH1253\Car.cs" /> + <Compile Include="NHSpecificTest\NH1253\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1275\A.cs" /> <Compile Include="NHSpecificTest\NH1275\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1284\Fixture.cs" /> @@ -1361,6 +1363,7 @@ <ItemGroup> <EmbeddedResource Include="DynamicEntity\Interceptor\Customer.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1253\Mappings.hbm.xml" /> <EmbeddedResource Include="EntityModeTest\Map\Basic\ProductLine.hbm.xml" /> <EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" /> </ItemGroup> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-3.5.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-3.5.csproj 2008-07-21 15:21:34 UTC (rev 3644) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-3.5.csproj 2008-07-22 18:55:18 UTC (rev 3645) @@ -294,6 +294,8 @@ <Compile Include="NHSpecificTest\NH1144\Fixture.cs" /> <Compile Include="NHSpecificTest\CriteriaFromHql\Person.cs" /> <Compile Include="NHSpecificTest\CriteriaFromHql\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1253\Car.cs" /> + <Compile Include="NHSpecificTest\NH1253\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1284\Fixture.cs"> <SubType>Code</SubType> </Compile> @@ -1321,6 +1323,9 @@ <EmbeddedResource Include="NHSpecificTest\NH1359\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH1253\Mappings.hbm.xml" /> + </ItemGroup> + <ItemGroup> <Folder Include="Properties\" /> <Folder Include="Unionsubclass2\" /> </ItemGroup> @@ -1340,4 +1345,4 @@ if exist "$(ProjectDir)hibernate.cfg.xml" (copy "$(ProjectDir)hibernate.cfg.xml" "hibernate.cfg.xml") copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent> </PropertyGroup> -</Project> \ No newline at end of file +</Project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |