Permalink
Browse files

Back ported fix for NH-901 to 1.2.x branch

SVN: branches/1.2.x@3082
  • Loading branch information...
1 parent ac8968b commit b1f1f7bc5168db917dc6b5f15148b32294dc4628 Karl Chu committed Nov 5, 2007
@@ -0,0 +1,114 @@
+using NUnit.Framework;
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NHibernate.Test.NHSpecificTest.NH901
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ public override string BugNumber
+ {
+ get { return "NH901"; }
+ }
+
+ private ISession OpenSession(IInterceptor interceptor)
+ {
+ lastOpenedSession = sessions.OpenSession(interceptor);
+ return lastOpenedSession;
+ }
+
+ protected override void OnTearDown()
+ {
+ base.OnTearDown();
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Delete("from Person");
+ tx.Commit();
+ }
+ }
+
+ [Test]
+ public void EmptyValueTypeComponent()
+ {
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ Person p = new Person("Jimmy Hendrix");
+ s.Save(p);
+ tx.Commit();
+ }
+
+ InterceptorStub interceptor = new InterceptorStub();
+ using (ISession s = OpenSession(interceptor))
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ Person jimmy = s.Get<Person>("Jimmy Hendrix");
+ interceptor.entityToCheck = jimmy;
+ tx.Commit();
+ }
+ Assert.IsFalse(interceptor.entityWasDeemedDirty);
+
+ InterceptorStub interceptor2 = new InterceptorStub();
+ using (ISession s = OpenSession(interceptor2))
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ Person jimmy = s.Get<Person>("Jimmy Hendrix");
+ jimmy.Address = new Address();
+ interceptor.entityToCheck = jimmy;
+ tx.Commit();
+ }
+ Assert.IsFalse(interceptor2.entityWasDeemedDirty);
+ }
+
+ [Test]
+ public void ReplaceValueTypeComponentWithSameValueDoesNotMakeItDirty()
+ {
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ Person p = new Person("Jimmy Hendrix");
+ Address a = new Address();
+ a.Street = "Some Street";
+ a.City = "Some City";
+ p.Address = a;
+
+ s.Save(p);
+ tx.Commit();
+ }
+
+ InterceptorStub interceptor = new InterceptorStub();
+ using (ISession s = OpenSession(interceptor))
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ Person jimmy = s.Get<Person>("Jimmy Hendrix");
+ interceptor.entityToCheck = jimmy;
+
+ Address a = new Address();
+ a.Street = "Some Street";
+ a.City = "Some City";
+ jimmy.Address = a;
+ Assert.AreNotSame(jimmy.Address, a);
+
+ tx.Commit();
+ }
+ Assert.IsFalse(interceptor.entityWasDeemedDirty);
+ }
+ }
+
+ public class InterceptorStub : EmptyInterceptor
+ {
+ public object entityToCheck;
+ public bool entityWasDeemedDirty = false;
+
+ public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
+ {
+ if (entity == entityToCheck) { entityWasDeemedDirty = true; }
+
+ return false;
+ }
+ }
+}
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH901"
+ assembly="NHibernate.Test"
+>
+ <class name="Person" table="NH901_Person">
+ <id name="Name">
+ <generator class="assigned"/>
+ </id>
+
+ <component name="Address">
+ <property name="Street"/>
+ <property name="City"/>
+ </component>
+ </class>
+</hibernate-mapping>
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NHibernate.Test.NHSpecificTest.NH901
+{
+ public class Person
+ {
+ protected Person() { }
+
+ public Person(string name) { this._Name = name; }
+
+ private string _Name;
+ public virtual string Name
+ {
+ get { return _Name; }
+ set { _Name = value; }
+ }
+
+ private Address _Address;
+ public virtual Address Address
+ {
+ get { return _Address; }
+ set { _Address = value; }
+ }
+ }
+
+ public struct Address
+ {
+ private string _Street;
+ public string Street
+ {
+ get { return _Street; }
+ set { _Street = value; }
+ }
+
+ private string _City;
+ public string City
+ {
+ get { return _City; }
+ set { _City = value; }
+ }
+ }
+}
@@ -410,6 +410,8 @@
<Compile Include="NHSpecificTest\NH898\ClassBParent.cs" />
<Compile Include="NHSpecificTest\NH898\ClassC.cs" />
<Compile Include="NHSpecificTest\NH898\NH898Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH901\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH901\Model.cs" />
<Compile Include="NHSpecificTest\NH930\NH930Fixture.cs" />
<Compile Include="NHSpecificTest\NH930\Model.cs" />
<Compile Include="NHSpecificTest\NH940\A.cs" />
@@ -927,6 +929,9 @@
<EmbeddedResource Include="NHSpecificTest\NH1061\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="NHSpecificTest\NH901\Mappings.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
@@ -25,7 +25,7 @@ public abstract class TestCase
private static readonly ILog log = LogManager.GetLogger(typeof(TestCase));
protected static readonly Dialect.Dialect Dialect = NHibernate.Dialect.Dialect.GetDialect();
- private ISession lastOpenedSession;
+ protected ISession lastOpenedSession;
private DebugConnectionProvider connectionProvider;
/// <summary>
@@ -688,8 +688,11 @@ public override object Hydrate(IDataReader rs, string[] names, ISessionImplement
values[i] = val;
begin += length;
}
-
- return notNull ? values : null;
+
+ if (this.componentClass.IsValueType)
+ return values;
+ else
+ return notNull ? values : null;
}
public override object ResolveIdentifier(object value, ISessionImplementor session, object owner)

0 comments on commit b1f1f7b

Please sign in to comment.