From: <fab...@us...> - 2008-12-16 16:17:53
|
Revision: 3957 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3957&view=rev Author: fabiomaulo Date: 2008-12-16 16:17:49 +0000 (Tue, 16 Dec 2008) Log Message: ----------- Fix NH-1613 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs Modified: trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2008-12-16 15:39:36 UTC (rev 3956) +++ trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2008-12-16 16:17:49 UTC (rev 3957) @@ -43,7 +43,7 @@ /// </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) + public SchemaExport(Configuration cfg, IDictionary<string, string> connectionProperties) { this.connectionProperties = connectionProperties; dialect = Dialect.Dialect.GetDialect(connectionProperties); @@ -87,6 +87,11 @@ Execute(script, export, false, true); } + public void Create(Action<string> scriptAction, bool export) + { + Execute(scriptAction, export, false, true); + } + /// <summary> /// Run the drop schema script /// </summary> @@ -101,8 +106,8 @@ Execute(script, export, true, true); } - private void Execute(bool script, bool export, bool format, bool throwOnError, TextWriter exportOutput, - IDbCommand statement, string sql) + private void Execute(Action<string> scriptAction, bool export, bool format, bool throwOnError, TextWriter exportOutput, + IDbCommand statement, string sql) { try { @@ -120,9 +125,9 @@ { formatted += delimiter; } - if (script) + if (scriptAction != null) { - Console.WriteLine(formatted); + scriptAction(formatted); } log.Debug(formatted); if (exportOutput != null) @@ -165,8 +170,21 @@ /// It does NOT close the given connection! /// </remarks> public void Execute(bool script, bool export, bool justDrop, bool format, - IDbConnection connection, TextWriter exportOutput) + IDbConnection connection, TextWriter exportOutput) { + if (script) + { + Execute(Console.WriteLine, export, justDrop, format, connection, exportOutput); + } + else + { + Execute(null, export, justDrop, format, connection, exportOutput); + } + } + + public void Execute(Action<string> scriptAction, bool export, bool justDrop, bool format, + IDbConnection connection, TextWriter exportOutput) + { IDbCommand statement = null; if (export && connection == null) @@ -182,14 +200,14 @@ { for (int i = 0; i < dropSQL.Length; i++) { - Execute(script, export, format, false, exportOutput, statement, dropSQL[i]); + Execute(scriptAction, export, format, false, exportOutput, statement, dropSQL[i]); } if (!justDrop) { for (int j = 0; j < createSQL.Length; j++) { - Execute(script, export, format, true, exportOutput, statement, createSQL[j]); + Execute(scriptAction, export, format, true, exportOutput, statement, createSQL[j]); } } } @@ -218,8 +236,10 @@ } } } + } + /// <summary> /// Executes the Export of the Schema. /// </summary> @@ -232,6 +252,17 @@ /// </remarks> public void Execute(bool script, bool export, bool justDrop, bool format) { + if (script) + { + Execute(Console.WriteLine, export, justDrop, format); + } + else + { + Execute(null, export, justDrop, format); + } + } + public void Execute(Action<string> scriptAction, bool export, bool justDrop, bool format) + { IDbConnection connection = null; StreamWriter fileOutput = null; IConnectionProvider connectionProvider = null; @@ -263,7 +294,7 @@ connection = connectionProvider.GetConnection(); } - Execute(script, export, justDrop, format, connection, fileOutput); + Execute(scriptAction, export, justDrop, format, connection, fileOutput); } catch (HibernateException) { @@ -283,6 +314,7 @@ connectionProvider.Dispose(); } } + } /// <summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |