달력

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

'I.lib()/I.lib(S.Batch)'에 해당되는 글 4

  1. 2010.04.19 SqlMapClient 와 SqlMapClientTemplate
  2. 2010.04.07 Spring Batch sample source [일부] 2
  3. 2010.03.16 Spring_Batch_v1.1.2 2
  4. 2010.03.04 Spring Batch Operator 사용법에 관한 글 3
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.
2010. 4. 7. 15:35

Spring Batch sample source [일부] I.lib()/I.lib(S.Batch)2010. 4. 7. 15:35

.. .. ..

Sample Name

분석 여부

필요 기간

기타

skip

O

-

 

retry

O

-

 

restart

O

-

 

automatic-mapping

O

-

 

asynch launch

X

2 day

 

validation

O

-

 

delegation

O

-

 

write behind

X

1/2 day

 

non-sequential

X

1/2 day

loof Flow와 동일.

asynch process

X

2 day

 

filtering

O

-

 

delimited input

O

-

 

fixed-length input

O

-

 

xml input

O

-

 

db paging input

X

1/2 day

 

db cursor input

X

1/2 day

 iBatis는 포함안됨

delimited output

O

-

 

fixed-length output

O

-

 

xml output

O

-

 

db output

O

-

 

multiple files

X

1/2 day

 

multi-line

X

1/2 day

 

multi-record

X

1 day

 



 

Multi-thread Step (asynch process)

<job id="basic_Sample" xmlns="http://www.springframework.org/schema/batch">

          <split id="split1" task-executor="taskExecutor" next="addr">

                      <flow>

                           <step id="wbras_bsid_1-1" next="dong_1-2"/>

                           <step id="dong_1-2"/>

                </flow>

                      <flow>

                           <step id="wbras_bsid_2-1" next="dong_2-2"/>                                                  <step id="dong_2-2"/>

                </flow>

     </split>

     <step  id=”addr”>

     </step>

</job>

 

위의 예제같이 흐름이 그려진다면  wbras_bsid_1-1 wbras_Bsid_2-1이 같이실행되며 스레드 구조로 다음 스텝들을 서로의 플로어(flow) 안에서 실행이 된다.
각각의 플로어가 종료되면 split1에서 설정한 next=”addr” 로 인해 step addr로 이동하며 실행하게 된다.
기타사항으로는 플로어중 exception이 있는 플로어는 실행도중 종료되며 다른 플로어는 계속 실행을 하게된다. 하지만 split안의 플로어중 exception이 일어났을경우는 다음 스텝으로 가지 못하고 fail이 된다. (skip , retry 설정으로 극복

 


 

Multi-record

n  Read된 값들의 종류에 따라 record되는 값이 달라진다.

if (item instanceof Trade) {

        return this.tradeLineAggregator.aggregate((Trade) item);

}

else if (item instanceof CustomerCredit) {

        return this.customerLineAggregator.aggregate((CustomerCredit) item);

}

else {

        throw new RuntimeException();

}                 

라인 어그리에이터의 소스 부분의 모습이다. 받아온 item의 타입에 따라 사용되는 어그리에이터가 달라지는 것이다
 




Multi-line

public Trade read() throws Exception {

Trade t = null;

           for (FieldSet line = null; (line = this.delegate.read()) != null;) {

                      String prefix = line.readString(0);

                     if (prefix.equals("BEGIN")) {

                                t = new Trade(); // Record must start with 'BEGIN'

                     }

                     else if (prefix.equals("INFO")) {

                                Assert.notNull(t, "No 'BEGIN' was found.");

                                t.setIsin(line.readString(1));

                                t.setCustomer(line.readString(2));

                     }

                     else if (prefix.equals("AMNT")) {

                                Assert.notNull(t, "No 'BEGIN' was found.");

                                t.setQuantity(line.readInt(1));

                                t.setPrice(line.readBigDecimal(2));

                     }

                     else if (prefix.equals("END")) {

                                return t; // Record must end with 'END'

                     }

           }

           Assert.isNull(t, "No 'END' was found.");

           return null;

}

ItemReader 부분이다. Read 해서 FieldSet으로 나눠서 나오는 첫번째 값에따라 반환값이 달라진다.

begin일땐 새로 생성하고 info 일땐 값을 입력하고 amnt일땐 다른 값을 입력한다. 이들은 다 리턴을 널값으로 보내준다. 오직 end 값일때만 만들어진 Trade를 리턴해준다. 

요약하면 여러라인 받아놓고 반환 라인 타이밍을 조절하는 것이 Multi-line이다.

 

Multi-file

<bean id="itemReaderForTest" parent="itemReaderParent">

     <property name="resources" value="classpath:data/ /input/delimited*.csv" />

</bean>


이런 식의 빈설정으로 resources는 여러 개의 리소스 값들을 받아온다. 이를 setresources할 때 값은

private Resource[] resources;
이런식으로 배열로 들어가게 된다. 이후 안에 있는값들은 JAVA로 만든 핸들러를 통해 사용된다.


 

Paging query

<bean id="addr_paging_query " class="Infrastructure.read.IbatisPagingItemReader">

<property name="sqlMapClient" ref="sqlMapClient"/>

           <property name="queryId" value="getselect_addr"/>

           <property name="pageSize" value="10000"/>

</bean>


ibatisPagingItemReader
라는 클레스는 원하는 pagesize만큼 read 해서 처리하는 구조이다. Ibatis fetchsize와 비슷한 개념이지만 bean 상태에서 configuration 할수 있다는 장점이 있다. 참고로 batch에서 제공하는 소스상에는 limit 0부터 시작하는데 이것은 Mysql의 구조이기 때문에 limit 1부터 시작하는 altibase와는 맞지 않다. 해서 소스의 변경이 필요하다.

 



 

      synch launch

     <bean id="jobLauncher"
        class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
       <property name="jobRepository" ref="jobRepository" />
       <property name="taskExecutor">
           <bean             
                 class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
       </property>
</bean> 


이와 같이 레퍼런스에 나와있다. http 의 요청으로 launch의 실행시간이 길어지면 다른 작업을 할수 없기때문에 taskExecutor를 사용한다고 나와있다.
ExitStatus 값은 종료되지 않고 thread 상태가 되기때문에 UNKNOWN 상태가 되며 작업은 백그라운드로 실행되게 된다.


 

 

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

SqlMapClient 와 SqlMapClientTemplate  (0) 2010.04.19
Spring_Batch_v1.1.2  (2) 2010.03.16
Spring Batch Operator 사용법에 관한 글  (3) 2010.03.04
.
:
Posted by .07274.
2010. 3. 16. 11:13

Spring_Batch_v1.1.2 I.lib()/I.lib(S.Batch)2010. 3. 16. 11:13

.. .. ..
세미나 발표전 자료


.
:
Posted by .07274.
.. .. ..

1. vo 통하여 선태된 JobExecution Id선택

String jobExecutionId = vo.getJOB_EXECUTION_ID();
  this.logger.debug(" jobExecutionId " + jobExecutionId);

 

 2. ApplicationContext 설정하기
  ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
          new String[] { "simple-job-launcher-context.xml", "jobs/ CF_EI10000Job.xml", "jobs/DD20101BJob.xml" });

 

3. ApplicationContext 에서 operator 가져오기
  SimpleJobOperator oper = (SimpleJobOperator)classPathXmlApplicationContext.getBean("jobOperator");

 

4. ApplicationContext에서 Job가져오기
  Job job = (Job) classPathXmlApplicationContext.getBean ("CF_EI10000");
  Job DD20101B = (Job) classPathXmlApplicationContext.getBean ("DD20101B");

 

5. job 이용하여 잡팩토리 생성
  ReferenceJobFactory jobfactory = new ReferenceJobFactory(job);
  ReferenceJobFactory DD20101Bjobfactory = new ReferenceJobFactory (DD20101B);

  ListableJobRegistry jobRegistry = new MapJobRegistry();

try {


      /* registry
잡팩토리 등록  */
      jobRegistry.register(DD20101Bjobfactory);
      jobRegistry.register(jobfactory);

 

           Or

 

<bean  class="org.springframework.batch.core.configuration.support.JobRegistryBean­PostProcessor">
  <property name="jobRegistry" ref="jobRegistry"/>
 </bean>

 <bean id="jobRegitry" class="....MapJobRegistry">

선언만 들어와 있으면 applicationContext올라가면서 자동으로 jobRegitry Job들이 등록된다.

 

      /* operator JobRegistry 등록 */
      oper.setJobRegistry(jobRegistry);

 

      /* operator 이용하여 실행 */
      oper.restart(Long.parseLong(jobExecutionId));

 

6. JobRegistryBeanPostProcessor 이용해 MapJobRepository 초기화하는 방법

<bean  class="org.springframework.batch.core.configuration.support.JobRegistryBean­­PostProcessor">
   <property name="jobRegistry" ref="jobRegistry"/>
 </bean>

 

ClassPathXmlJobRegitry 쓰면 기본적으로 Job interface 구현한 모든 bean들을 등록해준다..  MapJobRegitry 따로 등록절차 거쳐서 job 관리할 필요가 있을 사용.

 

7. Operator 예제 소스

 ClassPathXmlApplicationContext classPathXmlApplicationContext = new  ClassPathXmlApplicationContext(
                 new String[] { "simple-job-launcher-context.xml",  "jobs/CF_EI10000Job.xml" });

         SimpleJobOperator oper = (SimpleJobOperator) classPathXmlApplicationContext.getBean("jobOperator");

         JobParametersBuilder builder = new JobParametersBuilder();
         builder.addString("CORP_SECD", "TI01");
         builder.addString("PROC_STD_YMD", "20090831");
         builder.addDate("START_TIME", new Date());
         builder.toJobParameters();

      oper.start("CF_EI10000", builder.toString());

 


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

SqlMapClient 와 SqlMapClientTemplate  (0) 2010.04.19
Spring Batch sample source [일부]  (2) 2010.04.07
Spring_Batch_v1.1.2  (2) 2010.03.16
.
:
Posted by .07274.