public static void InitializeGlobalProperties(IHibernateConfiguration config) { GlobalProperties.Clear(); if (config != null) { HibernateConfiguration = config; GlobalProperties[PropertyBytecodeProvider] = config.ByteCodeProviderType; GlobalProperties[PropertyUseReflectionOptimizer] = config.UseReflectionOptimizer.ToString(); if (config.SessionFactory != null) { foreach (var kvp in config.SessionFactory.Properties) { GlobalProperties[kvp.Key] = kvp.Value; } } } else { GlobalProperties[PropertyUseReflectionOptimizer] = bool.TrueString; } VerifyProperties(GlobalProperties); BytecodeProviderInstance = BuildBytecodeProvider(GlobalProperties); EnableReflectionOptimizer = PropertiesHelper.GetBoolean(PropertyUseReflectionOptimizer, GlobalProperties); if (EnableReflectionOptimizer) { log.Info("Using reflection optimizer"); } }
public void FromAppConfigTest() { IHibernateConfiguration hc = ConfigurationProvider.Current.GetConfiguration(); Assert.That(hc.ByteCodeProviderType, Is.EqualTo("lcg")); Assert.IsTrue(hc.UseReflectionOptimizer); Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name); }
public void FromAppConfigTest() { IHibernateConfiguration hc = ConfigurationManager.GetSection("hibernate-configuration") as IHibernateConfiguration; hc.ByteCodeProviderType.Should().Be("lcg"); Assert.IsTrue(hc.UseReflectionOptimizer); Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name); }
public void FromAppConfigTest() { Assume.That(TestsContext.ExecutingWithVsTest, Is.False); IHibernateConfiguration hc = ConfigurationManager.GetSection("hibernate-configuration") as IHibernateConfiguration; Assert.That(hc.ByteCodeProviderType, Is.EqualTo("lcg")); Assert.IsTrue(hc.UseReflectionOptimizer); Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name); }
public void IgnoreSystemOutOfAppConfig() { IHibernateConfiguration hc = ConfigurationProvider.Current.GetConfiguration(); string xml = @"<?xml version='1.0' encoding='utf-8' ?> <hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'> <bytecode-provider type='lcg'/> <reflection-optimizer use='false'/> <session-factory name='MyFactoryName'> </session-factory> </hibernate-configuration>"; XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null); HibernateConfiguration newhc = new HibernateConfiguration(xtr); Assert.AreEqual(hc.ByteCodeProviderType, newhc.ByteCodeProviderType); Assert.AreEqual(hc.UseReflectionOptimizer, newhc.UseReflectionOptimizer); }
/// <summary> /// /// </summary> /// <param name="sessionFactoryConfigPath"></param> /// <returns></returns> protected virtual Configuration BuildConfig(string sessionFactoryConfigPath) { Configuration cfg = LoadConfigurationFromCache(sessionFactoryConfigPath); if (cfg == null) { cfg = new Configuration(); if (string.IsNullOrEmpty(cfg.GetProperty("connection.provider"))) { SetDefaultProperties(cfg); } //if (sessionFactoryConfigPath == s_emptySessionFactoryConfigPath) //{ // AddDefaultMappings(cfg); //} //else { if (sessionFactoryConfigPath == s_appSessionFactoryConfigPath) { IHibernateConfiguration section = System.Configuration.ConfigurationManager.GetSection("hibernate-configuration") as IHibernateConfiguration; if (section != null) { cfg.Configure(); } } else { cfg.Configure(ServiceProvider.GetService <IApplicationDirectory>().GetFullPath(sessionFactoryConfigPath)); } //AddMappings(sessionFactoryConfigPath, cfg); AddDefaultMappings(cfg); } SaveConfigurationToCache(sessionFactoryConfigPath, cfg); } m_configurations[sessionFactoryConfigPath] = cfg; cfg.SetProperty("Name", sessionFactoryConfigPath); return(cfg); }
public void IgnoreSystemOutOfAppConfig() { Assume.That(TestsContext.ExecutingWithVsTest, Is.False); IHibernateConfiguration hc = ConfigurationManager.GetSection("hibernate-configuration") as IHibernateConfiguration; string xml = @"<?xml version='1.0' encoding='utf-8' ?> <hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'> <bytecode-provider type='lcg'/> <reflection-optimizer use='false'/> <session-factory name='MyFactoryName'> </session-factory> </hibernate-configuration>"; XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null); HibernateConfiguration newhc = new HibernateConfiguration(xtr); Assert.AreEqual(hc.ByteCodeProviderType, newhc.ByteCodeProviderType); Assert.AreEqual(hc.UseReflectionOptimizer, newhc.UseReflectionOptimizer); }
// Not ported - configure(org.w3c.dom.Document) protected Configuration DoConfigure(IHibernateConfiguration hc) { if (!string.IsNullOrEmpty(hc.SessionFactory.Name)) { properties[Environment.SessionFactoryName] = hc.SessionFactory.Name; } AddProperties(hc); // Load mappings foreach (MappingConfiguration mc in hc.SessionFactory.Mappings) { if (mc.IsEmpty()) throw new HibernateConfigException("<mapping> element in configuration specifies no attributes"); if (!string.IsNullOrEmpty(mc.Resource)) { log.Debug(hc.SessionFactory.Name + "<-" + mc.Resource + " in " + mc.Assembly); AddResource(mc.Resource, Assembly.Load(mc.Assembly)); } else if (!string.IsNullOrEmpty(mc.Assembly)) { log.Debug(hc.SessionFactory.Name + "<-" + mc.Assembly); AddAssembly(mc.Assembly); } else if (!string.IsNullOrEmpty(mc.File)) { log.Debug(hc.SessionFactory.Name + "<-" + mc.File); AddFile(mc.File); } } // Load class-cache foreach (ClassCacheConfiguration ccc in hc.SessionFactory.ClassesCache) { System.Type clazz; try { clazz = ReflectHelper.ClassForName(ccc.Class); } catch (TypeLoadException tle) { throw new HibernateConfigException("class-cache Configuration: Could not find class " + ccc.Class, tle); } string region = string.IsNullOrEmpty(ccc.Region) ? ccc.Class : ccc.Region; bool includeLazy = (ccc.Include != ClassCacheInclude.NonLazy); SetCacheConcurrencyStrategy(clazz, CfgXmlHelper.ClassCacheUsageConvertToString(ccc.Usage), region, includeLazy); } // Load collection-cache foreach (CollectionCacheConfiguration ccc in hc.SessionFactory.CollectionsCache) { string role = ccc.Collection; NHibernate.Mapping.Collection collection = GetCollectionMapping(role); if (collection == null) { throw new HibernateConfigException("collection-cache Configuration: Cannot configure cache for unknown collection role " + role); } string region = string.IsNullOrEmpty(ccc.Region) ? role : ccc.Region; SetCacheConcurrencyStrategy(role, CfgXmlHelper.ClassCacheUsageConvertToString(ccc.Usage), region); } // Events foreach (EventConfiguration ec in hc.SessionFactory.Events) { string[] listenerClasses = new string[ec.Listeners.Count]; for (int i = 0; i < ec.Listeners.Count; i++) { listenerClasses[i] = ec.Listeners[i].Class; } log.Debug("Event listeners: " + ec.Type + "=" + StringHelper.ToString(listenerClasses)); SetListeners(ec.Type, listenerClasses); } // Listeners foreach (ListenerConfiguration lc in hc.SessionFactory.Listeners) { log.Debug("Event listener: " + lc.Type + "=" + lc.Class); SetListeners(lc.Type, new string[] { lc.Class }); } if (!string.IsNullOrEmpty(hc.SessionFactory.Name)) { log.Info("Configured SessionFactory: " + hc.SessionFactory.Name); } log.Debug("properties: " + properties); return this; }
private void AddProperties(IHibernateConfiguration hc) { foreach (KeyValuePair<string, string> kvp in hc.SessionFactory.Properties) { if (log.IsDebugEnabled) { log.Debug(kvp.Key + "=" + kvp.Value); } properties[kvp.Key] = kvp.Value; } Environment.VerifyProperties(properties); }