From: Michael D. <mik...@us...> - 2004-04-13 02:49:16
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Mapping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15524/Mapping Modified Files: Table.cs Log Message: Synching Table with H2.0.3 Index: Table.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Mapping/Table.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Table.cs 13 Apr 2004 02:06:54 -0000 1.8 --- Table.cs 13 Apr 2004 02:35:21 -0000 1.9 *************** *** 118,125 **** } ! //TODO: NH2.0.3 has an ICollection SqlAlterStrings method instead of this one... ! public string SqlAlterString(Dialect.Dialect dialect, IMapping p, DataTable tableInfo) { ! StringBuilder buf = new StringBuilder(50); foreach(Column col in ColumnCollection) { --- 118,130 ---- } ! public IList SqlAlterStrings(Dialect.Dialect dialect, IMapping p, DataTable tableInfo) { ! StringBuilder root = new StringBuilder("alter table ") ! .Append( GetQualifiedName(dialect) ) ! .Append(" ") ! .Append( dialect.AddColumnString ); ! ! IList results = new ArrayList(ColumnCollection.Count); ! foreach(Column col in ColumnCollection) { *************** *** 128,148 **** if (columnInfo == null) { ! // the column doesnt exist at all ! if (buf.Length != 0) ! buf.Append(StringHelper.CommaSpace); ! buf.Append(col.GetQuotedName(dialect)) ! .Append(' ') ! .Append(col.GetSqlType(dialect, p)); ! if (col.IsUnique && dialect.SupportsUnique) { ! buf.Append(" unique"); } } } ! if (buf.Length == 0) ! return null; ! ! return new StringBuilder("alter table ").Append(GetQualifiedName(dialect)).Append(" add ").Append(buf).ToString(); ! } --- 133,152 ---- if (columnInfo == null) { ! StringBuilder alter = new StringBuilder( root.ToString() ) ! .Append(" ") ! .Append( col.GetQuotedName(dialect) ) ! .Append(" ") ! .Append(col.GetSqlType(dialect, p)); ! ! if (col.IsUnique && dialect.SupportsUnique) ! { ! alter.Append(" unique"); } + + results.Add( alter.ToString() ); } } ! return results; } *************** *** 157,167 **** // try to find out the name of the pk to create it as identity if the identitygenerator is used string pkname = null; ! if (primaryKey != null && identityColumn ) { ! foreach(Column col in primaryKey.ColumnCollection) { pkname = col.GetQuotedName(dialect); //should only go through this loop once } } int i = 0; ! foreach(Column col in ColumnCollection) { i++; buf.Append( col.GetQuotedName(dialect) ) --- 161,175 ---- // try to find out the name of the pk to create it as identity if the identitygenerator is used string pkname = null; ! if (primaryKey != null && identityColumn ) ! { ! foreach(Column col in primaryKey.ColumnCollection) ! { pkname = col.GetQuotedName(dialect); //should only go through this loop once } } + int i = 0; ! foreach(Column col in ColumnCollection) ! { i++; buf.Append( col.GetQuotedName(dialect) ) *************** *** 169,189 **** .Append( col.GetSqlType(dialect, p) ); ! if ( identityColumn && col.GetQuotedName(dialect).Equals(pkname) ) { buf.Append(' ') .Append( dialect.IdentityColumnString); ! } else { ! if (col.IsNullable) { buf.Append( dialect.NullColumnString ); ! } else { buf.Append(" not null" ); } } ! if ( col.IsUnique && dialect.SupportsUnique ) { ! buf.Append(" unique"); } if ( i < ColumnCollection.Count ) buf.Append(StringHelper.CommaSpace); } ! if (primaryKey != null) { //if ( dialect is HSQLDialect && identityColumn ) { // //ugly hack... --- 177,214 ---- .Append( col.GetSqlType(dialect, p) ); ! if ( identityColumn && col.GetQuotedName(dialect).Equals(pkname) ) ! { buf.Append(' ') .Append( dialect.IdentityColumnString); ! } ! else ! { ! if (col.IsNullable) ! { buf.Append( dialect.NullColumnString ); ! } ! else ! { buf.Append(" not null" ); } } ! if ( col.IsUnique) ! { ! if(dialect.SupportsUnique) ! { ! buf.Append(" unique"); ! } ! else ! { ! UniqueKey uk = GetUniqueKey(col.GetQuotedName(dialect) + "_"); ! uk.AddColumn(col); ! } } if ( i < ColumnCollection.Count ) buf.Append(StringHelper.CommaSpace); } ! ! if (primaryKey != null) ! { //if ( dialect is HSQLDialect && identityColumn ) { // //ugly hack... *************** *** 192,200 **** //} } ! if ( dialect.SupportsUnique ) { ! foreach(UniqueKey uk in UniqueKeyCollection) { ! buf.Append(',').Append( uk.SqlConstraintString(dialect) ); ! } } buf.Append(StringHelper.ClosedParen); --- 217,226 ---- //} } ! ! foreach(UniqueKey uk in UniqueKeyCollection) ! { ! buf.Append(',').Append( uk.SqlConstraintString(dialect) ); } + buf.Append(StringHelper.ClosedParen); *************** *** 206,218 **** } ! public PrimaryKey PrimaryKey { get { return primaryKey; } set { primaryKey = value; } } ! public Index GetIndex(string name) { Index index = (Index) indexes[name]; ! if (index == null) { index = new Index(); index.Name = name; --- 232,247 ---- } ! public PrimaryKey PrimaryKey ! { get { return primaryKey; } set { primaryKey = value; } } ! public Index GetIndex(string name) ! { Index index = (Index) indexes[name]; ! if (index == null) ! { index = new Index(); index.Name = name; *************** *** 224,228 **** } ! public UniqueKey GetUniqueKey(string name) { UniqueKey uk = (UniqueKey) uniqueKeys[name]; --- 253,258 ---- } ! public UniqueKey GetUniqueKey(string name) ! { UniqueKey uk = (UniqueKey) uniqueKeys[name]; *************** *** 233,240 **** uniqueKeys.Add(name, uk); } return uk; } ! public ForeignKey CreateForeignKey(IList columns) { string name = "FK" + UniqueColumnString( columns ); ForeignKey fk = (ForeignKey) foreignKeys[name]; --- 263,272 ---- uniqueKeys.Add(name, uk); } + return uk; } ! public ForeignKey CreateForeignKey(IList columns) ! { string name = "FK" + UniqueColumnString( columns ); ForeignKey fk = (ForeignKey) foreignKeys[name]; *************** *** 246,261 **** foreignKeys.Add(name, fk); } ! foreach(Column col in columns) { fk.AddColumn( col ); } return fk; } ! public string UniqueColumnString(ICollection col) { int result = 0; ! foreach(object obj in col) { ! // this is marked as unchecked because the GetHashCode could potentially // cause an integer overflow. This way if there is an overflow it will --- 278,297 ---- foreignKeys.Add(name, fk); } ! ! foreach(Column col in columns) ! { fk.AddColumn( col ); } + return fk; } ! public string UniqueColumnString(ICollection col) ! { int result = 0; ! foreach(object obj in col) ! { // this is marked as unchecked because the GetHashCode could potentially // cause an integer overflow. This way if there is an overflow it will *************** *** 267,283 **** } ! public string Schema { get { return schema; } set { schema = value; } } ! public int UniqueInteger { get { return uniqueInteger; } } ! public void SetIdentifierValue(Value idValue) { this.idValue = idValue; } --- 303,327 ---- } ! public string Schema ! { get { return schema; } set { schema = value; } } ! public int UniqueInteger ! { get { return uniqueInteger; } } ! public void SetIdentifierValue(Value idValue) ! { this.idValue = idValue; } + public bool IsQuoted + { + get { return quoted; } + set { quoted = value; } + } |