|
From: <fab...@us...> - 2009-06-03 06:15:31
|
Revision: 4404
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4404&view=rev
Author: fabiomaulo
Date: 2009-06-03 06:15:26 +0000 (Wed, 03 Jun 2009)
Log Message:
-----------
Fix NH-1487
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1487/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1487/Fixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-06-03 04:22:51 UTC (rev 4403)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-06-03 06:15:26 UTC (rev 4404)
@@ -1108,9 +1108,9 @@
{
if (indexAttribute != null && table != null)
{
- StringTokenizer tokens = new StringTokenizer(indexAttribute.Value, ", ");
+ var tokens = new StringTokenizer(indexAttribute.Value, ",", false);
foreach (string token in tokens)
- table.GetOrCreateIndex(token).AddColumn(column);
+ table.GetOrCreateIndex(token.Trim()).AddColumn(column);
}
}
@@ -1118,9 +1118,9 @@
{
if (uniqueKeyAttribute != null && table != null)
{
- StringTokenizer tokens = new StringTokenizer(uniqueKeyAttribute.Value, ", ");
+ var tokens = new StringTokenizer(uniqueKeyAttribute.Value, ",", false);
foreach (string token in tokens)
- table.GetOrCreateUniqueKey(token).AddColumn(column);
+ table.GetOrCreateUniqueKey(token.Trim()).AddColumn(column);
}
}
@@ -1287,9 +1287,9 @@
{
if (indexAttribute != null && table != null)
{
- StringTokenizer tokens = new StringTokenizer(indexAttribute, ", ");
+ var tokens = new StringTokenizer(indexAttribute, ",", false);
foreach (string token in tokens)
- table.GetOrCreateIndex(token).AddColumn(column);
+ table.GetOrCreateIndex(token.Trim()).AddColumn(column);
}
}
@@ -1297,9 +1297,9 @@
{
if (uniqueKeyAttribute != null && table != null)
{
- StringTokenizer tokens = new StringTokenizer(uniqueKeyAttribute, ", ");
+ var tokens = new StringTokenizer(uniqueKeyAttribute, ",", false);
foreach (string token in tokens)
- table.GetOrCreateUniqueKey(token).AddColumn(column);
+ table.GetOrCreateUniqueKey(token.Trim()).AddColumn(column);
}
}
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs 2009-06-03 04:22:51 UTC (rev 4403)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs 2009-06-03 06:15:26 UTC (rev 4404)
@@ -152,16 +152,16 @@
if (columnSchema.index != null && id.Table != null)
{
- StringTokenizer tokens = new StringTokenizer(columnSchema.index, ", ");
+ var tokens = new StringTokenizer(columnSchema.index, ",", false);
foreach (string token in tokens)
- id.Table.GetOrCreateIndex(token).AddColumn(column);
+ id.Table.GetOrCreateIndex(token.Trim()).AddColumn(column);
}
if (columnSchema.uniquekey != null && id.Table != null)
{
- StringTokenizer tokens = new StringTokenizer(columnSchema.uniquekey, ", ");
+ var tokens = new StringTokenizer(columnSchema.uniquekey, ",", false);
foreach (string token in tokens)
- id.Table.GetOrCreateUniqueKey(token).AddColumn(column);
+ id.Table.GetOrCreateUniqueKey(token.Trim()).AddColumn(column);
}
}
}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1487/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1487/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1487/Fixture.cs 2009-06-03 06:15:26 UTC (rev 4404)
@@ -0,0 +1,215 @@
+using System.Text;
+using NHibernate.Cfg;
+using NHibernate.Dialect;
+using NHibernate.Tool.hbm2ddl;
+using NUnit.Framework;
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH1487
+{
+ public class Entity
+ {
+ int field;
+ public int Id { get { return field; } set { field = value; } }
+ public int A { get { return field; } set { field = value; } }
+ public int B { get { return field; } set { field = value; } }
+ public int C { get { return field; } set { field = value; } }
+ }
+
+ /// <summary>
+ /// Summary description for TestTestCase.
+ /// </summary>
+ [TestFixture]
+ public class Fixture
+ {
+
+ public Configuration GetConf()
+ {
+ var cfg = new Configuration();
+ if (TestConfigurationHelper.hibernateConfigFile != null)
+ cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
+ return cfg;
+ }
+
+ [Test]
+ public void GenerateSchemaMultipleUniqueKeys()
+ {
+ if(!(Dialect.Dialect.GetDialect() is MsSql2000Dialect))
+ {
+ Assert.Ignore("Specific for MsSql2000Dialect");
+ }
+ const string hbm = @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+namespace='NHibernate.Test.NHSpecificTest.NH1487'
+assembly='NHibernate.Test'>
+ <class name='Entity' >
+ <id name='Id' >
+ <generator class='assigned' />
+ </id>
+ <property name='A' unique-key='AC'/>
+ <property name='B' unique-key='BC'/>
+ <property name='C' unique-key='AC, BC'/>
+ </class>
+</hibernate-mapping>";
+
+ var cfg = GetConf();
+
+ cfg.AddXmlString(hbm);
+
+ // Can create the schema
+ var scriptB = new StringBuilder();
+ new SchemaExport(cfg).Create(sl => scriptB.Append(sl), true);
+ var script = scriptB.ToString();
+ Assert.That(script, Text.Contains("unique (A, C)"));
+ Assert.That(script, Text.Contains("unique (B, C)"));
+ Assert.That(script, Text.DoesNotContain("unique (C)"));
+
+ new SchemaExport(cfg).Drop(false, true);
+ }
+
+ [Test]
+ public void GenerateSchemaMultipleIndex()
+ {
+ if (!(Dialect.Dialect.GetDialect() is MsSql2000Dialect))
+ {
+ Assert.Ignore("Specific for MsSql2000Dialect");
+ }
+ const string hbm = @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+namespace='NHibernate.Test.NHSpecificTest.NH1487'
+assembly='NHibernate.Test'>
+ <class name='Entity' >
+ <id name='Id' >
+ <generator class='assigned' />
+ </id>
+ <property name='A' index='AC'/>
+ <property name='B' index='BC'/>
+ <property name='C' index='AC, BC'/>
+ </class>
+</hibernate-mapping>";
+
+ var cfg = GetConf();
+ cfg.AddXmlString(hbm);
+
+ var scriptB = new StringBuilder();
+ new SchemaExport(cfg).Create(sl => scriptB.Append(sl), true);
+ var script = scriptB.ToString();
+ Assert.That(script, Text.Contains("create index AC on Entity (A, C)"));
+ Assert.That(script, Text.Contains("create index BC on Entity (B, C)"));
+
+ new SchemaExport(cfg).Drop(false, true);
+ }
+
+ [Test]
+ public void GenerateSchemaMultipleIndexOnColumn()
+ {
+ if (!(Dialect.Dialect.GetDialect() is MsSql2000Dialect))
+ {
+ Assert.Ignore("Specific for MsSql2000Dialect");
+ }
+ const string hbm = @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+namespace='NHibernate.Test.NHSpecificTest.NH1487'
+assembly='NHibernate.Test'>
+ <class name='Entity' >
+ <id name='Id' >
+ <generator class='assigned' />
+ </id>
+ <property name='A'>
+ <column name='A' index='AC'/>
+ </property>
+ <property name='B'>
+ <column name='B' index='BC'/>
+ </property>
+ <property name='C'>
+ <column name='C' index='AC,BC'/>
+ </property>
+ </class>
+</hibernate-mapping>";
+
+ var cfg = GetConf();
+ cfg.AddXmlString(hbm);
+
+ var scriptB = new StringBuilder();
+ new SchemaExport(cfg).Create(sl => scriptB.Append(sl), true);
+ var script = scriptB.ToString();
+ Assert.That(script, Text.Contains("create index AC on Entity (A, C)"));
+ Assert.That(script, Text.Contains("create index BC on Entity (B, C)"));
+
+ new SchemaExport(cfg).Drop(false, true);
+ }
+ [Test]
+ public void GenerateSchemaIndexOnId()
+ {
+ if (!(Dialect.Dialect.GetDialect() is MsSql2000Dialect))
+ {
+ Assert.Ignore("Specific for MsSql2000Dialect");
+ }
+ const string hbm = @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+namespace='NHibernate.Test.NHSpecificTest.NH1487'
+assembly='NHibernate.Test'>
+ <class name='Entity' >
+ <id name='Id' >
+ <column name='Id' index='IdxId1,IdxId2'/>
+ <generator class='assigned' />
+ </id>
+ <property name='A'/>
+ <property name='B'/>
+ <property name='C'/>
+ </class>
+</hibernate-mapping>";
+
+ var cfg = GetConf();
+ cfg.AddXmlString(hbm);
+
+ var scriptB = new StringBuilder();
+ new SchemaExport(cfg).Create(sl => scriptB.Append(sl), true);
+ var script = scriptB.ToString();
+ Assert.That(script, Text.Contains("create index IdxId1 on Entity (Id)"));
+ Assert.That(script, Text.Contains("create index IdxId2 on Entity (Id)"));
+
+ new SchemaExport(cfg).Drop(false, true);
+ }
+
+ [Test]
+ public void GenerateSchemaUniqueOnId()
+ {
+ if (!(Dialect.Dialect.GetDialect() is MsSql2000Dialect))
+ {
+ Assert.Ignore("Specific for MsSql2000Dialect");
+ }
+ const string hbm = @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+namespace='NHibernate.Test.NHSpecificTest.NH1487'
+assembly='NHibernate.Test'>
+ <class name='Entity' >
+ <id name='Id' >
+ <column name='Id' unique-key='UIdxId1,UIdxId2'/>
+ <generator class='assigned' />
+ </id>
+ <property name='A'/>
+ <property name='B'/>
+ <property name='C'/>
+ </class>
+</hibernate-mapping>";
+
+ var cfg = GetConf();
+ cfg.AddXmlString(hbm);
+
+ var scriptB = new StringBuilder();
+ new SchemaExport(cfg).Create(sl => scriptB.AppendLine(sl), true);
+ var script = scriptB.ToString().Split(new[] { System.Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
+ int count=0;
+ foreach (var s in script)
+ {
+ if (s.Contains("unique (Id)"))
+ count++;
+ }
+ Assert.That(count, Is.EqualTo(2));
+
+ new SchemaExport(cfg).Drop(false, true);
+ }
+
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-03 04:22:51 UTC (rev 4403)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-03 06:15:26 UTC (rev 4404)
@@ -364,6 +364,7 @@
<Compile Include="NHSpecificTest\NH1343\Product.cs" />
<Compile Include="NHSpecificTest\NH1343\ProductFixture.cs" />
<Compile Include="NHSpecificTest\NH1388\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1487\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1531\DomainClass.cs" />
<Compile Include="NHSpecificTest\NH1531\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1553\MsSQL\Person.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|