public static ISessionFactory CreateSessionFactory (string path, SessionFactoryConfig config) { string uncCompatiblePath = Util.GetSQLiteUncCompatiblePath(path); // update the existing database's schema if necessary, and if updated, recreate the indexes if (path != ":memory:" && File.Exists(path) && IsValidFile(path) && SchemaUpdater.Update(path, null)) { using (var conn = new SQLiteConnection(String.Format("Data Source={0};Version=3", uncCompatiblePath))) { conn.Open(); conn.ExecuteNonQuery(@"PRAGMA journal_mode=DELETE; PRAGMA synchronous=OFF; PRAGMA automatic_indexing=OFF; PRAGMA cache_size=30000; PRAGMA temp_store=MEMORY; PRAGMA page_size=32768; PRAGMA mmap_size=70368744177664; -- 2^46"); DropIndexes(conn); CreateIndexes(conn); } } bool pooling = path == ":memory:"; var configuration = new Configuration() .SetProperty("show_sql", config.WriteSqlToConsoleOut ? "true" : "false") .SetProperty("dialect", typeof(CustomSQLiteDialect).AssemblyQualifiedName) .SetProperty("hibernate.cache.use_query_cache", "true") //.SetProperty("adonet.batch_size", batchSize.ToString()) .SetProperty("connection.connection_string", String.Format("Data Source={0};Version=3;{1}", uncCompatiblePath, (pooling ? "Pooling=True;Max Pool Size=1;" : ""))) .SetProperty("connection.driver_class", typeof(NHibernate.Driver.SQLite20Driver).AssemblyQualifiedName) .SetProperty("connection.provider", typeof(NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedName) .SetProperty("connection.release_mode", "on_close") ; ConfigureMappings(configuration); if (config.UseUnfilteredTables) { configuration.ClassMappings.Single(o => o.Table.Name == "Protein").Table.Name = "UnfilteredProtein"; configuration.ClassMappings.Single(o => o.Table.Name == "Peptide").Table.Name = "UnfilteredPeptide"; configuration.ClassMappings.Single(o => o.Table.Name == "PeptideInstance").Table.Name = "UnfilteredPeptideInstance"; configuration.ClassMappings.Single(o => o.Table.Name == "PeptideSpectrumMatch").Table.Name = "UnfilteredPeptideSpectrumMatch"; configuration.ClassMappings.Single(o => o.Table.Name == "Spectrum").Table.Name = "UnfilteredSpectrum"; } ISessionFactory sessionFactory = null; lock(mutex) sessionFactory = configuration.BuildSessionFactory(); sessionFactory.OpenStatelessSession().CreateSQLQuery(@"PRAGMA cache_size=10000; PRAGMA temp_store=MEMORY; PRAGMA page_size=32768; PRAGMA mmap_size=70368744177664; -- 2^46").ExecuteUpdate(); if (config.CreateSchema) CreateFile(path); return sessionFactory; }