달력

3

« 2024/3 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2010. 4. 19. 15:02

SqlMapClient 와 SqlMapClientTemplate I.lib()/I.lib(S.Batch)2010. 4. 19. 15:02

.. .. ..
* iBATIS API의 핵심은 com.ibatis.sqlmap.client.SqlMapClient 인터페이스이다. 

* SqlMapClientTemplate은 SqlMapClient를 감싸서 애플리케이션 대신 물 밑에서 세션을 열고 닫아주며, 발생하는     모든 SQLException을 잡아서 스프링의 비검사형 예외 중 하나로 변환해 다시 던지는 역할을 한다. 


1. SqlMapClientTemplate 구성
   
  - SqlMapClientTemplate 애플리케이션 컨텍스트 설정 ( SqlMapClient를 Template에 와이어링 )
  <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient" />
  </bean>

  - SqlMapClient 빈 생성
  <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="sql-map-config.xml" />
  </bean>


2. iBATIS SQL 맵 정의

  - configLocation 프로퍼티에는 반드시 iBATIS SQL 매핑 파일들의 위치가 나열된 XML 파일 경로가 설정되야 함
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE ....>
  <sqlMapConfig>
<sqlMap resource="ssboard/dao/User-sql.xml" />    <- 이런식으로
  </sqlMapConfig>

  - xml 파일은 결과매핑정의와 질의문 선언으로 되어있다. 


3. DAO에서 템플릿 사용하기

  - sqlMapClientDaoSupport 클래스는 iBATIS용 DAO 지원 클래스다. 

  - SqlMapClientDaoSupport에 SqlMapClient 객체가 주입되면 iBATIS의 단순 반복적인 코드를 숨기기 위해                SqlMapClient 를 감싼 SqlMapClientTemplate 이 생성된다. 

  - SqlMapClientTemplate을 DAO에 직접 와이어링 하는 것과 SqlMapClientDaoSupport 클래스를 상속 받는 것의        가장 큰 차이점은, 스프링 설정 파일에서 빈 하나를 덜 설정해도 된다는 데 있다. 

  - DAO가 SqlMapClientDaoSupport 클래스를 상속하게 되면, SqlMapClientTemplate 빈은 건너뛰고 SqlMapClient     ( 또는 SqlMapClient를 생성하는 SqlMapClientFactoryBean )을 DAO에 직접 와이어링 할 수 있게 된다. 

  
<bean id="rantDao" class="com.roadrantz.dao.ibatis.IbatisRantDao">
<property name="sqlMapClient" ref="sqlMapClient" />
   </bean>

  * "IbatisRantDao"는 SqlMapClientDaoSupport 클래스를 상속한 클래스



참고자료 : 
Spring In Action - 5.6 스프링과 iBATIS

'I.lib() > I.lib(S.Batch)' 카테고리의 다른 글

Spring Batch sample source [일부]  (2) 2010.04.07
Spring_Batch_v1.1.2  (2) 2010.03.16
Spring Batch Operator 사용법에 관한 글  (3) 2010.03.04
.
:
Posted by .07274.