/// <summary> /// Create a schema exporter for the given Configuration, with the given /// database connection properties /// </summary> /// <param name="cfg">The NHibernate Configuration to generate the schema from.</param> /// <param name="connectionProperties">The Properties to use when connecting to the Database.</param> public SchemaExport(Configuration cfg, IDictionary<string, string> connectionProperties) { this.connectionProperties = connectionProperties; dialect = Dialect.Dialect.GetDialect(connectionProperties); dropSQL = cfg.GenerateDropSchemaScript(dialect); createSQL = cfg.GenerateSchemaCreationScript(dialect); }
/// <summary> /// Create a schema exporter for the given Configuration, with the given /// database connection properties /// </summary> /// <param name="cfg">The NHibernate Configuration to generate the schema from.</param> /// <param name="configProperties">The Properties to use when connecting to the Database.</param> public SchemaExport(Configuration cfg, IDictionary<string, string> configProperties) { this.configProperties = configProperties; dialect = Dialect.Dialect.GetDialect(configProperties); dropSQL = cfg.GenerateDropSchemaScript(dialect); createSQL = cfg.GenerateSchemaCreationScript(dialect); formatter = (PropertiesHelper.GetBoolean(Environment.FormatSql, configProperties, true) ? FormatStyle.Ddl : FormatStyle.None).Formatter; }
public void BuildSchema(ISession session, Configuration configuration) { IDbConnection connection = session.Connection; Dialect dialect = Dialect.GetDialect(configuration.Properties); string[] drops = configuration.GenerateDropSchemaScript(dialect); ExecuteScripts(drops, connection); string[] scripts = configuration.GenerateSchemaCreationScript(dialect); ExecuteScripts(scripts, connection); }
static LiveSqliteSchema() { var config = new Configuration(); config.SetProperty(Environment.Dialect, "NHibernate.Dialect.SQLiteDialect"); config.AddInputStream(HbmSerializer.Default.Serialize(Assembly.Load("tanzer.lotto.core"))); Dialect dialect = Dialect.GetDialect(config.Properties); // pause at critical moments; row COUNT; rollback journal; isolation level // @sa http://www.sqlite.org/pragma.html script = "PRAGMA synchronous=FALSE;PRAGMA count_changes=FALSE;PRAGMA journal_mode=FALSE;PRAGMA read_uncommitted=TRUE;"; script += String.Join(";", config.GenerateDropSchemaScript(dialect)); script += ";"; script += String.Join(";", config.GenerateSchemaCreationScript(dialect)); script += ";"; }
/// <summary> /// Execute schema drop script, determined by the Configuration object /// used for creating the SessionFactory. A replacement for NHibernate's /// SchemaExport class, to be invoked on application setup. /// </summary> /// <remarks> /// Fetch the LocalSessionFactoryBean itself rather than the exposed /// SessionFactory to be able to invoke this method, e.g. via /// <code>LocalSessionFactoryObject lsfb = (LocalSessionFactoryObject) ctx.GetObject("mySessionFactory");</code>. /// <p> /// Uses the SessionFactory that this bean generates for accessing a ADO.NET /// connection to perform the script. /// </p> /// </remarks> public void DropDatabaseSchema() { log.Info("Dropping database schema for NHibernate SessionFactory"); HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory); hibernateTemplate.Execute( new HibernateDelegate(delegate(ISession session) { IDbConnection con = session.Connection; Dialect dialect = Dialect.GetDialect(Configuration.Properties); string[] sql = Configuration.GenerateDropSchemaScript(dialect); ExecuteSchemaScript(con, sql); return(null); })); }
static int Main(string[] args) { try { log4net.Config.XmlConfigurator.Configure(); string scriptDir = Settings.Default.ScriptsDir; if (!Path.IsPathRooted (scriptDir)) { scriptDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, scriptDir); } Console.WriteLine("Generating script..."); Configuration cfg = new Configuration(); cfg.Configure(); Dialect dialect = Dialect.GetDialect(cfg.Properties); string[] dropStatements = cfg.GenerateDropSchemaScript(dialect); string[] createStatements = cfg.GenerateSchemaCreationScript(dialect); using (StreamWriter writer = new StreamWriter(Path.Combine(scriptDir, Settings.Default.ScriptToGenerate), false, Encoding.Default)) { foreach (string s in dropStatements) { string f = Format(ParseDropConstraint(s)); writer.WriteLine(f); } writer.WriteLine(); foreach (string s in createStatements) { string f = Format(ParseCreateTable(s)); writer.WriteLine(f); } foreach (string scriptToAppend in Settings.Default.ScriptsToAppend) { writer.WriteLine(); writer.WriteLine(File.ReadAllText(Path.Combine(scriptDir, scriptToAppend),Encoding.Default)); } } Console.WriteLine("Done"); } catch (Exception e) { log.Error(e); Console.WriteLine(e); return 1; } return 0; }
public static string[] ExportDropeSchema(Dialect dialect) { Configuration cfg = new Configuration(); cfg.Configure(); return cfg.GenerateDropSchemaScript(dialect); }