Database configuration section for nhibernate database connection.
Inheritance: N2.Configuration.ContentConfigurationSectionBase
Example #1
0
        public IndexerServer(DatabaseSection config)
        {
            if (config == null)
                config = new DatabaseSection();

            Init(config.Search.Server.UrlPrefix, config.Search.Server.SharedSecret, config.Search.IndexPath);
        }
Example #2
0
		public SessionProvider(IConfigurationBuilder builder, NHInterceptorFactory interceptorFactory, IWebContext webContext, DatabaseSection config)
		{
			nhSessionFactory = builder.BuildSessionFactory();
			this.webContext = webContext;
			this.interceptorFactory = interceptorFactory;
			this.isolation = config.Isolation;
		}
 public SearchConfigurationBuilderParticipator(IWebContext webContext, DatabaseSection config)
 {
     this.webContext = webContext;
     searchEnabled = config.Search.Enabled;
     asyncIndexing = config.Search.AsyncIndexing;
     indexPath = config.Search.IndexPath;
 }
Example #4
0
		public IndexerClient(DatabaseSection config)
		{
			serverUrl = config.Search.Client.Url;
			timeout = config.Search.Client.IndexTimeout;
			sharedSecret = config.Search.Client.SharedSecret;
			instanceName = config.Search.Client.InstanceName;
		}
        public ContentChangeTracker(IAsyncIndexer indexer, IPersister persister, ConnectionMonitor connection, DatabaseSection config)
        {
            this.indexer = indexer;

            if (!config.Search.Enabled)
                return;
            if (!string.IsNullOrEmpty(config.Search.IndexOnMachineNamed) && config.Search.IndexOnMachineNamed != Environment.MachineName)
                return;

            connection.Online += delegate
            {
                IsMonitoring = true;
                persister.ItemSaved += persister_ItemSaved;
                persister.ItemMoving += persister_ItemMoving;
                persister.ItemMoved += persister_ItemMoved;
                persister.ItemCopied += persister_ItemCopied;
                persister.ItemDeleted += persister_ItemDeleted;
            };
            connection.Offline += delegate
            {
                IsMonitoring = false;
                persister.ItemSaved -= persister_ItemSaved;
                persister.ItemMoving -= persister_ItemMoving;
                persister.ItemMoved -= persister_ItemMoved;
                persister.ItemCopied -= persister_ItemCopied;
                persister.ItemDeleted -= persister_ItemDeleted;
            };
        }
        public DiagnosticController(IContentItemRepository repository, IHost host, IDefinitionManager definitions,
            ILinkGenerator linkGenerator, IUrlParser parser, DatabaseSection config, IFlushable flushable, IReplicationStorage repstore, 
            IFileSystemFactory fileSystemFactory)
        {
            _repository = repository;
            _host = host;
            _definitions = definitions;
            _linkGenerator = linkGenerator;
            _parser = parser;
            _flushable = flushable;
            _tablePrefix = config.TablePrefix;

            _repstore = repstore;

            if (_forceWriteLockManager != null) return;

            // Create Force Write Lock Manager
            var storageConfig = (FileSystemNamespace) Enum.Parse(typeof (FileSystemNamespace),
                ConfigurationManager.AppSettings["AzureReplicationStorageContainerName"] ??
                "ReplicationStorageDebug");

            var fileSystem = fileSystemFactory.Create(storageConfig);
            _forceWriteLockManager = new ReplicationForceWriteLockManager(fileSystem);
            _writeLockManager = new ReplicationWriteLockManager(fileSystem);
        }
		private void SetupMappings(DatabaseSection config)
		{
			foreach (MappingElement me in config.Mappings)
			{
				mappingNames.Add(me.Name);
			}
		}
Example #8
0
        public ContentChangeTracker(IIndexer indexer, IPersister persister, IWorker worker, ConnectionMonitor connection, IErrorNotifier errors, DatabaseSection config)
        {
            this.indexer = indexer;
            this.persister = persister;
            this.worker = worker;
            this.errors = errors;
            this.async = config.Search.AsyncIndexing;
            this.handleErrors = config.Search.HandleErrors;

            RetryInterval = TimeSpan.FromMinutes(2);

            if(config.Search.Enabled)
            {
                connection.Online += delegate
                {
                    persister.ItemSaved += persister_ItemSaved;
                    persister.ItemMoving += persister_ItemMoving;
                    persister.ItemMoved += persister_ItemMoved;
                    persister.ItemCopied += persister_ItemCopied;
                    persister.ItemDeleted += persister_ItemDeleted;
                };
                connection.Offline += delegate
                {
                    persister.ItemSaved -= persister_ItemSaved;
                    persister.ItemMoving -= persister_ItemMoving;
                    persister.ItemMoved -= persister_ItemMoved;
                    persister.ItemCopied -= persister_ItemCopied;
                    persister.ItemDeleted -= persister_ItemDeleted;
                };
            }
        }
		/// <summary>Sets properties configuration dictionary based on configuration in the database section.</summary>
		/// <param name="config">The database section configuration.</param>
		/// <param name="connectionStrings">Connection strings from configuration</param>
		protected void SetupProperties(DatabaseSection config, ConnectionStringsSection connectionStrings)
		{
			NHibernate.Cfg.Environment.UseReflectionOptimizer = Utility.GetTrustLevel() > System.Web.AspNetHostingPermissionLevel.Medium;

			// connection

			Properties[NHibernate.Cfg.Environment.ConnectionStringName] = config.ConnectionStringName;
			Properties[NHibernate.Cfg.Environment.ConnectionProvider] = "NHibernate.Connection.DriverConnectionProvider";
			Properties[NHibernate.Cfg.Environment.Hbm2ddlKeyWords] = "none";

			SetupFlavourProperties(config, connectionStrings);

			bool useNonBatcher = 
				// configured batch size <= 1
				(batchSize.HasValue && batchSize.Value <= 1)
				// medium trust in combination with sql client driver 
				// causes fault: Attempt by method 'NHibernate.AdoNet.SqlClientSqlCommandSet..ctor()' to access method 'System.Data.SqlClient.SqlCommandSet..ctor()' failed.   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
				|| (Utility.GetTrustLevel() <= System.Web.AspNetHostingPermissionLevel.Medium && typeof(SqlClientDriver).IsAssignableFrom(Type.GetType(Properties[Environment.ConnectionDriver])));
			if (useNonBatcher)
				Properties[NHibernate.Cfg.Environment.BatchStrategy] = typeof(NonBatchingBatcherFactory).AssemblyQualifiedName;

			SetupCacheProperties(config);

			if (config.Isolation.HasValue)
				Properties[NHibernate.Cfg.Environment.Isolation] = config.Isolation.ToString();

			foreach (string key in config.HibernateProperties.AllKeys)
			{
				Properties[key] = config.HibernateProperties[key].Value;
			}
		}
Example #10
0
		public SessionProvider(IConfigurationBuilder builder, NHInterceptorFactory interceptorFactory, IWebContext webContext, DatabaseSection config)
		{
			nhSessionFactory = builder.BuildSessionFactory();
			this.webContext = webContext;
			this.interceptorFactory = interceptorFactory;
			this.isolation = config.Isolation;
			this.autoStartTransaction = config.AutoStartTransaction;
			this.CacheEnabled = config.Caching;
		}
Example #11
0
        public AsyncIndexer(IContentIndexer indexer, IPersister persister, IWorker worker, IErrorNotifier errors, DatabaseSection config)
        {
            RetryInterval = TimeSpan.FromMinutes(2);
            this.async = config.Search.AsyncIndexing;
            this.handleErrors = config.Search.HandleErrors;

            this.indexer = indexer;
            this.persister = persister;
            this.worker = worker;
            this.errors = errors;
        }
        public AzureFileSystem(ISessionProvider sessionProvider, DatabaseSection config)
        {
            var storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

            this.container = storageAccount.CreateCloudBlobClient().GetContainerReference("le-upload");

            container.CreateIfNotExists();
            container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });

            CreateDirectory("/upload/");
        }
 public ReplicationManager(
     IPersister persister,
     IItemFinder finder,
     IReplicationStorage repstore,
     IFileSystemFactory fileSystemFactory,
     DatabaseSection dataBaseSection,
     ISecurityManager security
 )
     : this(persister, finder, repstore, fileSystemFactory, dataBaseSection, security, null, null)
 {
     // needed to be able to execute N2 unit tests w/o additional dependecies
 }
Example #14
0
		public InstallationManager(IHost host, DefinitionMap map, ContentActivator activator, Importer importer, IPersister persister, ISessionProvider sessionProvider, IConfigurationBuilder configurationBuilder, IWebContext webContext, ConnectionMonitor connectionContext, DatabaseSection config)
		{
			this.host = host;
			this.map = map;
			this.activator = activator;
			this.importer = importer;
			this.persister = persister;
			this.sessionProvider = sessionProvider;
			this.configurationBuilder = configurationBuilder;
			this.webContext = webContext;
			this.connectionContext = connectionContext;
			this.isDatabaseFileSystemEnbled = config.Files.StorageLocation == FileStoreLocation.Database;
		}
Example #15
0
        /// <summary>Creates a new instance of the <see cref="ConfigurationBuilder"/>.</summary>
        public ConfigurationBuilder(IDefinitionProvider[] definitionProviders, ClassMappingGenerator generator, IWebContext webContext, ConfigurationBuilderParticipator[] participators, DatabaseSection config, ConnectionStringsSection connectionStrings)
        {
            this.definitionProviders = definitionProviders;
            this.generator = generator;
            this.webContext = webContext;
            this.participators = participators;

            if (config == null) config = new DatabaseSection();
            TryLocatingHbmResources = config.TryLocatingHbmResources;
            tablePrefix = config.TablePrefix;
            batchSize = config.BatchSize;
            childrenLaziness = config.ChildrenLaziness;

            SetupProperties(config, connectionStrings);
            SetupMappings(config);
        }
Example #16
0
        /// <summary>Creates a new instance of the <see cref="ConfigurationBuilder"/>.</summary>
        public ConfigurationBuilder(IDefinitionManager definitions, ClassMappingGenerator generator, DatabaseSection config, ConnectionStringsSection connectionStrings)
        {
            this.definitions = definitions;
            this.generator = generator;

            if (config == null) config = new DatabaseSection();

            if (!string.IsNullOrEmpty(config.HibernateMapping))
                DefaultMapping = config.HibernateMapping;

            SetupProperties(config, connectionStrings);
            SetupMappings(config);

            TryLocatingHbmResources = config.TryLocatingHbmResources;
            tablePrefix = config.TablePrefix;
            batchSize = config.BatchSize;
            childrenLaziness = config.ChildrenLaziness;
        }
        public ContentChangeTracker(IAsyncIndexer indexer, IPersister persister, ConnectionMonitor connection, DatabaseSection config)
        {
            this.indexer = indexer;

            if(config.Search.Enabled)
            {
                connection.Online += delegate
                {
                    persister.ItemSaved += persister_ItemSaved;
                    persister.ItemMoving += persister_ItemMoving;
                    persister.ItemMoved += persister_ItemMoved;
                    persister.ItemCopied += persister_ItemCopied;
                    persister.ItemDeleted += persister_ItemDeleted;
                };
                connection.Offline += delegate
                {
                    persister.ItemSaved -= persister_ItemSaved;
                    persister.ItemMoving -= persister_ItemMoving;
                    persister.ItemMoved -= persister_ItemMoved;
                    persister.ItemCopied -= persister_ItemCopied;
                    persister.ItemDeleted -= persister_ItemDeleted;
                };
            }
        }
 public FileConfigurationParticipator(DatabaseSection config)
 {
     tablePrefix = config.TablePrefix;
     chunkSize = config.Files.ChunkSize;
 }
Example #19
0
		public RavenStoreFactory(DatabaseSection config)
		{
			connectionStringName = config.ConnectionStringName;
			RunInMemory = config.Raven.RunInMemory;
			EmbeddedDocumentStore = config.Raven.EmbeddedDocumentStore;
		}
		private void SetupCacheProperties(DatabaseSection config)
		{
			Properties[NHibernate.Cfg.Environment.UseSecondLevelCache] = config.Caching.ToString();
			Properties[NHibernate.Cfg.Environment.UseQueryCache] = config.Caching.ToString();
			Properties[NHibernate.Cfg.Environment.CacheProvider] = config.CacheProviderClass;
		}
		/// <summary>
		/// Configures the properties of each supported database flavor. You need to extend this method if you want to 
		/// add your own database flavor. 
		/// </summary>
		/// <param name="config"></param>
		/// <param name="connectionStrings"></param>
		/// <returns></returns>
		private DatabaseFlavour SetupFlavourProperties(DatabaseSection config, ConnectionStringsSection connectionStrings)
		{
			DatabaseFlavour flavour = config.Flavour;
			if (flavour == DatabaseFlavour.AutoDetect)
			{
				ConnectionStringSettings css = connectionStrings.ConnectionStrings[config.ConnectionStringName];
				if (css == null)
					throw new ConfigurationErrorsException("Could not find the connection string named '" + config.ConnectionStringName + "' that was defined in the n2/database configuration section. If you installed using NuGet try installing 'N2 CMS SQLite config' or configuring this connection string manually.");
				flavour = DetectFlavor(css);
			}

			// HACK: used to support seamless text/nvarchar(max) support across databases
			if (flavour == DatabaseFlavour.MySql)
				stringLength = 16777215;

			switch (flavour)
			{
				case DatabaseFlavour.SqlServer2000:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2000Dialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.SqlServer2005:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2005Dialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.SqlServer:
				case DatabaseFlavour.SqlServer2008:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2008Dialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.SqlCe3:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSqlCeDialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.SqlCe:
				case DatabaseFlavour.SqlCe4:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSqlCe40Dialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.MySql:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.MySqlDataDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MySQL5Dialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.SqLite:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SQLite20Driver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.SQLiteDialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.Firebird:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.FirebirdDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.FirebirdDialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.Generic:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OleDbDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.GenericDialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.Jet:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.JetDriver.JetDriver, NHibernate.JetDriver";
					Properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.JetDriver.JetDialect, NHibernate.JetDriver";
					break;
				case DatabaseFlavour.DB2:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OdbcDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.DB2Dialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.Oracle9i:
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleClientDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.Oracle9iDialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.Oracle:
				case DatabaseFlavour.Oracle10g:
					// if you have OracleOdpDriver installed
					// use the following line instead of the the later one (NOTICE both apply to the same property)
					// Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleDataClientDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleClientDriver).AssemblyQualifiedName;
					Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.Oracle10gDialect).AssemblyQualifiedName;
					break;
				case DatabaseFlavour.MongoDB:
					return DatabaseFlavour.MongoDB;
				case DatabaseFlavour.Xml:
					return DatabaseFlavour.Xml;
				default:
					throw new ConfigurationErrorsException("Couldn't determine database flavour. Please check the 'flavour' attribute of the n2/database configuration section.");
			}
			return flavour;
		}
        public ReplicationManager(
            IPersister persister,
            IItemFinder finder,
            IReplicationStorage repstore,
            IFileSystemFactory fileSystemFactory,
            DatabaseSection dataBaseSection,
            ISecurityManager security,
            IIndexer indexer, // optional
            IFlushable flushable // optional
            )
        {
            _repstore = repstore;
            _security = security;
            _persister = persister;
            _finder = finder;
            _indexer = indexer;
            _flushable = flushable;

            // detect sync direction from Database Type and double check via config
            string value = ConfigurationManager.AppSettings["XmlReplication"] ?? "false";
            IsSlave = value.Equals("Slave", StringComparison.InvariantCultureIgnoreCase) & (dataBaseSection.Flavour == DatabaseFlavour.Xml);
            IsMaster = value.Equals("Master", StringComparison.InvariantCultureIgnoreCase) & !IsSlave;

            if (IsMaster || IsSlave)
            {
                // only initialize if replication is active
                var storageConfig = (FileSystemNamespace) Enum.Parse(typeof (FileSystemNamespace),
                               ConfigurationManager.AppSettings["AzureReplicationStorageContainerName"] ??
                               "ReplicationStorageDebug");

                _fileSystem = fileSystemFactory.Create(storageConfig);

                // constructing these dependencies to ensure same filesystem and simplify construction
                _replicationWriteLockManager = new ReplicationWriteLockManager(_fileSystem);
                _replicationReadLockManager = new ReplicationReadLockManager(_fileSystem);
            }
            _replicationLogPath = "/_Xml_Sync_Log";
        }
Example #23
0
 public DatabaseFileSystem(ISessionProvider sessionProvider, DatabaseSection config)
 {
     this._sessionProvider = sessionProvider;
     this.chunkSize = config.Files.ChunkSize;
 }
		public StatisticsTablesParticipator(DatabaseSection config)
        {
            tablePrefix = config.TablePrefix;
		}
Example #25
0
		public LuceneAccesor(IWebContext webContext, DatabaseSection config)
		{
			LockTimeout = 2000L;
			indexPath = Path.Combine(webContext.MapPath(config.Search.IndexPath), "Pages");
		}
        /// <summary>Sets properties configuration dictionary based on configuration in the database section.</summary>
        /// <param name="config">The database section configuration.</param>
        /// <param name="connectionStrings">Connection strings from configuration</param>
        protected void SetupProperties(DatabaseSection config, ConnectionStringsSection connectionStrings)
        {
            NHibernate.Cfg.Environment.UseReflectionOptimizer = Utility.GetTrustLevel() > System.Web.AspNetHostingPermissionLevel.Medium;
            Properties[NHibernate.Cfg.Environment.ProxyFactoryFactoryClass] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

            // connection

            Properties[NHibernate.Cfg.Environment.ConnectionStringName] = config.ConnectionStringName;
            Properties[NHibernate.Cfg.Environment.ConnectionProvider] = "NHibernate.Connection.DriverConnectionProvider";
            Properties[NHibernate.Cfg.Environment.Hbm2ddlKeyWords] = "none";

            SetupFlavourProperties(config, connectionStrings);

            SetupCacheProperties(config);

            // custom config properties

            foreach (string key in config.HibernateProperties.AllKeys)
            {
                Properties[key] = config.HibernateProperties[key].Value;
            }
        }
Example #27
0
		public RavenInstallationManager(IHost host, DefinitionMap map, ContentActivator activator, Importer importer, IPersister persister, ISessionProvider sessionProvider, IConfigurationBuilder configurationBuilder, IWebContext webContext, ConnectionMonitor connectionContext, DatabaseSection config, RavenConnectionProvider cp)
			: base(connectionContext, importer, webContext, persister, activator)
		{
			this.cp = cp;
		}
        private void SetupFlavourProperties(DatabaseSection config, ConnectionStringsSection connectionStrings)
        {
            DatabaseFlavour flavour = config.Flavour;
            if (flavour == DatabaseFlavour.AutoDetect)
            {
                ConnectionStringSettings css = connectionStrings.ConnectionStrings[config.ConnectionStringName];
                if (css == null)
                    throw new ConfigurationErrorsException("Could not find the connection string named '" + config.ConnectionStringName + "' that was defined in the n2/database configuration section.");
                flavour = DetectFlavor(css);
            }

            // HACK: used to support seamless text/nvarchar(max) support across databases
            if (flavour == DatabaseFlavour.MySql)
                stringLength = 16777215;

            switch (flavour)
            {
                case DatabaseFlavour.SqlServer2000:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2000Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlServer:
                case DatabaseFlavour.SqlServer2005:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2005Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlServer2008:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2008Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlCe3:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSqlCeDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlCe:
                case DatabaseFlavour.SqlCe4:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSqlCe40Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.MySql:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.MySqlDataDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MySQL5Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqLite:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SQLite20Driver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.SQLiteDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Firebird:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.FirebirdDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.FirebirdDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Generic:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OleDbDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.GenericDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Jet:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.JetDriver.JetDriver, NHibernate.JetDriver";
                    Properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.JetDriver.JetDialect, NHibernate.JetDriver";
                    break;
                case DatabaseFlavour.DB2:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OdbcDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.DB2Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Oracle9i:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.Oracle9iDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Oracle:
                case DatabaseFlavour.Oracle10g:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.Oracle10gDialect).AssemblyQualifiedName;
                    break;
                default:
                    throw new ConfigurationErrorsException("Couldn't determine database flavour. Please check the 'flavour' attribute of the n2/database configuration section.");
            }
        }
Example #29
0
        /// <summary>Sets properties configuration dictionary based on configuration in the database section.</summary>
        /// <param name="config">The database section configuration.</param>
        /// <param name="connectionStrings">Connection strings from configuration</param>
        protected void SetupProperties(DatabaseSection config, ConnectionStringsSection connectionStrings)
        {
            NHibernate.Cfg.Environment.UseReflectionOptimizer = Utility.GetTrustLevel() > System.Web.AspNetHostingPermissionLevel.Medium;
            Properties[NHibernate.Cfg.Environment.ProxyFactoryFactoryClass] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

            Properties[NHibernate.Cfg.Environment.ConnectionStringName] = config.ConnectionStringName;
            Properties[NHibernate.Cfg.Environment.ConnectionProvider] = "NHibernate.Connection.DriverConnectionProvider";
            Properties[NHibernate.Cfg.Environment.Hbm2ddlKeyWords] = "none";

            DatabaseFlavour flavour = config.Flavour;
            if (flavour == DatabaseFlavour.AutoDetect)
            {
                ConnectionStringSettings css = connectionStrings.ConnectionStrings[config.ConnectionStringName];
                if (css == null)
                    throw new ConfigurationErrorsException("Could not find the connection string named '" + config.ConnectionStringName + "' that was defined in the n2/database configuration section.");
                flavour = DetectFlavor(css);
            }

            // HACK: used to support seamless text/nvarchar(max) support across databases
            if (flavour == DatabaseFlavour.MySql)
                stringLength = 16777215;

            switch (flavour)
            {
                case DatabaseFlavour.SqlServer2000:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2000Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlServer:
                case DatabaseFlavour.SqlServer2005:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2005Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlServer2008:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSql2008Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlCe3:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSqlCeDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqlCe:
                case DatabaseFlavour.SqlCe4:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MsSqlCe40Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.MySql:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.MySqlDataDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.MySQL5Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.SqLite:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.SQLite20Driver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.SQLiteDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Firebird:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.FirebirdDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.FirebirdDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Generic:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OleDbDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.GenericDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Jet:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.JetDriver.JetDriver, NHibernate.JetDriver";
                    Properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.JetDriver.JetDialect, NHibernate.JetDriver";
                    break;
                case DatabaseFlavour.DB2:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OdbcDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.DB2Dialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Oracle9i:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.Oracle9iDialect).AssemblyQualifiedName;
                    break;
                case DatabaseFlavour.Oracle:
                case DatabaseFlavour.Oracle10g:
                    Properties[NHibernate.Cfg.Environment.ConnectionDriver] = typeof(NHibernate.Driver.OracleClientDriver).AssemblyQualifiedName;
                    Properties[NHibernate.Cfg.Environment.Dialect] = typeof(NHibernate.Dialect.Oracle10gDialect).AssemblyQualifiedName;
                    break;
                default:
                    throw new ConfigurationErrorsException("Couldn't determine database flavour. Please check the 'flavour' attribute of the n2/database configuration section.");
            }

            Properties[NHibernate.Cfg.Environment.UseSecondLevelCache] = config.Caching.ToString();
            Properties[NHibernate.Cfg.Environment.UseQueryCache] = config.Caching.ToString();
            Properties[NHibernate.Cfg.Environment.CacheProvider] = config.CacheProviderClass;

            foreach (string key in config.HibernateProperties.AllKeys)
            {
                Properties[key] = config.HibernateProperties[key].Value;
            }
        }