From: <aye...@us...> - 2010-01-06 20:12:33
|
Revision: 4905 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4905&view=rev Author: ayenderahien Date: 2010-01-06 20:12:26 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Fixing NH-2047 - standardizing the format of Oracle Batcher to match SqlClient Batcher and ensure that we only output batch statements once Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2010-01-06 05:08:17 UTC (rev 4904) +++ branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2010-01-06 20:12:26 UTC (rev 4905) @@ -97,7 +97,6 @@ { try { - LogCommand(cmd); IDbConnection sessionConnection = connectionManager.GetConnection(); if (cmd.Connection != null) @@ -201,7 +200,8 @@ public int ExecuteNonQuery(IDbCommand cmd) { CheckReaders(); - Prepare(cmd); + LogCommand(cmd); + Prepare(cmd); Stopwatch duration = null; if(log.IsDebugEnabled) duration = Stopwatch.StartNew(); @@ -225,7 +225,8 @@ public IDataReader ExecuteReader(IDbCommand cmd) { CheckReaders(); - Prepare(cmd); + LogCommand(cmd); + Prepare(cmd); Stopwatch duration = null; if (log.IsDebugEnabled) duration = Stopwatch.StartNew(); Modified: branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-01-06 05:08:17 UTC (rev 4904) +++ branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-01-06 20:12:26 UTC (rev 4905) @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Data; using System.Reflection; +using System.Text; +using NHibernate.AdoNet.Util; namespace NHibernate.AdoNet { @@ -18,20 +20,40 @@ private IDbCommand currentBatch; private IDictionary<string, List<object>> parameterValueListHashTable; private IDictionary<string, bool> parameterIsAllNullsHashTable; + private StringBuilder currentBatchCommandsLog; public OracleDataClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) : base(connectionManager, interceptor) { batchSize = Factory.Settings.AdoBatchSize; - } + //we always create this, because we need to deal with a scenario in which + //the user change the logging configuration at runtime. Trying to put this + //behind an if(log.IsDebugEnabled) will cause a null reference exception + //at that point. + currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); + } public override void AddToBatch(IExpectation expectation) { bool firstOnBatch = true; totalExpectedRowsAffected += expectation.ExpectedRowCount; - log.Info("Adding to batch"); - LogCommand(CurrentCommand); + string lineWithParameters = null; + var sqlStatementLogger = Factory.Settings.SqlStatementLogger; + if (sqlStatementLogger.IsDebugEnabled || log.IsDebugEnabled) + { + lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(CurrentCommand); + var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic); + lineWithParameters = formatStyle.Formatter.Format(lineWithParameters); + currentBatchCommandsLog.Append("command ") + .Append(countOfCommands) + .Append(":") + .AppendLine(lineWithParameters); + } + if (log.IsDebugEnabled) + { + log.Debug("Adding to batch:" + lineWithParameters); + } if (currentBatch == null) { @@ -87,6 +109,12 @@ CheckReaders(); Prepare(currentBatch); + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) + { + Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); + currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); + } + foreach (IDataParameter currentParameter in currentBatch.Parameters) { List<object> parameterValueArray = parameterValueListHashTable[currentParameter.ParameterName]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |