/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="query"></param> public void AddSQLQuery(string name, NamedSQLQuery query) { CheckQueryExists(name); sqlqueries[name] = query; }
/// <summary> /// /// </summary> /// <param name="cfg"></param> /// <param name="settings"></param> public SessionFactoryImpl(Configuration cfg, Settings settings) { log.Info("building session factory"); this.properties = cfg.Properties; this.interceptor = cfg.Interceptor; this.settings = settings; if (log.IsDebugEnabled) { log.Debug("instantiating session factory with properties: " + CollectionPrinter.ToString(properties)); } // Persisters: classPersisters = new Hashtable(); classPersistersByName = new Hashtable(); IDictionary classMeta = new Hashtable(); foreach (PersistentClass model in cfg.ClassMappings) { IClassPersister cp = PersisterFactory.CreateClassPersister(model, this); classPersisters[model.MappedClass] = 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.MappedClass.AssemblyQualifiedName] = cp; classMeta[model.MappedClass] = cp.ClassMetadata; } classMetadata = new Hashtable(classMeta); collectionPersisters = new Hashtable(); foreach (Mapping.Collection map in cfg.CollectionMappings) { collectionPersisters[map.Role] = PersisterFactory .CreateCollectionPersister(map, this) .CollectionMetadata; } collectionMetadata = new Hashtable(collectionPersisters); // after *all* persisters are registered foreach (IClassPersister persister in classPersisters.Values) { // TODO: H2.1 doesn't pass this to PostInstantiate persister.PostInstantiate(this); } //TODO: // For databinding: //templates = XMLDatabinder.GetOutputStyleSheetTemplates( properties ); // serialization info name = settings.SessionFactoryName; try { uuid = ( string )UuidGenerator.Generate(null, null); } catch (Exception) { throw new AssertionFailure("could not generate UUID"); } SessionFactoryObjectFactory.AddInstance(uuid, name, this, properties); // Named queries: // TODO: precompile and cache named queries namedQueries = new Hashtable(cfg.NamedQueries); namedSqlQueries = new Hashtable(cfg.NamedSQLQueries.Count); foreach (DictionaryEntry de in cfg.NamedSQLQueries) { NamedSQLQuery nsq = ( NamedSQLQuery )de.Value; namedSqlQueries[de.Key] = new InternalNamedSQLQuery(nsq.QueryString, nsq.ReturnAliases, nsq.ReturnClasses, nsq.SynchronizedTables); } imports = new Hashtable(cfg.Imports); log.Debug("Instantiated session factory"); if (settings.IsAutoCreateSchema) { new SchemaExport(cfg).Create(false, true); } /* * if ( settings.IsAutoUpdateSchema ) * { * new SchemaUpdate( cfg ).Execute( false, true ); * } */ if (settings.IsAutoDropSchema) { schemaExport = new SchemaExport(cfg); } // Obtaining TransactionManager - not ported from H2.1 if (settings.IsQueryCacheEnabled) { updateTimestampsCache = new UpdateTimestampsCache(settings.CacheProvider, properties); queryCache = settings.QueryCacheFactory .GetQueryCache(null, settings.CacheProvider, updateTimestampsCache, properties); queryCaches = Hashtable.Synchronized(new Hashtable()); } else { updateTimestampsCache = null; queryCache = null; queryCaches = null; } }