From: Kevin W. <kev...@us...> - 2004-12-31 22:40:04
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Tool/hbm2ddl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11770 Modified Files: AdoColumn.cs AdoTable.cs SchemaExport.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: AdoColumn.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Tool/hbm2ddl/AdoColumn.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AdoColumn.cs 21 Mar 2003 19:49:11 -0000 1.1 --- AdoColumn.cs 31 Dec 2004 22:39:53 -0000 1.2 *************** *** 1,15 **** - using System; using System.Data; ! namespace NHibernate.Tool.hbm2ddl { ! ! public class AdoColumn { private string name; private System.Type type; private int columnSize; private bool isNullable; - ! public AdoColumn(DataColumn column) { name = column.ColumnName; type = column.DataType; --- 1,20 ---- using System.Data; ! namespace NHibernate.Tool.hbm2ddl ! { ! /// <summary></summary> ! public class AdoColumn ! { private string name; private System.Type type; private int columnSize; private bool isNullable; ! /// <summary> ! /// ! /// </summary> ! /// <param name="column"></param> ! public AdoColumn( DataColumn column ) ! { name = column.ColumnName; type = column.DataType; *************** *** 18,41 **** } ! public string Name { get { return name; } } ! public System.Type Type { get { return type; } } ! public int ColumnSize { get { return columnSize; } } ! public bool IsNullable { get { return isNullable; } } ! public override string ToString() { return name; } ! public override int GetHashCode() { return name.GetHashCode(); } } ! } --- 23,74 ---- } ! /// <summary></summary> ! public string Name ! { get { return name; } } ! ! /// <summary></summary> ! public System.Type Type ! { get { return type; } } ! ! /// <summary></summary> ! public int ColumnSize ! { get { return columnSize; } } ! ! /// <summary></summary> ! public bool IsNullable ! { get { return isNullable; } } ! /// <summary></summary> ! public override string ToString() ! { return name; } ! /// <summary></summary> ! public override int GetHashCode() ! { return name.GetHashCode(); } + + /// <summary> + /// + /// </summary> + /// <param name="obj"></param> + /// <returns></returns> + public override bool Equals( object obj ) + { + if( this == obj ) return true; + AdoColumn c = obj as AdoColumn; + if( c == null || !c.Equals( this ) ) return false; + return c.Name == this.name; + } } ! } \ No newline at end of file Index: AdoTable.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Tool/hbm2ddl/AdoTable.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AdoTable.cs 21 Mar 2003 19:49:12 -0000 1.1 --- AdoTable.cs 31 Dec 2004 22:39:53 -0000 1.2 *************** *** 1,22 **** - using System; - using System.Data; using System.Collections; ! namespace NHibernate.Tool.hbm2ddl { ! ! public class AdoTable { ! private string name; private IDictionary columns = new Hashtable(); ! private IDictionary foreignKeys = new Hashtable(); ! private IDictionary indexes = new Hashtable(); ! ! public AdoTable(DataTable table) { name = table.TableName; ! foreach(DataColumn column in table.Columns) { ! columns.Add( column.ColumnName, new AdoColumn(column) ); } } ! public ICollection Columns { get { return columns.Values; } } --- 1,31 ---- using System.Collections; + using System.Data; ! namespace NHibernate.Tool.hbm2ddl ! { ! /// <summary></summary> ! public class AdoTable ! { ! private string name; // not used !?! private IDictionary columns = new Hashtable(); ! // private IDictionary foreignKeys = new Hashtable(); ! // private IDictionary indexes = new Hashtable(); ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="table"></param> ! public AdoTable( DataTable table ) ! { name = table.TableName; ! foreach( DataColumn column in table.Columns ) ! { ! columns.Add( column.ColumnName, new AdoColumn( column ) ); } } ! /// <summary></summary> ! public ICollection Columns ! { get { return columns.Values; } } *************** *** 24,26 **** } ! } --- 33,35 ---- } ! } \ No newline at end of file Index: SchemaExport.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SchemaExport.cs 27 Dec 2004 02:27:28 -0000 1.12 --- SchemaExport.cs 31 Dec 2004 22:39:53 -0000 1.13 *************** *** 4,15 **** using System.IO; using System.Text; - using NHibernate.Cfg; using NHibernate.Connection; - using NHibernate.Dialect; using NHibernate.Util; ! ! namespace NHibernate.Tool.hbm2ddl { /// <summary> --- 4,12 ---- using System.IO; using System.Text; using NHibernate.Cfg; using NHibernate.Connection; using NHibernate.Util; ! namespace NHibernate.Tool.hbm2ddl { /// <summary> *************** *** 20,27 **** /// used when a dll can not be directly used. /// </remarks> ! public class SchemaExport { ! private string[] dropSQL; ! private string[] createSQL; private IDictionary connectionProperties; private string outputFile = null; --- 17,24 ---- /// used when a dll can not be directly used. /// </remarks> ! public class SchemaExport { ! private string[ ] dropSQL; ! private string[ ] createSQL; private IDictionary connectionProperties; private string outputFile = null; *************** *** 33,37 **** /// </summary> /// <param name="cfg">The NHibernate Configuration to generate the schema from.</param> ! public SchemaExport(Configuration cfg) : this(cfg, cfg.Properties) { } --- 30,34 ---- /// </summary> /// <param name="cfg">The NHibernate Configuration to generate the schema from.</param> ! public SchemaExport( Configuration cfg ) : this( cfg, cfg.Properties ) { } *************** *** 43,52 **** /// <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 connectionProperties) { this.connectionProperties = connectionProperties; ! dialect = Dialect.Dialect.GetDialect(connectionProperties); ! dropSQL = cfg.GenerateDropSchemaScript(dialect); ! createSQL = cfg.GenerateSchemaCreationScript(dialect); } --- 40,49 ---- /// <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 connectionProperties ) { this.connectionProperties = connectionProperties; ! dialect = Dialect.Dialect.GetDialect( connectionProperties ); ! dropSQL = cfg.GenerateDropSchemaScript( dialect ); ! createSQL = cfg.GenerateSchemaCreationScript( dialect ); } *************** *** 56,65 **** /// <param name="filename">The name of the file to output the ddl to.</param> /// <returns>The SchemaExport object.</returns> ! public SchemaExport SetOutputFile(string filename) { outputFile = filename; return this; } ! /// <summary> /// Set the end of statement delimiter --- 53,62 ---- /// <param name="filename">The name of the file to output the ddl to.</param> /// <returns>The SchemaExport object.</returns> ! public SchemaExport SetOutputFile( string filename ) { outputFile = filename; return this; } ! /// <summary> /// Set the end of statement delimiter *************** *** 67,75 **** /// <param name="delimiter">The end of statement delimiter.</param> /// <returns>The SchemaExport object.</returns> ! public SchemaExport SetDelimiter(string delimiter) { this.delimiter = delimiter; return this; } /// <summary> /// Run the schema creation script --- 64,73 ---- /// <param name="delimiter">The end of statement delimiter.</param> /// <returns>The SchemaExport object.</returns> ! public SchemaExport SetDelimiter( string delimiter ) { this.delimiter = delimiter; return this; } + /// <summary> /// Run the schema creation script *************** *** 81,87 **** /// the justDrop parameter to false and the format parameter to true. /// </remarks> ! public void Create(bool script, bool export) { ! Execute(script, export, false, true); } --- 79,85 ---- /// the justDrop parameter to false and the format parameter to true. /// </remarks> ! public void Create( bool script, bool export ) { ! Execute( script, export, false, true ); } *************** *** 95,101 **** /// the justDrop and format parameter to true. /// </remarks> ! public void Drop(bool script, bool export) { ! Execute(script, export, true, true); } --- 93,99 ---- /// the justDrop and format parameter to true. /// </remarks> ! public void Drop( bool script, bool export ) { ! Execute( script, export, true, true ); } *************** *** 110,116 **** /// This method allows for both the drop and create ddl script to be executed. /// </remarks> ! public void Execute(bool script, bool export, bool justDrop, bool format) { ! IDbConnection connection = null; StreamWriter fileOutput = null; IConnectionProvider connectionProvider = null; --- 108,114 ---- /// This method allows for both the drop and create ddl script to be executed. /// </remarks> ! public void Execute( bool script, bool export, bool justDrop, bool format ) { ! IDbConnection connection = null; StreamWriter fileOutput = null; IConnectionProvider connectionProvider = null; *************** *** 118,240 **** IDictionary props = new Hashtable(); ! foreach(DictionaryEntry de in dialect.DefaultProperties) { ! props[de.Key] = de.Value ; } ! ! if (connectionProperties!=null) { ! foreach(DictionaryEntry de in connectionProperties) { ! props[de.Key] = de.Value; } } ! ! try { ! if (outputFile!=null) { ! fileOutput = new StreamWriter(outputFile); } ! if (export) { ! connectionProvider = ConnectionProviderFactory.NewConnectionProvider(props); connection = connectionProvider.GetConnection(); statement = connection.CreateCommand(); } ! for (int i=0; i<dropSQL.Length; i++) { ! try { string formatted; ! if(format) { ! formatted = Format( dropSQL[i] ); } ! else { ! formatted = dropSQL[i]; } ! if (delimiter!=null) formatted += delimiter; ! if (script) Console.WriteLine(formatted); ! if (outputFile!=null) fileOutput.WriteLine( formatted ); ! if (export) { ! statement.CommandText = dropSQL[i]; statement.CommandType = CommandType.Text; statement.ExecuteNonQuery(); } ! } ! catch(Exception e) { ! if (!script) Console.WriteLine( dropSQL[i] ); Console.WriteLine( "Unsuccessful: " + e.Message ); } } ! if (!justDrop) { ! for (int j=0; j<createSQL.Length; j++) { ! try { string formatted; ! if(format) { ! formatted = Format( createSQL[j] ); } ! else { ! formatted = createSQL[j]; } ! if (delimiter!=null) formatted += delimiter; ! if (script) Console.WriteLine(formatted); ! if (outputFile!=null) fileOutput.WriteLine( formatted ); ! if (export) { ! statement.CommandText = createSQL[j]; statement.CommandType = CommandType.Text; statement.ExecuteNonQuery(); } ! } ! catch(Exception e) { ! if (!script) Console.WriteLine( createSQL[j] ); Console.WriteLine( "Unsuccessful: " + e.Message ); } } } ! ! } ! catch (Exception e) { ! Console.Write(e.StackTrace); throw new HibernateException( e.Message, e ); ! } ! finally { ! try { ! if (statement!=null) statement.Dispose(); ! if (connection!=null) { ! connectionProvider.CloseConnection(connection); connectionProvider.Close(); } ! } ! catch(Exception e) { Console.Error.WriteLine( "Could not close connection: " + e.Message ); } ! if (fileOutput!=null) { ! try { fileOutput.Close(); ! } ! catch (Exception ioe) { Console.Error.WriteLine( "Error closing output file " + outputFile + ": " + ioe.Message ); --- 116,265 ---- IDictionary props = new Hashtable(); ! foreach( DictionaryEntry de in dialect.DefaultProperties ) { ! props[ de.Key ] = de.Value; } ! ! if( connectionProperties != null ) { ! foreach( DictionaryEntry de in connectionProperties ) { ! props[ de.Key ] = de.Value; } } ! ! try { ! if( outputFile != null ) { ! fileOutput = new StreamWriter( outputFile ); } ! if( export ) { ! connectionProvider = ConnectionProviderFactory.NewConnectionProvider( props ); connection = connectionProvider.GetConnection(); statement = connection.CreateCommand(); } ! for( int i = 0; i < dropSQL.Length; i++ ) { ! try { string formatted; ! if( format ) { ! formatted = Format( dropSQL[ i ] ); } ! else { ! formatted = dropSQL[ i ]; } ! if( delimiter != null ) { ! formatted += delimiter; ! } ! if( script ) ! { ! Console.WriteLine( formatted ); ! } ! if( outputFile != null ) ! { ! fileOutput.WriteLine( formatted ); ! } ! if( export ) ! { ! statement.CommandText = dropSQL[ i ]; statement.CommandType = CommandType.Text; statement.ExecuteNonQuery(); } ! } ! catch( Exception e ) { ! if( !script ) ! { ! Console.WriteLine( dropSQL[ i ] ); ! } Console.WriteLine( "Unsuccessful: " + e.Message ); } } ! if( !justDrop ) { ! for( int j = 0; j < createSQL.Length; j++ ) { ! try { string formatted; ! if( format ) { ! formatted = Format( createSQL[ j ] ); } ! else { ! formatted = createSQL[ j ]; } ! if( delimiter != null ) { ! formatted += delimiter; ! } ! if( script ) ! { ! Console.WriteLine( formatted ); ! } ! if( outputFile != null ) ! { ! fileOutput.WriteLine( formatted ); ! } ! if( export ) ! { ! statement.CommandText = createSQL[ j ]; statement.CommandType = CommandType.Text; statement.ExecuteNonQuery(); } ! } ! catch( Exception e ) { ! if( !script ) ! { ! Console.WriteLine( createSQL[ j ] ); ! } Console.WriteLine( "Unsuccessful: " + e.Message ); } } } ! ! } ! catch( Exception e ) { ! Console.Write( e.StackTrace ); throw new HibernateException( e.Message, e ); ! } ! finally { ! try { ! if( statement != null ) { ! statement.Dispose(); ! } ! if( connection != null ) ! { ! connectionProvider.CloseConnection( connection ); connectionProvider.Close(); } ! } ! catch( Exception e ) { Console.Error.WriteLine( "Could not close connection: " + e.Message ); } ! if( fileOutput != null ) { ! try { fileOutput.Close(); ! } ! catch( Exception ioe ) { Console.Error.WriteLine( "Error closing output file " + outputFile + ": " + ioe.Message ); *************** *** 266,272 **** /// </list> /// </remarks> ! private static string Format(string sql) { ! if ( sql.IndexOf("\"") > 0 || sql.IndexOf("'") > 0) { return sql; --- 291,297 ---- /// </list> /// </remarks> ! private static string Format( string sql ) { ! if( sql.IndexOf( "\"" ) > 0 || sql.IndexOf( "'" ) > 0 ) { return sql; *************** *** 275,304 **** string formatted; ! if ( sql.ToLower().StartsWith("create table") ) { ! StringBuilder result = new StringBuilder(60); ! StringTokenizer tokens = new StringTokenizer( sql, "(,)", true); int depth = 0; ! foreach(string tok in tokens) { ! if ( StringHelper.ClosedParen.Equals(tok) ) { depth--; ! if (depth==0) result.Append("\n"); } ! result.Append(tok); ! if ( StringHelper.Comma.Equals(tok) && depth==1 ) result.Append("\n "); ! if ( StringHelper.OpenParen.Equals(tok) ) { depth++; ! if ( depth==1 ) result.Append("\n "); } } formatted = result.ToString(); ! } ! else { formatted = sql; --- 300,338 ---- string formatted; ! if( sql.ToLower().StartsWith( "create table" ) ) { ! StringBuilder result = new StringBuilder( 60 ); ! StringTokenizer tokens = new StringTokenizer( sql, "(,)", true ); int depth = 0; ! foreach( string tok in tokens ) { ! if( StringHelper.ClosedParen.Equals( tok ) ) { depth--; ! if( depth == 0 ) ! { ! result.Append( "\n" ); ! } } ! result.Append( tok ); ! if( StringHelper.Comma.Equals( tok ) && depth == 1 ) ! { ! result.Append( "\n " ); ! } ! if( StringHelper.OpenParen.Equals( tok ) ) { depth++; ! if( depth == 1 ) ! { ! result.Append( "\n " ); ! } } } formatted = result.ToString(); ! } ! else { formatted = sql; *************** *** 306,310 **** return formatted; ! } } ! } --- 340,344 ---- return formatted; ! } } ! } \ No newline at end of file |