1 / 16

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

작성자 : 김민재. 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 이름의 유래.

sibyl
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 작성자 : 김민재 Ibatis에 대한 소개, 활용방안, Spring 프레임워크와 통합

  2. 목차 • iBATIS 이름의 유래 • Data Mapper(a.k.a SQL Maps) • 소개 • XML Configuration File • Mapped Statements • Parameter Maps • Result Maps • Dynamic Mapped Statements • DAO • 소개 • XML Configuration File • 핵심사항

  3. 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는 적의 공격을 방어하기 위한 장애물이라는 뜻이니,,, 인터넷를 지키는데 쓰는 암호를 의미하는 것이다.

  4. SQL Maps - 소개 • ibatis-common.jar, ibatis-sqlmap.jar, ibatis-dao.jar

  5. 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" />

  6. 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>

  7. SQL Maps - Mapped Statements • <![CDATA[ ]]> • Auto-Generated Keys • <insert> • <selectKey>

  8. SQL Maps – parameterClass/parameterMap • parameterClass • <statement id=”statementName” parameterClass=”examples.domain.Product”> 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>

  9. SQL Maps – resultClass/resultMap • resultClass • <statement id="getPerson" parameterClass=”int” resultClass="examples.domain.Person"> SELECT PER_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 heightInMeters FROM PERSON WHERE PER_ID = #value# </statement>

  10. 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>

  11. SQL Maps – 기타사항 • Inline Parameter Maps • #id:NUMERIC:-999999#, #description:VARCHAR:NO_ENTRY# • #propertyName# - OR - #propertyName:jdbcType# - OR - #propertyName:jdbcType:nullValue#

  12. SQL Maps – 기타사항 • The use of java.sql.Date types is discouraged. It is a best practice to use java.util.Date instead.

  13. SQL Maps - Dynamic Mapped Statements • <iterate prepend=”AND” property=”userList” open=”(” close=”)” conjunction=”OR”> firstname=#userList[].firstName# and lastname=#userList[].lastName# </iterate> • <isNotEmpty prepend=”AND” property=”firstName” > FIRST_NAME=#firstName# </isNotEmpty>

  14. 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.

  15. 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"/>

  16. DAO - 핵심사항 • public class SqlMapProductDao extends SqlMapDaoTemplate implements ProductDao { }

More Related