From: Paul H. <pha...@us...> - 2005-03-14 18:53:27
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6901/nhibernate/src/NHibernate/SqlCommand Modified Files: ForUpdateFragment.cs SelectFragment.cs SqlDeleteBuilder.cs SqlSelectBuilder.cs SqlUpdateBuilder.cs Log Message: Refactored as per 2.1 Index: SqlDeleteBuilder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlDeleteBuilder.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SqlDeleteBuilder.cs 23 Jan 2005 15:48:00 -0000 1.6 --- SqlDeleteBuilder.cs 14 Mar 2005 18:53:13 -0000 1.7 *************** *** 91,95 **** public SqlDeleteBuilder AddWhereFragment( string whereSql ) { ! whereStrings.Add( new SqlString( whereSql ) ); return this; } --- 91,98 ---- public SqlDeleteBuilder AddWhereFragment( string whereSql ) { ! if ( whereSql != null && whereSql.Length > 0 ) ! { ! whereStrings.Add( new SqlString( whereSql ) ); ! } return this; } Index: SqlUpdateBuilder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlUpdateBuilder.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SqlUpdateBuilder.cs 23 Jan 2005 15:48:00 -0000 1.6 --- SqlUpdateBuilder.cs 14 Mar 2005 18:53:13 -0000 1.7 *************** *** 159,163 **** public SqlUpdateBuilder AddWhereFragment( string whereSql ) { ! whereStrings.Add( new SqlString( whereSql ) ); return this; } --- 159,167 ---- public SqlUpdateBuilder AddWhereFragment( string whereSql ) { ! // Don't add empty condition's - we get extra ANDs ! if ( whereSql != null && whereSql.Length > 0 ) ! { ! whereStrings.Add( new SqlString( whereSql ) ); ! } return this; } Index: SqlSelectBuilder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlSelectBuilder.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SqlSelectBuilder.cs 31 Dec 2004 22:25:44 -0000 1.7 --- SqlSelectBuilder.cs 14 Mar 2005 18:53:13 -0000 1.8 *************** *** 170,174 **** public SqlSelectBuilder AddWhereClause( SqlString whereSqlString ) { ! whereSqlStrings.Add( whereSqlString ); return this; } --- 170,178 ---- public SqlSelectBuilder AddWhereClause( SqlString whereSqlString ) { ! // Don't add empty condition's - we get extra ANDs ! if ( whereSqlString.ToString() != string.Empty ) ! { ! whereSqlStrings.Add( whereSqlString ); ! } return this; } Index: ForUpdateFragment.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/ForUpdateFragment.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ForUpdateFragment.cs 31 Dec 2004 22:24:48 -0000 1.6 --- ForUpdateFragment.cs 14 Mar 2005 18:53:13 -0000 1.7 *************** *** 1,4 **** --- 1,5 ---- using System; using System.Text; + using NHibernate.Dialect; using NHibernate.Util; *************** *** 41,49 **** /// <summary></summary> ! public SqlString ToSqlStringFragment() { ! return aliases.Length == 0 ? ! new SqlString( String.Empty ) : ! new SqlString( " for update of " + aliases + ( nowait ? " nowait" : String.Empty ) ); } --- 42,62 ---- /// <summary></summary> ! public SqlString ToSqlStringFragment( Dialect.Dialect dialect ) { ! if ( aliases.Length == 0 ) ! { ! return new SqlString( String.Empty ); ! } ! bool nowait = NoWait && dialect.SupportsForUpdateNoWait; ! if ( dialect.SupportsForUpdateOf ) ! { ! return new SqlString( " for update of " + aliases + ( nowait ? " nowait" : String.Empty ) ); ! } ! else if ( dialect.SupportsForUpdate ) ! { ! return new SqlString( " for update" + ( nowait ? " nowait" : String.Empty ) ); ! } ! else ! return new SqlString( String.Empty ); } Index: SelectFragment.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SelectFragment.cs 14 Feb 2005 03:26:10 -0000 1.8 --- SelectFragment.cs 14 Mar 2005 18:53:13 -0000 1.9 *************** *** 1,4 **** --- 1,5 ---- using System.Collections; using System.Text; + using Iesi.Collections; using NHibernate.Util; *************** *** 14,17 **** --- 15,19 ---- private IList columnAliases = new ArrayList(); private Dialect.Dialect dialect; + private string[] usedAliases; /// <summary> *************** *** 27,30 **** --- 29,41 ---- /// /// </summary> + public SelectFragment SetUsedAliases( string[] usedAliases ) + { + this.usedAliases = usedAliases; + return this; + } + + /// <summary> + /// + /// </summary> /// <param name="suffix"></param> /// <returns></returns> *************** *** 173,189 **** { StringBuilder buf = new StringBuilder( columns.Count*10 ); for( int i = 0; i < columns.Count; i++ ) { string col = columns[ i ] as string; ! if( i > 0 || includeLeadingComma ) { ! buf.Append( StringHelper.CommaSpace ); ! } ! string columnAlias = columnAliases[ i ] as string; ! buf.Append( col ) ! .Append( " as " ) ! .Append( new Alias( suffix ).ToAliasString( columnAlias, dialect ) ); } return new SqlString( buf.ToString() ); --- 184,214 ---- { StringBuilder buf = new StringBuilder( columns.Count*10 ); + HashedSet columnsUnique = new HashedSet(); + + if ( usedAliases != null ) + { + columnsUnique.AddAll( usedAliases ); + } + bool found = false; for( int i = 0; i < columns.Count; i++ ) { string col = columns[ i ] as string; ! string columnAlias = columnAliases[ i ] as string; ! ! if ( columnsUnique.Add( columnAlias ) ) { ! if( found || includeLeadingComma ) ! { ! buf.Append( StringHelper.CommaSpace ); ! } ! buf.Append( col ) ! .Append( " as " ) ! .Append( new Alias( suffix ).ToAliasString( columnAlias, dialect ) ); ! ! // Set the flag for the next time ! found = true; ! } } return new SqlString( buf.ToString() ); |