16
We bring e-business to your business! http://springframework.co.kr Ibatis Ibatis 에 에에 에에 에 에에 에에 , , 에에에에 에에에에 , , Spring Spring 에에에에에에 에에 에에에에에에 에에 에에에 : 에에에

Ibatis 에 대한 소개 , 활용방안 , Spring 프레임워크와 통합

  • Upload
    sibyl

  • View
    103

  • Download
    0

Embed Size (px)

DESCRIPTION

작성자 : 김민재. Ibatis 에 대한 소개 , 활용방안 , Spring 프레임워크와 통합. 목차. iBATIS 이름의 유래 Data Mapper(a.k.a SQL Maps) 소개 XML Configuration File Mapped Statements Parameter Maps Result Maps Dynamic Mapped Statements DAO 소개 XML Configuration File 핵심사항. iBATIS 이름의 유래. - PowerPoint PPT Presentation

Citation preview

Page 1: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

We bring e-business to your business!http://springframework.co.kr

IbatisIbatis 에 대한 소개에 대한 소개 , , 활용방안활용방안 , , Spring Spring 프레임워크와 통합프레임워크와 통합

작성자 : 김민재

Page 2: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

2 http://springframework.co.kr

목차

iBATIS 이름의 유래 Data Mapper(a.k.a SQL Maps)

• 소개• XML Configuration File

• Mapped Statements

• Parameter Maps

• Result Maps

• Dynamic Mapped Statements

DAO• 소개• XML Configuration File

• 핵심사항

Page 3: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

3 http://springframework.co.kr

iBATIS 이름의 유래

Clinton Begin 이라는 사람에 의해 2001 년에 시작된 프로젝트 .원래는 암호 관련 소프트웨어 개발에 초점을 맞춘 프로젝트였다 . iBATIS 에 의한 첫 산출물은 Secrets 라는 이름의 툴이다 .

그러다가 2002 년 초반에 마이크로소프트가 .NET 이 J2EE 에 비해 10 배 빠르고 4 배 생산성이 좋다는 논문을 발표했는데 , 이에 iBATIS 팀은 (역자주 : 열받아서 ..) 같은해 7 월 1 일 JPetStore 1.0 을 릴리스했다 . 그럼으로해서 자바가 .NET 보다 생산성뿐 아니라 아키텍처면에서도 이점이 있음을 보여줬다 .

그런데 , JPetStore 가 아주 재밌는 persistene layer 를 사용했는데 , 이것이 오픈소스 진영의 관심을 끈 것이다 . 그후 관련된 질문과 요구가 Data Mapper(SQL Maps) 와 DAO 라는 두개의 프레임워크로 구성된 새로운 관점에 집중한 iBATIS 프로젝트의 전이를 가져온 것이다 .

ibatis 는 원래 암호 관련 프로젝트로 시작되었음을 알려주는 이름이다 . 즉 "internet" 과 "abatis" 의 합성어인데 ,, abatis 는 적의 공격을 방어하기 위한 장애물이라는 뜻이니 ,,, 인터넷를 지키는데 쓰는 암호를 의미하는 것이다 .

Page 4: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

4 http://springframework.co.kr

SQL Maps - 소개

ibatis-common.jar, ibatis-sqlmap.jar, ibatis-dao.jar

Page 5: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

5 http://springframework.co.kr

SQL Maps - XML Configuration File

http://ibatis.apache.org/dtd/sql-map-config-2.dtd SqlMapConfig.xml -> PDF 참조할 것 The <typeAlias> Element The <transactionManager> Element

• JDBC• JTA• EXTERNAL

The <dataSource> Element• SimpleDataSourceFactory• DbcpDataSourceFactory• JndiDataSourceFactory

The <sqlMap> Element• <sqlMap resource="com/ibatis/examples/sql/Customer.xml" />

Page 6: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

6 http://springframework.co.kr

SQL Maps - Mapped Statements

Product.xml -> PDF 참조할 것 <statement id=”statementName”

[parameterClass=”some.class.Name”][resultClass=”some.class.Name”][parameterMap=”nameOfParameterMap”][resultMap=”nameOfResultMap”][cacheModel=”nameOfCache”][timeout=“5”]>

select * from PRODUCT where PRD_ID = [?|#propertyName#]

order by [$simpleDynamic$]</statement>

<statement id=”insertTestProduct” >insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (1, “Shih Tzu”)

</statement>

Page 7: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

7 http://springframework.co.kr

SQL Maps - Mapped Statements

<![CDATA[]]>

Auto-Generated Keys• <insert>

– <selectKey>

Page 8: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

8 http://springframework.co.kr

SQL Maps – parameterClass/parameterMap

parameterClass• <statement id=”statementName” parameterClass=” examples.domain.Pr

oduct”>insert into PRODUCT values (#id#, #description#, #price#)</statement>

parameterMap• <parameterMap id=”insert-product-param” class=”com.domain.Product”>

<parameter property=”id”/><parameter property=”description”/>

</parameterMap><statement id=”insertProduct” parameterMap=”insert-product-param”>

insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?);

</statement>

Page 9: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

9 http://springframework.co.kr

SQL Maps – resultClass/resultMap

resultClass• <statement id="getPerson" parameterClass=”int” resultClass="example

s.domain.Person">SELECTPER_ID as id,PER_FIRST_NAME as firstName,PER_LAST_NAME as lastName,PER_BIRTH_DATE as birthDate,PER_WEIGHT_KG as weightInKilograms,PER_HEIGHT_M as heightInMetersFROM PERSONWHERE PER_ID = #value#

</statement>

Page 10: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

10 http://springframework.co.kr

SQL Maps – resultClass/resultMap

resultMap• <resultMap id=”get-product-result” class=”com.ibatis.example.Product”>

<result property=”id” column=”PRD_ID”/><result property=”description” column=”PRD_DESCRIPTION”/>

</resultMap><statement id=”getProduct” resultMap=”get-product-result”>

select * from PRODUCT</statement>

Page 11: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

11 http://springframework.co.kr

SQL Maps – 기타사항

Inline Parameter Maps• #id:NUMERIC:-999999#, #description:VARCHAR:NO_ENTRY#• #propertyName# - OR -

#propertyName:jdbcType# - OR -#propertyName:jdbcType:nullValue#

Page 12: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

12 http://springframework.co.kr

SQL Maps – 기타사항

The use of java.sql.Date types is discouraged. It is a best practice to use java.util.Date instead.

Page 13: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

13 http://springframework.co.kr

SQL Maps - Dynamic Mapped Statements

<iterate prepend=”AND” property=”userList”open=”(” close=”)” conjunction=”OR”>firstname=#userList[].firstName# andlastname=#userList[].lastName#</iterate>

<isNotEmpty prepend=”AND” property=”firstName” >FIRST_NAME=#firstName#</isNotEmpty>

Page 14: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

14 http://springframework.co.kr

DAO - 소개

The DAO framework and SQLMaps Framework are completely separate and are not dependent on each other in any way. Please feel free to use either one separately, or both together.

Page 15: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

15 http://springframework.co.kr

DAO - XML Configuration File

dao.xml –The Configuration File (http://ibatis.apache.org/dtd/dao-2.dtd)

<dao interface="com.domain.dao.PersonDao"implementation="com.domain.dao.sqlmap.SqlMapPersonDao"/>

Page 16: Ibatis 에 대한 소개 ,  활용방안 ,  Spring  프레임워크와 통합

16 http://springframework.co.kr

DAO - 핵심사항

public class SqlMapProductDao extends SqlMapDaoTemplate implements ProductDao {}