From: <fab...@us...> - 2009-07-09 16:10:41
|
Revision: 4598 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4598&view=rev Author: fabiomaulo Date: 2009-07-09 16:10:33 +0000 (Thu, 09 Jul 2009) Log Message: ----------- Minor (reformatting) Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Id/TableGenerator.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Id/TableGenerator.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Id/TableGenerator.cs 2009-07-09 15:31:05 UTC (rev 4597) +++ branches/2.1.x/nhibernate/src/NHibernate/Id/TableGenerator.cs 2009-07-09 16:10:33 UTC (rev 4598) @@ -4,9 +4,9 @@ using System.Data; using System.Runtime.CompilerServices; using log4net; +using NHibernate.AdoNet.Util; using NHibernate.Dialect; using NHibernate.Engine; -using NHibernate.Engine.Transaction; using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Type; @@ -14,9 +14,6 @@ namespace NHibernate.Id { - using System.Transactions; - using NHibernate.AdoNet.Util; - /// <summary> /// An <see cref="IIdentifierGenerator" /> that uses a database table to store the last /// generated value. @@ -38,7 +35,8 @@ /// </remarks> public class TableGenerator : TransactionHelper, IPersistentIdentifierGenerator, IConfigurable { - private static readonly ILog log = LogManager.GetLogger(typeof(TableGenerator)); + private static readonly ILog log = LogManager.GetLogger(typeof (TableGenerator)); + /// <summary> /// An additional where clause that is added to /// the queries against the table. @@ -83,7 +81,6 @@ /// <param name="dialect">The <see cref="Dialect"/> to help with Configuration.</param> public virtual void Configure(IType type, IDictionary<string, string> parms, Dialect.Dialect dialect) { - tableName = PropertiesHelper.GetString(TableParamName, parms, DefaultTableName); columnName = PropertiesHelper.GetString(ColumnParamName, parms, DefaultColumnName); whereClause = PropertiesHelper.GetString(Where, parms, ""); @@ -119,21 +116,14 @@ columnSqlType = SqlTypeFactory.Int32; } - parameterTypes = new SqlType[2] {columnSqlType, columnSqlType}; + parameterTypes = new[] {columnSqlType, columnSqlType}; - SqlStringBuilder builder = new SqlStringBuilder(); - builder.Add("update " + tableName + " set ") - .Add(columnName) - .Add(" = ") - .Add(Parameter.Placeholder) - .Add(" where ") - .Add(columnName) - .Add(" = ") - .Add(Parameter.Placeholder); + var builder = new SqlStringBuilder(); + builder.Add("update " + tableName + " set ").Add(columnName).Add(" = ").Add(Parameter.Placeholder).Add(" where ").Add + (columnName).Add(" = ").Add(Parameter.Placeholder); if (string.IsNullOrEmpty(whereClause) == false) { - builder.Add(" and ") - .Add(whereClause); + builder.Add(" and ").Add(whereClause); } updateSql = builder.ToSqlString(); @@ -172,16 +162,16 @@ /// create the necessary database objects and to create the first value as <c>1</c> /// for the TableGenerator. /// </returns> - public string[] SqlCreateStrings(Dialect.Dialect dialect) + public virtual string[] SqlCreateStrings(Dialect.Dialect dialect) { // changed the first value to be "1" by default since an uninitialized Int32 is 0 - leaving // it at 0 would cause problems with an unsaved-value="0" which is what most people are // defaulting <id>'s with Int32 types at. - return new string[] - { - "create table " + tableName + " ( " + columnName + " " + dialect.GetTypeName(columnSqlType) + " )", - "insert into " + tableName + " values ( 1 )" - }; + return new[] + { + "create table " + tableName + " ( " + columnName + " " + dialect.GetTypeName(columnSqlType) + " )", + "insert into " + tableName + " values ( 1 )" + }; } /// <summary> @@ -191,9 +181,9 @@ /// <returns> /// A <see cref="string"/> that will drop the database objects for the TableGenerator. /// </returns> - public string[] SqlDropString(Dialect.Dialect dialect) + public virtual string[] SqlDropString(Dialect.Dialect dialect) { - return new string[] { dialect.GetDropTableString(tableName) }; + return new[] {dialect.GetDropTableString(tableName)}; } /// <summary> @@ -209,7 +199,8 @@ #endregion - public override object DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction) + public override object DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, + IDbTransaction transaction) { long result; int rows; @@ -243,15 +234,18 @@ } finally { - if (rs != null) rs.Close(); + if (rs != null) + { + rs.Close(); + } qps.Dispose(); } - IDbCommand ups = - session.Factory.ConnectionProvider.Driver.GenerateCommand(CommandType.Text, updateSql, parameterTypes); + IDbCommand ups = session.Factory.ConnectionProvider.Driver.GenerateCommand(CommandType.Text, updateSql, + parameterTypes); ups.Connection = conn; ups.Transaction = transaction; - + try { columnType.Set(ups, result + 1, 0); @@ -270,9 +264,10 @@ { ups.Dispose(); } - } while (rows == 0); + } + while (rows == 0); return result; } } -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |