From: <fab...@us...> - 2009-02-21 03:05:30
|
Revision: 4091 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4091&view=rev Author: fabiomaulo Date: 2009-02-21 03:05:27 +0000 (Sat, 21 Feb 2009) Log Message: ----------- Fix NH-1677 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Map/Basic/DynamicClassFixture.cs Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2009-02-20 20:18:28 UTC (rev 4090) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2009-02-21 03:05:27 UTC (rev 4091) @@ -583,26 +583,37 @@ public string[] GetImplementors(string className) { System.Type clazz = null; - // NH Different implementation: we have better performance checking, first of all, if we know the class - // and take the System.Type directly from the persister (className have high probability to be entityName) - IEntityPersister checkPersister; - if (entityPersisters.TryGetValue(className, out checkPersister)) - { - clazz = checkPersister.GetMappedClass(EntityMode.Poco); - } - if (clazz == null) + // NH Different implementation for performance: a class without at least a namespace sure can't be found by reflection + if (className.IndexOf('.') > 0) { - try + IEntityPersister checkPersister; + // NH Different implementation: we have better performance checking, first of all, if we know the class + // and take the System.Type directly from the persister (className have high probability to be entityName) + if (entityPersisters.TryGetValue(className, out checkPersister)) { - clazz = ReflectHelper.ClassForFullName(className); + // NH : take care with this because we are forcing the Poco EntityMode + clazz = checkPersister.GetMappedClass(EntityMode.Poco); } - catch (Exception) + + if (clazz == null) { - return new string[] {className}; //for a dynamic-class + try + { + clazz = ReflectHelper.ClassForFullName(className); + } + catch (Exception) + { + clazz = null; + } } } + if (clazz == null) + { + return new[] {className}; //for a dynamic-class + } + List<string> results = new List<string>(); foreach (IEntityPersister p in entityPersisters.Values) { Modified: trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Map/Basic/DynamicClassFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Map/Basic/DynamicClassFixture.cs 2009-02-20 20:18:28 UTC (rev 4090) +++ trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Map/Basic/DynamicClassFixture.cs 2009-02-21 03:05:27 UTC (rev 4091) @@ -3,6 +3,7 @@ using NHibernate.Cfg; using NHibernate.Engine; using NUnit.Framework; +using NHibernate.Criterion; namespace NHibernate.Test.EntityModeTest.Map.Basic { @@ -24,13 +25,30 @@ configuration.SetProperty(Environment.DefaultEntityMode, EntityModeHelper.ToString(EntityMode.Map)); } + public delegate IDictionary SingleCarQueryDelegate(ISession session); + public delegate IList AllModelQueryDelegate(ISession session); + [Test] - public void TestLazyDynamicClass() + public void ShouldWorkWithHQL() { + TestLazyDynamicClass(s => (IDictionary) s.CreateQuery("from ProductLine pl order by pl.Description").UniqueResult(), + s => s.CreateQuery("from Model m").List()); + } + + [Test] + public void ShouldWorkWithCriteria() + { + TestLazyDynamicClass( + s => (IDictionary) s.CreateCriteria("ProductLine").AddOrder(Order.Asc("Description")).UniqueResult(), + s => s.CreateCriteria("Model").List()); + } + + public void TestLazyDynamicClass(SingleCarQueryDelegate singleCarQueryHandler, AllModelQueryDelegate allModelQueryHandler) + { ITransaction t; - using(ISession s = OpenSession()) + using (ISession s = OpenSession()) { - ISessionImplementor si = (ISessionImplementor) s; + var si = (ISessionImplementor)s; Assert.IsTrue(si.EntityMode == EntityMode.Map, "Incorrectly handled default_entity_mode"); ISession other = s.GetSession(EntityMode.Poco); other.Close(); @@ -55,9 +73,7 @@ hsv["Name"] = "hsv"; hsv["Description"] = "Holden hsv"; - models = new List<IDictionary>(); - models.Add(monaro); - models.Add(hsv); + models = new List<IDictionary> {monaro, hsv}; cars["Models"] = models; @@ -68,19 +84,19 @@ using (ISession s = OpenSession()) { t = s.BeginTransaction(); - cars = (IDictionary) s.CreateQuery("from ProductLine pl order by pl.Description").UniqueResult(); - models = (IList) cars["Models"]; + cars = singleCarQueryHandler(s); + models = (IList)cars["Models"]; Assert.IsFalse(NHibernateUtil.IsInitialized(models)); Assert.AreEqual(2, models.Count); Assert.IsTrue(NHibernateUtil.IsInitialized(models)); s.Clear(); - IList list = s.CreateQuery("from Model m").List(); + IList list = allModelQueryHandler(s); foreach (IDictionary ht in list) { Assert.IsFalse(NHibernateUtil.IsInitialized(ht["ProductLine"])); } - IDictionary model = (IDictionary) list[0]; - Assert.IsTrue(((IList) ((IDictionary) model["ProductLine"])["Models"]).Contains(model)); + var model = (IDictionary)list[0]; + Assert.IsTrue(((IList)((IDictionary)model["ProductLine"])["Models"]).Contains(model)); s.Clear(); t.Commit(); @@ -89,7 +105,7 @@ using (ISession s = OpenSession()) { t = s.BeginTransaction(); - cars = (IDictionary) s.CreateQuery("from ProductLine pl order by pl.Description").UniqueResult(); + cars = singleCarQueryHandler(s); s.Delete(cars); t.Commit(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |