'나만의 작업/iBatis'에 해당되는 글 9건
- [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) 2009/01/20
- [iBatis] 자동 생성 Key (2) 2009/01/18
- [iBatis] 자바빈즈와 Map 타입의 결과 2009/01/18
- [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) 2008/09/03
- [iBATIS] 7. iBATIS + Spring + transaction 2008/09/02
- [iBATIS] 6. iBATIS + Spring 2008/09/01
- [iBATIS] 5. Transaction (2) 2008/09/01
- [iBATIS] 4. How to (2) 2008/08/29
- [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) 2008/08/28
[iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면?
Posted at 2009/01/20 10:33// Posted in 나만의 작업/iBatis'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBatis] 자동 생성 Key
Posted at 2009/01/18 21:28// Posted in 나만의 작업/iBatis'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
-
2009/01/22 16:11 [Edit/Del] [Reply]덕분에 좋은 정보 얻어갑니다^^;
딴지는 아니고, sqlMap 예제에 selectKey부분에 from절이 빠졌네요^^;;;-
2009/01/29 11:12 [Edit/Del]^^방문해주셔서 감사해요^^
음 위의 예제는 PostgreSQL의 경우에
select nextval('seq');
select currval('seq');
이렇게 쓰는걸로 알고 있습니다. ^^
-
[iBatis] 자바빈즈와 Map 타입의 결과
Posted at 2009/01/18 01:20// Posted in 나만의 작업/iBatis'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference
Posted at 2008/09/03 10:13// Posted in 나만의 작업/iBatis8. Annotation 기반으로 JUnit4를 이용한 Spring TDD
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback=true)
@RunWith : 테스트를 실행할 org.junit.runner.Runner 구현 클래스를 지정할 수 있다.
스프링은 스프링 컨텍스트 설정 및 DI, 트랜잭션 처리 등을 지원해주는 Runner 구현 클래스를 제공하고 있다.
Junit 4 기반의 테스트에서 스프링 컨텍스트에 설정된 빈 객체를 사용하고 싶다면 SpringJunit4ClassRunner 클래스를 @RunWith 어노테이션 값으로 설정하면 된다.
@ContextConfiguration : 스프링 컨텍스트를 생성할 때 사용될 설정 파일의 경로
@Autowired, @Resource : 테스트 코드에서 필요로 하는 스프링 빈 객체 설정
- 트랜잭션 처리를 위한 설정
@TransactionConfiguration : 테스트 클래스에 적용되며, 트랜잭션 관리자와 기본 롤백 규칙을 설정한다.
@Rollback : 테스트 메소드에 적용되며, 메소드 단위로 롤백 규칙을 설정한다.
@NotTransactional : 트랜잭션을 적용하지 않을 메소드에 적용한다.
@Transactional : 테스트 클래스에 적용. 이 어노테이션을 적용함으로써 각 테스트 메소드는 트랜잭션 범위 내에서 실행된다.
만약 테스트 메소드에서 명시적으로 롤백 여부를 설정하고 싶다면 @Rollback 어노테이션을 사용하면 된다.
@Rollback(false)
테스트 메소드에 대한 트랜잭션이 시작되기 전에 어떤 초기화 작업을 해주어야 한다며, @BeforeTransaction 어노테이션이 적용된 메소드를 작성하면 된다.
반대로 트랜잭션이 종료된 이후에 정리 작업을 해주어야 할 경우에는 @AfterTransaction 어노테이션이 적용된 메소드를 작성하면 된다.
@RunWith (SpringJUnit4ClassRunner. class )
@ContextConfiguration (locations = { "classpath:/com/mydomain/data/beans.xml" })
@TransactionConfiguration (transactionManager = "transactionManager" ,defaultRollback= true )
@Transactional
public class iBatisDaoTest {
@Autowired
private ImageService imageService ;
private int id ;
@Test
public void testInsertImage() {}
}
9. Reference
SQL Maps2.0 개발자가이드 ( 한글판 )
http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_ko.pdf
SQL Maps2.0 tutorial( 한글판 )
http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2-Tutorial_ko.pdf
iBATIS 에서 생성되는 SQL 문을 보기 위한 log4j 셋팅
http://openframework.or.kr/JSPWiki/Wiki.jsp?page=IbatisLog4jSettingToShowSQL
Sql2ibatis
http://openframework.or.kr/JSPWiki/Wiki.jsp?page=Sql2ibatis
DDL2iBatis
http://openframework.or.kr/JSPWiki/attach/Hibernate/DDL2iBatis-exe.zip
Spring 2.5, Eclipse and JUnit 4.4
http://dertompson.com/index.php/2007/12/12/spring-25-eclipse-and-junit-44/
iBATIS 인 액션: 쉽고 강력한 SQL 매핑 프레임워크 아이바티스
- 클린턴 비긴.브랜든 구딘.래리 메도스 지음 | 이동국.손권남 번역, 위키북스
스프링 2.5 프로그래밍
- 최범균 , 가메출판사
'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBATIS] 7. iBATIS + Spring + transaction
Posted at 2008/09/02 10:03// Posted in 나만의 작업/iBatis7. iBATIS + Spring + transaction
1. 코드 기반의 트랜잭션 처리 (Progrmmatic Transaction)
2. 선언적 트랜잭션 (Declarative Transaction)
- <tx:advice> 태그를 이용
- TransactionProxyFactoryBean 태그를 이용
- @Transactional 어노테이션을 이용
<tx:advice> 태그 이용
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="fooService" class="x.y.service.DefaultFooService"/>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
<aop:pointcut id="fooServiceOperation" expression="execution(* x.y.service.FooService.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
@ Transactional 어노테이션을 이용
@Transactional(readOnly = true)
public class DefaultFooService implements FooService {
public Foo getFoo(String fooName) {
// do something
}
// these settings have precedence for this method
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateFoo(Foo foo) {
// do something
}
}
<bean id="fooService" class="x.y.service.DefaultFooService"/>
<tx:annotation-driven transaction-manager="txManager"/>
'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBATIS] 6. iBATIS + Spring
Posted at 2008/09/01 19:57// Posted in 나만의 작업/iBatis6. iBATIS + Spring
SqlMapClientFactoryBean
(org.springframework.orm.ibatis.SqlMapClientFactoryBean)
SqlMapClientTemplate
(org.springframework.orm.ibatis.SqlMapClientTemplate)
SqlMapClientDaoSupport
(org.springframework.orm.ibatis.support.SqlMapClientDaoSupport)
스프링의 iBATIS 연동지원
iBATIS 에서 데이터베이스 연동을 처리할 때 사용되는 SqlMapClient 역시 JDBC 프로그램을 할 때와 마찬가지로 try-catch 블록을 사용해서 예외를 처리해 주어야 한다 .
또한 에러원인에 따라 알맞은 예외를 발생시키기보다는 SQLException 을 발생하고 있다 .
스프링은 SqlMapClient 를 사용할 때 발생하는 코드 중복을 없애고 SQLException 을 스프링이 제공하는 예외 클래스로 변환해 주는 SqlMapClientTempalte 클래스를 제공하고 있다 .
1.
SqlMapClient 를 위한 스프링 설정
스프링이 제공하는 SqlMapClientTemplate 클래스는 내부적으로 iBATIS 의 SqlMapClient 를 사용한다 .
스프링은 SqlMapClient 를 스프링 설정 파일에서 쉽게 설정할 수 있도록 돕는 SqlMapClientFactoryBean
클래스를 제공하고 있다 .
이 클래스를 사용하면 SqlMapClient 를 스프링 빈으로 설정할 수 있다 .
dataSource 프로퍼티에는 DataSource 를 전달하며 , configLocation 프로퍼티는 iBATIS 설정 파일을 명시
2.
SqlMapClientTemplate 을 이용한 DAO 구현
SqlMapClient 를 위한 빈을 설정했다면 SqlMapClientTemplate 을 이용해서 iBATIS 를 연동할 수 있다 .
SqlMapClientTemplate
클래스는 iBATIS 의 SqlMapClient
클래스가 제공하는 대부분의 메소드와 동일한 이름과 파라미터 타입 , 리턴 타입을 갖는 메소드를 정의하고 있다.
차이점이 있다면 SQLException 을 발생하는 대신 스프링이 제공하는 예외를 발생한다 .
iBATIS 의 SqlMapExecutor 를 직접 사용하고 싶다면 ,
SqlMapClientCallback 인터페이스의 구현 객체를 전달받는 execute() 메소드를 사용하면 된다 .
SqlMapClientCallback
구현 객체의 doInSqlMapClient()
메소드에 SqlMapExecutor 파라미터가 전달되므로 , 직접 SqlMapExecutor 를 사용해서 데이터베이스 연동을 구현할 수 있다 .
3.
SqlMapClientDaoSupport 클래스를 이용한 DAO 구현
스프링은 SqlMapClientTemplate 클래스를 DAO 클래스에서 좀 더 쉽게 사용할 수 있도록 하기 위해 SqlMapClientDaoSupport 클래스를 제공한다 .
이 클래스를 상속받은 클래스는 sqlMapClientTemplate 프로퍼티를 통해서 SqlMapClientTemplate 를 전달받는다 .
'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBATIS] 5. Transaction
Posted at 2008/09/01 19:56// Posted in 나만의 작업/iBatis5. Transaction
iBatis 가 지원하는 네 가지 트랜잭션 범위
*
자동 트랜잭션 : 단순한 한 개의 SQL 구문은 명시적으로 구분된 트랜잭션을 필요로 하지 않는다 .
*
로컬 트랜잭션 : 간단하고 범위가 좁은 트랜잭션으로 여러 SQL 구문을 포함하지만 단일 데이터베이스에서 수행된다 .
*
글로벌 트랜잭션 : 복잡하고 범위가 넓은 트랜잭션으로 여러 SQL 구문을 여러 데이터베이스 혹은 잠재적으로 데이터베이스가 아닌 JMS 의 큐나 JCA 커넥션 같은 다른 트랜잭션이 가능한 리소스상에서 실행된다 .
*
사용자 정의 트랜잭션 : 사용자 맘대로 ~
'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBATIS] 4. How to
Posted at 2008/08/29 10:07// Posted in 나만의 작업/iBatis4. How to
< 실행절차 >
1. 객체를 파라미터로 전달
JavaBeans, Map or primitive wrapper
2. 매핑되는 SQL 문장을 수행
SQL Maps 프레임워크는 PreparedStatment 인스턴스 생성
객체로부터 제공되는 값들을 파라미터로 세팅
3. SQL 문장을 수행하고 ResultSet 으로부터 결과 객체를 생성 .
Update 의 경우에는 영향을 받은 rows 수가 반환
쿼리의 경우 하나 혹은 여러 객체들이 반환
결과객체는 자바빈즈 , Map 원시타입래퍼 또는 XML 이 될 수 있다 .
SQL Maps 설정파일 -SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>
<sqlMap resource="sqlmaps/Image.xml" />
</sqlMapConfig>
SQL Map 파일 - Image.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Image">
<typeAlias alias="image" type="com.mydomain.domain.Image" />
<cacheModel id="oneDayProduct" type="LRU">
<flushInterval hours="24" />
</cacheModel>
<resultMap id="imageMap" class="image">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="mimeType" column="mimetype" />
<result property="width" column="width" />
<result property="height" column="height" />
<result property="resolution" column="resolution" />
<result property="fileSize" column="filesize" />
<result property="regDate" column="regdate" />
<result property="license" column="license" />
<result property="author" column="author" />
<result property="description" column="description" />
</resultMap>
<select id="getImages" resultClass="image">
SELECT * FROM images
</select>
SQLMaps : 데이터베이스 접속에서부터 실제 사용할 SQL Map 들까지 모든 것들을 프레임워크에 제공해 준다 .
SQLMaps 프레임워크를 사용하기 위해 당신은 당신의 애플리케이션을 통해 실행될 SQL 쿼리문의 모든 리스트를 가지는 XML 파일을 생성한다 . 각각의 SQL 쿼리를 위해 당신은 쿼리문이 파라미터와 ResultSets 을 교체되는 자바 클래스를 정의한다 .
자바 코드내에서 당신이 특정 쿼리문을 실행하길 원할때 당신은 쿼리 파라미터와 필요한 조건을 넘기기 위한 객체를 생성할 것이고 SQLMaps 를 실행하기 위한 쿼리의 객체와 이름을 넘겨준다 . 쿼리가 실행되었을때 SQLMaps 는 쿼리 결과를 받기 위해 정의된 클래스의 인스턴스를 생성할 것이고 데이터베이스에 의해 반환된 ResultSet 로 부터 넘겨진 값으로 이것을 생성할것이다 .
SQL Map 파일 - Mapped Statement
<statement id="statementName"
[parameterClass="some.class.Name"]
[resultClass="some.class.Name"]
[parameterMap="nameOfParameterMap"]
[resultMap="nameOfResultMap"]
[cacheModel="nameOfCache"]
>
<![CDATA
select * from PRODUCT where PRD_ID = [?|#propertyName#]
order by [$simpleDynamic$]
]]>
name : 'buri'
# : 데이터형에 맞는 sql 데이터형으로 변환
#name# : 'buri'
$ : 기존 데이터를 그대로 사용
'%$name$%' : '%buri%'
? : parameterMap에 정의된 순서대로 ? 에 바인딩
맵핑된 (Mapped) Statements
SQL Maps 개념은 맵핑된 statement 에 집중한다 . 맵핑된 statement 는 어떠한 SQL 문을 사용할수도 있고 파라미터 maps(input)과 result maps(output) 를 가질수 있다 . 만약 간단한 경우라면 맵핑된 statement 는 파라미터와 result 를 위한 클래스로 직접 설정할수 있다 . 맵핑된 statement 는 메모리내에 생산된 results 를 캐슁하기 위해 캐쉬 모델을 사용하도록 설정할수도 있다 .
parameter class
당신이 parameterMap 을 사용한다면 parameterClass 속성을 사용할 필요가 없다 . 예를 들면 당신이 파
라미터로 전달하기 위한 "examples.domain.Product" 타입의 객체를 허락하길 원한다면 당신은 다음처럼 할수 있을것이다 .
resultClass
mapped statement 를 통한 ResultSet 의 columns 을 JavaBeans property 와 mapping 하는 역할
parameterMap
resultMap
자주 사용되고 중요한 attribute 는 resultMap 으로 정의
cacheModel
Query mapped statements 를 통한 결과를 cacheModel parameters 를 통하여 caching 할 수 있다 .
XML CDATA 섹션
하나의문서에서 SQL 과 XML 을 혼합하기 때문에 특수문자의 충돌이 잠재적으로 존재한다 . 대부분의 공통적인 것은 greater-than 과 less-than 문자들이다 .(<>). 이것들은 SQL 문에서 공통적으로 요구되고 XML 에서는 예약어이다 . 당신의 SQL 문에 들어갈 필요가 있는 특수 XML 문자를 처리하기 위한 간단한 해결법이 있다 . 표준적인 XML CDATA 섹션을 사용함으로써 특수문자의 어떤것도 파싱되지 않고 문제는 해결된다
JavaBeans
public class Image {
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
// ....
}
매핑 구문의 타입
- <insert>
- child element : <selectKey>
- <update>
- <delete>
- <select>
- <statement>
- <procedure>
SQL Map API
- insert()
- update()
- delete()
- queryForObejct()
- queryForList()
- queryForMap()
Auto Generation Key
<insert id="insertImage" parameterClass="image">
INSERT INTO images(name,mimetype,width,height,resolution,filesize,regdate,license,author,description)
VALUES (#name#, #mimeType#, #width#, #height#, #resolution#,#fileSize#, #regDate#, #license#, #author#, #description#)
<selectKey keyProperty="id" resultClass="int">
values IDENTITY_VAL_LOCAL()
</selectKey>
</insert>
Cache Model
< cacheModel id = " oneDayProduct " type = " LRU " >
< flushInterval hours = " 24 " / >
< / cacheModel >
Dynamic Query
< update id = " dynamicUpdateImage " parameterClass = " image " >
Update images
< dynamic prepend = " SET " >
< isNotNull property = " name " prepend = " , " >
name = #name#
< / isNotNull >
< isNotNull property = " mimeType " prepend = " , " >
mimetype = #mimeType#
< / isNotNull >
< isNotNull property = " width " prepend = " , " >
width = #width#
< / isNotNull >
< isNotNull property = " height " prepend = " , " >
height = #height#
< / isNotNull >
< isNotNull property = " resolution " prepend = " , " >
resolution = #resolution#
< / isNotNull >
< isNotNull property = " fileSize " prepend = " , " >
fileSize = #fileSize#
< / isNotNull >
< isNotNull property = " regDate " prepend = " , " >
regDate = #regDate#
< / isNotNull >
< isNotNull property = " license " prepend = " , " >
license = #license#
< / isNotNull >
< isNotNull property = " author " prepend = " , " >
author = #author#
< / isNotNull >
< isNotNull property = " description " prepend = " , " >
description = #description#
< / isNotNull >
< / dynamic >
WHERE id=#id#
< / update >
Reuse SQL
<include>를 쓰지 않았을 경우
< select id = " selectItemCount " resultClass = " int " >
SELECT COUNT(*) AS total
FROM images
WHERE id = 1
< / select >
< select id = " selectItems " resultClass = " image " >
SELECT id, name
FROM images
WHERE id = 1
< / select >
<include>를 썼을 경우
< sql id = " selectItem_fragment " >
FROM images
WHERE id = #value#
< / sql >
< select id = " selectItemCount " parameterClass = " int " resultClass = " int " >
SELECT COUNT(*) AS total
< include refid = " selectItem_fragment " / >
< / select >
< select id = " selectItems " parameterClass = " int " resultClass = " image " >
SELECT id, name
< include refid = " selectItem_fragment " / >
< / select >
'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
[iBATIS] 1.Overview ~ 3. Introduce iBATIS
Posted at 2008/08/28 19:06// Posted in 나만의 작업/iBatisiBATIS
1. Overview
2. Why use iBATIS?
3. Introduce iBATIS
4. How to
5. Transaction
6. iBATIS + Spring
7. iBATIS + Spring + transaction
8. Annotation 기반으로 JUnit4를 이용한 Spring TDD
9. Reference
1. Overview
개발자에게 JavaBeans objects를 PreparedStatement parameters와 ResultMaps로 쉽게 매핑을 할 수 있도록 한다. 이를 통하여 database에 접근하기 위한 자바코드의 양을 줄일수있다.
현재 iBatis는 세가지 언어: 자바, C#, Ruby로 구현되어 있다.
2. Why use iBATIS?
OR맵핑툴을 사용하지 않을때 하위레벨의 JDBC코드를 쓰거나 관리할때 많은 자원을 소비 한다는것이다. 모든JDBC애플리케이션은 다음과 같은 반복코드를 가진다.
1. 데이터베이스연결및트랜잭션관리
2. 쿼리파라미터를자바객체와셋팅하기.
3. SQL ResultSets를자바객체로변환하기.
4. 쿼리문생성하기.
iBatis는 진입장벽이 낮은 프레임워크, JDBC의 복잡하고 반복적인 코드를 모두 없애주면서도 SQL을 그대로 사용하기 때문에 "익숙해서 배우기 쉬우면서, 생산성과 유지보수성을 높여 주는 프레임워크" 자바코드의20%를 사용하여 JDBC기능의 80%를 제공하는 간단한 프레임워크
=> 더빠른 JDBC 코딩을 위한 일반화된 프레임워크
3. Introduce iBATIS
iBATIS 퍼시스턴스계층의 중요한 특징: SQL의 외부저장과 캡슐화=> 간결함과 일관성
외부로뺀SQL :
SQL을 애플리케이션소스 코드로부터 분리하여 유지. 이렇게함으로써 SQL은 상대적으로 특정언어나 플랫폼에 독립적인 상태가 된다. SQL문만 튜닝을 하고 싶을때 SQL문만 보낼수있다.
캡슐화된SQL :
캡슐화는 코드를 응집성있는 모듈로 조직하는것뿐만 아니라 또한 세부적인 구현을 숨기고 호출하는 코드에게인터페이스만을 노출시키는 모듈화의 한 형태
애플리케이션의 다른 부분으로부터 SQL코드를 숨겨서 SQL을 캡슐화 할수있다.
iBATIS는 SQL을 캡슐화 하기 위해 XML을 사용한다. XML은 모든 플랫폼에 이식가능. iBATIS는 XML을 사용하여 SQL 구문의 입력과 출력을 정의
iBATIS는 파라미터와 실행 결과를 객체의 프로퍼티로 매핑하게 한다.
특징
간단함: 가장 간단한 퍼시스턴스 프레임워크로 간주됨
생산성: JDBC에 비해 62% 정도 줄어드는 간결한 코드와 간단한설정
성능: 데이터접근 속도를 높여주는 join 매핑과 같은 구조적인 강점
관심사의 분리: 차후 유지보수성을 높여줄 수 있도록 설계를 향상 시킬수있다.
작업의 분배: 전문성을 강화하기 위해 팀을 세분화하는것을돕는다(프로그램 잘짜면 프로그램짜고, 쿼리잘짜면 쿼리짜고)
이식성
'나만의 작업 > iBatis' 카테고리의 다른 글
| [iBatis] iBatis에서 Log4j를 이용하여 쿼리를 로그로 남기려면? (4) | 2009/01/20 |
|---|---|
| [iBatis] 자동 생성 Key (2) | 2009/01/18 |
| [iBatis] 자바빈즈와 Map 타입의 결과 (0) | 2009/01/18 |
| [iBATIS] 8. Annotation 기반으로 JUnit4를 이용한 Spring TDD ~ 9. Reference (4) | 2008/09/03 |
| [iBATIS] 7. iBATIS + Spring + transaction (0) | 2008/09/02 |
| [iBATIS] 6. iBATIS + Spring (0) | 2008/09/01 |
| [iBATIS] 5. Transaction (2) | 2008/09/01 |
| [iBATIS] 4. How to (2) | 2008/08/29 |
| [iBATIS] 1.Overview ~ 3. Introduce iBATIS (4) | 2008/08/28 |
-
-
오우2009/10/12 11:10 [Edit/Del] [Reply]아주 체계적으로 정리를 잘해놓으셨네요.
아이바티스 진입장벽이 낮다는 생각은 저는 아니네요.
어렵다..??
어쟀든 감사합니다.-
2009/10/12 21:04 [Edit/Del]방문해 주셔서 감사해요
^^ 이 포스팅 내용은 iBatis2를 기준으로 한 글이에요
iBatis 3 에선 조금씩 달라졌으니 참고하세요^^
-



늘 좋은일만 생기길 바래요~
올해엔 [NC]...YellOw님의 해가 되길 간절히 빌게요^^
좋은 기능까지 찾을줄이야..
어째든 다음 플젝에 사용하면.. 문자열 정렬 기능도 사용해봐야겠어..