Sunday, May 27, 2012

MyBatis Koans: A Path to Enlightenment


/*---[ MyBatis Koans ]---*/

For much of this month, I've been working on developing a set of koans for the MyBatis data mapper framework. I now have enough completed and tested that I'm sending out notices for others to try them out: https://github.com/midpeter444/mybatis-koans

The first koans I ever tried are the excellent and challenging set of Neo4j koans by Jim Webber and colleagues, which was the subject of my first blog post.

Then I tried the Clojure koans (and then finished about half of the even more challenging 4Clojure koans).

A koan is a question or statement to be meditated upon in order to improve and test a student's progress. Among programmers, software koans have become a clever way to learn a software language or tool. As the Ruby koan website says: "The Koans walk you along the path to enlightenment" -- in this case to learn and practice with the MyBatis 3 data mapper framework.

A software koan comes in the form of a broken unit test that you must fix to get it to pass, usually by filling in the blanks or entire missing sections. The koan is intended to teach one or a small set of cohesive features about the language or tool being studied.


/*---[ Rationale ]---*/

The MyBatis data mapper framework doesn't have the mindshare in the Java world that it should, so this and my earlier "User Guide Companion" are my contributions to helping others learn to use it. I hope others will suggest and contribute new koans.

I'm actually not a MyBatis expert and writing these was my way of learning the framework better. Critiques and suggestions for improvements are welcome.

The koans focus on just the MyBatis Persistence Framework. Be aware that the MyBatis project has other features available such as a Migration Tool and code generator.


/*---[ Getting Started ]---*/

On the MyBatis koans github page, I've tried to provide detailed instructions on how to get set up and do each koan. As this is a relational database mapping framework, you will need to set up a database and install the sakila example schema and dataset.

I've tested the koans with PostgreSQL and MySQL. See the GitHub page for details.


[26-July-2012 Update]: Thanks to some help from collaborator Andrei Pozolotin, the koans have been mavenized to make it easier to get dependencies in place. Andrei also added the Java H2 database with the sakila database set up so you can get started without having to install an enterprise grade database.