Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

MyBatis

2011-02-14 sixclick
by

so-yeun park

on 12 February 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of MyBatis

MyBatis는 더 빠른 JDBC 코딩을 위한 일반화 된 프레임워크 MyBatis 소개 퍼시스턴스 계층
◆ 객체와 데이터베이스 그리고 매퍼 자체를 독립적으로 유지 + 객체와 데이터베이스 간에 데이터를 이동
◆ SQL 매핑으로 객체를 관계형 데이터베이스에 저장
◆ 애플리케이션이 퍼시스턴스 계층에 일관성있게 접근하는 것을 도와줌 ibatis 3.0 -> mybatis Spring3.0이 mybatis를 지원하지 않음? mybatis에서 스프링용 라이브러리를 제공한다. * MyBatis-Spring 1.0.0
Stop to RCs, that's the first GA release of the Spring module
integration, few issues from RC3 - that proved to be robust & stable -
had been open and quickly closed, more detailed infos on
http://tinyurl.com/3ambxfz
2011년 1월 1일에 정식 1.0.0버전이 나왔다. if foreach choose when
<!-- Very Complex Result Map -->
<resultMap id="detailedBlogResultMap" type="Blog">
<constructor>
<idArg column="blog_id" javaType="int"/>
</constructor>
<result property="title" column="blog_title"/>
<association property="author" column="blog_author_id" javaType=" Author">
<id property="id" column="author_id"/>
<result property="username" column="author_username"/>
<result property="password" column="author_password"/>
</association>
<collection property="posts" ofType="Post">
<id property="id" column="post_id"/>
<result property="subject" column="post_subject"/>
<association property="author" column="post_author_id" javaType="Author"/>
<collection property="comments" column="post_id" ofType=" Comment">
<id property="id" column="comment_id"/>
</collection>
<collection property="tags" column="post_id" ofType=" Tag" >
<id property="id" column="tag_id"/>
</collection>
<discriminator javaType="int" column="draft">
<case value="1" resultType="DraftPost"/>
</discriminator>
</collection>
</resultMap>

constructor
모델 셋팅에
public class User {    //…    public User(int id, String username) { 순서 상관있음.

association
모델의 element 중 하나만 있는 관계.
다른 association 설정으로는
<resultMap id=”blogResult” type=”Blog”>  
<association property="author" column="blog_author_id" javaType="Author"  select=”selectAuthor”/>
</resultMap>

collection
모델 안에 private List<Post> posts; 이런 경우
다른 설정으로
<resultMap id=”blogResult” type=”Blog”>  
<collection property="posts" javaType=”ArrayList” column="blog_id"  ofType="Post" select=”selectPostsForBlog”/>
</resultMap>

discriminator
컬럼 값에 따라서 interface나 추상 클래스의 타입을 명시해버리는 기능.
이런 예도 있음.
<discriminator javaType="int" column="vehicle_type">  
<case value="1" resultMap="carResult"/>  
<case value="2" resultMap="truckResult"/>  
<case value="3" resultMap="vanResult"/>  
<case value="4" resultMap="suvResult"/>
</discriminator> 지향하는 바 sql이 이제 더이상 java 코드안에 들어가지 않고, sql을 java처럼 만드는것이 자신들의 sql의 끝

그거에 더해서 도메인 기반의 언어에 가깝게 만드는게 목표 selectBuilder private String selectPersonSql() {
BEGIN(); // Clears ThreadLocal variable
SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FULL_NAME");
SELECT("P.LAST_NAME, P.CREATED_ON, P.UPDATED_ON");
FROM("PERSON P");
FROM("ACCOUNT A");
INNER_JOIN("DEPARTMENT D on D.ID = P.DEPARTMENT_ID");
INNER_JOIN("COMPANY C on D.COMPANY_ID = C.ID");
WHERE("P.ID = A.ID");
WHERE("P.FIRST_NAME like ?");
OR();
WHERE("P.LAST_NAME like ?");
GROUP_BY("P.ID");
HAVING("P.LAST_NAME like ?");
OR();
HAVING("P.FIRST_NAME like ?");
ORDER_BY("P.ID");
ORDER_BY("P.FULL_NAME");
return SQL();
} sqlBuilder
public String deletePersonSql() {
BEGIN(); // Clears ThreadLocal variable
DELETE_FROM("PERSON");
WHERE("ID = ${id}");
return SQL();
}

public String insertPersonSql() {
BEGIN(); // Clears ThreadLocal variable
INSERT_INTO("PERSON");
VALUES("ID, FIRST_NAME", "${id}, ${firstName}");
VALUES("LAST_NAME", "${lastName}");
return SQL();
}

public String updatePersonSql() {
BEGIN(); // Clears ThreadLocal variable
UPDATE("PERSON");
SET("FIRST_NAME = ${firstName}");
WHERE("ID = ${id}");
return SQL();
} mybatis-spring 1. Integration Spring
2. Spring이 mybatis의 factory, session class를 로드할 수 있도록 함
3. 서비스 Bean을 통해서 mapper와 SqlSession을 injection 가능
4. Transaction과 mybatis의 exception을 Spring을 통해서 관리

In these cases MyBatis is automatically creating a ResultMap behind the scenes to map the columns to the JavaBean properties based on name.  
If the column names did not match exactly, you could employ select clause aliases (a standard SQL feature) on the column names to make the labels match.  
For example:

<select id=”selectUsers” parameterType=”int” resultType=”User”>  
select  user_id    as “id”,  
user_name    as “userName”,  
hashed_password   as “hashedPassword”
from some_table  
where id = #{id}
...
http://namoda.springnote.com/pages/586397
http://hanavy.egloos.com/10579837

공식 위키 사이트: http://code.google.com/p/mybatis/wiki/
참고 URL
Full transcript