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. |
From: <fab...@us...> - 2010-07-27 17:08:29
|
Revision: 5061 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5061&view=rev Author: fabiomaulo Date: 2010-07-27 17:08:22 +0000 (Tue, 27 Jul 2010) Log Message: ----------- Refactoring (lazy initialization of private fields) 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 2010-07-26 09:30:53 UTC (rev 5060) +++ trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-07-27 17:08:22 UTC (rev 5061) @@ -21,13 +21,15 @@ public class SchemaExport { private static readonly ILog log = LogManager.GetLogger(typeof (SchemaExport)); + private bool wasInitialized; + private readonly Configuration cfg; private readonly IDictionary<string, string> configProperties; - private readonly string[] createSQL; - private readonly Dialect.Dialect dialect; - private readonly string[] dropSQL; + private string[] createSQL; + private Dialect.Dialect dialect; + private string[] dropSQL; + private IFormatter formatter; private string delimiter; private string outputFile; - private readonly IFormatter formatter; /// <summary> /// Create a schema exported for a given Configuration @@ -43,11 +45,21 @@ /// <param name="configProperties">The Properties to use when connecting to the Database.</param> public SchemaExport(Configuration cfg, IDictionary<string, string> configProperties) { + this.cfg = cfg; this.configProperties = configProperties; + } + + private void Initialize() + { + if(wasInitialized) + { + return; + } 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; } /// <summary> @@ -108,6 +120,7 @@ private void Execute(Action<string> scriptAction, bool export, bool throwOnError, TextWriter exportOutput, IDbCommand statement, string sql) { + Initialize(); try { string formatted = formatter.Format(sql); @@ -196,6 +209,7 @@ public void Execute(Action<string> scriptAction, bool export, bool justDrop, IDbConnection connection, TextWriter exportOutput) { + Initialize(); IDbCommand statement = null; if (export && connection == null) @@ -272,6 +286,7 @@ public void Execute(Action<string> scriptAction, bool export, bool justDrop) { + Initialize(); IDbConnection connection = null; StreamWriter fileOutput = null; IConnectionProvider connectionProvider = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |