From: <fab...@us...> - 2008-10-25 20:07:02
|
Revision: 3879 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3879&view=rev Author: fabiomaulo Date: 2008-10-25 20:06:57 +0000 (Sat, 25 Oct 2008) Log Message: ----------- Improvement of generic entity usage (it don't need to specify the entity-name in session API) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/ISessionFactoryImplementor.cs trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs trunk/nhibernate/src/NHibernate.Test/GenericTest/Overall/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Engine/ISessionFactoryImplementor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/ISessionFactoryImplementor.cs 2008-10-25 17:23:21 UTC (rev 3878) +++ trunk/nhibernate/src/NHibernate/Engine/ISessionFactoryImplementor.cs 2008-10-25 20:06:57 UTC (rev 3879) @@ -177,6 +177,12 @@ /// </returns> IEntityPersister TryGetEntityPersister(string entityName); + /// <summary> + /// Get the entity-name for a given mapped class. + /// </summary> + /// <param name="implementor">the mapped class</param> + /// <returns>the enntity name where available or null</returns> + string TryGetGuessEntityName(System.Type implementor); #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs 2008-10-25 17:23:21 UTC (rev 3878) +++ trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs 2008-10-25 20:06:57 UTC (rev 3879) @@ -40,7 +40,6 @@ * to link an entityName with its AssemblyQualifiedName (strongly typed). * I would like to maitain <imports> like the holder of the association of an entityName (or a class Name) and * its Type (in the future: Dictionary<string, System.Type> imports;) - * Note : The same AssemblyQualifiedName should be associaded with more than one emtityName (in case of use generic). * ********************************************************************************************************* */ return TypeNameParser.Parse(assemblyQualifiedName).Type; Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2008-10-25 17:23:21 UTC (rev 3878) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2008-10-25 20:06:57 UTC (rev 3879) @@ -102,6 +102,13 @@ [NonSerialized] private readonly ICurrentSessionContext currentSessionContext; [NonSerialized] private readonly IEntityNotFoundDelegate entityNotFoundDelegate; [NonSerialized] private readonly IDictionary<string, IEntityPersister> entityPersisters; + + /// <summary> + /// NH specific : to avoid the use of entityName for generic implementation + /// </summary> + /// <remarks>this is a shortcut.</remarks> + [NonSerialized] private readonly IDictionary<System.Type, string> implementorToEntityName; + [NonSerialized] private readonly EventListeners eventListeners; [NonSerialized] private readonly Dictionary<string, FilterDefinition> filters; @@ -178,6 +185,8 @@ Dictionary<string, ICacheConcurrencyStrategy> caches = new Dictionary<string, ICacheConcurrencyStrategy>(); entityPersisters = new Dictionary<string, IEntityPersister>(); + implementorToEntityName = new Dictionary<System.Type, string>(); + Dictionary<string, IClassMetadata> classMeta = new Dictionary<string, IClassMetadata>(); foreach (PersistentClass model in cfg.ClassMappings) @@ -198,6 +207,11 @@ IEntityPersister cp = PersisterFactory.CreateClassPersister(model, cache, this, mapping); entityPersisters[model.EntityName] = cp; classMeta[model.EntityName] = cp.ClassMetadata; + + if (model.HasPocoRepresentation) + { + implementorToEntityName[model.MappedClass] = model.EntityName; + } } classMetadata = new UnmodifiableDictionary<string, IClassMetadata>(classMeta); @@ -1125,5 +1139,15 @@ return null; } } + + #region NHibernate specific + public string TryGetGuessEntityName(System.Type implementor) + { + string result; + implementorToEntityName.TryGetValue(implementor, out result); + return result; + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2008-10-25 17:23:21 UTC (rev 3878) +++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2008-10-25 20:06:57 UTC (rev 3879) @@ -870,7 +870,8 @@ string entityName = interceptor.GetEntityName(entity); if (entityName == null) { - entityName = entity.GetType().FullName; + System.Type t = entity.GetType(); + entityName = Factory.TryGetGuessEntityName(t) ?? t.FullName; } return entityName; } Modified: trunk/nhibernate/src/NHibernate.Test/GenericTest/Overall/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GenericTest/Overall/Fixture.cs 2008-10-25 17:23:21 UTC (rev 3878) +++ trunk/nhibernate/src/NHibernate.Test/GenericTest/Overall/Fixture.cs 2008-10-25 20:06:57 UTC (rev 3879) @@ -27,14 +27,14 @@ using (ISession session = OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { - session.Save("AInt", entity); + session.Save(entity); transaction.Commit(); } using (ISession session = OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { - session.Delete("AInt", entity); + session.Delete(entity); transaction.Commit(); } } @@ -53,14 +53,14 @@ using (ISession session = OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { - session.Save("AB", entity); + session.Save(entity); transaction.Commit(); } using (ISession session = OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { - session.Delete("AB", entity); + session.Delete(entity); transaction.Commit(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |