public static ISessionFactory CreateSessionFactory(String path, SessionFactoryFlags flags) { var configuration = GetConfiguration(DatabaseTypeEnum.sqlite, flags) .SetProperty("connection.connection_string", new SQLiteConnectionStringBuilder { DataSource = path }.ToString()); if (0 != (flags & SessionFactoryFlags.CreateSchema)) { configuration.SetProperty("hbm2ddl.auto", "create"); } return configuration.BuildSessionFactory(); }
public static ISessionFactory CreateSessionFactory(String path, SessionFactoryFlags flags) { var configuration = GetConfiguration(DatabaseTypeEnum.sqlite, flags) .SetProperty("connection.connection_string", new SQLiteConnectionStringBuilder { DataSource = path }.ToString()); if (0 != (flags & SessionFactoryFlags.CreateSchema)) { configuration.SetProperty("hbm2ddl.auto", "create"); } return(configuration.BuildSessionFactory()); }
public static Configuration GetConfiguration(DatabaseTypeEnum databaseTypeEnum, SessionFactoryFlags flags) { Assembly assembly = typeof(SessionFactoryFactory).Assembly; var configuration = new Configuration() .SetProperty("dialect", GetDialectClass(databaseTypeEnum).AssemblyQualifiedName) .SetProperty("connection.driver_class", GetDriverClass(databaseTypeEnum).AssemblyQualifiedName) .SetProperty("connection.provider", typeof (NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedName) .SetProperty("command_timeout", "1800"); if (databaseTypeEnum == DatabaseTypeEnum.mysql) { configuration.SetProperty("sessionVariables", "storage_engine=InnoDB"); } configuration.AddInputStream(assembly.GetManifestResourceStream("pwiz.Topograph.Data.mapping.xml")); return configuration; }
public static ISessionFactory CreateSessionFactory(TpgLinkDef tpgLinkDef, SessionFactoryFlags flags) { var configuration = GetConfiguration(tpgLinkDef.DatabaseTypeEnum, flags) .SetProperty("connection.connection_string", tpgLinkDef.GetConnectionString()); var sessionFactory = configuration.BuildSessionFactory(); if (0 != (flags & SessionFactoryFlags.CreateSchema)) { using (var session = sessionFactory.OpenSession()) { var schemaExport = new SchemaExport(configuration); if (DatabaseTypeEnum.mysql == tpgLinkDef.DatabaseTypeEnum) { session.CreateSQLQuery("SET storage_engine = 'InnoDB'").ExecuteUpdate(); } schemaExport.Execute(false, true, false, session.Connection, null); } } return sessionFactory; }
public static ISessionFactory CreateSessionFactory(TpgLinkDef tpgLinkDef, SessionFactoryFlags flags) { var configuration = GetConfiguration(tpgLinkDef.DatabaseTypeEnum, flags) .SetProperty("connection.connection_string", tpgLinkDef.GetConnectionString()); var sessionFactory = configuration.BuildSessionFactory(); if (0 != (flags & SessionFactoryFlags.CreateSchema)) { using (var session = sessionFactory.OpenSession()) { var schemaExport = new SchemaExport(configuration); if (DatabaseTypeEnum.mysql == tpgLinkDef.DatabaseTypeEnum) { session.CreateSQLQuery("SET storage_engine = 'InnoDB'").ExecuteUpdate(); } schemaExport.Execute(false, true, false, session.Connection, null); } } return(sessionFactory); }
public static Configuration GetConfiguration(DatabaseTypeEnum databaseTypeEnum, SessionFactoryFlags flags) { Assembly assembly = typeof(SessionFactoryFactory).Assembly; var configuration = new Configuration() .SetProperty("dialect", GetDialectClass(databaseTypeEnum).AssemblyQualifiedName) .SetProperty("connection.driver_class", GetDriverClass(databaseTypeEnum).AssemblyQualifiedName) .SetProperty("connection.provider", typeof(NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedName) .SetProperty("command_timeout", "1800"); if (databaseTypeEnum == DatabaseTypeEnum.mysql) { configuration.SetProperty("sessionVariables", "storage_engine=InnoDB"); } configuration.AddInputStream(assembly.GetManifestResourceStream("pwiz.Topograph.Data.mapping.xml")); return(configuration); }