MyBatisで
流れるような
メソッドチェーン
MyBatis
ご存知ですか?
JavaのDAO
フレームワーク
です。
MyBatisは
テーブル定義から
ソースを自動生成
できます!
自動生成したソースを使ってこんな感じのソースが
かけます!

EmployeeEntityMapper mapper = manager.getMapper(EmployeeEntityMapper.class);
EmployeeEntityExample example = new EmployeeEntityExample();
example.createCriteria().andEmployeeCodeEqualTo("00001").andTaishaDateIsNull();

List<EmployeeEntity> list = mapper.selectByExample(example);
for (EmployeeEntity employee : list) {
    System.out.println(employee.getName());
}
・・・
かっこ悪
Playみたいに
書きたい!
こんな感じで


List<Post> posts = Post.all().fetch(100); // 100 max posts
List<Post> posts = Post.all().from(50).fetch(100); // 100 max posts start at 50
Post.find("byTitle", "My first post").fetch();
頑張ってみた
目標!


List<Employee> list = Employee.where().
       employeeCodeEqualTo("00001").and().taishaDateIsNull().from(50).fetch(100);
for (Employee employee : list) {
    System.out.println(employee.getName());
}
Where句はこんな感じで

                and/or


where
        クライテリ
                order by          fetch
        アの条件



                fetch/count
                /update/delete


                from             fetch
allは条件なしでこんな感じで


          order by         fetch


 all     fetch/count
         /update/delete

          from            fetch
それぞれに
インターフェース
を用意する。
完成!!
実演!!
結論
MyBatisでもPlayみたいにサクサク可能

条件にクライテリア使えるので、IDEと
組み合わせて更にサクサク

あとはMyBatisGeneratorを改良して
この(きもい大量IFを)自動生成するだけ
Thank You!

MyBatisで流れるようなメソッドチェーン