|
From: <fab...@us...> - 2009-10-14 22:04:07
|
Revision: 4753
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4753&view=rev
Author: fabiomaulo
Date: 2009-10-14 22:03:56 +0000 (Wed, 14 Oct 2009)
Log Message:
-----------
Merge r4752 (fix NH-1931)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryNonScalarReturn.cs
trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryScalarReturn.cs
trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQuerySpecification.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryNonScalarReturnTest.cs
trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryScalarReturnTest.cs
trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQuerySpecificationTest.cs
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryNonScalarReturn.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryNonScalarReturn.cs 2009-10-14 22:02:56 UTC (rev 4752)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryNonScalarReturn.cs 2009-10-14 22:03:56 UTC (rev 4753)
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using NHibernate.Util;
using System.Collections.Generic;
@@ -51,5 +50,28 @@
{
get { return propertyResults; }
}
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as NativeSQLQueryNonScalarReturn);
+ }
+
+ public bool Equals(NativeSQLQueryNonScalarReturn other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Equals(other.alias, alias);
+ }
+
+ public override int GetHashCode()
+ {
+ return alias.GetHashCode();
+ }
}
}
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryScalarReturn.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryScalarReturn.cs 2009-10-14 22:02:56 UTC (rev 4752)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQueryScalarReturn.cs 2009-10-14 22:03:56 UTC (rev 4753)
@@ -28,5 +28,28 @@
{
get { return type; }
}
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as NativeSQLQueryScalarReturn);
+ }
+
+ public bool Equals(NativeSQLQueryScalarReturn other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Equals(other.columnAlias, columnAlias);
+ }
+
+ public override int GetHashCode()
+ {
+ return columnAlias.GetHashCode();
+ }
}
}
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQuerySpecification.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQuerySpecification.cs 2009-10-14 22:02:56 UTC (rev 4752)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/Sql/NativeSQLQuerySpecification.cs 2009-10-14 22:03:56 UTC (rev 4753)
@@ -38,7 +38,7 @@
hCode = 29 * hCode + CollectionHelper.GetHashCode(this.querySpaces);
if (this.sqlQueryReturns != null)
{
- hCode = 29 * hCode + sqlQueryReturns.Length;
+ hCode = 29 * hCode + CollectionHelper.GetHashCode(this.sqlQueryReturns);
}
}
@@ -65,16 +65,13 @@
if (this == obj)
return true;
- NativeSQLQuerySpecification that = obj as NativeSQLQuerySpecification;
+ var that = obj as NativeSQLQuerySpecification;
if (that == null)
return false;
- return hashCode == that.hashCode &&
- CollectionHelper.CollectionEquals(querySpaces, that.querySpaces) &&
- querySpaces.Equals(that.querySpaces) &&
- queryString.Equals(that.queryString) &&
- CollectionHelper.CollectionEquals<INativeSQLQueryReturn>(sqlQueryReturns, that.sqlQueryReturns);
+ // NHibernate different impl.: NativeSQLQuerySpecification is immutable and the hash is calculated at Ctor
+ return hashCode == that.hashCode;
}
public override int GetHashCode()
Added: trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryNonScalarReturnTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryNonScalarReturnTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryNonScalarReturnTest.cs 2009-10-14 22:03:56 UTC (rev 4753)
@@ -0,0 +1,57 @@
+using NHibernate.Engine.Query.Sql;
+using NUnit.Framework;
+
+namespace NHibernate.Test.EngineTest
+{
+ [TestFixture]
+ public class NativeSQLQueryNonScalarReturnTest
+ {
+ [Test]
+ public void NativeSQLQueryCollectionReturnEqualsByAlias()
+ {
+ var sr1 = new NativeSQLQueryCollectionReturn("myAlias", "owner", "ownerProp", null,LockMode.None);
+ var sr2 = new NativeSQLQueryCollectionReturn("myAlias", "owner", "ownerProp", null, LockMode.None);
+ Assert.AreEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void NativeSQLQueryCollectionReturnHashCodeByAlias()
+ {
+ var sr1 = new NativeSQLQueryCollectionReturn("myAlias", "owner", "ownerProp", null,LockMode.None);
+ var sr2 = new NativeSQLQueryCollectionReturn("myAlias", "owner", "ownerProp", null, LockMode.None);
+ Assert.AreEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+
+ [Test]
+ public void NativeSQLQueryJoinReturnEqualsByAlias()
+ {
+ var sr1 = new NativeSQLQueryJoinReturn("myAlias", "owner", "ownerProp", null, LockMode.None);
+ var sr2 = new NativeSQLQueryJoinReturn("myAlias", "owner", "ownerProp", null, LockMode.None);
+ Assert.AreEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void NativeSQLQueryJoinReturnHashCodeByAlias()
+ {
+ var sr1 = new NativeSQLQueryJoinReturn("myAlias", "owner", "ownerProp", null, LockMode.None);
+ var sr2 = new NativeSQLQueryJoinReturn("myAlias", "owner", "ownerProp", null, LockMode.None);
+ Assert.AreEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+
+ [Test]
+ public void NativeSQLQueryRootReturnEqualsByAlias()
+ {
+ var sr1 = new NativeSQLQueryRootReturn("myAlias", "entity", null, LockMode.None);
+ var sr2 = new NativeSQLQueryRootReturn("myAlias", "entity", null, LockMode.None);
+ Assert.AreEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void NativeSQLQueryRootReturnHashCodeByAlias()
+ {
+ var sr1 = new NativeSQLQueryRootReturn("myAlias", "entity", null, LockMode.None);
+ var sr2 = new NativeSQLQueryRootReturn("myAlias", "entity", null, LockMode.None);
+ Assert.AreEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryScalarReturnTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryScalarReturnTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQueryScalarReturnTest.cs 2009-10-14 22:03:56 UTC (rev 4753)
@@ -0,0 +1,25 @@
+using NHibernate.Engine.Query.Sql;
+using NUnit.Framework;
+
+namespace NHibernate.Test.EngineTest
+{
+ [TestFixture]
+ public class NativeSQLQueryScalarReturnTest
+ {
+ [Test]
+ public void EqualsByAlias()
+ {
+ var sr1 = new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32);
+ var sr2 = new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32);
+ Assert.AreEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void HashCodeByAlias()
+ {
+ var sr1 = new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32);
+ var sr2 = new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32);
+ Assert.AreEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQuerySpecificationTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQuerySpecificationTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/EngineTest/NativeSQLQuerySpecificationTest.cs 2009-10-14 22:03:56 UTC (rev 4753)
@@ -0,0 +1,59 @@
+using NHibernate.Engine.Query.Sql;
+using NUnit.Framework;
+using System.Collections.Generic;
+
+namespace NHibernate.Test.EngineTest
+{
+ [TestFixture]
+ public class NativeSQLQuerySpecificationTest
+ {
+ [Test]
+ public void Equality()
+ {
+ var sr1 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ var sr2 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ Assert.AreEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void HashCode()
+ {
+ var sr1 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ var sr2 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ Assert.AreEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+
+ [Test]
+ public void WhenChangeReturns_NotEqual()
+ {
+ var sr1 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ var sr2 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAliasChanged", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ Assert.AreNotEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void WhenChangeReturns_NotEqualHashCode()
+ {
+ var sr1 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ var sr2 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAliasChanged", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ Assert.AreNotEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+
+ [Test]
+ public void WhenChangeSpace_NotEqual()
+ {
+ var sr1 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ var sr2 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "ANOTHER" });
+ Assert.AreNotEqual(sr1, sr2);
+ }
+
+ [Test]
+ public void WhenChangeSpace_NotEqualHashCode()
+ {
+ var sr1 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "SOMETHING" });
+ var sr2 = new NativeSQLQuerySpecification("SELECT * FROM SOMETHING", new INativeSQLQueryReturn[] { new NativeSQLQueryScalarReturn("myAlias", NHibernateUtil.Int32), new NativeSQLQueryScalarReturn("otherAlias", NHibernateUtil.Int32) }, new List<string> { "ANOTHER" });
+ Assert.AreNotEqual(sr1.GetHashCode(), sr2.GetHashCode());
+ }
+
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-14 22:02:56 UTC (rev 4752)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-14 22:03:56 UTC (rev 4753)
@@ -161,6 +161,9 @@
<Compile Include="Criteria\Reptile.cs" />
<Compile Include="DriverTest\SqlClientDriverFixture.cs" />
<Compile Include="DriverTest\SqlServerCeDriverFixture.cs" />
+ <Compile Include="EngineTest\NativeSQLQueryNonScalarReturnTest.cs" />
+ <Compile Include="EngineTest\NativeSQLQueryScalarReturnTest.cs" />
+ <Compile Include="EngineTest\NativeSQLQuerySpecificationTest.cs" />
<Compile Include="ExpressionTest\RestrictionsFixture.cs" />
<Compile Include="Criteria\Student.cs" />
<Compile Include="Criteria\StudentDTO.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|