From: <fab...@us...> - 2009-05-14 17:40:20
|
Revision: 4304 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4304&view=rev Author: fabiomaulo Date: 2009-05-14 17:40:11 +0000 (Thu, 14 May 2009) Log Message: ----------- Fix NH-1776 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/FilterQueryTwiceFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2009-05-14 16:26:47 UTC (rev 4303) +++ trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2009-05-14 17:40:11 UTC (rev 4304) @@ -77,7 +77,7 @@ { if (entry.SqlLocations[index] >= existingParameterLocation) { - entry.SqlLocations[index]++; + entry.IncrementLocation(index); } } } @@ -138,30 +138,36 @@ } } + [Serializable] public class ParameterInfo { - private readonly int[] _sqlLocations; - private readonly IType _expectedType; + private readonly int[] originalLocation; + private readonly int[] sqlLocations; public ParameterInfo(int[] sqlPositions, IType expectedType) { - _sqlLocations = sqlPositions; - _expectedType = expectedType; + originalLocation = (int[])sqlPositions.Clone(); + sqlLocations = sqlPositions; + ExpectedType = expectedType; } - public ParameterInfo(int sqlPosition, IType expectedType) { - _sqlLocations = new int[] { sqlPosition }; - _expectedType = expectedType; + public ParameterInfo(int sqlPosition, IType expectedType) + { + originalLocation = new[] { sqlPosition }; + sqlLocations = new[] { sqlPosition }; + ExpectedType = expectedType; } public int[] SqlLocations { - get { return _sqlLocations; } + get { return sqlLocations; } } - public IType ExpectedType + public IType ExpectedType { get; private set; } + + public void IncrementLocation(int index) { - get { return _expectedType; } + sqlLocations[index] = originalLocation[index] + 1; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/FilterQueryTwiceFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/FilterQueryTwiceFixture.cs 2009-05-14 16:26:47 UTC (rev 4303) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/FilterQueryTwiceFixture.cs 2009-05-14 17:40:11 UTC (rev 4304) @@ -3,34 +3,42 @@ namespace NHibernate.Test.NHSpecificTest.NH1776 { - [TestFixture, Ignore("Not fixed yet.")] + [TestFixture] public class FilterQueryTwiceFixture : BugTestCase { + // Note : in this test what is really important is the usage of the same HQL + // because QueryPlan + [Test] [Description("Can Query using Session's filter Twice")] public void Bug() { + var c = new Category { Code = "2600", Deleted = false }; + SaveCategory(c); + + // exec queries, twice, different session + ExecQuery(); + ExecQuery(); + + // cleanup using filter using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { - var c = new Category {Code = "2600", Deleted = false}; - s.SaveOrUpdate(c); + s.EnableFilter("state").SetParameter("deleted", false); + s.Delete("from Category"); tx.Commit(); } } + } - // exec queries, twice, different session - ExecQuery(); - ExecQuery(); - - // cleanup + private void SaveCategory(Category c) + { using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { - s.EnableFilter("state").SetParameter("deleted", false); - s.Delete("from Category"); + s.Save(c); tx.Commit(); } } @@ -48,5 +56,93 @@ Assert.That(result.Count > 0); } } + + [Test] + [Description("Executing same query with and without filter and with different filter parameter value.")] + public void FilterOnOffOn() + { + var c = new Category { Code = "2600", Deleted = true }; + SaveCategory(c); + + using (ISession s = OpenSession()) + { + s.EnableFilter("state").SetParameter("deleted", false); + + IList<Category> result = + s.CreateQuery("from Category where Code = :code").SetParameter("code", "2600").List<Category>(); + + Assert.That(result.Count == 0); + } + + using (ISession s = OpenSession()) + { + IList<Category> result = + s.CreateQuery("from Category where Code = :code").SetParameter("code", "2600").List<Category>(); + + Assert.That(result.Count > 0); + } + + using (ISession s = OpenSession()) + { + s.EnableFilter("state").SetParameter("deleted", true); + + IList<Category> result = + s.CreateQuery("from Category where Code = :code").SetParameter("code", "2600").List<Category>(); + + Assert.That(result.Count > 0); + } + + Cleanup(); + } + + private void Cleanup() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.CreateQuery("delete from Category").ExecuteUpdate(); + tx.Commit(); + } + } + + [Test] + [Description("Executing same query with different filters combinations.")] + public void MultiFilterOnOffOn() + { + var c = new Category { Code = "2600", Deleted = true }; + SaveCategory(c); + + using (ISession s = OpenSession()) + { + s.EnableFilter("state").SetParameter("deleted", false); + + IList<Category> result = + s.CreateQuery("from Category where Code = :code").SetParameter("code", "2600").List<Category>(); + + Assert.That(result.Count == 0); + } + + using (ISession s = OpenSession()) + { + s.EnableFilter("state").SetParameter("deleted", true); + s.EnableFilter("CodeLike").SetParameter("codepattern", "2%"); + + IList<Category> result = + s.CreateQuery("from Category where Code = :code").SetParameter("code", "NotExists").List<Category>(); + + Assert.That(result.Count == 0); + } + + using (ISession s = OpenSession()) + { + s.EnableFilter("CodeLike").SetParameter("codepattern", "2%"); + + IList<Category> result = + s.CreateQuery("from Category where Code = :code").SetParameter("code", "2600").List<Category>(); + + Assert.That(result.Count > 0); + } + Cleanup(); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/Mappings.hbm.xml 2009-05-14 16:26:47 UTC (rev 4303) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1776/Mappings.hbm.xml 2009-05-14 17:40:11 UTC (rev 4304) @@ -10,10 +10,15 @@ <property name="Code"/> <property name="Deleted"/> <filter name="state" condition=":deleted = Deleted"/> + <filter name="CodeLike" condition="Code like :codepattern"/> </class> <filter-def name="state" condition=":deleted = Deleted"> <filter-param name="deleted" type="Boolean"/> </filter-def> + + <filter-def name="CodeLike"> + <filter-param name="codepattern" type="string"/> + </filter-def> </hibernate-mapping> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |