This is a collaborative development space to discuss the future of dynamic SQL in iBATIS SQL Mapping files. This is a key feature of iBATIS that gives it great power. The current implementation has some limitations that we'd like to resolve by introducing a new and improved Dynamic SQL syntax. This page represents the current state of the decisions and future design.
- Inflexible iterators
- Odd iterator syntax ( vs. item definition)
- More flexible variable definition and consistent access
- Old school proprietary XML
- New/improved proprietary XML
- 3rd Party XML
Introducing pluggable scripting languages into the ibatis mix will not provide anything but needless complexity. My feeling is that we need to settle on a scoped EL implementation and make our xml simpler. Following is a recommendation i posted to the developer's list:
I did a little more research on where we can take dyna sql and here is a short proposal.
<isEqual>;<isNotEqual>;<isGreaterThan>;<isGreaterEqual>;<isLessThan>;<isLessEqual> <isPropertyAvailable>;<isNotPropertyAvailable>;<isNull>;<isNotNull>;<isEmpty>;<isNotEmpty> <isParameterPresent>;<isNotParameterPresent>
These could be condensed down to a simpler set of tags:
- <choose> - for mulitple conditionals. used in conjunction with when and otherwise.
- attributes: none
- attributes: prepend, test, append
- attributes: prepend, append
- <if> - for single conditionals
- Attributes: prepend, test, append
- <foreach> - for iterating over arrays. Also, i was thinking we can place a test attribute on this to gain a for loop [for(x=0; x<y; x++)] effect.
- <while> - for looping a "do while" condition.
In light of making this cross platform it may a good idea to use JEXL as a reference point and implement our own el with ANTLR.
The EL should be simple and used for value extraction, boolean tests, and math. It should not have control structure syntax like for, if, while.
ANTLR - http://www.antlr.org/ – ANTLR looks to be the most popular and cross-language (for our C# friends). A quote from the ANTLR website - "ANTLR currently generates Java, C#, and C++. A prototype Python generator is almost ready."