Permalink
Browse files

Target : NHibernate.Mapping namespace port

- Some classes (NHibernate.Mapping) was full ported
- ComponentType now work with PocoComponentTuplizer
- Refactoring of some Exceptions

BREAKING CHANGE:
- INamingStrategy

Possible Braking-Change looking changes in tests:
- Entity and its mapping must be compatible even if the entity have a custom persister (look changes in DomainModel/Custom.cs and MasterDetailTest)
- PropertyNotFoundException now is one of the ExceptionTree (can't catch directly)
- For missed def-ctor the Exception is InstantiationException

SVN: trunk@3177
  • Loading branch information...
1 parent 73a4fde commit 52775d1ff34d3d98baa812a73f343f80693e8b32 @fabiomaulo fabiomaulo committed Dec 16, 2007
Showing with 993 additions and 734 deletions.
  1. +2 −2 src/NHibernate.DomainModel/Custom.cs
  2. +1 −1 src/NHibernate.DomainModel/Custom.hbm.xml
  3. +6 −6 src/NHibernate.DomainModel/CustomPersister.cs
  4. +2 −2 src/NHibernate.Test/Legacy/MasterDetailTest.cs
  5. +1 −15 src/NHibernate.Test/MappingExceptions/MissingDefCtorFixture.cs
  6. +11 −10 src/NHibernate.Test/MappingExceptions/PropertyNotFoundExceptionFixture.cs
  7. +8 −2 src/NHibernate.Test/MappingTest/ColumnFixture.cs
  8. +26 −7 src/NHibernate.Test/NHSpecificTest/NH642/Fixture.cs
  9. +9 −9 src/NHibernate.Test/NHSpecificTest/NH712/Fixture.cs
  10. +8 −8 src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs
  11. +1 −18 src/NHibernate/Cfg/Configuration.cs
  12. +5 −0 src/NHibernate/Cfg/DefaultNamingStrategy.cs
  13. +10 −2 src/NHibernate/Cfg/INamingStrategy.cs
  14. +5 −1 src/NHibernate/Cfg/ImprovedNamingStrategy.cs
  15. +5 −0 src/NHibernate/Cfg/XmlHbmBinding/Binder.cs
  16. +43 −52 src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
  17. +36 −45 src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs
  18. +13 −9 src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs
  19. +4 −4 src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs
  20. +11 −12 src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs
  21. +5 −2 src/NHibernate/Engine/EntityKey.cs
  22. +6 −0 src/NHibernate/InstantiationException.cs
  23. +35 −23 src/NHibernate/Mapping/Any.cs
  24. +138 −34 src/NHibernate/Mapping/Collection.cs
  25. +23 −50 src/NHibernate/Mapping/Column.cs
  26. +93 −20 src/NHibernate/Mapping/Component.cs
  27. +6 −7 src/NHibernate/Mapping/Constraint.cs
  28. +1 −1 src/NHibernate/Mapping/DenormalizedTable.cs
  29. +3 −3 src/NHibernate/Mapping/Formula.cs
  30. +1 −3 src/NHibernate/Mapping/IValue.cs
  31. +52 −33 src/NHibernate/Mapping/Index.cs
  32. +17 −25 src/NHibernate/Mapping/ManyToOne.cs
  33. +15 −14 src/NHibernate/Mapping/MetaAttribute.cs
  34. +15 −4 src/NHibernate/Mapping/OneToMany.cs
  35. +42 −38 src/NHibernate/Mapping/OneToOne.cs
  36. +36 −3 src/NHibernate/Mapping/PersistentClass.cs
  37. +13 −4 src/NHibernate/Mapping/SimpleAuxiliaryDatabaseObject.cs
  38. +76 −66 src/NHibernate/Mapping/SimpleValue.cs
  39. +2 −2 src/NHibernate/Mapping/Subclass.cs
  40. +26 −2 src/NHibernate/Mapping/ToOne.cs
  41. +39 −32 src/NHibernate/Mapping/UniqueKey.cs
  42. +6 −6 src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs
  43. +0 −5 src/NHibernate/Persister/Collection/ICollectionPersister.cs
  44. +3 −3 src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
  45. +1 −1 src/NHibernate/Persister/Entity/UnionSubclassEntityPersister.cs
  46. +31 −7 src/NHibernate/PropertyNotFoundException.cs
  47. +1 −2 src/NHibernate/Tuple/Component/ComponentEntityModeToTuplizerMapping.cs
  48. +1 −1 src/NHibernate/Tuple/Component/ComponentMetamodel.cs
  49. +2 −2 src/NHibernate/Tuple/Component/PocoComponentTuplizer.cs
  50. +4 −0 src/NHibernate/Tuple/PocoInstantiator.cs
  51. +1 −3 src/NHibernate/Type/CollectionType.cs
  52. +68 −127 src/NHibernate/Type/ComponentType.cs
  53. +7 −6 src/NHibernate/Type/MetaType.cs
  54. +17 −0 src/NHibernate/Util/ReflectHelper.cs
@@ -7,10 +7,10 @@ namespace NHibernate.DomainModel
/// </summary>
public class Custom : ICloneable
{
- private long _id;
+ private string _id;
private string _name;
- public long Id
+ public string Id
{
get { return _id; }
set { _id = value; }
@@ -6,7 +6,7 @@
>
<id
type="String"
- name="key"
+ name="Id"
column="id_"
length="64"
unsaved-value="null"
@@ -19,7 +19,7 @@ namespace NHibernate.DomainModel
public class CustomPersister : IEntityPersister
{
private static readonly Hashtable Instances = new Hashtable();
- private static readonly IIdentifierGenerator Generator = new CounterGenerator();
+ private static readonly IIdentifierGenerator Generator = new UUIDHexGenerator();
private static readonly IType[] Types = new IType[] {NHibernateUtil.String};
private static readonly string[] Names = new string[] {"name"};
@@ -101,7 +101,7 @@ public bool HasCascades
public object Instantiate(object id)
{
Custom c = new Custom();
- c.Id = (long) id;
+ c.Id = (string) id;
return c;
}
@@ -137,7 +137,7 @@ public void Insert(object id, object[] fields, object obj, ISessionImplementor s
public bool IsUnsaved(object id)
{
- return (long) id == 0;
+ return id == null;
}
public bool HasIdentifierPropertyOrEmbeddedCompositeIdentifier
@@ -183,7 +183,7 @@ public System.Type ConcreteProxyClass
public object GetIdentifier(object obj)
{
- return (long) ((Custom) obj).Id;
+ return ((Custom) obj).Id;
}
public object GetPropertyValue(object obj, int i)
@@ -218,7 +218,7 @@ public bool HasProxy
public void SetIdentifier(object obj, object id)
{
- ((Custom) obj).Id = (long) id;
+ ((Custom) obj).Id = (string) id;
}
public bool ImplementsLifecycle
@@ -259,7 +259,7 @@ public int VersionProperty
public IType IdentifierType
{
- get { return NHibernateUtil.Int64; }
+ get { return NHibernateUtil.String; }
}
public PropertyInfo ProxyIdentifierProperty
@@ -1102,8 +1102,8 @@ public void CustomPersister()
ISession s = OpenSession();
Custom c = new Custom();
c.Name = "foo";
- c.Id = 100;
- long id = (long) s.Save(c);
+ c.Id = "100";
+ string id = (string)s.Save(c);
Assert.AreSame(c, s.Load(typeof(Custom), id));
s.Flush();
s.Close();
@@ -11,28 +11,14 @@ namespace NHibernate.Test.MappingExceptions
[TestFixture]
public class MissingDefCtorFixture
{
- [Test]
+ [Test, ExpectedException(typeof(InstantiationException))]
public void ClassMissingDefaultCtor()
{
- bool excCaught = false;
-
// add a resource that doesn't exist
string resource = "NHibernate.Test.MappingExceptions.MissingDefCtor.hbm.xml";
Configuration cfg = new Configuration();
- try
- {
cfg.AddResource(resource, this.GetType().Assembly);
cfg.BuildSessionFactory();
- }
- catch (MappingException me)
- {
- Assert.AreEqual(
- "Object class NHibernate.Test.MappingExceptions.MissingDefCtor must declare a default (no-argument) constructor",
- me.Message);
- excCaught = true;
- }
-
- Assert.IsTrue(excCaught, "Should have caught the MappingException about default ctor being missing.");
}
}
}
@@ -17,20 +17,21 @@ public void MisspelledPropertyName()
Configuration cfg = new Configuration();
try
{
- cfg.AddResource(resource, this.GetType().Assembly);
+ cfg.AddResource(resource, GetType().Assembly);
cfg.BuildSessionFactory();
}
catch (MappingException me)
{
- //"Problem trying to set property type by reflection"
- // "Could not find a getter for property 'Naame' in class 'NHibernate.Test.MappingExceptions.A'"
- Assert.IsTrue(me.InnerException is MappingException);
- Assert.IsTrue(me.InnerException.InnerException is PropertyNotFoundException);
-
- Exception inner = me.InnerException.InnerException;
- Assert.IsTrue(inner.Message.IndexOf("Naame") > 0, "should contain name of missing property 'Naame' in exception");
- Assert.IsTrue(inner.Message.IndexOf("NHibernate.Test.MappingExceptions.A") > 0,
- "should contain name of class that is missing the property");
+ PropertyNotFoundException found = null;
+ Exception find = me;
+ while (find != null)
+ {
+ found = find as PropertyNotFoundException;
+ find = find.InnerException;
+ }
+ Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
+ Assert.AreEqual("Naame", found.PropertyName, "should contain name of missing property 'Naame' in exception");
+ Assert.AreEqual(typeof(A), found.TargetType, "should contain name of class that is missing the property");
excCaught = true;
}
@@ -19,15 +19,21 @@ public void SetUp()
[Test]
public void YesNoSqlType()
{
- Column column = new Column(NHibernateUtil.YesNo, 0);
+ SimpleValue sv = new SimpleValue();
+ sv.TypeName = NHibernateUtil.YesNo.Name;
+ Column column = new Column();
+ column.Value = sv;
string type = column.GetSqlType(_dialect, null);
Assert.AreEqual("CHAR(1)", type);
}
[Test]
public void StringSqlType()
{
- Column column = new Column(NHibernateUtil.String, 0);
+ SimpleValue sv = new SimpleValue();
+ sv.TypeName = NHibernateUtil.String.Name;
+ Column column = new Column();
+ column.Value = sv;
Assert.AreEqual("NVARCHAR(255)", column.GetSqlType(_dialect, null));
column.Length = 100;
@@ -4,6 +4,12 @@
namespace NHibernate.Test.NHSpecificTest.NH642
{
+ //<summary>ArgumentNullException if no setter exists and no access strategy was specified</summary>
+ //<type id="1">Bug</type>
+ //<priority id="3">Major</priority>
+ //<created>Fri, 9 Jun 2006 07:34:32 -0400 (EDT)</created>
+ //<component>Core</component>
+ //<link>http://jira.nhibernate.org</link>
public class MissingSetter
{
public virtual int ReadOnly
@@ -25,20 +31,33 @@ public class Fixture
{
private void DoTest(string name)
{
- ISessionFactory factory = new Configuration()
- .AddResource("NHibernate.Test.NHSpecificTest.NH642." + name + ".hbm.xml",
- typeof(Fixture).Assembly)
- .BuildSessionFactory();
- factory.Close();
+ try
+ {
+ ISessionFactory factory =
+ new Configuration().AddResource("NHibernate.Test.NHSpecificTest.NH642." + name + ".hbm.xml",
+ typeof (Fixture).Assembly).BuildSessionFactory();
+ factory.Close();
+ }
+ catch (MappingException me)
+ {
+ PropertyNotFoundException found = null;
+ Exception find = me;
+ while (find != null)
+ {
+ found = find as PropertyNotFoundException;
+ find = find.InnerException;
+ }
+ Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
+ }
}
- [Test, ExpectedException(typeof(PropertyNotFoundException))]
+ [Test]
public void MissingGetter()
{
DoTest("MissingGetter");
}
- [Test, ExpectedException(typeof(PropertyNotFoundException))]
+ [Test]
public void MissingSetter()
{
DoTest("MissingSetter");
@@ -4,27 +4,27 @@
namespace NHibernate.Test.NHSpecificTest.NH712
{
+ //<summary>Improve returned error message when default constructor is not present on a class mapped as a component</summary>
+ //<type id="4">Improvement</type>
+ //<priority id="4">Minor</priority>
+ //<created>Fri, 15 Sep 2006 07:31:13 -0400 (EDT)</created>
+ //<version>1.2.0.Alpha1</version>
+ //<component>Core</component>
+ //<link>http://jira.nhibernate.org/browse/NH-712</link>
[TestFixture]
public class Fixture
{
- [Test]
+ [Test, ExpectedException(typeof(InstantiationException))]
public void Bug()
{
if (!Cfg.Environment.UseReflectionOptimizer)
{
Assert.Ignore("Test only works with reflection optimization enabled");
}
- try
- {
+ else
new Configuration()
.AddResource(GetType().Namespace + ".Mappings.hbm.xml", GetType().Assembly)
.BuildSessionFactory();
- Assert.Fail();
- }
- catch (MappingException ex)
- {
- Assert.IsTrue(ex.InnerException is MappingException);
- }
}
}
}
@@ -83,14 +83,14 @@ private CreateInstanceInvoker CreateCreateInstanceMethod(System.Type type)
ConstructorInfo constructor = ReflectHelper.GetDefaultConstructor(type);
if (constructor == null)
{
- throw new MappingException("Object class " + type + " must declare a default (no-argument) constructor");
+ throw new InstantiationException("Object class " + type + " must declare a default (no-argument) constructor", type);
}
il.Emit(OpCodes.Newobj, constructor);
}
il.Emit(OpCodes.Ret);
- return (CreateInstanceInvoker) method.CreateDelegate(typeof(CreateInstanceInvoker));
+ return (CreateInstanceInvoker)method.CreateDelegate(typeof(CreateInstanceInvoker));
}
protected DynamicMethod CreateDynamicMethod(System.Type returnType, System.Type[] argumentTypes)
@@ -117,7 +117,7 @@ private static void EmitCastToReference(ILGenerator il, System.Type type)
/// </summary>
private GetPropertyValuesInvoker GenerateGetPropertyValuesMethod(IGetter[] getters)
{
- System.Type[] methodArguments = new System.Type[] {typeof(object), typeof(GetterCallback)};
+ System.Type[] methodArguments = new System.Type[] { typeof(object), typeof(GetterCallback) };
DynamicMethod method = CreateDynamicMethod(typeof(object[]), methodArguments);
ILGenerator il = method.GetILGenerator();
@@ -159,7 +159,7 @@ private GetPropertyValuesInvoker GenerateGetPropertyValuesMethod(IGetter[] gette
// using the getter itself via a callback
MethodInfo invokeMethod =
typeof(GetterCallback).GetMethod(
- "Invoke", new System.Type[] {typeof(object), typeof(int)});
+ "Invoke", new System.Type[] { typeof(object), typeof(int) });
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldc_I4, i);
@@ -174,7 +174,7 @@ private GetPropertyValuesInvoker GenerateGetPropertyValuesMethod(IGetter[] gette
il.Emit(OpCodes.Ldloc, dataLocal.LocalIndex);
il.Emit(OpCodes.Ret);
- return (GetPropertyValuesInvoker) method.CreateDelegate(typeof(GetPropertyValuesInvoker));
+ return (GetPropertyValuesInvoker)method.CreateDelegate(typeof(GetPropertyValuesInvoker));
}
/// <summary>
@@ -183,7 +183,7 @@ private GetPropertyValuesInvoker GenerateGetPropertyValuesMethod(IGetter[] gette
/// <returns></returns>
private SetPropertyValuesInvoker GenerateSetPropertyValuesMethod(IGetter[] getters, ISetter[] setters)
{
- System.Type[] methodArguments = new System.Type[] {typeof(object), typeof(object[]), typeof(SetterCallback)};
+ System.Type[] methodArguments = new System.Type[] { typeof(object), typeof(object[]), typeof(SetterCallback) };
DynamicMethod method = CreateDynamicMethod(null, methodArguments);
ILGenerator il = method.GetILGenerator();
@@ -222,7 +222,7 @@ private SetPropertyValuesInvoker GenerateSetPropertyValuesMethod(IGetter[] gette
// using the setter itself via a callback
MethodInfo invokeMethod =
typeof(SetterCallback).GetMethod(
- "Invoke", new System.Type[] {typeof(object), typeof(int), typeof(object)});
+ "Invoke", new System.Type[] { typeof(object), typeof(int), typeof(object) });
il.Emit(OpCodes.Ldarg_2);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldc_I4, i);
@@ -239,7 +239,7 @@ private SetPropertyValuesInvoker GenerateSetPropertyValuesMethod(IGetter[] gette
// Setup the return
il.Emit(OpCodes.Ret);
- return (SetPropertyValuesInvoker) method.CreateDelegate(typeof(SetPropertyValuesInvoker));
+ return (SetPropertyValuesInvoker)method.CreateDelegate(typeof(SetPropertyValuesInvoker));
}
}
}
@@ -445,23 +445,6 @@ public Mappings CreateMappings()
defaultAssembly,
defaultNamespace
);
-
- //return new Mappings(
- // classes,
- // collections,
- // tables,
- // namedQueries,
- // namedSqlQueries,
- // sqlResultSetMappings,
- // imports,
- // secondPasses,
- // propertyReferences,
- // namingStrategy,
- // filterDefinitions,
- // auxiliaryDatabaseObjects,
- // defaultAssembly,
- // defaultNamespace
- // );
}
/// <summary>
@@ -854,7 +837,7 @@ private void SecondPassCompile()
}
NHibernate.Mapping.Property prop = clazz.GetReferencedProperty(upr.propertyName);
- ((SimpleValue)prop.Value).IsUnique = true;
+ ((SimpleValue)prop.Value).IsAlternateUniqueKey = true;
}
//TODO: Somehow add the newly created foreign keys to the internal collection
@@ -70,6 +70,11 @@ public string PropertyToTableName(string className, string propertyName)
return StringHelper.Unqualify(propertyName);
}
+ public string LogicalColumnName(string columnName, string propertyName)
+ {
+ return StringHelper.IsNotEmpty(columnName) ? columnName : StringHelper.Unqualify(propertyName);
+ }
+
#endregion
}
}
Oops, something went wrong.

0 comments on commit 52775d1

Please sign in to comment.