User: ecrutchfield Date: 06/08/04 09:14:21 Modified: andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export App.config nhibernate.config.vsl Program.cs Added: andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export SchemaExport.csproj AssemblyInfo.cs App.ico Log: Updated to support latest AndroMDA.NHibernateSupport.dll and 'regenerating' of a database. Revision Changes Path 1.2 +37 -34 plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/App.config Index: App.config =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/App.config,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- App.config 5 Mar 2006 06:16:55 -0000 1.1 +++ App.config 4 Aug 2006 16:14:20 -0000 1.2 @@ -19,7 +19,7 @@ <!-- levels: DEBUG, INFO, WARN, ERROR, FATAL --> <root> - <level value="WARN"/> + <level value="INFO"/> <appender-ref ref="NHibernateLog"/> </root> @@ -30,6 +30,9 @@ <appSettings> <add key="nhibernate.config" value="nhibernate.config" /> + + <add key="schema.create.file" value="schema-create.sql"/> + <add key="schema.drop.file" value="schema-drop.sql"/> </appSettings> </configuration> \ No newline at end of file 1.2 +13 -13 plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/nhibernate.config.vsl Index: nhibernate.config.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/nhibernate.config.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- nhibernate.config.vsl 5 Mar 2006 06:16:55 -0000 1.1 +++ nhibernate.config.vsl 4 Aug 2006 16:14:20 -0000 1.2 @@ -8,7 +8,7 @@ <property name="hibernate.connection.connection_string">server=localhost;database=${applicationId};Integrated Security=SSPI;</property> <property name="hibernate.use_outer_join">true</property> <property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> - <property name="hibernate.cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property> + <!--property name="hibernate.cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property--> <property name="hibernate.show_sql">false</property> <!-- mapping files --> <mapping assembly="${applicationId}Core" /> 1.2 +98 -41 plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/Program.cs Index: Program.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/Program.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- Program.cs 5 Mar 2006 06:16:55 -0000 1.1 +++ Program.cs 4 Aug 2006 16:14:20 -0000 1.2 @@ -1,47 +1,104 @@ using System; -using NHibernate; +using System.Configuration; +using System.Data; +using System.IO; using AndroMDA.NHibernateSupport; +using log4net; namespace SchemaExport { class Program { + public static void Main(string[] args) { + string createDDL = ConfigurationSettings.AppSettings.Get("schema.create.file"); + string dropDDL = ConfigurationSettings.AppSettings.Get("schema.drop.file"); + + string msg = String.Empty; + // Show usage information - Console.WriteLine(); - Console.WriteLine("Usage:"); - Console.WriteLine(" SchemaExport [script] [export]"); - Console.WriteLine(" script=t outputs DDL to the console"); - Console.WriteLine(" export=t exports schema to the database"); - Console.WriteLine("Example:"); - Console.WriteLine(" SchemaExport t f"); - Console.WriteLine(); + string usage = @"Usage: + SchemaExport [-o|-e] + -o = outputs DDL to the console + -e = exports schema to the database + The following example will display the DDL, AND change the database schema: + SchemaExport -o -e + The following example will display the DDL, but NOT change the database schema: + SchemaExport -o + +"; // Initialize Log4Net log4net.Config.XmlConfigurator.Configure(); - // Start NHibernate - SessionManagerFactory.SessionManager = new ThreadLocalSessionManager(); - SessionManagerFactory.SessionManager.HandleApplicationStart(); - // Initialize parameters for SchemaExport - bool script = true; + bool script = false; bool export = false; - if (args.Length >= 1) - { script = args[0].ToLower().Equals("t"); } - if (args.Length >= 2) - { export = args[1].ToLower().Equals("t"); } - - // Call CreateDatabase with the specified parameters - Console.WriteLine( - "Calling CreateDatabase with script = " + script + - " and export = " + export + "..."); - Console.WriteLine(); - DbSupport.CreateDatabase(script, export); - // Stop NHibernate - SessionManagerFactory.SessionManager.HandleApplicationEnd(); + foreach (string arg in args) + { + switch (arg) + { + case "-o": + script = true; + break; + case "-e": + export = true; + break; + } + } + + //They need to enter one of the switches, otherwise we'll kick them out. + if (!export && !script) + { + Console.WriteLine(usage); + return; + } + + string outScript = String.Empty; + DbSupport dbSupport = new DbSupport(); + if (export) + { + if (createDDL == null || createDDL.Trim().Length == 0) + createDDL = "schema-create.sql"; + if (dropDDL == null || dropDDL.Trim().Length == 0) + dropDDL = "schema-drop.sql"; + + //Use the supplied file name to create a FileInfo object to pass to + //the DbSupport method. + FileInfo createFile = new FileInfo(createDDL); + FileInfo deleteFile = new FileInfo(dropDDL); + + try + { + outScript = dbSupport.RegenerateDatabase(createFile, deleteFile); + + Console.WriteLine("SchemaExport COMPLETED SUCCESSFULLY!"); + msg = "\r\n\r\nThe new tables will be in the database defined by the 'hibernate.connection.connection_string' property in the nhibernate.config file.\r\n\r\nAlso, SQL scripts containing the commands required to create and remove all the tables for this version of the schema were saved in the '{0}' and '{1}' files."; + Console.WriteLine(String.Format(msg, createFile.FullName, deleteFile.FullName)); + } + catch (Exception) + { + Console.WriteLine("SchemaExport ENCOUNTERED PROBLEMS!"); + msg = "\r\n\r\nIn some cases, this will be a non-issue. Look back through the errors generated by SchemaExport (in the log file) to determine the specific failure. You may need to manually drop the tables and rerun this program to have the new schema fully generated.\r\n\r\nA SQL script containing the commands required to remove all the tables added by this version of the schema was saved in the {0} file."; + Console.WriteLine(String.Format(msg, deleteFile.FullName)); + } + } + else + { + //we still need the delete and create scripts to send to the console. + string[] dropSql = dbSupport.GenerateDropSQL(); + string[] createSql = dbSupport.GenerateCreateSQL(); + outScript += String.Join(Environment.NewLine, dropSql); + outScript += String.Join(Environment.NewLine, createSql); + } + + if (script) + Console.WriteLine(outScript); + + dbSupport.Dispose(); + dbSupport = null; } } } \ No newline at end of file 1.1 plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/SchemaExport.csproj Index: SchemaExport.csproj =================================================================== <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{D34BE505-BD1E-46DF-BA39-882E26EBA5AF}" > <Build> <Settings ApplicationIcon = "App.ico" AssemblyKeyContainerName = "" AssemblyName = "SchemaExport" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Exe" PreBuildEvent = "" PostBuildEvent = 'xcopy /Y "$(ProjectDir)nhibernate.config" .' RootNamespace = "SchemaExport" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "SchemaExport.Program" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "AndroMDA.NHibernateSupport" Project = "{8349509A-0F7D-411A-AA7B-176AA6452911}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "log4net" AssemblyName = "log4net" HintPath = "..\..\Lib\log4net.dll" /> <Reference Name = "core" Project = "{C953435E-5623-4A29-AA67-3A462F7183E6}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> </References> </Build> <Files> <Include> <File RelPath = "App.config" BuildAction = "None" /> <File RelPath = "App.ico" BuildAction = "Content" /> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "nhibernate.config" BuildAction = "None" /> <File RelPath = "Program.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> 1.1 plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/AssemblyInfo.cs Index: AssemblyInfo.cs =================================================================== using System.Reflection; using System.Runtime.CompilerServices; // // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // 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.*")] // // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] 1.1 plugins/andromdapp/projects/csharp/maven2/src/main/resources/templates/csharp/maven2/schema-export/App.ico <<Binary file>> |