ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ron Grabowski (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Created: (IBATISNET-278) Iterator literals ($filters[].FieldName) aren't parsed properly when used within conditional tags
Date Sat, 19 Jul 2008 00:30:31 GMT
Iterator literals ($filters[].FieldName) aren't parsed properly when used within conditional
tags
-------------------------------------------------------------------------------------------------

                 Key: IBATISNET-278
                 URL: https://issues.apache.org/jira/browse/IBATISNET-278
             Project: iBatis for .NET
          Issue Type: Bug
          Components: DataMapper
            Reporter: Ron Grabowski


Apparently we don't fully support using iterate literals inside conditional tags. This doesn't
work:

<isPropertyAvailable property="filters">
 AND
 <iterate open="(" close=")" property="filters" conjunction=" AND ">
  <isEqual property="filters[].FilterTypeValue" compareValue="IsEqualTo">$filters[].FieldName$
= #filters[].Begin#</isEqual>
  <isEqual property="filters[].FilterTypeValue" compareValue="IsNotEqualTo">$filters[].FieldName$
&lt;&gt; #filters[].Begin#</isEqual>
  <isEqual property="filters[].FilterTypeValue" compareValue="IsGreaterThan">$filters[].FieldName$
> #filters[].Begin#</isEqual>
 </iterate>
</isPropertyAvailable>

The problem is that the filters[] tokens aren't being expanded to hold the current iterator
value:

 #filters[0].Begin#
 #filters[1].Begin#
 etc...

 $filters[0].FieldName$
 $filters[0].FieldName$
 etc...

I hacked up the code in DynamicSql.cs that handles adding SqlText fragments (around line 256):

// DynamicSql.cs
ParameterProperty[] parameters = sqlText.Parameters;
if (parameters != null) 
{
 int length = parameters.Length;
 for (int i = 0; i< length; i++) 
 {
ParameterProperty parameterProperty = parameters[i];

// HACK!
IterateContext iterateContext = ctx.PeekIterateContext();
if (iterateContext != null)
{
 int currentIterateIndex = 0;
 if (ctx.PeekIterateContext().Index > 0)
 {
  currentIterateIndex = ctx.PeekIterateContext().Index;
 }

  parameterProperty.PropertyName = parameterProperty.PropertyName.Replace("[]", "[" + currentIterateIndex
+ "]");
}
                                
ctx.AddParameterMapping(parameterProperty);
 }
}

as well as ConditionalTagHandler.DoEndFragment. Its not really patch worthy...I just hacked
the code to make my stuff work :-/

// ConditionalTagHandler.cs
public override int DoEndFragment(...)
{
 Iterate iterateTag = tag.Parent as Iterate;

 if (iterateTag != null)
 {
  // HACK! iterate.Index starts at -1
  IterateContext iterate = ctx.PeekIterateContext();
  string find = iterateTag.Property + "[]";
  tring replace = iterateTag.Property + "[" + (iterate.Index + 1) + "]"; //Parameter-index-Dynamic
  Replace(bodyContent, find, replace);
 }

 return BaseTagHandler.INCLUDE_BODY;
}

The Java version seems to support that as well as the concept of nested iterators:

 http://issues.apache.org/jira/browse/IBATIS-131
 http://issues.apache.org/jira/browse/IBATIS-281
 http://issues.apache.org/jira/browse/IBATIS-293

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message