static IEnumerable <string> GetReservedWords(Dialect.Dialect dialect, IConnectionHelper connectionHelper)
 {
     connectionHelper.Prepare();
     try
     {
         var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
         return(metaData.GetReservedWords());
     }
     finally
     {
         connectionHelper.Release();
     }
 }
		private static Iesi.Collections.Generic.ISet<string> GetReservedWords(Dialect.Dialect dialect, IConnectionHelper connectionHelper)
		{
			Iesi.Collections.Generic.ISet<string> reservedDb = new HashedSet<string>();
			connectionHelper.Prepare();
			try
			{
				var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
				foreach (var rw in metaData.GetReservedWords())
				{
					reservedDb.Add(rw.ToLowerInvariant());
				}
			}
			finally
			{
				connectionHelper.Release();
			}
			return reservedDb;
		}
Пример #3
0
        private static ISet <string> GetReservedWords(Dialect.Dialect dialect, IConnectionHelper connectionHelper)
        {
            ISet <string> reservedDb = new HashedSet <string>();

            connectionHelper.Prepare();
            try
            {
                var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
                foreach (var rw in metaData.GetReservedWords())
                {
                    reservedDb.Add(rw.ToLowerInvariant());
                }
            }
            finally
            {
                connectionHelper.Release();
            }
            return(reservedDb);
        }
Пример #4
0
        /**
         * Perform the validations.
         */

        public void Validate()
        {
            log.Info("Running schema validator");
            try
            {
                DatabaseMetadata meta;
                try
                {
                    log.Info("fetching database metadata");
                    connectionHelper.Prepare();
                    DbConnection connection = connectionHelper.Connection;
                    meta = new DatabaseMetadata(connection, dialect, false);
                }
                catch (Exception sqle)
                {
                    log.Error("could not get database metadata", sqle);
                    throw;
                }
                configuration.ValidateSchema(dialect, meta);
            }
            catch (Exception e)
            {
                log.Error("could not complete schema validation", e);
                throw;
            }
            finally
            {
                try
                {
                    connectionHelper.Release();
                }
                catch (Exception e)
                {
                    log.Error("Error closing connection", e);
                }
            }
        }
Пример #5
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");

            Initialize();

            DbConnection connection;
            DbCommand    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(sqle, "could not get database metadata");
                    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(e, "Unsuccessful: {0}", sql);
                    }
                }

                log.Info("schema update complete");
            }
            catch (Exception e)
            {
                exceptions.Add(e);
                log.Error(e, "could not complete schema update");
            }
            finally
            {
                try
                {
                    if (stmt != null)
                    {
                        stmt.Dispose();
                    }
                    connectionHelper.Release();
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                    log.Error(e, "Error closing connection");
                }
            }
        }
Пример #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);
                }
            }
        }