|
From: <fab...@us...> - 2009-03-01 14:23:33
|
Revision: 4102
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4102&view=rev
Author: fabiomaulo
Date: 2009-03-01 14:23:27 +0000 (Sun, 01 Mar 2009)
Log Message:
-----------
Fix NH-1691
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Domain.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2009-02-28 19:42:24 UTC (rev 4101)
+++ trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2009-03-01 14:23:27 UTC (rev 4102)
@@ -1446,7 +1446,7 @@
if (type.IsComponentType)
{
- // NH-1612: Recursively add column aliases for nested components to support the selection
+ // NH-1612+NH-1691: Recursively add column aliases for nested components to support the selection
// of individual component properties in native SQL queries. This also seems to provide
// a more complete solution to HHH-1019 (http://opensource.atlassian.com/projects/hibernate/browse/HHH-1019)
// because it works for <load-collection> and <return-join>.
@@ -1458,10 +1458,10 @@
{
string name = propertyNames[propertyIndex];
IType propertyType = ct.Subtypes[propertyIndex];
- int propertyColSpan = propertyType.IsComponentType
- ? ((IAbstractComponentType) propertyType).PropertyNames.Length
- : 1;
+ int propertyColSpan = 0;
+ CalcPropertyColumnSpan(propertyType, ref propertyColSpan);
+
var propertyColumnAliases = new string[propertyColSpan];
var propertyColumnNames = new string[propertyColSpan];
System.Array.Copy(columnAliases, columnIndex, propertyColumnAliases, 0, propertyColSpan);
@@ -1473,6 +1473,22 @@
}
}
+ private static void CalcPropertyColumnSpan(IType propertyType, ref int count)
+ {
+ if (!propertyType.IsComponentType)
+ {
+ count++;
+ }
+ else
+ {
+ var componentType = (IAbstractComponentType) propertyType;
+ foreach (var subtype in componentType.Subtypes)
+ {
+ CalcPropertyColumnSpan(subtype, ref count);
+ }
+ }
+ }
+
public int GetSize(object key, ISessionImplementor session)
{
try
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Domain.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Domain.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Domain.cs 2009-03-01 14:23:27 UTC (rev 4102)
@@ -0,0 +1,35 @@
+using System.Collections;
+
+namespace NHibernate.Test.NHSpecificTest.NH1691
+{
+ public class SubComponent
+ {
+ public string SubName { get; set; }
+ public string SubName1 { get; set; }
+ public SubComponent Nested { get; set; }
+ }
+
+ public class Component
+ {
+ public string Name { get; set; }
+ public SubComponent SubComponent { get; set; }
+ }
+
+ public class DeepComponent
+ {
+ public string Prop1 { get; set; }
+ public string Prop2 { get; set; }
+ public string Prop3 { get; set; }
+ public string Prop4 { get; set; }
+ public Component Component { get; set; }
+ }
+
+ public class Nest
+ {
+ public virtual Component Component { get; set; }
+ public virtual int Id { get; set; }
+ public string Name { get; set; }
+ public virtual IList Components { get; set; }
+ public virtual IList ComplexComponents { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Fixture.cs 2009-03-01 14:23:27 UTC (rev 4102)
@@ -0,0 +1,115 @@
+using System.Collections;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1691
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ private static Component GetInitializedComponent()
+ {
+ var component = new Component();
+ var sub1 = new SubComponent();
+ var sub2 = new SubComponent();
+ component.Name = "Comp1";
+ sub1.SubName = "Sub1";
+ sub1.SubName1 = "Sub1x";
+
+ sub2.SubName = "Sub2";
+ sub2.SubName1 = "Sub2x";
+
+ sub1.Nested = sub2;
+
+ component.SubComponent = sub1;
+ return component;
+ }
+
+ [Test]
+ public void ComplexNest()
+ {
+ Component comp1 = GetInitializedComponent();
+ var nest = new Nest {Name = "NAME", Components = new ArrayList {comp1}};
+ var deep1 = new DeepComponent {Prop1 = "PROP1", Prop2 = "PROP2", Prop3 = "PROP3", Prop4 = "PROP4"};
+ Component innerComp = GetInitializedComponent();
+ deep1.Component = innerComp;
+ Component innerComp2 = GetInitializedComponent();
+ var deep2 = new DeepComponent
+ {Prop1 = "PROP1", Prop2 = "PROP2", Prop3 = "PROP3", Prop4 = "PROP4", Component = innerComp2};
+
+ nest.ComplexComponents = new ArrayList {deep1, deep2};
+
+ object nestId;
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
+ session.Save(nest);
+ transaction.Commit();
+ nestId = nest.Id;
+ }
+ }
+
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
+ var loadedNest = session.Load<Nest>(nestId);
+ transaction.Commit();
+
+ Assert.AreEqual(2, loadedNest.ComplexComponents.Count);
+ Assert.IsNotNull(((DeepComponent) loadedNest.ComplexComponents[0]).Component.SubComponent.Nested.SubName1);
+ Assert.IsNull(((DeepComponent) loadedNest.ComplexComponents[0]).Component.SubComponent.SubName1);
+ }
+ }
+
+ using (ISession s = OpenSession())
+ {
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Delete("from Nest");
+ t.Commit();
+ }
+ }
+ }
+
+ [Test]
+ public void NestedComponentCollection()
+ {
+ var nest = new Nest {Name = "NAME"};
+ Component comp1 = GetInitializedComponent();
+
+ nest.Components = new ArrayList {comp1};
+
+ object nestId;
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
+ session.Save(nest);
+ transaction.Commit();
+ nestId = nest.Id;
+ }
+ }
+
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
+ var nest2 = session.Load<Nest>(nestId);
+ transaction.Commit();
+
+ Assert.IsNotNull(((Component) nest2.Components[0]).SubComponent.Nested.SubName);
+ }
+ }
+
+ using (ISession s = OpenSession())
+ {
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Delete("from Nest");
+ t.Commit();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Fixture.cs
___________________________________________________________________
Added: svn:mergeinfo
+
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1691/Mappings.hbm.xml 2009-03-01 14:23:27 UTC (rev 4102)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1691"
+ assembly="NHibernate.Test"
+ default-lazy="false">
+ <class name="Nest">
+ <id name="Id">
+ <generator class="native"/>
+ </id>
+
+ <bag name="Components"
+ access="property"
+ table="Nest_Components"
+ cascade="all-delete-orphan"
+ lazy="false">
+ <key column="NestId"/>
+ <composite-element class="Component">
+ <property name="Name" column="Component_Name" />
+ <nested-composite-element name="SubComponent" access="property" class="SubComponent">
+ <property name="SubName" column="Component_SubComponent_SubName" />
+ <property name="SubName1" column="Component_SubComponent_SubName1" />
+ <nested-composite-element name="Nested" access="property" class="SubComponent">
+ <property name="SubName" column="Component_SubComponent_Nested_SubName" />
+ <property name="SubName1" column="Component_SubComponent_Nested_SubName1" />
+ </nested-composite-element>
+ </nested-composite-element>
+ </composite-element>
+ </bag>
+
+ <bag name="ComplexComponents"
+ access="property"
+ table="Nest_DeepComponents"
+ cascade="all-delete-orphan"
+ lazy="false">
+ <key column="NestId"/>
+ <composite-element class="DeepComponent">
+ <property name="Prop1" column="DeepComponent_Prop1" />
+ <property name="Prop2" column="DeepComponent_Prop2" />
+ <property name="Prop3" column="DeepComponent_Prop3" />
+ <property name="Prop4" column="DeepComponent_Prop4" />
+ <nested-composite-element name="Component" class="Component">
+ <property name="Name" column="Component_Name" />
+ <nested-composite-element name="SubComponent" access="property" class="SubComponent">
+ <property name="SubName" column="Component_SubComponent_SubName" />
+ <nested-composite-element name="Nested" access="property" class="SubComponent">
+ <property name="SubName" column="Component_SubComponent_Nested_SubName" />
+ <property name="SubName1" column="Component_SubComponent_Nested_SubName1" />
+ </nested-composite-element>
+ </nested-composite-element>
+ </nested-composite-element>
+
+ </composite-element>
+ </bag>
+
+ </class>
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-28 19:42:24 UTC (rev 4101)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-01 14:23:27 UTC (rev 4102)
@@ -634,6 +634,8 @@
<Compile Include="NHSpecificTest\NH1679\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1689\DomainClass.cs" />
<Compile Include="NHSpecificTest\NH1689\SampleTest.cs" />
+ <Compile Include="NHSpecificTest\NH1691\Domain.cs" />
+ <Compile Include="NHSpecificTest\NH1691\Fixture.cs" />
<Compile Include="NHSpecificTest\NH280\Fixture.cs" />
<Compile Include="NHSpecificTest\NH280\Foo.cs" />
<Compile Include="NHSpecificTest\NH1018\Employee.cs" />
@@ -1668,6 +1670,7 @@
<EmbeddedResource Include="Cascade\JobBatch.hbm.xml" />
<EmbeddedResource Include="Deletetransient\Person.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1691\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1689\Mappings.hbm.xml" />
<EmbeddedResource Include="VersionTest\Db\MsSQL\SimpleVersioned.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1675\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|