|
From: <fab...@us...> - 2009-05-31 16:39:13
|
Revision: 4392
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4392&view=rev
Author: fabiomaulo
Date: 2009-05-31 16:39:08 +0000 (Sun, 31 May 2009)
Log Message:
-----------
Fix NH-1802
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs
trunk/nhibernate/src/NHibernate/Cache/QueryKey.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.cs
trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.xml
trunk/nhibernate/src/NHibernate.Test/CacheTest/FilterKeyFixture.cs
trunk/nhibernate/src/NHibernate.Test/CacheTest/QueryKeyFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs 2009-05-30 03:49:14 UTC (rev 4391)
+++ trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs 2009-05-31 16:39:08 UTC (rev 4392)
@@ -48,7 +48,7 @@
public override string ToString()
{
- return "FilterKey[" + filterName + filterParameters + ']';
+ return string.Format("FilterKey[{0}{1}]", filterName, CollectionPrinter.ToString(filterParameters));
}
public static ISet CreateFilterKeys(IDictionary<string, IFilter> enabledFilters, EntityMode entityMode)
Modified: trunk/nhibernate/src/NHibernate/Cache/QueryKey.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cache/QueryKey.cs 2009-05-30 03:49:14 UTC (rev 4391)
+++ trunk/nhibernate/src/NHibernate/Cache/QueryKey.cs 2009-05-31 16:39:08 UTC (rev 4392)
@@ -122,12 +122,12 @@
}
}
- if (!CollectionHelper.DictionaryEquals(namedParameters, that.namedParameters))
+ if (!CollectionHelper.SetEquals(filters, that.filters))
{
return false;
}
- if (!CollectionHelper.SetEquals(filters, that.filters))
+ if (!CollectionHelper.DictionaryEquals(namedParameters, that.namedParameters))
{
return false;
}
@@ -217,6 +217,10 @@
.Append("; named parameters: ")
.Append(print.ToString(namedParameters));
}
+ if (filters != null)
+ {
+ buf.Append("; filters: ").Append(CollectionPrinter.ToString(filters));
+ }
if (firstRow != RowSelection.NoValue)
{
buf.Append("; first row: ").Append(firstRow);
Added: trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.cs 2009-05-31 16:39:08 UTC (rev 4392)
@@ -0,0 +1,9 @@
+namespace NHibernate.Test.CacheTest
+{
+ public class EntityWithFilters
+ {
+ public virtual int Id { get; set; }
+ public virtual string Description { get; set; }
+ public virtual int Value { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CacheTest/EntityWithFilters.xml 2009-05-31 16:39:08 UTC (rev 4392)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.CacheTest">
+ <class name="EntityWithFilters">
+ <id type="int"/>
+ <property name="Description"/>
+ <property name="Value"/>
+
+ <filter name="DescriptionLike" />
+ <filter name="DescriptionEqualAndValueGT" />
+ </class>
+ <query name="EntityWithFilters.All" cache-region="aRegion" cacheable="true">
+ from EntityWithFilters
+ </query>
+ <filter-def name="DescriptionLike" condition="Description like :pLike">
+ <filter-param name="pLike" type="string"/>
+ </filter-def>
+ <filter-def name="DescriptionEqualAndValueGT" condition="Description = :pDesc and Value > :pValue">
+ <filter-param name="pDesc" type="string"/>
+ <filter-param name="pValue" type="int"/>
+ </filter-def>
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CacheTest/FilterKeyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CacheTest/FilterKeyFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CacheTest/FilterKeyFixture.cs 2009-05-31 16:39:08 UTC (rev 4392)
@@ -0,0 +1,112 @@
+using System.Collections;
+using NHibernate.Cache;
+using NHibernate.Impl;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CacheTest
+{
+ [TestFixture]
+ public class FilterKeyFixture: TestCase
+ {
+ protected override string MappingsAssembly
+ {
+ get{return "NHibernate.Test";}
+ }
+
+ protected override IList Mappings
+ {
+ get { return new[] { "CacheTest.EntityWithFilters.xml" }; }
+ }
+
+ [Test]
+ public void ToStringIncludeAll()
+ {
+ string filterName = "DescriptionLike";
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pLike", "so%");
+ var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ Assert.That(fk.ToString(), Is.EqualTo("FilterKey[DescriptionLike{'pLike'='so%'}]"));
+
+ filterName = "DescriptionEqualAndValueGT";
+ f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
+ fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ Assert.That(fk.ToString(), Is.EqualTo("FilterKey[DescriptionEqualAndValueGT{'pDesc'='something', 'pValue'='10'}]"));
+ }
+
+ [Test]
+ public void Equality()
+ {
+ // Equality is aware only by parameters names not values
+ FilterKey fk, fk1;
+ FilterDescLikeToCompare(out fk, out fk1);
+ Assert.That(fk, Is.EqualTo(fk1));
+
+ FilterDescValueToCompare(out fk, out fk1);
+ Assert.That(fk, Is.EqualTo(fk1));
+ }
+
+ private void FilterDescLikeToCompare(out FilterKey fk, out FilterKey fk1)
+ {
+ const string filterName = "DescriptionLike";
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pLike", "so%");
+ fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+
+ var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f1.SetParameter("pLike", "%ing");
+ fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ }
+
+ private void FilterDescValueToCompare(out FilterKey fk, out FilterKey fk1)
+ {
+ const string filterName = "DescriptionEqualAndValueGT";
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
+ fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+
+ var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f1.SetParameter("pDesc", "something").SetParameter("pValue", 11);
+ fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ }
+
+ [Test]
+ public void NotEquality()
+ {
+ FilterKey fk, fk1;
+ FilterDescLikeToCompare(out fk, out fk1);
+
+ FilterKey fvk, fvk1;
+ FilterDescValueToCompare(out fvk, out fvk1);
+
+ Assert.That(fk, Is.Not.EqualTo(fvk));
+ Assert.That(fk1, Is.Not.EqualTo(fvk1));
+ }
+
+ [Test]
+ public void HashCode()
+ {
+ // HashCode is aware only by parameters names not values (should work as Equal)
+ FilterKey fk, fk1;
+ FilterDescLikeToCompare(out fk, out fk1);
+ Assert.That(fk.GetHashCode(), Is.EqualTo(fk1.GetHashCode()));
+
+ FilterDescValueToCompare(out fk, out fk1);
+ Assert.That(fk.GetHashCode(), Is.EqualTo(fk1.GetHashCode()));
+
+ }
+
+ [Test]
+ public void NotEqualHashCode()
+ {
+ FilterKey fk, fk1;
+ FilterDescLikeToCompare(out fk, out fk1);
+
+ FilterKey fvk, fvk1;
+ FilterDescValueToCompare(out fvk, out fvk1);
+
+ Assert.That(fk.GetHashCode(), Is.Not.EqualTo(fvk.GetHashCode()));
+ Assert.That(fk1.GetHashCode(), Is.Not.EqualTo(fvk1.GetHashCode()));
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CacheTest/QueryKeyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CacheTest/QueryKeyFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CacheTest/QueryKeyFixture.cs 2009-05-31 16:39:08 UTC (rev 4392)
@@ -0,0 +1,147 @@
+using System.Collections;
+using Iesi.Collections.Generic;
+using NHibernate.Cache;
+using NHibernate.Engine;
+using NHibernate.Impl;
+using NHibernate.SqlCommand;
+using NUnit.Framework;
+using Iesi.Collections;
+
+namespace NHibernate.Test.CacheTest
+{
+ [TestFixture]
+ public class QueryKeyFixture : TestCase
+ {
+ private readonly SqlString SqlAll =
+ new SqlString("select entitywith0_.id as id0_, entitywith0_.Description as Descript2_0_, entitywith0_.Value as Value0_ from EntityWithFilters entitywith0_");
+
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override IList Mappings
+ {
+ get { return new[] { "CacheTest.EntityWithFilters.xml" }; }
+ }
+
+ [Test]
+ public void EqualityWithFilters()
+ {
+ QueryKey qk, qk1;
+ QueryKeyFilterDescLikeToCompare(out qk, out qk1);
+ Assert.That(qk, Is.EqualTo(qk1));
+
+ QueryKeyFilterDescValueToCompare(out qk, out qk1);
+ Assert.That(qk, Is.EqualTo(qk1));
+ }
+
+ private void QueryKeyFilterDescLikeToCompare(out QueryKey qk, out QueryKey qk1)
+ {
+ const string filterName = "DescriptionLike";
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pLike", "so%");
+ var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ ISet<FilterKey> fks = new HashedSet<FilterKey> { fk };
+ qk = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+
+ var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f1.SetParameter("pLike", "%ing");
+ var fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ fks = new HashedSet<FilterKey> { fk1 };
+ qk1 = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+ }
+
+ private void QueryKeyFilterDescValueToCompare(out QueryKey qk, out QueryKey qk1)
+ {
+ const string filterName = "DescriptionEqualAndValueGT";
+
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
+ var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ ISet<FilterKey> fks = new HashedSet<FilterKey> { fk };
+ qk = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+
+ var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f1.SetParameter("pDesc", "something").SetParameter("pValue", 11);
+ var fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ fks = new HashedSet<FilterKey> { fk1 };
+ qk1 = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+ }
+
+ [Test]
+ public void NotEqualityWithFilters()
+ {
+ QueryKey qk, qk1;
+ QueryKeyFilterDescLikeToCompare(out qk, out qk1);
+
+ QueryKey qvk, qvk1;
+ QueryKeyFilterDescValueToCompare(out qvk, out qvk1);
+
+ Assert.That(qk, Is.Not.EqualTo(qvk));
+ Assert.That(qk1, Is.Not.EqualTo(qvk1));
+ }
+
+ [Test]
+ public void HashCodeWithFilters()
+ {
+ QueryKey qk, qk1;
+ QueryKeyFilterDescLikeToCompare(out qk, out qk1);
+ Assert.That(qk.GetHashCode(), Is.EqualTo(qk1.GetHashCode()));
+
+ QueryKeyFilterDescValueToCompare(out qk, out qk1);
+ Assert.That(qk.GetHashCode(), Is.EqualTo(qk1.GetHashCode()));
+ }
+
+ [Test]
+ public void NotEqualHashCodeWithFilters()
+ {
+ QueryKey qk, qk1;
+ QueryKeyFilterDescLikeToCompare(out qk, out qk1);
+
+ QueryKey qvk, qvk1;
+ QueryKeyFilterDescValueToCompare(out qvk, out qvk1);
+
+ Assert.That(qk.GetHashCode(), Is.Not.EqualTo(qvk.GetHashCode()));
+ Assert.That(qk1.GetHashCode(), Is.Not.EqualTo(qvk1.GetHashCode()));
+ }
+
+ [Test]
+ public void ToStringWithFilters()
+ {
+ string filterName = "DescriptionLike";
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pLike", "so%");
+ var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ ISet<FilterKey> fks = new HashedSet<FilterKey> { fk };
+ var qk = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+ Assert.That(qk.ToString(), Text.Contains(string.Format("filters: ['{0}']",fk)));
+
+ filterName = "DescriptionEqualAndValueGT";
+ f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
+ fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+ fks = new HashedSet<FilterKey> { fk };
+ qk = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+ Assert.That(qk.ToString(), Text.Contains(string.Format("filters: ['{0}']", fk)));
+ }
+
+ [Test]
+ public void ToStringWithMoreFilters()
+ {
+ string filterName = "DescriptionLike";
+ var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ f.SetParameter("pLike", "so%");
+ var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+
+ filterName = "DescriptionEqualAndValueGT";
+ var fv = new FilterImpl(sessions.GetFilterDefinition(filterName));
+ fv.SetParameter("pDesc", "something").SetParameter("pValue", 10);
+ var fvk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
+
+ ISet<FilterKey> fks = new HashedSet<FilterKey> { fk, fvk };
+ var qk = new QueryKey(sessions, SqlAll, new QueryParameters(), (ISet)fks);
+ Assert.That(qk.ToString(), Text.Contains(string.Format("filters: ['{0}', '{1}']", fk, fvk)));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-30 03:49:14 UTC (rev 4391)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-31 16:39:08 UTC (rev 4392)
@@ -93,7 +93,10 @@
<Compile Include="Bytecode\Lightweight\BytecodeProviderFixture.cs" />
<Compile Include="Bytecode\WrongProxyFactoryFactory.cs" />
<Compile Include="CacheTest\CacheFixture.cs" />
+ <Compile Include="CacheTest\EntityWithFilters.cs" />
+ <Compile Include="CacheTest\FilterKeyFixture.cs" />
<Compile Include="CacheTest\QueryCacheFixture.cs" />
+ <Compile Include="CacheTest\QueryKeyFixture.cs" />
<Compile Include="CacheTest\TimestamperFixture.cs" />
<Compile Include="Cascade\Job.cs" />
<Compile Include="Cascade\JobBatch.cs" />
@@ -1833,6 +1836,7 @@
<EmbeddedResource Include="BulkManipulation\SimpleClass.hbm.xml" />
<EmbeddedResource Include="Ado\VerySimple.hbm.xml" />
<EmbeddedResource Include="Ado\AlmostSimple.hbm.xml" />
+ <EmbeddedResource Include="CacheTest\EntityWithFilters.xml" />
<Content Include="DynamicEntity\package.html" />
<EmbeddedResource Include="NHSpecificTest\NH1553\MsSQL\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1788\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|