From: <aye...@us...> - 2009-05-08 00:04:11
|
Revision: 4263 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4263&view=rev Author: ayenderahien Date: 2009-05-08 00:04:03 +0000 (Fri, 08 May 2009) Log Message: ----------- Log batch commands to NHibernate.SQL logger if it is enable as a single unit Better log output for byte arrays so they would go as hex strings Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-05-07 18:00:44 UTC (rev 4262) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-05-08 00:04:03 UTC (rev 4263) @@ -66,7 +66,10 @@ Prepare(currentBatch.BatchCommand); if (log.IsDebugEnabled) { - log.Debug(currentBatchCommandsLog.ToString()); + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) + Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); + else + log.Debug(currentBatchCommandsLog.ToString()); currentBatchCommandsLog = new StringBuilder(); } int rowsAffected = currentBatch.ExecuteNonQuery(); Modified: trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs 2009-05-07 18:00:44 UTC (rev 4262) +++ trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs 2009-05-08 00:04:03 UTC (rev 4263) @@ -60,6 +60,11 @@ } } + public virtual void LogBatchCommand(string batchCommand) + { + log.Debug(batchCommand); + } + /// <summary> Log a IDbCommand. </summary> /// <param name="command">The SQL statement. </param> /// <param name="style">The requested formatting style. </param> @@ -104,16 +109,32 @@ { if(parameter.Value == null || DBNull.Value.Equals(parameter.Value)) { - return "null"; + return "NULL"; } - else if (IsStringType(parameter.DbType)) - { - return string.Concat("'", parameter.Value.ToString(), "'"); - } - return parameter.Value.ToString(); + if (IsStringType(parameter.DbType)) + { + return string.Concat("'", parameter.Value.ToString(), "'"); + } + var buffer = parameter.Value as byte[]; + if(buffer != null) + { + return GetBufferAsHexString(buffer); + } + return parameter.Value.ToString(); } - private static bool IsStringType(DbType dbType) + private static string GetBufferAsHexString(byte[] buffer) + { + var sb = new StringBuilder(buffer.Length*2 + 2); + sb.Append("0x"); + foreach (var b in buffer) + { + sb.Append(b.ToString("X2")); + } + return sb.ToString(); + } + + private static bool IsStringType(DbType dbType) { return DbType.String.Equals(dbType) || DbType.AnsiString.Equals(dbType) || DbType.AnsiStringFixedLength.Equals(dbType) || DbType.StringFixedLength.Equals(dbType); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2009-05-11 13:59:25
|
Revision: 4279 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4279&view=rev Author: ayenderahien Date: 2009-05-11 13:59:15 +0000 (Mon, 11 May 2009) Log Message: ----------- Will now log a warning when getting exception from the database Logging of messages in the SqlClientBatchingBatcher now follow a more consistent approach per logging based on which logger is used Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2009-05-11 13:43:54 UTC (rev 4278) +++ trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2009-05-11 13:59:15 UTC (rev 4279) @@ -199,6 +199,7 @@ catch (Exception e) { e.Data["actual-sql-query"] = cmd.CommandText; + log.Warn("Could not execute command: " + cmd.CommandText, e); throw; } } @@ -216,6 +217,7 @@ catch (Exception e) { e.Data["actual-sql-query"] = cmd.CommandText; + log.Warn("Could not exeucte query: " + cmd.CommandText, e); throw; } Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-05-11 13:43:54 UTC (rev 4278) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-05-11 13:59:15 UTC (rev 4279) @@ -19,10 +19,7 @@ { batchSize = Factory.Settings.AdoBatchSize; currentBatch = new SqlClientSqlCommandSet(); - if(log.IsDebugEnabled) - { - currentBatchCommandsLog = new StringBuilder(); - } + currentBatchCommandsLog = new StringBuilder(); } public override int BatchSize @@ -35,22 +32,15 @@ { totalExpectedRowsAffected += expectation.ExpectedRowCount; IDbCommand batchUpdate = CurrentCommand; - if (log.IsDebugEnabled) + string lineWithParameters = Factory.Settings.SqlStatementLogger.GetCommandLineWithParameters(batchUpdate); + currentBatchCommandsLog.Append("Batch command: ").AppendLine(lineWithParameters); + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) { - string lineWithParameters = Factory.Settings.SqlStatementLogger.GetCommandLineWithParameters(batchUpdate); - if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) - { - Factory.Settings.SqlStatementLogger.LogCommand("Adding to batch:", batchUpdate, FormatStyle.Basic); - } - else - { - log.Debug("Adding to batch:" + lineWithParameters); - } - currentBatchCommandsLog.Append("Batch command: ").AppendLine(lineWithParameters); + Factory.Settings.SqlStatementLogger.LogCommand("Adding to batch:", batchUpdate, FormatStyle.Basic); } - else + else if (log.IsDebugEnabled) { - Factory.Settings.SqlStatementLogger.LogCommand(batchUpdate, FormatStyle.Basic); + log.Debug("Adding to batch:" + lineWithParameters); } currentBatch.Append((System.Data.SqlClient.SqlCommand) batchUpdate); if (currentBatch.CountOfCommands >= batchSize) @@ -64,14 +54,11 @@ log.Debug("Executing batch"); CheckReaders(); Prepare(currentBatch.BatchCommand); - if (log.IsDebugEnabled) - { - if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) - Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); - else - log.Debug(currentBatchCommandsLog.ToString()); - currentBatchCommandsLog = new StringBuilder(); - } + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) + Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); + else if (log.IsDebugEnabled) + log.Debug(currentBatchCommandsLog.ToString()); + currentBatchCommandsLog = new StringBuilder(); int rowsAffected = currentBatch.ExecuteNonQuery(); Expectations.VerifyOutcomeBatched(totalExpectedRowsAffected, rowsAffected); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dav...@us...> - 2009-08-05 19:58:40
|
Revision: 4684 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4684&view=rev Author: davybrion Date: 2009-08-05 19:58:32 +0000 (Wed, 05 Aug 2009) Log Message: ----------- Fix NH-1913 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-08-05 19:46:31 UTC (rev 4683) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-08-05 19:58:32 UTC (rev 4684) @@ -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: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs 2009-08-05 19:46:31 UTC (rev 4683) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs 2009-08-05 19:58:32 UTC (rev 4684) @@ -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. |