Skip to content

Commit 2004e71

Browse files
author
Will Shaver
committed
Fixes NH 1611, NH 1274.
1611 is an uncommon one-to-one mapping issue. 1274 fills requests for schema-action="none|drop|export|update|validate|all" SVN: trunk@3954
1 parent 1f5bb20 commit 2004e71

20 files changed

+711
-124
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH1274ExportExclude
2+
{
3+
public class Home
4+
{
5+
private int id;
6+
private int zip;
7+
private string city;
8+
9+
public Home()
10+
{
11+
12+
}
13+
14+
public Home(string city, int zip)
15+
{
16+
this.city = city;
17+
this.zip = zip;
18+
}
19+
20+
virtual public int Id
21+
{
22+
get { return id; }
23+
set { id = value; }
24+
}
25+
26+
virtual public string City
27+
{
28+
get { return city; }
29+
set { city = value; }
30+
}
31+
32+
virtual public int Zip
33+
{
34+
get { return zip; }
35+
set { zip = value; }
36+
}
37+
}
38+
39+
public class Home_Update : Home { public Home_Update() { } public Home_Update(string city, int zip) : base(city, zip) { } }
40+
41+
public class Home_Export : Home { public Home_Export() { } public Home_Export(string city, int zip) : base(city, zip) { } }
42+
43+
public class Home_Validate : Home { public Home_Validate() { } public Home_Validate(string city, int zip) : base(city, zip) { } }
44+
45+
public class Home_Drop : Home { public Home_Drop() { } public Home_Drop(string city, int zip) : base(city, zip) { } }
46+
47+
public class Home_None : Home {public Home_None() { } public Home_None(string city, int zip) : base(city, zip) { } }
48+
49+
public class Home_All : Home {public Home_All() { } public Home_All(string city, int zip) : base(city, zip) { } }
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH1274ExportExclude">
5+
6+
<class name="Home_None" schema-action="none">
7+
<id name="Id">
8+
<generator class="native" />
9+
</id>
10+
<property name="City"/>
11+
<property name="Zip"/>
12+
</class>
13+
14+
<class name="Home_Drop" schema-action="drop">
15+
<id name="Id">
16+
<generator class="native" />
17+
</id>
18+
<property name="City"/>
19+
<property name="Zip"/>
20+
</class>
21+
22+
<class name="Home_Export" schema-action="export">
23+
<id name="Id">
24+
<generator class="native" />
25+
</id>
26+
<property name="City"/>
27+
<property name="Zip"/>
28+
</class>
29+
30+
<class name="Home_Update" schema-action="update">
31+
<id name="Id">
32+
<generator class="native" />
33+
</id>
34+
<property name="City"/>
35+
<property name="Zip"/>
36+
</class>
37+
38+
<class name="Home_Validate" schema-action="validate">
39+
<id name="Id">
40+
<generator class="native" />
41+
</id>
42+
<property name="City"/>
43+
<property name="Zip"/>
44+
</class>
45+
46+
<class name="Home_All" schema-action="all">
47+
<id name="Id">
48+
<generator class="native" />
49+
</id>
50+
<property name="City"/>
51+
<property name="Zip"/>
52+
</class>
53+
54+
<class name="Person">
55+
<id name="Id">
56+
<generator class="native" />
57+
</id>
58+
<property name="Name"/>
59+
<many-to-one name="Home_Drop" column="Home_DropID" />
60+
<many-to-one name="Home_Export" column="Home_ExportID" />
61+
<many-to-one name="Home_Update" column="Home_UpdateID" />
62+
<many-to-one name="Home_Validate" column="Home_ValidateID" />
63+
</class>
64+
65+
66+
</hibernate-mapping>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Reflection;
6+
using NHibernate.Cfg;
7+
using NHibernate.Criterion;
8+
using NHibernate.Engine;
9+
using NHibernate.Tool.hbm2ddl;
10+
using NUnit.Framework;
11+
12+
namespace NHibernate.Test.NHSpecificTest.NH1274ExportExclude
13+
{
14+
[TestFixture]
15+
public class NH1274ExportExcludeFixture
16+
{
17+
18+
[Test]
19+
public void SchemaExport_Drop_CreatesDropScript()
20+
{
21+
Configuration configuration = GetConfiguration();
22+
SchemaExport export = new SchemaExport(configuration);
23+
TextWriter tw = new StringWriter();
24+
Console.SetOut(tw);
25+
export.Drop(true, false);
26+
string s = tw.ToString();
27+
Assert.IsTrue(s.Contains("drop table Home_Drop"));
28+
Assert.IsTrue(s.Contains("drop table Home_All"));
29+
}
30+
31+
[Test]
32+
public void SchemaExport_Export_CreatesExportScript()
33+
{
34+
Configuration configuration = GetConfiguration();
35+
SchemaExport export = new SchemaExport(configuration);
36+
TextWriter tw = new StringWriter();
37+
Console.SetOut(tw);
38+
export.Create(true, false);
39+
string s = tw.ToString();
40+
Assert.IsTrue(s.Contains("drop table Home_Drop"));
41+
Assert.IsTrue(s.Contains("drop table Home_All"));
42+
Assert.IsTrue(s.Contains("create table Home_All"));
43+
Assert.IsTrue(s.Contains("create table Home_Export"));
44+
}
45+
46+
[Test]
47+
public void SchemaExport_Update_CreatesUpdateScript()
48+
{
49+
Configuration configuration = GetConfiguration();
50+
SchemaUpdate update = new SchemaUpdate(configuration);
51+
TextWriter tw = new StringWriter();
52+
Console.SetOut(tw);
53+
update.Execute(true, false);
54+
55+
string s = tw.ToString();
56+
Assert.IsTrue(s.Contains("create table Home_Update"));
57+
Assert.IsTrue(s.Contains("create table Home_All"));
58+
}
59+
60+
[Test]
61+
public void SchemaExport_Validate_CausesValidateException()
62+
{
63+
Configuration configuration = GetConfiguration();
64+
SchemaValidator validator = new SchemaValidator(configuration);
65+
try
66+
{
67+
validator.Validate();
68+
}
69+
catch (HibernateException he)
70+
{
71+
Assert.IsTrue(he.Message.Contains("Home_Validate"));
72+
return;
73+
}
74+
throw new Exception("Should not get to this exception");
75+
}
76+
77+
private Configuration GetConfiguration()
78+
{
79+
Configuration cfg = new Configuration();
80+
if (TestConfigurationHelper.hibernateConfigFile != null)
81+
cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
82+
83+
Assembly assembly = Assembly.Load(MappingsAssembly);
84+
85+
foreach (string file in Mappings)
86+
{
87+
cfg.AddResource(MappingsAssembly + "." + file, assembly);
88+
}
89+
return cfg;
90+
}
91+
92+
93+
protected static string MappingsAssembly
94+
{
95+
get { return "NHibernate.Test"; }
96+
}
97+
98+
public virtual string BugNumber
99+
{
100+
get
101+
{
102+
string ns = GetType().Namespace;
103+
return ns.Substring(ns.LastIndexOf('.') + 1);
104+
}
105+
}
106+
107+
protected IList Mappings
108+
{
109+
get
110+
{
111+
return new string[]
112+
{
113+
"NHSpecificTest." + BugNumber + ".Mappings.hbm.xml"
114+
};
115+
}
116+
}
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH1274ExportExclude
2+
{
3+
public class Person
4+
{
5+
private int id;
6+
private int iq;
7+
private int shoeSize;
8+
private string name;
9+
private Home_Drop home_drop;
10+
private Home_Export home_export;
11+
private Home_Validate home_validate;
12+
private Home_Update home_update;
13+
14+
public Person()
15+
{
16+
17+
}
18+
19+
public Person(string name, int iq, int shoeSize)
20+
{
21+
this.name = name;
22+
this.iq = iq;
23+
this.shoeSize = shoeSize;
24+
}
25+
26+
virtual public int Id
27+
{
28+
get { return id; }
29+
set { id = value; }
30+
}
31+
32+
virtual public string Name
33+
{
34+
get { return name; }
35+
set { name = value; }
36+
}
37+
38+
virtual public int IQ
39+
{
40+
get { return iq; }
41+
set { iq = value; }
42+
}
43+
44+
virtual public int ShoeSize
45+
{
46+
get { return shoeSize; }
47+
set { shoeSize = value; }
48+
}
49+
50+
virtual public Home_Drop Home_Drop
51+
{
52+
get { return home_drop; }
53+
set { home_drop = value; }
54+
}
55+
56+
virtual public Home_Export Home_Export
57+
{
58+
get { return home_export; }
59+
set { home_export = value; }
60+
}
61+
62+
virtual public Home_Validate Home_Validate
63+
{
64+
get { return home_validate; }
65+
set { home_validate = value; }
66+
}
67+
68+
virtual public Home_Update Home_Update
69+
{
70+
get { return home_update; }
71+
set { home_update = value; }
72+
}
73+
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH1611OneToOneIdentity
2+
{
3+
public class Adjunct
4+
{
5+
private int id;
6+
private string adjunctDescription;
7+
8+
public Adjunct()
9+
{
10+
11+
}
12+
13+
virtual public int ID
14+
{
15+
get { return id; }
16+
set { id = value; }
17+
}
18+
19+
virtual public string AdjunctDescription
20+
{
21+
get { return adjunctDescription; }
22+
set { adjunctDescription = value; }
23+
}
24+
25+
public override bool Equals(object obj)
26+
{
27+
if (ReferenceEquals(null, obj)) return false;
28+
if (ReferenceEquals(this, obj)) return true;
29+
if (obj.GetType() != typeof (Adjunct)) return false;
30+
return Equals((Adjunct) obj);
31+
}
32+
33+
public virtual bool Equals(Adjunct obj)
34+
{
35+
if (ReferenceEquals(null, obj)) return false;
36+
if (ReferenceEquals(this, obj)) return true;
37+
return obj.id == id;
38+
}
39+
40+
public override int GetHashCode()
41+
{
42+
unchecked
43+
{
44+
return (id*397);
45+
}
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH1611OneToOneIdentity">
5+
6+
<class name="Primary" table="PrimaryTable">
7+
<composite-id>
8+
<key-property name="ID"/>
9+
</composite-id>
10+
11+
<one-to-one name="Adjunct" lazy="false" />
12+
13+
<property name="Description" />
14+
</class>
15+
16+
<class name="Adjunct" table="AdjunctTable">
17+
<composite-id>
18+
<key-property name="ID"/>
19+
</composite-id>
20+
<property name="AdjunctDescription" />
21+
</class>
22+
23+
24+
</hibernate-mapping>
25+

0 commit comments

Comments
 (0)