hbwf / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Enhanced dynamic sql with groovy within xml mapper #639

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I think it would be nice to have the possibility to use groovy to enhance 
dynamic sql.

In my case I have some legacy pojos (I'm not able to change them. also 
extension doesn't work because object instantiation is also legacy.) In my 
database I have to add a extra column which value based on the other fields.
It would be nice if I can calculate the value of the new column inside my xml 
mapper definition like:

 <insert id="insert" parameterType="legacyObject">    
        insert into table (
        col1,
col2,
col3,
newCol4
)
        values 
        <foreach collection="collection" item="item" separator=",">
            (
            #{col1},
            #{col2},
            #{col3},
<groovy>
def newCol4 = #{col1} * 100 + #{col2}/10
</groovy>
            )
        </foreach>
        ;
    </insert>

Original issue reported on code.google.com by mis...@gmx.at on 26 Jul 2012 at 4:13

GoogleCodeExporter commented 9 years ago
3.2.0 version will support pluggable languajes so you can do something like
<insert id="insert" parameterType="legacyObject" lang="groovy">

There is not a groovy driver yet but contributions are welcome. There is a 
velocity driver that can serve as a model.

Original comment by eduardo.macarron on 30 Jul 2012 at 7:10

GoogleCodeExporter commented 9 years ago
Issue 662 has been merged into this issue.

Original comment by eduardo.macarron on 27 Aug 2012 at 9:28