From: <dav...@us...> - 2009-08-05 19:46:38
|
Revision: 4683 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4683&view=rev Author: davybrion Date: 2009-08-05 19:46:31 +0000 (Wed, 05 Aug 2009) Log Message: ----------- Fix NH-1913 Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-08-04 19:52:18 UTC (rev 4682) +++ branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-08-05 19:46:31 UTC (rev 4683) @@ -1,6 +1,7 @@ using System.Data; using System.Text; using NHibernate.AdoNet.Util; +using NHibernate.Util; namespace NHibernate.AdoNet { @@ -21,6 +22,7 @@ { batchSize = Factory.Settings.AdoBatchSize; currentBatch = new SqlClientSqlCommandSet(); + SetCommandTimeout(); //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 @@ -28,6 +30,26 @@ currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); } + private void SetCommandTimeout() + { + int timeout = PropertiesHelper.GetInt32(Cfg.Environment.CommandTimeout, Cfg.Environment.Properties, -1); + + if (timeout > 0) + { + try + { + currentBatch.CommandTimeout = timeout; + } + catch (Exception e) + { + if (log.IsWarnEnabled) + { + log.Warn(e.ToString()); + } + } + } + } + public override int BatchSize { get { return batchSize; } Modified: branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs 2009-08-04 19:52:18 UTC (rev 4682) +++ branches/2.1.x/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs 2009-08-05 19:46:31 UTC (rev 4683) @@ -18,6 +18,7 @@ private object instance; private PropSetter<SqlConnection> connectionSetter; private PropSetter<SqlTransaction> transactionSetter; + private PropSetter<int> commandTimeoutSetter; private PropGetter<SqlConnection> connectionGetter; private SqlClientSqlCommandSet.PropGetter<System.Data.SqlClient.SqlCommand> commandGetter; private AppendCommand doAppend; @@ -41,6 +42,9 @@ transactionSetter = (PropSetter<SqlTransaction>) Delegate.CreateDelegate(typeof(PropSetter<SqlTransaction>), instance, "set_Transaction"); + commandTimeoutSetter = (PropSetter<int>) + Delegate.CreateDelegate(typeof(PropSetter<int>), + instance, "set_CommandTimeout"); connectionGetter = (PropGetter<SqlConnection>) Delegate.CreateDelegate(typeof(PropGetter<SqlConnection>), instance, "get_Connection"); @@ -130,6 +134,11 @@ set { transactionSetter(value); } } + public int CommandTimeout + { + set { commandTimeoutSetter(value); } + } + ///<summary> ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. ///</summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |