Beispiel #1
0
        public static Configuration Init(
            ISessionStorage storage,
            string cfgFile,
            IDictionary <string, string> cfgProperties,
            string validatorCfgFile,
            params HbmMapping[] mapping)
        {
            NHibernateSession.InitStorage(storage);
            var config = new Configuration();

            if (cfgProperties != null)
            {
                config.AddProperties(cfgProperties);
            }

            if (string.IsNullOrEmpty(cfgFile) == false)
            {
                config.Configure(cfgFile);
            }
            else
            {
                config.Configure();
            }

            foreach (var map in mapping)
            {
                config.AddDeserializedMapping(map, null);
            }

            return(NHibernateSession.AddConfiguration(NHibernateSession.DefaultFactoryKey, config.BuildSessionFactory(), config, validatorCfgFile));
        }
Beispiel #2
0
        public static Configuration AddConfiguration(string factoryKey, string[] mappingAssemblies, string cfgFile, IDictionary <string, string> cfgProperties, string validatorCfgFile)
        {
            Configuration config;
            var           configCache = NHibernateSession.ConfigurationCache;

            if (configCache != null)
            {
                config = configCache.LoadConfiguration(factoryKey, cfgFile, mappingAssemblies);
                if (config != null)
                {
                    var sessionFactory = config.BuildSessionFactory();
                    SessionFactories.Add(factoryKey, sessionFactory);
                    return(NHibernateSession.AddConfiguration(factoryKey, sessionFactory, config, validatorCfgFile));
                }
            }

            config = AddConfiguration(factoryKey, mappingAssemblies,
                                      ConfigureNHibernate(cfgFile, cfgProperties),
                                      validatorCfgFile);

            if (configCache != null)
            {
                configCache.SaveConfiguration(factoryKey, config);
            }

            return(config);
        }
Beispiel #3
0
 /// <summary>
 /// If you need to communicate to multiple databases, you'd add a line to this method to
 /// initialize the other database as well.
 /// </summary>
 private void InitializeNHibernateSession()
 {
     NHibernateSession.Init(
         this.webSessionStorage,
         new[] { this.Server.MapPath("~/bin/Store.Data.dll") },
         new AutoPersistenceModelGenerator().Generate());
     NHibernate.Cfg.Configuration cfg = ConfigureAccountDB(Server.MapPath("~/Web.config"), "hibernate-account-configuration");
     NHibernateSession.AddConfiguration(Store.Data.DataGlobals.ACCOUNT_DB_FACTORY_KEY, new string[] { Server.MapPath("~/bin/Store.Data.Account.dll") }, null, cfg, "", null);
     NHibernateSession.RegisterInterceptor(new AuditInterceptor());
 }
        public virtual void SetUp()
        {
            string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
            _configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                                    "../../../../app/wrms.Web/NHibernate.config");

            NHibernateSession.AddConfiguration(DataGlobals.SDE_DB_FACTORY_KEY,
                                               mappingAssemblies,
                                               null,
                                               "../../../../app/wrms.Web/NHibernateSde.config", null, null, null);
        }
Beispiel #5
0
        public static Configuration AddConfiguration(string factoryKey, string[] mappingAssemblies, Configuration cfg, string validatorCfgFile)
        {
            var sessionFactory = CreateSessionFactoryFor(mappingAssemblies, cfg);

            Check.Require(
                !SessionFactories.ContainsKey(factoryKey),
                "A session factory has already been configured with the key of " + factoryKey);
            SessionFactories.Add(factoryKey, sessionFactory);

            return(NHibernateSession.AddConfiguration(factoryKey, sessionFactory, cfg, validatorCfgFile));
        }
        public void CanInitializeWithConfigFileAndConfigurationFileCacheAndSecondDatabaseConfiguration()
        {
            var configFile        = "sqlite-nhibernate-config.xml";
            var mappingAssemblies = new string[] { };

            NHibernateSession.ConfigurationCache = new NHibernateConfigurationFileCache(new[] { "SharpArch.NHibernate" });
            var configuration1 = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies, configFile);
            var configuration2 = NHibernateSession.AddConfiguration(
                "secondDatabase", new string[] { }, null, configFile, null, null, null);

            Assert.That(configuration1, Is.Not.Null);
            Assert.That(configuration2, Is.Not.Null);
        }
Beispiel #7
0
        /// <summary>
        /// If you need to communicate to multiple databases, you'd add a line to this method to
        /// initialize the other database as well.
        /// </summary>
        private void InitializeNHibernateSession()
        {
            NHibernateSession.Init(
                _webSessionStorage,
                new[] { Server.MapPath("~/bin/wrms.Data.dll") },
                Server.MapPath("~/NHibernate.config"));
            //Add Sde connection
            NHibernateSession.AddConfiguration(DataGlobals.SDE_DB_FACTORY_KEY,
                                               new[] { Server.MapPath("~/bin/wrms.Data.dll") },
                                               null,
                                               Server.MapPath("~/NHibernateSde.config"), null, null, null);

            //new AutoPersistenceModelGenerator().Generate(),
        }
        /// <summary>
        /// Initializes the multi tenant NHibernate session.
        /// </summary>
        /// <param name="mappingAssemblies">The mapping assemblies.</param>
        /// <param name="configFile">The tenant config file.</param>
        /// <param name="tenant">The tenant.</param>
        private static void InitializeMultiTenantNHibernateSession(string[] mappingAssemblies, string configFile, Tenant tenant)
        {
            var configProperties = new Dictionary <string, string>
            {
                { "connection.connection_string", tenant.ConnectionString }
            };

            NHibernateSession.AddConfiguration(tenant.Domain,
                                               mappingAssemblies,
                                               new MultiTenantAutoPersistenceModelGenerator().Generate(),
                                               configFile,
                                               configProperties,
                                               null, null);
        }
        public virtual void SetUp()
        {
            ServiceLocatorInitializer.Init();

            string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
            _configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                                    "../../../../app/wrms.Web/NHibernate.config");

            NHibernateSession.AddConfiguration(DataGlobals.SDE_DB_FACTORY_KEY,
                                               mappingAssemblies,
                                               null,
                                               "../../../../app/wrms.Web/NHibernateSde.config", null, null, null);


            _workOrderRepository = new SdeWorkOrderRepository();
            //_requestRepository = new RequestRepository();
            //_wrmsSystemRepository = new WrmsSystemRepository();
        }