Esempio n. 1
0
 public void Configure(Configuration configuration)
 {
     configuration.SetProperty(DriverKey, this.driverType.AssemblyQualifiedName);
     configuration.SetProperty(DialectKey, this.dialectType.AssemblyQualifiedName);
     configuration.SetProperty(ConnectionStringKey, this.connectionString);
     configuration.SetProperty(DefaultSchemaKey, "dbo");
     configuration.SetProperty(UseReflectionOptimizerKey, "true");
 }
            public MyEndpoint()
            {
                EndpointSetup <DefaultServer>(c =>
                {
                    var cfg = new NHibernate.Cfg.Configuration();
                    cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, typeof(NHibernate.Dialect.MsSql2012Dialect).FullName);
                    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, typeof(NHibernate.Driver.Sql2008ClientDriver).FullName);
                    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @"Server=localhost\sqlexpress;Database=nservicebus;Trusted_Connection=True;");

                    c.UsePersistence <NHibernatePersistence>().UseConfiguration(cfg);
                });
            }
Esempio n. 3
0
        private static void BuildSchema(global::NHibernate.Cfg.Configuration config)
        {
            config.SetProperty(global::NHibernate.Cfg.Environment.CurrentSessionContextClass, "web");

            // this NHibernate tool takes a configuration (with mapping info in)
            // and exports a database schema from it
            new SchemaExport(config).Create(false, true);
        }
        private static global::NHibernate.Cfg.Configuration BuildConfiguration(Action <IDbIntegrationConfigurationProperties> configureAction)
        {
            var cfg = new global::NHibernate.Cfg.Configuration();

            cfg.DataBaseIntegration(db =>
            {
                configureAction(db);
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                db.IsolationLevel     = IsolationLevel.ReadCommitted;
            });

            cfg.SetProperty("hbm2ddl.auto", "create");

            return(cfg.AddConfigurationMappings());
        }
Esempio n. 5
0
        internal ISessionFactory CreateSessionFactory()
        {
            var cfg = new global::NHibernate.Cfg.Configuration().DataBaseIntegration(x =>
            {
                x.ConnectionString = connectionString;
                x.Driver <OracleManagedDataClientDriver>();
                x.Dialect <Oracle10gDialect>();
                x.LogSqlInConsole = true;
            });

            var mapper = new ModelMapper();

            mapper.AddMapping <TimeoutEntityMap>();
            mapper.AddMapping <StagedTimeoutEntityMap>();

            HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            cfg.AddMapping(mapping);
            cfg.SetProperty("hbm2ddl.auto", "update"); // creates the schema, destroying previous data

            return(cfg.BuildSessionFactory());
        }
Esempio n. 6
0
 public static global::NHibernate.Cfg.Configuration AutoQuote(this global::NHibernate.Cfg.Configuration configuration)
 {
     configuration.SetProperty("hbm2ddl.keywords", "auto-quote");
     return(configuration);
 }
Esempio n. 7
0
 public static global::NHibernate.Cfg.Configuration CommandTimeout(this global::NHibernate.Cfg.Configuration configuration, int seconds)
 {
     configuration.SetProperty("command_timeout", seconds.ToString());
     return(configuration);
 }
        private ISessionFactory GenerateNHibernateSessionFactory()
        {
            var sw = Stopwatch.StartNew();

            ForceLoadObjectModel(); // This is needed for "new Configuration()".
            var configuration = new global::NHibernate.Cfg.Configuration();
            configuration.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
            configuration.SetProperty("connection.connection_string", _connectionString);

            // Set factory-level property:
            configuration.SetProperty("command_timeout", SqlUtility.SqlCommandTimeout.ToString());
            // Set system-level property:
            // Note: Using NHibernate.Cfg.Environment.Properties does not allow setting properties becase the public property returns a copy of the dictionary.
            var globalPropertiesField = typeof(global::NHibernate.Cfg.Environment).GetField("GlobalProperties", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            var globalProperties = (Dictionary<string, string>)globalPropertiesField.GetValue(null);
            globalProperties.Add("command_timeout", SqlUtility.SqlCommandTimeout.ToString());

            if (SqlUtility.DatabaseLanguage == "MsSql")
            {
                configuration.SetProperty("dialect", "NHibernate.Dialect.MsSql2005Dialect");
                configuration.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
            }
            else if (SqlUtility.DatabaseLanguage == "Oracle")
            {
                configuration.SetProperty("dialect", "NHibernate.Dialect.Oracle10gDialect");
                configuration.SetProperty("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
            }
            else
                throw new FrameworkException(DatabaseLanguageError);

            ResolveEventHandler resolveAssembly = (s, args) => _domainObjectModel.Assembly;
            try
            {
                AppDomain.CurrentDomain.AssemblyResolve += resolveAssembly;
                configuration.AddXmlString(_nHibernateMapping.GetMapping());
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= resolveAssembly;
            }

            foreach (var configurationExtension in _nHibernateConfigurationExtensions)
                configurationExtension.ExtendConfiguration(configuration);

            SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
            var sessionFactory = configuration.BuildSessionFactory();

            _performanceLogger.Write(sw, "NHibernatePersistenceEngine.PrepareNHSessionFactory");
            return sessionFactory;
        }
 /// <summary> Reconfigures NHibernate config before it has been used by specifying connection string and command timeout
 /// </summary>
 /// <param name="config">NHibernate configuration</param>
 protected override void Reconfigure(ref global::NHibernate.Cfg.Configuration config)
 {
     config.SetProperty("connection.connection_string", _connectionString);
     config.SetProperty("command_timeout", _commandTimeout.ToString());
 }