4월, 2013의 게시물 표시

Spring Batch - Processor

return null를 할 경우 어떻게 처리 될까 궁금하여 =0=;; 복사 & 붙이기 ^^ return null item이 진행 되지 않는다.. 이말은 즉 writer에게 넘어가지 않는다. ㅡ0- transaction에서 동일한 id가 입력되어 오류가 발생 했는데. set를 이용하여 id 체크하고 중복이면 null를 뱉어내면 크크크 문제가 해결될듯.. process O process ( I  item) throws Exception Process the provided item, returning a potentially modified or new item for continued processing. If the returned result is null, it is assumed that processing of the item should not continue. Parameters: item  - to be processed Returns: potentially modified or new item for continued processing, null if processing of the provided item should not continue. Throws: Exception

Spring Batch - JobParameters Default Value 만들기

Spring batch에서 JobParameters에 입력되지 않은 값에 대한 default value를 설정 해야 할때는 아래와 같이 하자. <property name="userId" value=" #{jobParameters['userId']==null?'-':jobParameters['userId']} "></property> 위의 userId 속성 값 지정을 jobparameters로 di받아서 사용하는데. 위 방식으로 하면 userId가 입력 되지 않았을 경우, 즉 null인 경우 '-' 로 설정 되고, 입력되었을 경우 값이 전달 된다. 다른 방식은 SpEL를 더 찾아봐야 겠지만...나의 요구 사항은 여기 까지 ^^

Spring Batch - TaskletStep 작성

이번 요구사항은 특정 조건일 경우 이후 스텝을 진행할 것인가 말것인가에 대한 결정을 해야한다. 일단 step flow를 조정하는건 다음으로 넘기고, 특정 조건를 검사하는 스텝을 만들어야 하는데, 이런 경우에는 TaskletStep를 사용한다고 한다. TaskStep는 Reader + Processor + Writer의 구성이 아닌 경우의 스텝을 정의 할 때 사용한다. 구현방법은 http://static.springsource.org/spring-batch/reference/html/configureStep.html 의 5.2.2를 참조하면 될꺼 같고 자 이제 만들어 볼까나 ^^ -- 이슈 : Tasklet에서 조건이 맞지 않을 경우 다음 스텝을 중지 해야 하는데... execute의 return 타입이 FINISHED와 CONTINUE 밖에 없다.. 해결 방법 : Exeception 던진다. 참고 :   http://forum.springsource.org/showthread.php?66932-Tasklet-API-Change-ExitStatus-to-RepeatStatus

generic을 사용하는 Class에서 T의 객체 생성 하기.

참고 :  http://stackoverflow.com/questions/75175/create-instance-of-generic-type-in-java From  Java Tutorial - Restrictions on Generics : Cannot Create Instances of Type Parameters You cannot create an instance of a type parameter. For example, the following code causes a compile-time error: public static < E > void append ( List < E > list ) { E elem = new E (); // compile-time error list . add ( elem ); } As a workaround, you can create an object of a type parameter through reflection: public static < E > void append ( List < E > list , Class < E > cls ) throws Exception { E elem = cls . newInstance (); // OK list . add ( elem ); } You can invoke the append method as follows: List < String > ls = new ArrayList <>(); append ( ls , String . class );