Grails MyBatis

I’m rewriting one of existing application. It’s a messy Swing application. There’s no clear separation of concern. It makes direct JDBC calls from View , Controller, anywhere. It’s all over the places. WHAT THE FFHHH!!

My plan is as follow:

  • to move those SQLs to a separate application that serve the data via webservice APIs.
  • to replace JDBC call with ORM. I choose iBatis, well.. MyBatis.
  • to use Grails framework

First class ORM citizen in Grails is GORM which basically Hibernate. Fortunately, there’s Grails MyBatis plugin. Well, at first I’m a bit worried because the version number is 0.0.2, no review, and last updated last year. Anyway, I just installed it and find it works fine.

Just some notes:

  • put the gateway codes in grails-app/gateways instead of src/gateways.
  • I couldn’t find way to add configLocation. So I clone the MyBatis project and add few lines of code.

    so that I could specify “mybatis.configLocation=the-config-file.xml” in my Config.groovy

 

[Update]

If the mapper xml files reside under grails-app/gateways, you’ll need to add the following script in BuildConfig.groovy to copy those XML into war

Alternatively, you need to move all the XML under src/java.  Just make sure each mapper file resides in the same package as the corresponding gateway file.

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">