From: <fab...@us...> - 2011-03-26 16:27:46
|
Revision: 5541 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5541&view=rev Author: fabiomaulo Date: 2011-03-26 16:27:40 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Test for NH-2602 (fixed) Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Subselect/ trunk/nhibernate/src/NHibernate.Test/Subselect/Beings.hbm.xml trunk/nhibernate/src/NHibernate.Test/Subselect/ClassSubselectFixture.cs trunk/nhibernate/src/NHibernate.Test/Subselect/Domain.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-26 16:01:36 UTC (rev 5540) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-26 16:27:40 UTC (rev 5541) @@ -695,6 +695,8 @@ <Compile Include="ReadOnly\StudentDto.cs" /> <Compile Include="ReadOnly\TextHolder.cs" /> <Compile Include="ReadOnly\VersionedNode.cs" /> + <Compile Include="Subselect\ClassSubselectFixture.cs" /> + <Compile Include="Subselect\Domain.cs" /> <Compile Include="TestDialect.cs" /> <Compile Include="TestDialects\SQLiteTestDialect.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -2494,6 +2496,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="Subselect\Beings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2488\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2490\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1925\Mappings.hbm.xml" /> Added: trunk/nhibernate/src/NHibernate.Test/Subselect/Beings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Subselect/Beings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Subselect/Beings.hbm.xml 2011-03-26 16:27:40 UTC (rev 5541) @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- + + This mapping demonstrates + + (1) use of a class-to-subselect mapping, that allows data + defined in other classes to be exposed as a read-only + entity (you would do this if you really wanted a view, + but didn't or couldn't define one for some reason) + This is a "derived entity" mapping. + + (2) use of <synchronize/> to ensure that auto-flush happens + correctly, and that queries against the derived entity + do not return stale data + +--> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.Subselect" + assembly="NHibernate.Test"> + + <class name="Human" table="Humans"> + <id name="Id" column="bid"> + <generator class="hilo"/> + </id> + + <property name="Name" not-null="true"/> + <property name="Sex" not-null="true" update="false"/> + <property name="Address"/> + </class> + + <class name="Alien" table="Aliens"> + <id name="Id" column="bid"> + <generator class="hilo"/> + </id> + <property name="Identity" not-null="true" column="ident"/> + <property name="Planet"/> + <property name="Species" not-null="true" update="false"/> + + </class> + + <class name="Being" mutable="false"> + <subselect> + select bid, name as ident, address as loc, 'human' as species + from humans + union + select bid, ident, planet as loc, species + from aliens + </subselect> + + <synchronize table="Humans"/> + <synchronize table="Aliens"/> + + <id name="Id" column="bid"> + <generator class="native"/> + </id> + + <property name="Identity" column="ident"/> + <property name="Location" column="loc"/> + <property name="Species"/> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Subselect/ClassSubselectFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Subselect/ClassSubselectFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Subselect/ClassSubselectFixture.cs 2011-03-26 16:27:40 UTC (rev 5541) @@ -0,0 +1,62 @@ +using System.Collections; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.Subselect +{ + public class ClassSubselectFixture: TestCase + { + protected override IList Mappings + { + get { return new[] {"Subselect.Beings.hbm.xml"}; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + [Test] + public void EntitySubselect() + { + var s = OpenSession(); + var t = s.BeginTransaction(); + Human gavin = new Human(); + gavin.Name = "gavin"; + gavin.Sex = 'M'; + gavin.Address = "Melbourne, Australia"; + Alien x23y4 = new Alien(); + x23y4.Identity = "x23y4$$hu%3"; + x23y4.Planet = "Mars"; + x23y4.Species = "martian"; + s.Save(gavin); + s.Save(x23y4); + s.Flush(); + var beings = s.CreateQuery("from Being").List<Being>(); + beings.Should().Have.Count.GreaterThan(0); + foreach (var being in beings) + { + being.Location.Should().Not.Be.NullOrEmpty(); + being.Identity.Should().Not.Be.NullOrEmpty(); + being.Species.Should().Not.Be.NullOrEmpty(); + } + s.Clear(); + Sfi.Evict(typeof (Being)); + Being gav = s.Get<Being>(gavin.Id); + gav.Location.Should().Not.Be.NullOrEmpty(); + gav.Identity.Should().Not.Be.NullOrEmpty(); + gav.Species.Should().Not.Be.NullOrEmpty(); + s.Clear(); + //test the <synchronized> tag: + gavin = s.Get<Human>(gavin.Id); + gavin.Address = "Atlanta, GA"; + gav = s.CreateQuery("from Being b where b.Location like '%GA%'").UniqueResult<Being>(); + gav.Location.Should().Be(gavin.Address); + s.Delete(gavin); + s.Delete(x23y4); + s.CreateQuery("from Being").List<Being>().Should().Be.Empty(); + t.Commit(); + s.Close(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Subselect/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Subselect/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Subselect/Domain.cs 2011-03-26 16:27:40 UTC (rev 5541) @@ -0,0 +1,26 @@ +namespace NHibernate.Test.Subselect +{ + public class Human + { + public virtual int Id { get; set; } + public virtual char Sex { get; set; } + public virtual string Name { get; set; } + public virtual string Address { get; set; } + } + + public class Alien + { + public virtual int Id { get; set; } + public virtual string Identity { get; set; } + public virtual string Planet { get; set; } + public virtual string Species { get; set; } + } + + public class Being + { + public virtual int Id { get; set; } + public virtual string Identity { get; set; } + public virtual string Location { get; set; } + public virtual string Species { get; set; } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |