From: Chris M. <cm...@us...> - 2006-09-28 17:23:11
|
User: cmicali Date: 06/09/28 10:23:10 Modified: etc/andromda-dotnet/AndroMDA.NHibernateSupport AndroMDA.NHibernateSupport.VS2005.csproj AssemblyInfo.cs etc/andromda-dotnet/AndroMDA.NHibernateSupport/src DbSupport.cs etc/andromda-dotnet/Lib/AndroMDA.NHibernateSupport AndroMDA.NHibernateSupport.dll etc/andromda-dotnet/Lib DLL Versions.txt Removed: etc/andromda-dotnet/AndroMDA.NHibernateSupport AndroMDA.NHibernateSupport.csproj AndroMDA.NHibernateSupport.sln VS2005Build.bat VS2005Readme.txt Log: - Added patch to DbSupport.cs of NHibernateSupport.dll to fix issue when drop script exists - Updated version of dll to 1.0.6.0 Revision Changes Path 1.2 +1 -2 plugins/etc/andromda-dotnet/AndroMDA.NHibernateSupport/AndroMDA.NHibernateSupport.VS2005.csproj Index: AndroMDA.NHibernateSupport.VS2005.csproj =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.NHibernateSupport/AndroMDA.NHibernateSupport.VS2005.csproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- AndroMDA.NHibernateSupport.VS2005.csproj 17 Aug 2006 03:51:49 -0000 1.1 +++ AndroMDA.NHibernateSupport.VS2005.csproj 28 Sep 2006 17:23:09 -0000 1.2 @@ -1,4 +1,4 @@ -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <ProjectType>Local</ProjectType> <ProductVersion>8.0.50727</ProductVersion> @@ -122,7 +122,6 @@ </Compile> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> - <Import Project="$(MSBuildExtensionsPath)\MSBee\MSBuildExtras.FX1_1.CSharp.targets" Condition=" '$(BuildingInsideVisualStudio)' == '' AND '$(TargetFX1_1)'=='true'" /> <PropertyGroup> <PreBuildEvent> </PreBuildEvent> 1.3 +2 -2 plugins/etc/andromda-dotnet/AndroMDA.NHibernateSupport/AssemblyInfo.cs Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.NHibernateSupport/AssemblyInfo.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- AssemblyInfo.cs 17 Aug 2006 03:51:49 -0000 1.2 +++ AssemblyInfo.cs 28 Sep 2006 17:23:09 -0000 1.3 @@ -11,7 +11,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("The AndroMDA Project")] [assembly: AssemblyProduct("AndroMDA")] -[assembly: AssemblyCopyright("Copyright (c) 2002 - 2005, The AndroMDA Team")] +[assembly: AssemblyCopyright("Copyright (c) 2002 - 2006, The AndroMDA Team")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -26,7 +26,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.5.0")] +[assembly: AssemblyVersion("1.0.6.0")] // // In order to sign your assembly you must specify a key to use. Refer to the 1.3 +203 -244 plugins/etc/andromda-dotnet/AndroMDA.NHibernateSupport/src/DbSupport.cs Index: DbSupport.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.NHibernateSupport/src/DbSupport.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- DbSupport.cs 27 Jul 2006 02:08:19 -0000 1.2 +++ DbSupport.cs 28 Sep 2006 17:23:09 -0000 1.3 @@ -32,6 +32,43 @@ #endregion + #region Private static methods + /// <summary> + /// Executes the given array of sql commands. + /// </summary> + /// <param name="sqlCmds">Array of sql commands.</param> + /// <returns>Flag whether transaction was successful.</returns> + private static bool ExecuteSqlCommands(string[] sqlCmds) + { + // create command for this transaction: + ISession session = SessionManagerFactory.SessionManager.Session; + IDbCommand command = session.Connection.CreateCommand(); + + SessionManagerFactory.SessionManager.BeginTransaction(); + try + { + foreach (string sql in sqlCmds) + { + command.CommandText = sql; + command.CommandType = CommandType.Text; + session.Transaction.Enlist(command); + command.ExecuteNonQuery(); + } + + // all worked well: + SessionManagerFactory.SessionManager.CommitTransaction(); + return true; + } + catch (Exception ex) + { + SessionManagerFactory.SessionManager.RollbackTransaction(); + log.Error("An error occured while running SQL script.", ex); + return false; + } + } + + #endregion + #region Public instance methods /// <summary> /// Generates DDL for the target database to create the tables. @@ -79,10 +116,6 @@ /// <returns>The DDL used to create the tables.</returns> public string RegenerateDatabase(System.IO.FileInfo createFile, System.IO.FileInfo dropFile) { - string dropScriptFileName = null; - string dropSQL = null; - bool errorWhileExporting = false; - if (createFile == null) throw new ArgumentNullException("createFile", "The create FileInfo object can't be null."); @@ -96,14 +129,10 @@ string oldFile = Path.GetFileNameWithoutExtension(dropFile.Name) + "-old" + dropFile.Extension; File.Copy(dropFile.FullName, oldFile, true); - // Next, read the contents of the file + // read and execute drop script: try { - using (System.IO.TextReader reader = dropFile.OpenText()) - { - dropSQL = reader.ReadToEnd(); - reader.Close(); - } + ExecuteSqlCommands(File.ReadAllLines(dropFile.FullName)); } catch (Exception ex) { @@ -120,108 +149,39 @@ fs = null; } - IDbConnection conn = SessionManagerFactory.SessionManager.Session.Connection; - string[] dropSQLArray; - string[] createDBArray; - - using (IDbCommand command = conn.CreateCommand()) - { - // Execute the SQL script to drop the current schema - if (dropSQL != null && dropSQL.Trim().Length > 0) - { - command.CommandText = dropSQL; - command.CommandType = CommandType.Text; - - try - { - command.ExecuteNonQuery(); - - if (log.IsInfoEnabled) - log.Info("Dropped the current schema using the following SQL:" + Environment.NewLine + dropSQL); - } - catch (Exception ex) - { - log.Error("An error occured while trying to drop the existing database schema.", ex); - throw; - } - } - - // Now generate the 'drop sql' script for the new database schema - dropSQLArray = GenerateDropSQL(); - - // Now generate the 'create sql' script for the new database schema - createDBArray = GenerateCreateSQL(); - - // Run the create SQL code - SessionManagerFactory.SessionManager.BeginTransaction(); - foreach (string sql in createDBArray) - { - command.CommandText = sql; - command.CommandType = CommandType.Text; - SessionManagerFactory.SessionManager.Session.Transaction.Enlist(command); - try - { - command.ExecuteNonQuery(); - } - catch (Exception ex) - { - errorWhileExporting = true; - log.Error("An error occured while running the create script.", ex); - } - } - - if (errorWhileExporting) - SessionManagerFactory.SessionManager.RollbackTransaction(); - else - SessionManagerFactory.SessionManager.CommitTransaction(); - - } + // get new create and drop scripts: + string[] dropSQLArray = GenerateDropSQL(); + string[] createDBArray = GenerateCreateSQL(); - // Save the create script + // create new database and save ddl: + bool errorWhileExporting = false; try { - if (createFile.Exists) - { - createFile.Delete(); - createFile.Refresh(); - } - using (StreamWriter sw = createFile.CreateText()) - { - foreach (string sql in createDBArray) - { - sw.WriteLine(sql); - } - sw.Close(); - } + errorWhileExporting = !ExecuteSqlCommands(createDBArray); + File.WriteAllLines(createFile.FullName, createDBArray); } catch (Exception ex) { - log.Error(String.Format("A problem occurred while creating the {0} file containing the CREATE DDL.", createFile.FullName), ex); + log.Error(String.Format("A problem occurred while creating the CREATE DDL file '{0}'.", createFile.FullName), ex); } // Save the delete script so we can use it the next time + string dropScriptFileName = dropFile.FullName; try { - //If we had errors while creating the - //schema, then save the new 'drop schema' sql script to a new file + // if we had errors while creating the schema, then save the new + // 'drop schema' sql script to a new file: if (errorWhileExporting && dropFile != null) { //otherwise, save the old 'Delete' script and create the delete script with a new name. dropScriptFileName = System.IO.Path.GetFileNameWithoutExtension(dropFile.FullName) + ".failure" + dropFile.Extension; } - else - dropScriptFileName = dropFile.FullName; - // Remove the reference to the dropFile + // don't need this any longer: dropFile = null; - using (System.IO.StreamWriter writer = File.CreateText(dropScriptFileName)) - { - foreach (string sqlLine in dropSQLArray) - { - writer.WriteLine(sqlLine); - } - } + // store drop commands: + File.WriteAllLines(dropScriptFileName, dropSQLArray); log.Info(String.Format("The delete DDL was written to {0}", dropScriptFileName)); if (errorWhileExporting) @@ -240,7 +200,6 @@ } return String.Join(Environment.NewLine, createDBArray); - } #endregion 1.4 +198 -226 plugins/etc/andromda-dotnet/Lib/AndroMDA.NHibernateSupport/AndroMDA.NHibernateSupport.dll <<Binary file>> No revision No revision |