|
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.
|