|
From: <aye...@us...> - 2009-05-22 18:35:40
|
Revision: 4359
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4359&view=rev
Author: ayenderahien
Date: 2009-05-22 18:35:26 +0000 (Fri, 22 May 2009)
Log Message:
-----------
Making sure that the batcher output from batcher is formatted for human reading
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs
trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs
trunk/nhibernate/src/NHibernate.Test/Ado/BatcherFixture.cs
Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-05-22 18:28:52 UTC (rev 4358)
+++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2009-05-22 18:35:26 UTC (rev 4359)
@@ -23,7 +23,7 @@
//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();
+ currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
}
public override int BatchSize
@@ -38,10 +38,16 @@
IDbCommand batchUpdate = CurrentCommand;
string lineWithParameters = null;
- if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
+ var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
+ if (sqlStatementLogger.IsDebugEnabled)
{
- lineWithParameters = Factory.Settings.SqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
- currentBatchCommandsLog.Append("Batch command: ").AppendLine(lineWithParameters);
+ lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
+ var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
+ lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
+ currentBatchCommandsLog.Append("command ")
+ .Append(currentBatch.CountOfCommands)
+ .Append(":")
+ .AppendLine(lineWithParameters);
}
if (log.IsDebugEnabled)
{
@@ -63,7 +69,7 @@
if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
{
Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString());
- currentBatchCommandsLog = new StringBuilder();
+ currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
}
int rowsAffected = currentBatch.ExecuteNonQuery();
Modified: trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs 2009-05-22 18:28:52 UTC (rev 4358)
+++ trunk/nhibernate/src/NHibernate/AdoNet/Util/SqlStatementLogger.cs 2009-05-22 18:35:26 UTC (rev 4359)
@@ -135,7 +135,7 @@
|| DbType.AnsiStringFixedLength.Equals(dbType) || DbType.StringFixedLength.Equals(dbType);
}
- private FormatStyle DetermineActualStyle(FormatStyle style)
+ public FormatStyle DetermineActualStyle(FormatStyle style)
{
return FormatSql ? style : FormatStyle.None;
}
Modified: trunk/nhibernate/src/NHibernate.Test/Ado/BatcherFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Ado/BatcherFixture.cs 2009-05-22 18:28:52 UTC (rev 4358)
+++ trunk/nhibernate/src/NHibernate.Test/Ado/BatcherFixture.cs 2009-05-22 18:35:26 UTC (rev 4359)
@@ -1,7 +1,6 @@
using System.Collections;
using NHibernate.AdoNet;
using NHibernate.Cfg;
-using NHibernate.Dialect;
using NUnit.Framework;
namespace NHibernate.Test.Ado
@@ -125,7 +124,41 @@
Cleanup();
}
+ [Test]
+ [Description("SqlClient: The batcher log output should be formatted")]
+ public void BatchedoutputShouldBeFormatted()
+ {
+ if (sessions.Settings.BatcherFactory is SqlClientBatchingBatcherFactory == false)
+ Assert.Ignore("This test is for SqlClientBatchingBatcher only");
+ FillDb();
+
+ using (var sqlLog = new SqlLogSpy())
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Save(new VerySimple
+ {
+ Name = "test441",
+ Weight = 894
+ });
+
+ s.Save(new AlmostSimple
+ {
+ Name = "test441",
+ Weight = 894
+ });
+
+ tx.Commit();
+
+ var log = sqlLog.GetWholeLog();
+ Assert.IsTrue(log.Contains("INSERT \n INTO"));
+ }
+
+ Cleanup();
+ }
+
+
[Test]
[Description("The batcher should run all DELETE queries in only one roundtrip.")]
public void OneRoundTripDelete()
@@ -211,7 +244,7 @@
sessions.Statistics.Clear();
FillDb();
string logs = sl.GetWholeLog();
- Assert.That(logs, Text.Contains("Batch command:").IgnoreCase);
+ Assert.That(logs, Text.Contains("Batch commands:").IgnoreCase);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|