From: Kevin W. <kev...@us...> - 2004-12-31 18:57:33
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Id In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2367 Modified Files: SequenceHiLoGenerator.cs TableGenerator.cs TableHiLoGenerator.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: TableGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Id/TableGenerator.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TableGenerator.cs 30 Nov 2004 18:36:50 -0000 1.11 --- TableGenerator.cs 31 Dec 2004 18:57:22 -0000 1.12 *************** *** 1,8 **** using System; - using System.Data; using System.Collections; using System.Runtime.CompilerServices; ! ! using NHibernate.Dialect; using NHibernate.Engine; using NHibernate.SqlCommand; --- 1,7 ---- using System; using System.Collections; + using System.Data; using System.Runtime.CompilerServices; ! using log4net; using NHibernate.Engine; using NHibernate.SqlCommand; *************** *** 11,16 **** using NHibernate.Util; ! ! namespace NHibernate.Id { /// <summary> --- 10,14 ---- using NHibernate.Util; ! namespace NHibernate.Id { /// <summary> *************** *** 33,42 **** /// </para> /// </remarks> ! public class TableGenerator : IPersistentIdentifierGenerator, IConfigurable { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(TableGenerator)); public const string Column = "column"; public const string Table = "table"; public const string Schema = "schema"; --- 31,45 ---- /// </para> /// </remarks> ! public class TableGenerator : IPersistentIdentifierGenerator, IConfigurable { ! private static readonly ILog log = LogManager.GetLogger( typeof( TableGenerator ) ); + /// <summary></summary> public const string Column = "column"; + + /// <summary></summary> public const string Table = "table"; + + /// <summary></summary> public const string Schema = "schema"; *************** *** 44,66 **** private string columnName; private string query; ! private SqlString updateSql; ! public virtual void Configure(IType type, IDictionary parms, Dialect.Dialect dialect) { ! this.tableName = PropertiesHelper.GetString(Table, parms, "hibernate_unique_key"); ! this.columnName = PropertiesHelper.GetString(Column, parms, "next_hi"); ! string schemaName = (string) parms[Schema]; ! if(schemaName!=null && tableName.IndexOf(StringHelper.Dot)<0) tableName = schemaName + "." + tableName; query = "select " + columnName + " from " + tableName; ! if ( dialect.SupportsForUpdate ) query += " for update"; ! // build the sql string for the Update since it uses parameters Parameter setParam = new Parameter(); setParam.Name = columnName; setParam.SqlType = new Int32SqlType(); ! Parameter whereParam = new Parameter(); whereParam.Name = columnName; --- 47,80 ---- private string columnName; private string query; ! private SqlString updateSql; ! /// <summary> ! /// ! /// </summary> ! /// <param name="type"></param> ! /// <param name="parms"></param> ! /// <param name="dialect"></param> ! public virtual void Configure( IType type, IDictionary parms, Dialect.Dialect dialect ) { ! this.tableName = PropertiesHelper.GetString( Table, parms, "hibernate_unique_key" ); ! this.columnName = PropertiesHelper.GetString( Column, parms, "next_hi" ); ! string schemaName = ( string ) parms[ Schema ]; ! if( schemaName != null && tableName.IndexOf( StringHelper.Dot ) < 0 ) ! { tableName = schemaName + "." + tableName; + } query = "select " + columnName + " from " + tableName; ! if( dialect.SupportsForUpdate ) ! { ! query += " for update"; ! } ! // build the sql string for the Update since it uses parameters Parameter setParam = new Parameter(); setParam.Name = columnName; setParam.SqlType = new Int32SqlType(); ! Parameter whereParam = new Parameter(); whereParam.Name = columnName; *************** *** 68,86 **** SqlStringBuilder builder = new SqlStringBuilder(); ! builder.Add("update " + tableName + " set ") ! .Add(columnName) ! .Add(" = ") ! .Add(setParam) ! .Add(" where ") ! .Add(columnName) ! .Add(" = ") ! .Add(whereParam); updateSql = builder.ToSqlString(); ! } ! [MethodImpl(MethodImplOptions.Synchronized)] ! public virtual object Generate(ISessionImplementor session, object obj) { //this has to be done using a different connection to the containing --- 82,106 ---- SqlStringBuilder builder = new SqlStringBuilder(); ! builder.Add( "update " + tableName + " set " ) ! .Add( columnName ) ! .Add( " = " ) ! .Add( setParam ) ! .Add( " where " ) ! .Add( columnName ) ! .Add( " = " ) ! .Add( whereParam ); updateSql = builder.ToSqlString(); ! } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="obj"></param> ! /// <returns></returns> ! [MethodImpl( MethodImplOptions.Synchronized )] ! public virtual object Generate( ISessionImplementor session, object obj ) { //this has to be done using a different connection to the containing *************** *** 90,97 **** int result; int rows; ! try { IDbTransaction trans = conn.BeginTransaction(); ! do { //the loop ensure atomicitiy of the //select + uspdate even for no transaction --- 110,119 ---- int result; int rows; ! try ! { IDbTransaction trans = conn.BeginTransaction(); ! do ! { //the loop ensure atomicitiy of the //select + uspdate even for no transaction *************** *** 102,150 **** qps.CommandType = CommandType.Text; qps.Transaction = trans; ! try { IDataReader rs = qps.ExecuteReader(); ! if ( !rs.Read() ) { string err = "could not read a hi value - you need to populate the table: " + tableName; ! log.Error(err); ! throw new IdentifierGenerationException(err); } ! result = rs.GetInt32(0); rs.Close(); } ! // TODO: change to SqlException ! catch (Exception e) { ! log.Error("could not read a hi value", e); throw; ! } ! finally { } ! IDbCommand ups = session.Factory.ConnectionProvider.Driver.GenerateCommand(session.Factory.Dialect, updateSql); ups.Connection = conn; ups.Transaction = trans; ! try { ! ((IDbDataParameter)ups.Parameters[0]).Value = result + 1; ! ((IDbDataParameter)ups.Parameters[1]).Value = result; rows = ups.ExecuteNonQuery(); } ! // TODO: change to SqlException ! catch (Exception e) { ! log.Error("could not update hi value in: " + tableName, e); throw; ! } ! finally { } ! } while (rows==0); trans.Commit(); --- 124,173 ---- qps.CommandType = CommandType.Text; qps.Transaction = trans; ! try { IDataReader rs = qps.ExecuteReader(); ! if( !rs.Read() ) { string err = "could not read a hi value - you need to populate the table: " + tableName; ! log.Error( err ); ! throw new IdentifierGenerationException( err ); } ! result = rs.GetInt32( 0 ); rs.Close(); } ! // TODO: change to SqlException ! catch( Exception e ) { ! log.Error( "could not read a hi value", e ); throw; ! } ! finally { } ! IDbCommand ups = session.Factory.ConnectionProvider.Driver.GenerateCommand( session.Factory.Dialect, updateSql ); ups.Connection = conn; ups.Transaction = trans; ! try { ! ( ( IDbDataParameter ) ups.Parameters[ 0 ] ).Value = result + 1; ! ( ( IDbDataParameter ) ups.Parameters[ 1 ] ).Value = result; rows = ups.ExecuteNonQuery(); } ! // TODO: change to SqlException ! catch( Exception e ) { ! log.Error( "could not update hi value in: " + tableName, e ); throw; ! } ! finally { } ! } ! while( rows == 0 ); trans.Commit(); *************** *** 152,179 **** return result; ! } ! finally { ! session.Factory.CloseConnection(conn); } } ! public 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( SqlTypeFactory.GetInt32() ) + " )", ! "insert into " + tableName + " values ( 1 )" ! }; } ! public string SqlDropString(Dialect.Dialect dialect) { return "drop table " + tableName + dialect.CascadeConstraintsString; } ! public object GeneratorKey() { return tableName; --- 175,214 ---- return result; ! } ! finally { ! session.Factory.CloseConnection( conn ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="dialect"></param> ! /// <returns></returns> ! public 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( SqlTypeFactory.GetInt32() ) + " )", ! "insert into " + tableName + " values ( 1 )" ! }; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="dialect"></param> ! /// <returns></returns> ! public string SqlDropString( Dialect.Dialect dialect ) { return "drop table " + tableName + dialect.CascadeConstraintsString; } ! /// <summary></summary> ! public object GeneratorKey() { return tableName; *************** *** 181,183 **** } ! } --- 216,218 ---- } ! } \ No newline at end of file Index: SequenceHiLoGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Id/SequenceHiLoGenerator.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SequenceHiLoGenerator.cs 12 Jul 2004 01:31:09 -0000 1.5 --- SequenceHiLoGenerator.cs 31 Dec 2004 18:57:22 -0000 1.6 *************** *** 1,14 **** - using System; - using System.Data; using System.Collections; using System.Runtime.CompilerServices; ! using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; - using NHibernate.Dialect; - ! namespace NHibernate.Id { /// <summary> --- 1,10 ---- using System.Collections; using System.Runtime.CompilerServices; ! using log4net; using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; ! namespace NHibernate.Id { /// <summary> *************** *** 26,33 **** /// </para> /// </remarks> ! public class SequenceHiLoGenerator : SequenceGenerator { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(SequenceHiLoGenerator)); public const string MaxLo = "max_lo"; --- 22,30 ---- /// </para> /// </remarks> ! public class SequenceHiLoGenerator : SequenceGenerator { ! private static readonly ILog log = LogManager.GetLogger( typeof( SequenceHiLoGenerator ) ); + /// <summary></summary> public const string MaxLo = "max_lo"; *************** *** 37,60 **** private System.Type returnClass; ! public override void Configure(IType type, IDictionary parms, Dialect.Dialect d) { ! base.Configure(type, parms, d); ! maxLo = PropertiesHelper.GetInt32(MaxLo, parms, 9); lo = maxLo + 1; // so we "clock over" on the first invocation returnClass = type.ReturnedClass; } ! [MethodImpl(MethodImplOptions.Synchronized)] ! public override object Generate(ISessionImplementor session, object obj) { ! if ( lo > maxLo ) { ! long hival = ( (long) base.Generate(session, obj) ); lo = 1; ! hi = hival * ( maxLo+1 ); ! log.Debug("new hi value: " + hival); } return IdentifierGeneratorFactory.CreateNumber( hi + lo++, returnClass ); } } ! } --- 34,69 ---- private System.Type returnClass; ! /// <summary> ! /// ! /// </summary> ! /// <param name="type"></param> ! /// <param name="parms"></param> ! /// <param name="d"></param> ! public override void Configure( IType type, IDictionary parms, Dialect.Dialect d ) { ! base.Configure( type, parms, d ); ! maxLo = PropertiesHelper.GetInt32( MaxLo, parms, 9 ); lo = maxLo + 1; // so we "clock over" on the first invocation returnClass = type.ReturnedClass; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="obj"></param> ! /// <returns></returns> ! [MethodImpl( MethodImplOptions.Synchronized )] ! public override object Generate( ISessionImplementor session, object obj ) { ! if( lo > maxLo ) { ! long hival = ( ( long ) base.Generate( session, obj ) ); lo = 1; ! hi = hival*( maxLo + 1 ); ! log.Debug( "new hi value: " + hival ); } return IdentifierGeneratorFactory.CreateNumber( hi + lo++, returnClass ); } } ! } \ No newline at end of file Index: TableHiLoGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Id/TableHiLoGenerator.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TableHiLoGenerator.cs 12 Jul 2004 01:31:10 -0000 1.5 --- TableHiLoGenerator.cs 31 Dec 2004 18:57:22 -0000 1.6 *************** *** 1,14 **** - using System; - using System.Data; using System.Collections; using System.Runtime.CompilerServices; ! ! using NHibernate.Dialect; using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; ! ! namespace NHibernate.Id { /// <summary> --- 1,10 ---- using System.Collections; using System.Runtime.CompilerServices; ! using log4net; using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; ! namespace NHibernate.Id { /// <summary> *************** *** 28,35 **** /// </para> /// </remarks> ! public class TableHiLoGenerator : TableGenerator { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(TableHiLoGenerator)); public const string MaxLo = "max_lo"; --- 24,32 ---- /// </para> /// </remarks> ! public class TableHiLoGenerator : TableGenerator { ! private static readonly ILog log = LogManager.GetLogger( typeof( TableHiLoGenerator ) ); + /// <summary></summary> public const string MaxLo = "max_lo"; *************** *** 39,59 **** private System.Type returnClass; ! public override void Configure(IType type, IDictionary parms, Dialect.Dialect d) { ! base.Configure(type, parms, d); ! maxLo = PropertiesHelper.GetInt32(MaxLo, parms, short.MaxValue); lo = maxLo + 1; // so we "clock over" on the first invocation returnClass = type.ReturnedClass; } ! [MethodImpl(MethodImplOptions.Synchronized)] ! public override object Generate(ISessionImplementor session, object obj) { ! if (lo > maxLo) { ! int hival = ( (int) base.Generate(session, obj) ); lo = 1; ! hi = hival * (maxLo+1); ! log.Debug("new hi value: " + hival); } --- 36,68 ---- private System.Type returnClass; ! /// <summary> ! /// ! /// </summary> ! /// <param name="type"></param> ! /// <param name="parms"></param> ! /// <param name="d"></param> ! public override void Configure( IType type, IDictionary parms, Dialect.Dialect d ) { ! base.Configure( type, parms, d ); ! maxLo = PropertiesHelper.GetInt32( MaxLo, parms, short.MaxValue ); lo = maxLo + 1; // so we "clock over" on the first invocation returnClass = type.ReturnedClass; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="obj"></param> ! /// <returns></returns> ! [MethodImpl( MethodImplOptions.Synchronized )] ! public override object Generate( ISessionImplementor session, object obj ) { ! if( lo > maxLo ) { ! int hival = ( ( int ) base.Generate( session, obj ) ); lo = 1; ! hi = hival*( maxLo + 1 ); ! log.Debug( "new hi value: " + hival ); } *************** *** 61,63 **** } } ! } --- 70,72 ---- } } ! } \ No newline at end of file |