MyBatis-Spring by 맛있는 사과

MyBatis-Spring requires Spring 3.0 or higher, MyBatis 3.1 or higher and Java 5 or higher.


SqlSessionFactoryBean

SqlSessionFactoryBuilder 는 XML configuration file 을 통해 SqlSessionFactory를 build 한다. (XML configuration file 대신 java 를 통해 build 할 수도 있다.) XML configuration file 에는 MyBatis 를 어떻게 사용할 것인가에 대한 설정 정보와 Mapped XML file 에 대한 정보가 포함된다.

base MyBatis 에서는 SqlSessionFactoryBuilder 를 이용해 SqlSessionFactory를 build 하지만 MyBatis-Spring 에서는 SqlSessionFactoryBean 을 이용한다. (http://www.mybatis.org/spring/factorybean.html)

SqlSessionTemplate 
SqlSessionTemplate는 SqlSession의 implements 다. SqlSessionTemplate는 thread safe 하며 multiple DAOs 에서 공유 가능하다. SqlSessionTemplate 는 spring의 transaction configuration 안에서 session을 commit, rollbacks, close 하는 것을 보장한다. (http://www.mybatis.org/spring/sqlsession.html)

참조: http://www.mybatis.org/spring/

DataSource & DriverManager by 맛있는 사과

DataSource and the DriverManager are the two basic ways to connect to a database in a JEE application. The DriverManager is older facility, DataSource is newer. It is recommended to use the new DataSource facility to connect to databases and other resources. DataSource facility has several advantages over DriverManager facility. Using DataSource increases portability. The DataSource enables connection pooling and distributed transactions, the DriverManager does not allow such techniques. Properties of a DataSource are kept in a configuration file. Any changes to the data source or database drivers are made in the configuration file. In case of a DriverManager, these properties are hard coded in the application and for any changes we must recompile the code.

참고:


템플릿 메소드 패턴과 팩토리 메소드 패턴의 차이점. by 맛있는 사과

템플릿 메소드 패턴

상속을 통해 슈퍼클래스의 기능을 확장할 때 사용하는 대표적인 방법이다.
변하지 않는 기능은 슈퍼클래스에 만들어두고 자주 변경되며 확장할 기능은 서브클래스에서 만든다.


팩토리 메소드 패턴

슈퍼클래스에서 서브클래스에서 구현할 메소드를 호출하여 필요한 타입의 오브젝트를 가져와 사용한다. 
서브클래스에서 오브젝트 생성 방법과 클래스를 결정할 수 있도록 미리 정의해둔 메소드를 팩토리 메소드라고 하고, 이 방식을 통해 슈퍼클래스의 기본 코드에서 오브젝트 생성방법을 독립시키는 방법을 팩토리 메소드 패턴이라고 한다.


참고서적: 토비의 스프링3

1