You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2005/10/12 20:26:11 UTC

svn commit: r314989 - in /ibatis/trunk/cs/mapper: IBatisNet.Common/Utilities/Objects/ IBatisNet.DataMapper.Test/ IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ IBatisNet.DataMapper/ IBatisNet.DataMapper/TypeHandlers/

Author: gbayon
Date: Wed Oct 12 11:25:56 2005
New Revision: 314989

URL: http://svn.apache.org/viewcvs?rev=314989&view=rev
Log:
- Fixed IBATISNET-118 CacheKey.Equals(object) override can return true when the parameters have the same HashCode but are not equal

Added:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/CacheKey.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs?rev=314989&r1=314988&r2=314989&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs Wed Oct 12 11:25:56 2005
@@ -680,6 +680,7 @@
 					if (IsSimpleType(value.GetType())) 
 					{
 						hashcode += value.GetHashCode();
+						hashcode += value.ToString().GetHashCode();
 					} 
 					else 
 					{

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?rev=314989&r1=314988&r2=314989&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj Wed Oct 12 11:25:56 2005
@@ -697,6 +697,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "NUnit\SqlMapTests\CacheKeyTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "NUnit\SqlMapTests\CacheTest.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs?rev=314989&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs Wed Oct 12 11:25:56 2005
@@ -0,0 +1,46 @@
+using IBatisNet.DataMapper;
+using IBatisNet.DataMapper.TypeHandlers;
+using NUnit.Framework;
+
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests
+{
+	/// <summary>
+	/// Summary description for CacheKeyTest.
+	/// </summary>
+	[TestFixture]
+	public class CacheKeyTest
+	{
+		private const long A_LONG = 1L;
+		private const long ANOTHER_LONG_WITH_SAME_HASHCODE = -9223372034707292159;
+
+		[Test]
+		public void ShouldNotBeConsideredEqualWhenParametersHaveTheSameHashCodeButAreNotEqual()
+		{
+			TypeHandlerFactory factory = new TypeHandlerFactory();
+
+			// Two cache keys are equal except for the parameter.
+			CacheKey key = new CacheKey(factory, "STATEMENT", "SQL", new TestClass(A_LONG), new string[] {"AProperty"}, 0, 0, CacheKeyType.Object);
+			CacheKey aDifferentKey = new CacheKey(factory, "STATEMENT", "SQL", new TestClass(ANOTHER_LONG_WITH_SAME_HASHCODE), new string[] {"AProperty"}, 0, 0, CacheKeyType.Object);
+
+			Assert.IsFalse(aDifferentKey.Equals(key)); // should not be equal.
+		}
+
+		private class TestClass
+		{
+			private long _property = long.MinValue;
+
+			public TestClass(long aProperty)
+			{
+				_property = aProperty;
+			}
+
+			public long AProperty
+			{
+				get { return _property; }
+				set { _property = value; }
+			}
+		}
+
+	}
+}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/CacheKey.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/CacheKey.cs?rev=314989&r1=314988&r2=314989&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/CacheKey.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/CacheKey.cs Wed Oct 12 11:25:56 2005
@@ -40,7 +40,7 @@
 	/// Summary description for FlushInterval.
 	/// </summary>
 	[Serializable]
-	internal class CacheKey
+	public class CacheKey
 	{
 		#region Fields
 		private string[] _properties = null;
@@ -67,7 +67,7 @@
 		/// <param name="maxResults"></param>
 		/// <param name="type"></param>
 		/// <param name="typeHandlerFactory"></param>
-		internal CacheKey(TypeHandlerFactory typeHandlerFactory, string statementName, string sql, object parameter, string[] properties, 
+		public CacheKey(TypeHandlerFactory typeHandlerFactory, string statementName, string sql, object parameter, string[] properties, 
 			int skipRecords, int maxResults, CacheKeyType type)
 		{
 			_typeHandlerFactory = typeHandlerFactory;
@@ -81,10 +81,6 @@
 			_hashCode = GenerateHashCode();
 			_hashCodeString = Convert.ToString(_hashCode);
 		}
-
-
-		// name.GetHashCode() ^  age.GetHashCode(); 
-		// hash algorithms 
 
 
 		/// <summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs?rev=314989&r1=314988&r2=314989&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs Wed Oct 12 11:25:56 2005
@@ -36,7 +36,7 @@
 	/// <summary>
 	/// Not much of a suprise, this is a factory class for TypeHandler objects.
 	/// </summary>
-	internal class TypeHandlerFactory
+	public class TypeHandlerFactory
 	{
 
 		#region Fields