Exemplo n.º 1
0
        private void Initialize()
        {
            if (wasInitialized)
            {
                return;
            }

            string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configuration.Properties, "not-defined");

            if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
            {
                SchemaMetadataUpdater.Update(configuration, dialect);
                SchemaMetadataUpdater.QuoteTableAndColumns(configuration, dialect);
            }

            wasInitialized = true;
        }
        private async Task InitializeAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (wasInitialized)
            {
                return;
            }

            string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configuration.Properties, "not-defined");

            if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
            {
                await(SchemaMetadataUpdater.UpdateAsync(configuration, dialect, cancellationToken)).ConfigureAwait(false);
                SchemaMetadataUpdater.QuoteTableAndColumns(configuration, dialect);
            }

            wasInitialized = true;
        }
Exemplo n.º 3
0
        private void Initialize()
        {
            if (wasInitialized)
            {
                return;
            }
            string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configProperties, "not-defined");

            autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant();
            if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
            {
                SchemaMetadataUpdater.QuoteTableAndColumns(cfg);
            }

            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;
            wasInitialized = true;
        }
Exemplo n.º 4
0
		private async Task InitializeAsync(CancellationToken cancellationToken = default(CancellationToken))
		{
			cancellationToken.ThrowIfCancellationRequested();
			if(wasInitialized)
			{
				return;
			}
			dialect = Dialect.Dialect.GetDialect(configProperties);

			string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configProperties, "not-defined");
			if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
			{
				await (SchemaMetadataUpdater.UpdateAsync(cfg, dialect, cancellationToken)).ConfigureAwait(false);
				SchemaMetadataUpdater.QuoteTableAndColumns(cfg, dialect);
			}

			dropSQL = cfg.GenerateDropSchemaScript(dialect);
			createSQL = cfg.GenerateSchemaCreationScript(dialect);
			formatter = (PropertiesHelper.GetBoolean(Environment.FormatSql, configProperties, true) ? FormatStyle.Ddl : FormatStyle.None).Formatter;
			wasInitialized = true;
		}
Exemplo n.º 5
0
        private void Initialize()
        {
            if (wasInitialized)
            {
                return;
            }
            dialect = Dialect.Dialect.GetDialect(configProperties);

            string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configProperties, "not-defined");

            if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
            {
                SchemaMetadataUpdater.Update(cfg, dialect);
                SchemaMetadataUpdater.QuoteTableAndColumns(cfg, dialect);
            }

            dropSQL   = cfg.GenerateDropSchemaScript(dialect);
            createSQL = cfg.GenerateSchemaCreationScript(dialect);
            formatter = (PropertiesHelper.GetBoolean(Environment.FormatSql, configProperties, true) ? FormatStyle.Ddl : FormatStyle.None).Formatter;
            _requireTenantConnection = PropertiesHelper.GetEnum(Environment.MultiTenancy, configProperties, MultiTenancyStrategy.None) == MultiTenancyStrategy.Database;
            wasInitialized           = true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Execute the schema updates
        /// </summary>
        /// <param name="scriptAction">The action to write the each schema line.</param>
        /// <param name="doUpdate">Commit the script to DB</param>
        public void Execute(Action <string> scriptAction, bool doUpdate)
        {
            log.Info("Running hbm2ddl schema update");

            string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configuration.Properties, "not-defined");

            autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant();
            if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
            {
                SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
            }

            DbConnection connection;
            IDbCommand   stmt = null;

            exceptions.Clear();

            try
            {
                DatabaseMetadata meta;
                try
                {
                    log.Info("fetching database metadata");
                    connectionHelper.Prepare();
                    connection = connectionHelper.Connection;
                    meta       = new DatabaseMetadata(connection, dialect);
                    stmt       = connection.CreateCommand();
                }
                catch (Exception sqle)
                {
                    exceptions.Add(sqle);
                    log.Error("could not get database metadata", sqle);
                    throw;
                }

                log.Info("updating schema");

                string[] createSQL = configuration.GenerateSchemaUpdateScript(dialect, meta);
                for (int j = 0; j < createSQL.Length; j++)
                {
                    string sql       = createSQL[j];
                    string formatted = formatter.Format(sql);

                    try
                    {
                        if (scriptAction != null)
                        {
                            scriptAction(formatted);
                        }
                        if (doUpdate)
                        {
                            log.Debug(sql);
                            stmt.CommandText = sql;
                            stmt.ExecuteNonQuery();
                        }
                    }
                    catch (Exception e)
                    {
                        exceptions.Add(e);
                        log.Error("Unsuccessful: " + sql, e);
                    }
                }

                log.Info("schema update complete");
            }
            catch (Exception e)
            {
                exceptions.Add(e);
                log.Error("could not complete schema update", e);
            }
            finally
            {
                try
                {
                    if (stmt != null)
                    {
                        stmt.Dispose();
                    }
                    connectionHelper.Release();
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                    log.Error("Error closing connection", e);
                }
            }
        }