우리가 TDD를 하는 이유중의 하나도 가능한 빠른 시간에 코드를 런타임까지 만들어서 버그를 줄이는 것일 것이다. 런타임시에 버그를 줄일 수 있는 것은 코드품질과 밀접한 관계가 있다.
TDD를 통해서 빠르게 런타임 환경을 가져가는 것도 중요하지만, 자바와 같은 경우에는 새로 만든 코드들이 컴파일 타임에 모든 에러를 잡을 수 있으면 가장 좋을 것이라는 생각이다.
iBATIS는 국내에서 많이 사용되는 프레임워크 중의 하나이다. JDBC로 직접코딩하던 시절에 iBATIS와의 처음 만남은 아름다운 추억중의 하나였다. 여러가지 제약사항과 단점이 있긴 하지만, JDBC코딩보다는 중복이나 버그의 가능성을 줄여주는 것은 사실이다.
우리는 일반적으로 다음과 같이 구현을 한다. 써보신 분들은 너무나 자주 보던 syntax이고, 예제이다.
//...and...
List employees = sqlMapper.queryForList("listAllEmployees");
3.0에서는 다음과 같이 표현이 가능하다.
//...and...
List<Employee> employees = empMapper.listAllEmployees();
인터페이스 자체가 모든 의도를 표현을 한것이다.
보통의 코드개발을 하다가 보면, iBATIS이 유연성만큼 필요한 경우도 드물다. 너무 유연성만 강조하면 코드개발도 힘들고, 유지보수시에도 귀찮아질수도 있다. 그 경우는 spring JDBC가 오히려 간편하고 나아보였는데, 3.0에서 annotation을 통한 쿼리설정은 그런 불편함을 느끼지 않아도 된다.
"FROM EMPLOYEE")
List<Employee> selectAllEmployees();
ConstructorResults와 PropertyResults를 지원한다.
그토록 원하던 ConstructorResults였지만, 다음과 같은 내용이 적혀있다...-.-
@ResultClass (Company.class)
@ConstructorResults({
@Result(property="id", column="C.COMP_ID"),
@Result(property="name", column="C.NAME")
})
@PropertyResults({
@Result(property="departments.id", column="D.DEPT_ID"),
@Result(property="departments.name", column="D.NAME"),
@Result(property="departments.employee.id", column="E.EMP_ID"),
@Result(property="departments.employee.firstName", column="E.FIRST_NAME"),
@Result(property="departments.employee.lastName", column="E.LAST_NAME")
})
@Collections ({
@Collection(type=Department.class, property="departments", groupBy="id"),
@Collection(type=Employee.class, property="departments.employees", groupBy="departments.id")
})
@Select("SELECT #id, #name, " +
"#departments.id, #departments.name, " +
"#departments.employees.id, #departments.employees.firstName, " +
"#departments.employees.lastName " +
"FROM COMPANY C, DEPARTMENT D, EMPLOYEE E " +
"WHERE D.DEPT_ID = E.DEPT_ID " +
"AND C.COMP_ID = D.COMP_ID")
List<Company> selectAllCompaniesWithJoin();
iBATIS를 이용해서 자바에서 immutable domain 클래스로 result를 TypeHandler, TypeHandlerCallback를 이용해서 할수 있는 방법은 있을거 같다.
더 자세한 내용은 아래 링크를 확인하면 된다.
http://opensource.atlassian.com/confluence/oss/display/IBATIS/iBATIS+3.0+Whiteboard
http://opensource.atlassian.com/confluence/oss/display/IBATIS/iBATIS+3.0+Whiteboard+-+Korean
iBATIS3.0 에서 신경을 쓴 부분은 다음과 같다. 코드를 만들면서 생각해볼만한 주제는 굵은 글씨로 표시를 해봤다,
Themes for iBATIS 3.0
- Test driven development
- Code cleanliness over performance
- Simple design over flexible design
- One JAR file
- No required 3rd party dependencies
- Better plug-in support
- Third party plug-ins are hosted elsewhere (sub-project on SF or CodePlex) http://sourceforge.net/projects/ibatiscontrib/

