Author: gbayon
Date: Wed Feb 21 12:23:49 2007
New Revision: 510185
URL: http://svn.apache.org/viewvc?view=rev&rev=510185
Log:
- Internal refactoring on groupBy for better performance
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/petstore-init.sql
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/AutoResultMap.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/IResultMap.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/PropertyStrategyFactory.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml
Wed Feb 21 12:23:49 2007
@@ -74,7 +74,20 @@
<statements>
- <select id="GetAllCategories" resultMap="Category-Result" >
+ <select id="GetCategories" resultMap="Category-Result" >
+ SELECT
+ c.Category_Id, c.Category_Name,
+ p.Product_Id, p.Product_Name,
+ i.Item_Id, i.Item_UnitCost, i.Item_Status,
+ v.Inventory_Quantity
+ FROM
+ Items i INNER JOIN
+ Products p ON i.Product_Id = p.Product_Id INNER JOIN
+ Inventories v ON i.Item_Id = v.Item_Id RIGHT OUTER JOIN
+ Categories c ON p.Category_Id = c.Category_Id
+ </select>
+
+ <select id="GetAllCategories" resultMap="Category-Result" >
select
c.Category_Id, c.Category_Name,
p.Product_Id, p.Product_Name,
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
Wed Feb 21 12:23:49 2007
@@ -42,7 +42,14 @@
#endregion
[Test]
- public void TestGroupBy()
+ public void TestGroupByWithNullSon()
+ {
+ IList list = sqlMap.QueryForList("GetCategories", null);
+ Assert.AreEqual(6, list.Count);
+ }
+
+ [Test]
+ public void TestGroupBy()
{
IList list = sqlMap.QueryForList("GetAllCategories", null);
Assert.AreEqual(5, list.Count);
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/petstore-init.sql
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/petstore-init.sql?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/petstore-init.sql
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/petstore-init.sql
Wed Feb 21 12:23:49 2007
@@ -8,6 +8,7 @@
INSERT INTO [Categories] VALUES ('REPTILES', 'Reptiles', NULL)
INSERT INTO [Categories] VALUES ('CATS', 'Cats', NULL)
INSERT INTO [Categories] VALUES ('BIRDS', 'Birds', NULL)
+INSERT INTO [Categories] VALUES ('DINO', 'Dinos', NULL)
INSERT INTO [Products] VALUES ('FI-SW-01', 'FISH', 'Angelfish', 'Saltwater
fish from Australia')
INSERT INTO [Products] VALUES ('FI-SW-02', 'FISH', 'Tiger Shark', 'Saltwater
fish from Australia')
@@ -84,4 +85,4 @@
INSERT INTO [Inventories] VALUES ('EST-27', 10000)
INSERT INTO [Inventories] VALUES ('EST-28', 10000)
-INSERT INTO [Sequences] (Sequence_Name, Sequence_NextId) VALUES ('OrderNum', 0)
\ No newline at end of file
+INSERT INTO [Sequences] (Sequence_Name, Sequence_NextId) VALUES ('OrderNum', 0)
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
Wed Feb 21 12:23:49 2007
@@ -1879,19 +1879,19 @@
resultMap.Properties.Add(property);
}
// Add groupBy properties
- if (resultMap.GroupByProperties.Count == 0)
+ if (resultMap.GroupByPropertyNames.Count == 0)
{
- for(int i=0; i<superMap.GroupByProperties.Count; i++)
+ for(int i=0; i<superMap.GroupByPropertyNames.Count;
i++)
{
-
resultMap.GroupByProperties.Add(superMap.GroupByProperties[i]);
+
resultMap.GroupByPropertyNames.Add(superMap.GroupByPropertyNames[i]);
}
}
// Verify that that each groupBy element correspond to a
class member
// of one of result property
- for (int i = 0; i < resultMap.GroupByProperties.Count; i++)
+ for (int i = 0; i < resultMap.GroupByPropertyNames.Count;
i++)
{
- string memberName = resultMap.GroupByProperties[i];
+ string memberName = resultMap.GroupByPropertyNames[i];
if (!resultMap.Properties.Contains(memberName))
{
throw new ConfigurationException(
@@ -1901,6 +1901,7 @@
}
}
}
+ resultMap.InitializeGroupByProperties();
_configScope.SqlMapper.AddResultMap( resultMap
);
}
}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/AutoResultMap.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/AutoResultMap.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/AutoResultMap.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/AutoResultMap.cs
Wed Feb 21 12:23:49 2007
@@ -51,6 +51,7 @@
private IFactory _resultClassFactory = null;
[NonSerialized]
private ResultPropertyCollection _properties = new
ResultPropertyCollection();
+
[NonSerialized]
private IDataExchange _dataExchange = null;
@@ -73,9 +74,9 @@
/// The GroupBy Properties.
/// </summary>
[XmlIgnore]
- public StringCollection GroupByProperties
+ public StringCollection GroupByPropertyNames
{
- get { throw new NotImplementedException("The property
'GroupByProperties' is not implemented."); }
+ get { throw new NotImplementedException("The property
'GroupByPropertyNames' is not implemented."); }
}
/// <summary>
@@ -88,6 +89,15 @@
}
/// <summary>
+ /// The GroupBy Properties.
+ /// </summary>
+ /// <value></value>
+ public ResultPropertyCollection GroupByProperties
+ {
+ get { throw new NotImplementedException("The property
'GroupByProperties' is not implemented."); }
+ }
+
+ /// <summary>
/// The collection of constructor parameters.
/// </summary>
[XmlIgnore]
@@ -230,5 +240,6 @@
}
}
}
+
}
}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/IResultMap.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/IResultMap.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/IResultMap.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/IResultMap.cs
Wed Feb 21 12:23:49 2007
@@ -29,11 +29,8 @@
using System;
using System.Collections.Specialized;
using System.Data;
-using System.Reflection;
using System.Xml.Serialization;
using IBatisNet.DataMapper.DataExchange;
-using IBatisNet.DataMapper.Exceptions;
-using IBatisNet.DataMapper.Scope;
#endregion
namespace IBatisNet.DataMapper.Configuration.ResultMapping
@@ -49,13 +46,17 @@
[XmlIgnore]
ResultPropertyCollection Parameters { get; }
-
/// <summary>
/// The collection of ResultProperty.
/// </summary>
[XmlIgnore]
ResultPropertyCollection Properties { get; }
+ /// <summary>
+ /// The GroupBy Properties.
+ /// </summary>
+ [XmlIgnore]
+ ResultPropertyCollection GroupByProperties { get; }
/// <summary>
/// Identifier used to identify the resultMap amongst the others.
@@ -65,10 +66,10 @@
string Id { get; }
/// <summary>
- /// The GroupBy Properties.
+ /// The GroupBy Properties name.
/// </summary>
[XmlIgnore]
- StringCollection GroupByProperties { get; }
+ StringCollection GroupByPropertyNames { get; }
/// <summary>
/// The output type class of the resultMap.
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
Wed Feb 21 12:23:49 2007
@@ -37,11 +37,13 @@
#region Fields
[NonSerialized]
- private StringCollection _groupByProperties = new StringCollection();
+ private StringCollection _groupByPropertyNames = new
StringCollection();
[NonSerialized]
private ResultPropertyCollection _properties = new
ResultPropertyCollection();
[NonSerialized]
private ResultPropertyCollection _parameters = new
ResultPropertyCollection();
+ [NonSerialized]
+ private ResultPropertyCollection _groupByProperties = new
ResultPropertyCollection();
#endregion
@@ -50,7 +52,15 @@
/// <summary>
/// The GroupBy Properties.
/// </summary>
- public StringCollection GroupByProperties
+ public StringCollection GroupByPropertyNames
+ {
+ get { return _groupByPropertyNames; }
+ }
+
+ /// <summary>
+ /// The GroupBy Properties.
+ /// </summary>
+ public ResultPropertyCollection GroupByProperties
{
get { return _groupByProperties; }
}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
Wed Feb 21 12:23:49 2007
@@ -90,10 +90,13 @@
[NonSerialized]
private Type _class = null;
[NonSerialized]
- private StringCollection _groupByProperties = new StringCollection();
+ private StringCollection _groupByPropertyNames = new
StringCollection();
[NonSerialized]
private ResultPropertyCollection _properties = new
ResultPropertyCollection();
+ [NonSerialized]
+ private ResultPropertyCollection _groupByProperties = new
ResultPropertyCollection();
+
[NonSerialized]
private ResultPropertyCollection _parameters = new
ResultPropertyCollection();
@@ -115,9 +118,9 @@
/// The GroupBy Properties.
/// </summary>
[XmlIgnore]
- public StringCollection GroupByProperties
+ public StringCollection GroupByPropertyNames
{
- get { return _groupByProperties; }
+ get { return _groupByPropertyNames; }
}
/// <summary>
@@ -151,6 +154,15 @@
get { return _properties; }
}
+ /// <summary>
+ /// The GroupBy Properties.
+ /// </summary>
+ [XmlIgnore]
+ public ResultPropertyCollection GroupByProperties
+ {
+ get { return _groupByProperties; }
+ }
+
/// <summary>
/// The collection of constructor parameters.
/// </summary>
@@ -233,7 +245,7 @@
for (int i = 0; i < groupByProperties.Length; i++)
{
string memberName = groupByProperties[i].Trim();
- _groupByProperties.Add(memberName);
+ _groupByPropertyNames.Add(memberName);
}
}
@@ -262,7 +274,7 @@
// of one of result property
for (int i = 0; i < _groupByProperties.Count; i++)
{
- string memberName = GroupByProperties[i];
+ string memberName = GroupByPropertyNames[i];
if (!_properties.Contains(memberName))
{
throw new ConfigurationException(
@@ -279,6 +291,18 @@
, e);
}
}
+
+ /// <summary>
+ /// Initializes the groupBy properties.
+ /// </summary>
+ public void InitializeGroupByProperties()
+ {
+ for (int i = 0; i < GroupByPropertyNames.Count; i++)
+ {
+ ResultProperty resultProperty =
Properties.FindByPropertyName(this.GroupByPropertyNames[i]);
+ this.GroupByProperties.Add(resultProperty);
+ }
+ }
/// <summary>
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs
Wed Feb 21 12:23:49 2007
@@ -112,14 +112,33 @@
_innerList[index] = value;
}
}
-
- /// <summary>
- /// Add an ResultProperty
- /// </summary>
- /// <param name="value"></param>
- /// <returns>Index</returns>
- public int Add(ResultProperty value)
+ /// <summary>
+ /// Finds a property by his name.
+ /// </summary>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <returns></returns>
+ public ResultProperty FindByPropertyName(string propertyName)
+ {
+ ResultProperty resultProperty = null;
+ for (int i = 0; i < _count; i++)
+ {
+ if (_innerList[i].PropertyName == propertyName)
+ {
+ resultProperty = _innerList[i];
+ break;
+ }
+ }
+ return resultProperty;
+ }
+
+
+ /// <summary>
+ /// Add an ResultProperty
+ /// </summary>
+ /// <param name="value"></param>
+ /// <returns>Index</returns>
+ public int Add(ResultProperty value)
{
Resize(_count + 1);
int index = _count++;
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
Wed Feb 21 12:23:49 2007
@@ -56,16 +56,11 @@
{
StringBuilder keyBuffer = new StringBuilder();
- for (int i = 0; i < resultMap.Properties.Count; i++)
+ for (int i = 0; i < resultMap.GroupByProperties.Count; i++)
{
- ResultProperty resultProperty = resultMap.Properties[i];
- if
(resultMap.GroupByProperties.Contains(resultProperty.PropertyName))
- {
- // on peut surement utiliser
resultProperty.GetDataBaseValue
-
keyBuffer.Append(resultProperty.GetDataBaseValue(reader));
- //PropertyStrategy.Get(request,
resultMap, resultProperty, reader));
- keyBuffer.Append('-');
- }
+ ResultProperty resultProperty =
resultMap.GroupByProperties[i];
+ keyBuffer.Append(resultProperty.GetDataBaseValue(reader));
+ keyBuffer.Append('-');
}
if (keyBuffer.Length < 1)
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
Wed Feb 21 12:23:49 2007
@@ -98,7 +98,7 @@
object result = null;
IResultMap propertyRresultMap =
mapping.NestedResultMap.ResolveSubMap(reader);
- if (propertyRresultMap.GroupByProperties.Count>0)
+ if (propertyRresultMap.GroupByProperties.Count > 0)
{
string uniqueKey = GetUniqueKey(propertyRresultMap, request,
reader);
@@ -130,7 +130,7 @@
buildObjects = new Hashtable();
request.SetUniqueKeys(propertyRresultMap,
buildObjects);
}
- buildObjects[uniqueKey] = result;
+ buildObjects[uniqueKey] = result;
}
}
else // Last resultMap have no groupBy attribute
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/PropertyStrategyFactory.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/PropertyStrategyFactory.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/PropertyStrategyFactory.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/PropertyStrategyFactory.cs
Wed Feb 21 12:23:49 2007
@@ -78,7 +78,7 @@
}
else if (mapping.NestedResultMap != null) //
'resultMap' attribute
{
- if (mapping.NestedResultMap.GroupByProperties.Count>0)
+ if (mapping.NestedResultMap.GroupByPropertyNames.Count>0)
{
return _groupByStrategy;
}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs?view=diff&rev=510185&r1=510184&r2=510185
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
Wed Feb 21 12:23:49 2007
@@ -59,7 +59,7 @@
{
IResultMap resultMap =
request.CurrentResultMap.ResolveSubMap(reader);
- if (resultMap.GroupByProperties.Count>0)
+ if (resultMap.GroupByPropertyNames.Count>0)
{
return _groupByStrategy.Process(request, ref reader,
resultObject);
}