From: Michael D. <mik...@us...> - 2004-08-16 05:09:49
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30647/Impl Modified Files: SessionFactoryImpl.cs Log Message: Modified the contents of the classPersistersByName to have both the FullClassname and AssemblyQualifiedName. Implemented the FilterCacheKey and QueryCacheKey. Index: SessionFactoryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** SessionFactoryImpl.cs 14 Aug 2004 14:54:16 -0000 1.25 --- SessionFactoryImpl.cs 16 Aug 2004 05:09:30 -0000 1.26 *************** *** 190,194 **** --- 190,204 ---- cp = PersisterFactory.Create(model, this); classPersisters[model.PersistentClazz] = cp; + + // Adds the "Namespace.ClassName" (FullClassname) as a lookup to get to the Persiter. + // Most of the internals of NHibernate use this method to get to the Persister since + // Model.Name is used in so many places. It would be nice to fix it up to be Model.TypeName + // instead of just FullClassname classPersistersByName[model.Name] = cp ; + + // Add in the AssemblyQualifiedName (includes version) as a lookup to get to the Persister. + // In HQL the Imports are used to get from the Classname to the Persister. The + // Imports provide the ability to jump from the Classname to the AssemblyQualifiedName. + classPersistersByName[model.PersistentClazz.AssemblyQualifiedName] = cp; } *************** *** 241,273 **** [NonSerialized] private readonly IDictionary softQueryCache = new Hashtable(); //TODO: make soft reference map ! //TODO: All ! private static readonly QueryCacheKeyFactory QueryKeyFactory; ! private static readonly FilterCacheKeyFactory FilterKeyFactory; static SessionFactoryImpl() { ! /* ! * KeyFactory is a CGLIB item. ! QueryKeyFactory = (QueryCacheKeyFactory) KeyFactory.Create(QueryCacheKeyFactory.GetType(), QueryCacheKeyFactory......); ! FilterKeyFactory = (FilterCacheKeyFactory) KeyFactory.Create( ! FilterCacheKeyFactory.class, FilterCacheKeyFactory.class.getClassLoader() ); ! */ ! ! QueryKeyFactory = null; ! FilterKeyFactory = null; } ! ! interface QueryCacheKeyFactory { ! // will not recalculate hashKey for constant queries ! object NewInstance(string query, bool scalar); } ! interface FilterCacheKeyFactory { ! // will not recalculate hashKey for constant queries ! object NewInstance(string role, string query, bool scalar); } [MethodImpl(MethodImplOptions.Synchronized)] --- 251,374 ---- [NonSerialized] private readonly IDictionary softQueryCache = new Hashtable(); //TODO: make soft reference map ! static SessionFactoryImpl() { ! // used to do some CGLIB stuff in here for QueryKeyFactory and FilterKeyFactory } ! /// <summary> ! /// A class that can be used as a Key in a Hashtable for ! /// a Query Cache. ! /// </summary> ! private class QueryCacheKey { ! private string _query; ! private bool _scalar; ! ! internal QueryCacheKey(string query, bool scalar) ! { ! _query = query; ! _scalar = scalar; ! } ! ! public string Query ! { ! get { return _query; } ! } ! ! public bool Scalar ! { ! get { return _scalar; } ! } ! ! #region System.Object Members ! ! public override bool Equals(object obj) ! { ! QueryCacheKey other = obj as QueryCacheKey; ! if( other==null) return false; ! ! return Equals(other); ! } ! ! public bool Equals(QueryCacheKey obj) ! { ! return this.Query.Equals(obj.Query) && this.Scalar==obj.Scalar; ! } ! ! public override int GetHashCode() ! { ! unchecked ! { ! return this.Query.GetHashCode() + this.Scalar.GetHashCode(); ! } ! } ! ! #endregion ! ! } ! /// <summary> ! /// A class that can be used as a Key in a Hashtable for ! /// a Query Cache. ! /// </summary> ! private class FilterCacheKey { ! private string _role; ! private string _query; ! private bool _scalar; ! ! internal FilterCacheKey(string role, string query, bool scalar) ! { ! _role = role; ! _query = query; ! _scalar = scalar; ! } ! ! public string Role ! { ! get { return _role; } ! } ! ! public string Query ! { ! get { return _query; } ! } ! ! public bool Scalar ! { ! get { return _scalar; } ! } ! ! #region System.Object Members ! ! public override bool Equals(object obj) ! { ! FilterCacheKey other = obj as FilterCacheKey; ! if( other==null) return false; ! ! return Equals(other); ! } ! ! public bool Equals(FilterCacheKey obj) ! { ! return this.Role.Equals(obj.Role) && this.Query.Equals(obj.Query) && this.Scalar==obj.Scalar; ! } ! ! public override int GetHashCode() ! { ! unchecked ! { ! return this.Role.GetHashCode() + this.Query.GetHashCode() + this.Scalar.GetHashCode(); ! } ! } ! ! #endregion ! ! } + [MethodImpl(MethodImplOptions.Synchronized)] *************** *** 304,311 **** } - //TODO: h2.0.3 synch private QueryTranslator GetQuery(string query, bool shallow) { ! /*object cacheKey = QueryKeyFactory.NewInstance(query, shallow); // have to be careful to ensure that if the JVM does out-of-order execution --- 405,411 ---- } private QueryTranslator GetQuery(string query, bool shallow) { ! QueryCacheKey cacheKey = new QueryCacheKey(query, shallow); // have to be careful to ensure that if the JVM does out-of-order execution *************** *** 315,324 **** QueryTranslator q = (QueryTranslator) Get(cacheKey); ! if ( q==null) { ! q = new QueryTranslator(); Put(cacheKey, q); } ! */ ! QueryTranslator q = new QueryTranslator(dialect); q.Compile(this, query, querySubstitutions, shallow); --- 415,424 ---- QueryTranslator q = (QueryTranslator) Get(cacheKey); ! if ( q==null) ! { ! q = new QueryTranslator(dialect); Put(cacheKey, q); } ! q.Compile(this, query, querySubstitutions, shallow); *************** *** 328,340 **** public FilterTranslator GetFilter(string query, string collectionRole, bool scalar) { ! // object cacheKey = FilterKeyFactory.NewInstance(collectionRole, query, scalar ); ! // ! // FilterTranslator q = (FilterTranslator) Get(cacheKey); ! // if ( q==null ) ! // { ! // q = new FilterTranslator(dialect); ! // Put(cacheKey, q); ! // } ! FilterTranslator q = new FilterTranslator(dialect); q.Compile(collectionRole, this, query, querySubstitutions, scalar); --- 428,440 ---- public FilterTranslator GetFilter(string query, string collectionRole, bool scalar) { ! FilterCacheKey cacheKey = new FilterCacheKey( collectionRole, query, scalar ); ! ! FilterTranslator q = (FilterTranslator) Get(cacheKey); ! if ( q==null ) ! { ! q = new FilterTranslator(dialect); ! Put(cacheKey, q); ! } ! q.Compile(collectionRole, this, query, querySubstitutions, scalar); *************** *** 397,401 **** //(IClassPersister) was replaced by as IClassPersister result = classPersistersByName[className] as IClassPersister; ! //if ( result==null) throw new MappingException( "No persister for: " + className ); return result; } --- 497,503 ---- //(IClassPersister) was replaced by as IClassPersister result = classPersistersByName[className] as IClassPersister; ! //TODO: not throwing this exception results in a 50% perf gain with hql - not sure ! // where else this code is being used and expecting an exception... ! // if ( result==null) throw new MappingException( "No persister for: " + className ); return result; } |