From: Kevin W. <kev...@us...> - 2004-12-31 19:50:44
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12330 Modified Files: BatcherImpl.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: BatcherImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/BatcherImpl.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** BatcherImpl.cs 21 Dec 2004 20:43:40 -0000 1.13 --- BatcherImpl.cs 31 Dec 2004 19:50:33 -0000 1.14 *************** *** 2,25 **** using System.Collections; using System.Data; - using Iesi.Collections; ! using NHibernate.Driver; using NHibernate.Engine; using NHibernate.SqlCommand; ! namespace NHibernate.Impl { /// <summary> /// Manages prepared statements and batching. Class exists to enfores seperation of concerns /// </summary> ! internal abstract class BatcherImpl : IBatcher { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(BatcherImpl)); private static int openCommandCount; private static int openReaderCount; protected readonly ISessionImplementor session; protected readonly ISessionFactoryImplementor factory; --- 2,27 ---- using System.Collections; using System.Data; using Iesi.Collections; ! using log4net; using NHibernate.Driver; using NHibernate.Engine; using NHibernate.SqlCommand; ! namespace NHibernate.Impl { /// <summary> /// Manages prepared statements and batching. Class exists to enfores seperation of concerns /// </summary> ! internal abstract class BatcherImpl : IBatcher { ! private static readonly ILog log = LogManager.GetLogger( typeof( BatcherImpl ) ); private static int openCommandCount; private static int openReaderCount; + /// <summary></summary> protected readonly ISessionImplementor session; + + /// <summary></summary> protected readonly ISessionFactoryImplementor factory; *************** *** 37,41 **** private IDictionary commands; ! public BatcherImpl(ISessionImplementor session) { this.session = session; --- 39,47 ---- private IDictionary commands; ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! public BatcherImpl( ISessionImplementor session ) { this.session = session; *************** *** 47,60 **** /// Gets the current Command that is contained for this Batch /// </summary> ! protected IDbCommand GetCommand() { return batchCommand; } ! ! public IDbCommand Generate(SqlString sqlString) { IDbCommand cmd = commands[ sqlString ] as IDbCommand; ! if( cmd!=null ) { if( log.IsDebugEnabled ) --- 53,71 ---- /// Gets the current Command that is contained for this Batch /// </summary> ! protected IDbCommand GetCommand() { return batchCommand; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="sqlString"></param> ! /// <returns></returns> ! public IDbCommand Generate( SqlString sqlString ) { IDbCommand cmd = commands[ sqlString ] as IDbCommand; ! if( cmd != null ) { if( log.IsDebugEnabled ) *************** *** 67,72 **** // need to build the IDbCommand from the sqlString bec ! cmd = factory.ConnectionProvider.Driver.GenerateCommand(factory.Dialect, sqlString); ! if(log.IsDebugEnabled) { log.Debug( "Building an IDbCommand object for the SqlString: " + sqlString.ToString() ); --- 78,83 ---- // need to build the IDbCommand from the sqlString bec ! cmd = factory.ConnectionProvider.Driver.GenerateCommand( factory.Dialect, sqlString ); ! if( log.IsDebugEnabled ) { log.Debug( "Building an IDbCommand object for the SqlString: " + sqlString.ToString() ); *************** *** 75,79 **** commands[ sqlString ] = cmd; return cmd; ! } --- 86,90 ---- commands[ sqlString ] = cmd; return cmd; ! } *************** *** 87,146 **** /// supports preparing commands. /// </remarks> ! private void Prepare(IDbCommand command) { ! try { ! if(log.IsInfoEnabled) { ! log.Info("Preparing " + command.CommandText); } ! if( command.Connection!=null ) { // make sure the commands connection is the same as the Sessions connection // these can be different when the session is disconnected and then reconnected ! if( command.Connection!=session.Connection ) { command.Connection = session.Connection; } } ! else { command.Connection = session.Connection; } ! if( session.Transaction!=null ) { session.Transaction.Enlist( command ); } ! if( factory.PrepareSql && factory.ConnectionProvider.Driver.SupportsPreparingCommands ) { command.Prepare(); } } ! catch(Exception e) { throw new ApplicationException( "While preparing " + command.CommandText + " an error occurred" ! , e); } } ! public IDbCommand PrepareBatchCommand(SqlString sql) { ! if ( !sql.Equals(batchCommandSql) ) { ! batchCommand = PrepareCommand(sql); // calls ExecuteBatch() ! batchCommandSql=sql; } return batchCommand; } ! public IDbCommand PrepareCommand(SqlString sql) { ExecuteBatch(); LogOpenPreparedCommands(); ! // do not actually prepare the Command here - instead just generate it because // if the command is associated with an ADO.NET Transaction/Connection while --- 98,167 ---- /// supports preparing commands. /// </remarks> ! private void Prepare( IDbCommand command ) { ! try { ! if( log.IsInfoEnabled ) { ! log.Info( "Preparing " + command.CommandText ); } ! if( command.Connection != null ) { // make sure the commands connection is the same as the Sessions connection // these can be different when the session is disconnected and then reconnected ! if( command.Connection != session.Connection ) { command.Connection = session.Connection; } } ! else { command.Connection = session.Connection; } ! if( session.Transaction != null ) { session.Transaction.Enlist( command ); } ! if( factory.PrepareSql && factory.ConnectionProvider.Driver.SupportsPreparingCommands ) { command.Prepare(); } } ! catch( Exception e ) { throw new ApplicationException( "While preparing " + command.CommandText + " an error occurred" ! , e ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="sql"></param> ! /// <returns></returns> ! public IDbCommand PrepareBatchCommand( SqlString sql ) { ! if( !sql.Equals( batchCommandSql ) ) { ! batchCommand = PrepareCommand( sql ); // calls ExecuteBatch() ! batchCommandSql = sql; } return batchCommand; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="sql"></param> ! /// <returns></returns> ! public IDbCommand PrepareCommand( SqlString sql ) { ExecuteBatch(); LogOpenPreparedCommands(); ! // do not actually prepare the Command here - instead just generate it because // if the command is associated with an ADO.NET Transaction/Connection while *************** *** 149,154 **** return Generate( sql ); } ! ! public IDbCommand PrepareQueryCommand(SqlString sql, bool scrollable) { //TODO: figure out what to do with scrollable - don't think it applies --- 170,181 ---- return Generate( sql ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="sql"></param> ! /// <param name="scrollable"></param> ! /// <returns></returns> ! public IDbCommand PrepareQueryCommand( SqlString sql, bool scrollable ) { //TODO: figure out what to do with scrollable - don't think it applies *************** *** 160,171 **** // another open one Command is doing something then an exception will be // thrown. ! IDbCommand command = Generate( sql ); ! ! commandsToClose.Add(command); ! return command; } ! public void AbortBatch(Exception e) { // log the exception here --- 187,202 ---- // another open one Command is doing something then an exception will be // thrown. ! IDbCommand command = Generate( sql ); ! ! commandsToClose.Add( command ); ! return command; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="e"></param> ! public void AbortBatch( Exception e ) { // log the exception here *************** *** 176,180 **** } ! public int ExecuteNonQuery(IDbCommand cmd) { int rowsAffected = 0; --- 207,216 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <returns></returns> ! public int ExecuteNonQuery( IDbCommand cmd ) { int rowsAffected = 0; *************** *** 188,208 **** } ! public IDataReader ExecuteReader(IDbCommand cmd) { CheckReaders(); ! Prepare( cmd );; IDataReader reader; ! if( factory.ConnectionProvider.Driver.SupportsMultipleOpenReaders==false ) { reader = new NHybridDataReader( cmd.ExecuteReader() ); } ! else { reader = cmd.ExecuteReader(); } ! readersToClose.Add(reader); LogOpenReaders(); return reader; --- 224,250 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <returns></returns> ! public IDataReader ExecuteReader( IDbCommand cmd ) { CheckReaders(); ! Prepare( cmd ); ! ; IDataReader reader; ! if( factory.ConnectionProvider.Driver.SupportsMultipleOpenReaders == false ) { reader = new NHybridDataReader( cmd.ExecuteReader() ); } ! else { reader = cmd.ExecuteReader(); } ! readersToClose.Add( reader ); LogOpenReaders(); return reader; *************** *** 212,225 **** /// Ensures that the Driver's rules for Multiple Open DataReaders are being followed. /// </summary> ! private void CheckReaders() { // early exit because we don't need to move an open IDataReader into memory // since the Driver supports mult open readers. ! if( factory.ConnectionProvider.Driver.SupportsMultipleOpenReaders ) { return; } ! foreach( NHybridDataReader reader in readersToClose ) { reader.ReadIntoMemory(); --- 254,267 ---- /// Ensures that the Driver's rules for Multiple Open DataReaders are being followed. /// </summary> ! private void CheckReaders() { // early exit because we don't need to move an open IDataReader into memory // since the Driver supports mult open readers. ! if( factory.ConnectionProvider.Driver.SupportsMultipleOpenReaders ) { return; } ! foreach( NHybridDataReader reader in readersToClose ) { reader.ReadIntoMemory(); *************** *** 227,231 **** } ! public void CloseCommand(IDbCommand cmd, IDataReader reader) { //TODO: fix this up a little bit - don't like it having the same name and just --- 269,278 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <param name="reader"></param> ! public void CloseCommand( IDbCommand cmd, IDataReader reader ) { //TODO: fix this up a little bit - don't like it having the same name and just *************** *** 237,250 **** } ! public void CloseCommands() { ! foreach( IDataReader reader in readersToClose ) { ! try { LogCloseReaders(); reader.Close(); } ! catch( Exception e ) { log.Warn( "Could not close IDataReader", e ); --- 284,300 ---- } ! /// <summary> ! /// ! /// </summary> ! public void CloseCommands() { ! foreach( IDataReader reader in readersToClose ) { ! try { LogCloseReaders(); reader.Close(); } ! catch( Exception e ) { log.Warn( "Could not close IDataReader", e ); *************** *** 253,266 **** readersToClose.Clear(); ! foreach( IDbCommand cmd in commandsToClose ) { ! try { ! CloseQueryCommand(cmd); ! } ! catch(Exception e) { // no big deal ! log.Warn("Could not close a JDBC statement", e); } } --- 303,316 ---- readersToClose.Clear(); ! foreach( IDbCommand cmd in commandsToClose ) { ! try { ! CloseQueryCommand( cmd ); ! } ! catch( Exception e ) { // no big deal ! log.Warn( "Could not close a JDBC statement", e ); } } *************** *** 268,278 **** } ! private void CloseQueryCommand(IDbCommand cmd) { ! try { // no equiv to the java code in here } ! catch( Exception e ) { log.Warn( "exception clearing maxRows/queryTimeout", e ); --- 318,328 ---- } ! private void CloseQueryCommand( IDbCommand cmd ) { ! try { // no equiv to the java code in here } ! catch( Exception e ) { log.Warn( "exception clearing maxRows/queryTimeout", e ); *************** *** 284,298 **** } ! public void CloseQueryCommand(IDbCommand st, IDataReader reader) { ! commandsToClose.Remove(st); ! if( reader!=null ) { ! readersToClose.Remove(reader); } ! try { ! if( reader!=null) { LogCloseReaders(); --- 334,353 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="st"></param> ! /// <param name="reader"></param> ! public void CloseQueryCommand( IDbCommand st, IDataReader reader ) { ! commandsToClose.Remove( st ); ! if( reader != null ) { ! readersToClose.Remove( reader ); } ! try { ! if( reader != null ) { LogCloseReaders(); *************** *** 300,343 **** } } ! finally { ! CloseQueryCommand(st); } } ! public void ExecuteBatch() { ! if ( batchCommand!=null ) { IDbCommand ps = batchCommand; batchCommand = null; batchCommandSql = null; ! try { ! DoExecuteBatch(ps); } ! finally { ! CloseCommand(ps, null); } } } ! protected abstract void DoExecuteBatch(IDbCommand ps) ; ! public abstract void AddToBatch(int expectedRowCount); ! protected ISessionFactoryImplementor Factory { get { return factory; } } ! protected ISessionImplementor Session { get { return session; } } ! private static void LogOpenPreparedCommands() { ! if( log.IsDebugEnabled ) { log.Debug( "about to open: " + openCommandCount + " open IDbCommands, " + openReaderCount + " open DataReaders" ); --- 355,410 ---- } } ! finally { ! CloseQueryCommand( st ); } } ! /// <summary></summary> ! public void ExecuteBatch() { ! if( batchCommand != null ) { IDbCommand ps = batchCommand; batchCommand = null; batchCommandSql = null; ! try { ! DoExecuteBatch( ps ); } ! finally { ! CloseCommand( ps, null ); } } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="ps"></param> ! protected abstract void DoExecuteBatch( IDbCommand ps ); ! /// <summary> ! /// ! /// </summary> ! /// <param name="expectedRowCount"></param> ! public abstract void AddToBatch( int expectedRowCount ); ! ! /// <summary></summary> ! protected ISessionFactoryImplementor Factory { get { return factory; } } ! /// <summary></summary> ! protected ISessionImplementor Session { get { return session; } } ! private static void LogOpenPreparedCommands() { ! if( log.IsDebugEnabled ) { log.Debug( "about to open: " + openCommandCount + " open IDbCommands, " + openReaderCount + " open DataReaders" ); *************** *** 346,352 **** } ! private static void LogClosePreparedCommands() { ! if( log.IsDebugEnabled ) { openCommandCount--; --- 413,419 ---- } ! private static void LogClosePreparedCommands() { ! if( log.IsDebugEnabled ) { openCommandCount--; *************** *** 355,361 **** } ! private static void LogOpenReaders() { ! if( log.IsDebugEnabled ) { openReaderCount++; --- 422,428 ---- } ! private static void LogOpenReaders() { ! if( log.IsDebugEnabled ) { openReaderCount++; *************** *** 363,369 **** } ! private static void LogCloseReaders() { ! if( log.IsDebugEnabled ) { openReaderCount--; --- 430,436 ---- } ! private static void LogCloseReaders() { ! if( log.IsDebugEnabled ) { openReaderCount--; *************** *** 371,375 **** } ! } ! } --- 438,442 ---- } ! } ! } \ No newline at end of file |