Author: gbayon
Date: Mon Feb 19 13:47:06 2007
New Revision: 509346
URL: http://svn.apache.org/viewvc?view=rev&rev=509346
Log:
- IBATISNET-209 Added verification in configuration to verify that each
element of groupBy attribute corresponds to a result property.
Modified:
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
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=509346&r1=509345&r2=509346
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
Mon Feb 19 13:47:06 2007
@@ -232,7 +232,8 @@
string[] groupByProperties = groupBy.Split(',');
for (int i = 0; i < groupByProperties.Length; i++)
{
- _groupByProperties.Add(groupByProperties[i].Trim());
+ string memberName = groupByProperties[i].Trim();
+ _groupByProperties.Add(memberName);
}
}
@@ -256,11 +257,26 @@
// Load the child node
GetChildNode(configScope);
- }
+
+ // Verify that that each groupBy element correspond to a
class member
+ // of one of result property
+ for (int i = 0; i < _groupByProperties.Count; i++)
+ {
+ string memberName = GroupByProperties[i];
+ if (!_properties.Contains(GroupByProperties[i]))
+ {
+ throw new ConfigurationException(
+ string.Format(
+ "Could not configure ResultMap named \"{0}\".
Check the groupBy attribute. Cause: there's no result property named \"{1}\".",
+ _id, memberName));
+ }
+ }
+
+ }
catch(Exception e)
{
throw new ConfigurationException(
- string.Format("Could not configure
ResultMap. ResultMap named \"{0}\" not found, failed. {1} Cause: {2}", _id,
Environment.NewLine, e.Message)
+ string.Format("Could not configure
ResultMap named \"{0}\", Cause: {1}", _id, e.Message)
, e);
}
}
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=509346&r1=509345&r2=509346
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultPropertyCollection.cs
Mon Feb 19 13:47:06 2007
@@ -162,16 +162,25 @@
/// <returns>True fi is in</returns>
public bool Contains(ResultProperty value)
{
- for (int i = 0; i < _count; i++)
- {
-
if(_innerList[i].PropertyName==value.PropertyName)
- {
- return true;
- }
- }
- return false;
+ return Contains(value.PropertyName);
}
-
+
+ /// <summary>
+ /// Indicate if a ResultProperty is in the collection
+ /// </summary>
+ /// <param name="propertyName">A property name</param>
+ /// <returns>True fi is in</returns>
+ public bool Contains(string propertyName)
+ {
+ for (int i = 0; i < _count; i++)
+ {
+ if (_innerList[i].PropertyName == propertyName)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
/// <summary>
/// Insert a ResultProperty in the collection.
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=509346&r1=509345&r2=509346
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
Mon Feb 19 13:47:06 2007
@@ -70,6 +70,7 @@
if (keyBuffer.Length < 1)
{
+ // we should never go here
return null;
}
else
@@ -81,6 +82,7 @@
}
else
{
+ // we should never go here
return null;
}
}
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=509346&r1=509345&r2=509346
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
Mon Feb 19 13:47:06 2007
@@ -101,8 +101,10 @@
if (propertyRresultMap.GroupByProperties.Count>0)
{
string uniqueKey = GetUniqueKey(propertyRresultMap, request,
reader);
+
// Gets the [key, result object] already build
IDictionary buildObjects =
request.GetUniqueKeys(propertyRresultMap);
+
if (buildObjects != null && buildObjects.Contains(uniqueKey))
{
// Unique key is already known, so get the existing result
object and process additional results.
@@ -120,6 +122,7 @@
}
else if (uniqueKey == null || buildObjects == null ||
!buildObjects.Contains(uniqueKey))
{
+ // Unique key is NOT known, so create a new result object
and then process additional results.
result = _resultMapStrategy.Get(request, resultMap,
mapping, ref target, reader);
if (buildObjects == null)