|
From: <fab...@us...> - 2009-10-16 17:09:14
|
Revision: 4761
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4761&view=rev
Author: fabiomaulo
Date: 2009-10-16 17:09:03 +0000 (Fri, 16 Oct 2009)
Log Message:
-----------
Merge r4760 (fix NH-1987)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs
trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs
trunk/nhibernate/src/NHibernate.Test/Stats/StatsFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2009-10-15 23:52:32 UTC (rev 4760)
+++ trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2009-10-16 17:09:03 UTC (rev 4761)
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Data;
+using System.Diagnostics;
using Iesi.Collections;
using Iesi.Collections.Generic;
using log4net;
@@ -189,6 +190,14 @@
private void GetResultsFromDatabase(IList results)
{
+ bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled;
+ var stopWatch = new Stopwatch();
+ if (statsEnabled)
+ {
+ stopWatch.Start();
+ }
+ int rowCount = 0;
+
using (
IDbCommand command =
session.Batcher.PrepareCommand(CommandType.Text, sqlString, types.ToArray()))
@@ -228,6 +237,8 @@
int count;
for (count = 0; count < maxRows && reader.Read(); count++)
{
+ rowCount++;
+
object o =
loader.GetRowFromResultSet(reader, session, queryParameters, loader.GetLockModes(queryParameters.LockModes),
null, hydratedObjects[i], keys, false);
@@ -262,6 +273,11 @@
}
}
}
+ if (statsEnabled)
+ {
+ stopWatch.Stop();
+ session.Factory.StatisticsImplementor.QueryExecuted(string.Format("{0} queries (MultiCriteria)", loaders.Count), rowCount, stopWatch.Elapsed);
+ }
}
private void CreateCriteriaLoaders()
Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2009-10-15 23:52:32 UTC (rev 4760)
+++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2009-10-16 17:09:03 UTC (rev 4761)
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Data;
+using System.Diagnostics;
using System.Text.RegularExpressions;
using Iesi.Collections;
using log4net;
@@ -474,6 +475,14 @@
protected ArrayList DoList()
{
+ bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled;
+ var stopWatch = new Stopwatch();
+ if (statsEnabled)
+ {
+ stopWatch.Start();
+ }
+ int rowCount = 0;
+
IDbCommand command = PrepareQueriesCommand();
BindParameters(command);
@@ -535,6 +544,8 @@
log.Debug("result set row: " + count);
}
+ rowCount++;
+
object result =
translator.Loader.GetRowFromResultSet(reader,
session,
@@ -590,6 +601,11 @@
translator.Loader.CreateSubselects(subselectResultKeys[i], parameter, session);
}
}
+ if (statsEnabled)
+ {
+ stopWatch.Stop();
+ session.Factory.StatisticsImplementor.QueryExecuted(string.Format("{0} queries (MultiQuery)", translators.Count), rowCount, stopWatch.Elapsed);
+ }
return results;
}
Modified: trunk/nhibernate/src/NHibernate.Test/Stats/StatsFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Stats/StatsFixture.cs 2009-10-15 23:52:32 UTC (rev 4760)
+++ trunk/nhibernate/src/NHibernate.Test/Stats/StatsFixture.cs 2009-10-16 17:09:03 UTC (rev 4761)
@@ -1,5 +1,6 @@
using System.Collections;
using Iesi.Collections.Generic;
+using NHibernate.Criterion;
using NHibernate.Stat;
using NUnit.Framework;
@@ -209,5 +210,53 @@
tx.Commit();
s.Close();
}
+
+ [Test]
+ public void IncrementQueryExecutionCount_WhenExplicitQueryIsExecuted()
+ {
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ FillDb(s);
+ tx.Commit();
+ }
+
+ IStatistics stats = sessions.Statistics;
+ stats.Clear();
+ using (ISession s = OpenSession())
+ {
+ var r = s.CreateCriteria<Country>().List();
+ }
+ Assert.AreEqual(1, stats.QueryExecutionCount);
+
+ stats.Clear();
+ using (ISession s = OpenSession())
+ {
+ var r = s.CreateQuery("from Country").List();
+ }
+ Assert.AreEqual(1, stats.QueryExecutionCount);
+
+ stats.Clear();
+ using (ISession s = OpenSession())
+ {
+ var r = s.CreateMultiQuery().Add("from Country").Add("from Continent").List();
+ }
+ Assert.AreEqual(1, stats.QueryExecutionCount);
+
+ stats.Clear();
+ using (ISession s = OpenSession())
+ {
+ var r = s.CreateMultiCriteria().Add(DetachedCriteria.For<Country>()).Add(DetachedCriteria.For<Continent>()).List();
+ }
+ Assert.AreEqual(1, stats.QueryExecutionCount);
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ CleanDb(s);
+ tx.Commit();
+ }
+ }
+
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|