User: xtoff
Date: 2010/01/09 09:07 AM

Added:
 /ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/Model/
  ClassWithIndexOnHasMany.cs

Modified:
 /ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/
  Castle.ActiveRecord.Framework.Internal.Tests-vs2008.csproj, 
XmlGenerationTestCase.cs
 /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
  Castle.ActiveRecord.Tests-vs2008.csproj
 /ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
  BelongsToAttribute.cs
 /ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/
  XmlGenerationVisitor.cs

Log:
 - fixed AR-ISSUE-202 - "BelongsToAttribute lacks the possibility to specify an 
index" with patch from Jan Persson (+ test)

File Changes:

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
==================================================================

File [modified]: BelongsToAttribute.cs
Delta lines: +10 -8
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs
      2010-01-09 14:50:47 UTC (rev 6608)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs
      2010-01-09 16:07:28 UTC (rev 6609)
@@ -29,7 +29,7 @@
        /// </summary>
        public class XmlGenerationVisitor : AbstractDepthFirstVisitor
        {
-               private StringBuilder xmlBuilder = new StringBuilder();
+               private readonly StringBuilder xmlBuilder = new StringBuilder();
                private int identLevel = 0;
                private String currentTable;
 
@@ -606,19 +606,20 @@
 
                        if (model.BelongsToAtt.Column == null)
                        {
-                               
AppendF("<many-to-one{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}>",
+                               
AppendF("<many-to-one{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}>",
                                        MakeAtt("name", model.Property.Name),
                                        MakeAtt("access", 
model.BelongsToAtt.AccessString),
                                        MakeAtt("class", 
MakeTypeName(model.BelongsToAtt.Type)),
                                        WriteIfTrue("not-null", 
model.BelongsToAtt.NotNull),
                                        WriteIfTrue("unique", 
model.BelongsToAtt.Unique),
                                        WriteIfNonNull("unique-key", 
model.BelongsToAtt.UniqueKey),
+                                       WriteIfNonNull("index", 
model.BelongsToAtt.Index),
                                        WriteIfNonNull("cascade", cascade),
                                        WriteIfNonNull("fetch", fetch),
-                                               WriteIfNonNull("lazy", lazy),
+                                       WriteIfNonNull("lazy", lazy),
                                        WriteIfFalse("update", 
model.BelongsToAtt.Update),
                                        WriteIfFalse("insert", 
model.BelongsToAtt.Insert),
-                                               WriteIfNonNull("property-ref", 
model.BelongsToAtt.PropertyRef),
+                                       WriteIfNonNull("property-ref", 
model.BelongsToAtt.PropertyRef),
                                        WriteIfNonNull("foreign-key", 
model.BelongsToAtt.ForeignKey),
                                        WriteIfNonNull("not-found", 
notFoundMode));
                                Ident();
@@ -628,22 +629,23 @@
                        }
                        else
                        {
-                               
AppendF("<many-to-one{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14} />",
+                               
AppendF("<many-to-one{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15} />",
                                        MakeAtt("name", model.Property.Name),
                                        MakeAtt("access", 
model.BelongsToAtt.AccessString),
                                        MakeAtt("class", 
MakeTypeName(model.BelongsToAtt.Type)),
                                        MakeAtt("column", 
model.BelongsToAtt.Column),
                                        WriteIfFalse("insert", 
model.BelongsToAtt.Insert),
                                        WriteIfFalse("update", 
model.BelongsToAtt.Update),
-                                               WriteIfNonNull("property-ref", 
model.BelongsToAtt.PropertyRef),
+                                       WriteIfNonNull("property-ref", 
model.BelongsToAtt.PropertyRef),
                                        WriteIfTrue("not-null", 
model.BelongsToAtt.NotNull),
                                        WriteIfTrue("unique", 
model.BelongsToAtt.Unique),
                                        WriteIfNonNull("unique-key", 
model.BelongsToAtt.UniqueKey),
                                        WriteIfNonNull("foreign-key", 
model.BelongsToAtt.ForeignKey),
+                                       WriteIfNonNull("index", 
model.BelongsToAtt.Index),
                                        WriteIfNonNull("cascade", cascade),
                                        WriteIfNonNull("fetch", fetch),
-                                               WriteIfNonNull("lazy", lazy),
-                                               WriteIfNonNull("not-found", 
notFoundMode));
+                                       WriteIfNonNull("lazy", lazy),
+                                       WriteIfNonNull("not-found", 
notFoundMode));
                        }
                }

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/
================================================================================

File [modified]: Castle.ActiveRecord.Framework.Internal.Tests-vs2008.csproj
Delta lines: +31 -0
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/Model/ClassWithIndexOnHasMany.cs
                                (rev 0)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/Model/ClassWithIndexOnHasMany.cs
        2010-01-09 16:07:28 UTC (rev 6609)
@@ -0,0 +1,31 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.ActiveRecord.Framework.Internal.Tests.Model
+{
+       using System.Collections.Generic;
+
+       [ActiveRecord]
+       public class ClassWithIndexOnHasMany : ActiveRecordBase
+       {
+               [PrimaryKey]
+               public int Id { get; set; }
+
+               [BelongsTo("Parent_Id",Index = "parent_child_index")]
+               public ClassWithIndexOnHasMany Parent { get; set; }
+
+               [HasMany]
+               public IList<ClassWithIndexOnHasMany> Children { get; set; }
+       }
+}

File [modified]: XmlGenerationTestCase.cs
Delta lines: +4 -0
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
    2010-01-09 14:50:47 UTC (rev 6608)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
    2010-01-09 16:07:28 UTC (rev 6609)
@@ -105,6 +105,10 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\..\lib\net-3.5\Castle.DynamicProxy2.dll</HintPath>
     </Reference>
+    <Reference Include="HibernatingRhinos.Profiler.Appender, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=0774796e73ebf640, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>D:\dev\nh\HibernatingRhinos.Profiler.Appender.dll</HintPath>
+    </Reference>
     <Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, 
PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
=============================================================

File [modified]: Castle.ActiveRecord.Tests-vs2008.csproj
Delta lines: +0 -0
===================================================================

Directory: 
/ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/Model/
======================================================================================

File [added]: ClassWithIndexOnHasMany.cs
Delta lines: +34 -0
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/XmlGenerationTestCase.cs
        2010-01-09 14:50:47 UTC (rev 6608)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/XmlGenerationTestCase.cs
        2010-01-09 16:07:28 UTC (rev 6609)
@@ -1528,5 +1528,39 @@
 
                        Assert.AreEqual(expected, xml);
                }
+
+               [Test]
+               public void SimpleCaseIndexOnHasMany()
+               {
+                       ActiveRecordModelBuilder builder = new 
ActiveRecordModelBuilder();
+                       ActiveRecordModel model = 
builder.Create(typeof(ClassWithIndexOnHasMany));
+                       Assert.IsNotNull(model);
+
+                       SemanticVerifierVisitor semanticVisitor = new 
SemanticVerifierVisitor(builder.Models);
+                       semanticVisitor.VisitNode(model);
+
+                       XmlGenerationVisitor xmlVisitor = new 
XmlGenerationVisitor();
+                       xmlVisitor.CreateXml(model);
+
+                       String xml = xmlVisitor.Xml;
+
+                       const string expected =
+                               "<?xml version=\"1.0\" 
encoding=\"utf-16\"?>\r\n" +
+                               "<hibernate-mapping  auto-import=\"true\" 
default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"; 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"; 
xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" +
+                               "  <class 
name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithIndexOnHasMany,
 Castle.ActiveRecord.Framework.Internal.Tests\" 
table=\"ClassWithIndexOnHasMany\">\r\n" +
+                               "    <id name=\"Id\" access=\"property\" 
column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
+                               "      <generator class=\"native\">\r\n" +
+                               "      </generator>\r\n" +
+                               "    </id>\r\n" +
+                               "    <many-to-one name=\"Parent\" 
access=\"property\" 
class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithIndexOnHasMany,
 Castle.ActiveRecord.Framework.Internal.Tests\" column=\"Parent_Id\" 
index=\"parent_child_index\" lazy=\"proxy\" />\r\n" +
+                               "    <bag name=\"Children\" access=\"property\" 
table=\"ClassWithIndexOnHasMany\" lazy=\"false\">\r\n" +
+                               "      <key column=\"Parent_Id\" />\r\n" +
+                               "      <one-to-many 
class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithIndexOnHasMany,
 Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
+                               "    </bag>\r\n" +
+                               "  </class>\r\n" +
+                               "</hibernate-mapping>\r\n";
+
+                       Assert.AreEqual(expected, xml);
+               }
        }

Directory: 
/ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/
===================================================================================

File [modified]: XmlGenerationVisitor.cs
Delta lines: +1 -0
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/Castle.ActiveRecord.Framework.Internal.Tests-vs2008.csproj
      2010-01-09 14:50:47 UTC (rev 6608)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord.Framework.Internal.Tests/Castle.ActiveRecord.Framework.Internal.Tests-vs2008.csproj
      2010-01-09 16:07:28 UTC (rev 6609)
@@ -165,6 +165,7 @@
     </Compile>
     <Compile Include="Model\ClassWithAnyAttribute.cs" />
     <Compile Include="Model\ClassWithCompositeKey.cs" />
+    <Compile Include="Model\ClassWithIndexOnHasMany.cs" />
     <Compile Include="Model\ClassWithMultiplePrimaryKeys.cs" />
     <Compile Include="Model\ClassWithOverride.cs" />

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-commits?hl=en.


Reply via email to