JPAWriterPattern
JPAWriterPattern 패턴은 JPA(Java™ Persistence API) 연결을 사용하여 데이터를 데이터베이스에 쓰는 데 사용됩니다.
클래스 지원
JPAWriter 클래스는 EntityManager 클래스 얻기 및 트랜잭션 결합, 시작과 커미트의 기본 JPA 조작을 구현합니다. 기본적으로 JPAWriter는 기존 글로벌 트랜잭션을 결합합니다.
transaction-type 속성을 JTA로 설정하고 jta-data-source 요소를 선언하는 persistence.xml 파일을 패키지합니다. 선택적으로 JPAWriter 클래스를 글로벌 트랜잭션과 동기화하여 트랜잭션을 시작하고 커미트하도록 구성합니다. 이 트랜잭션은 non-jta-data-source 요소 및 연결 URL과 함께 사용됩니다. 이 경우 persistence.xml 파일은 transaction-type을 RESOURCE_LOCAL로 설정하고 non-jta-data-source 요소 또는 연결 URL을 선언합니다.
필수 특성
패턴에 다음 특성이 필요합니다.
특성 이름 | 값 |
---|---|
PATTERN_IMPL_CLASS | JPAWriterPattern 인터페이스를 구현하는 클래스 |
PERSISTENT_UNIT | 제공자 지속적 단위 이름 |
EntityManager 클래스에서 설정한 JPA 특성 | 이 특성의 값 |
선택적 특성
다음 특성은 패턴에 대해 선택사항입니다.
특성 이름 | 값 | 설명 |
---|---|---|
디버그 | true 또는 false(기본값은 false) | 이 일괄처리 데이터 스트림에 대한 자세한 추적을 사용으로 설정합니다. |
use_JTA_transactions | true 또는 false(기본값은 true) | non-jta-data-source 요소나 연결 URL을 사용하는 경우 값을 false로 설정합니다. |
EnablePerformanceMeasurement | true 또는 false(기본값은 false) | GenericXDBatchStep을 사용 중인 경우, 일괄처리 데이터 스트림과 processRecord 메소드에서 소요된 전체 시간을 계산합니다. |
인터페이스 정의
public interface JPAWriterPattern {
/**
* This method is invoked during create job step to allow the JPAWriter stream to
* initialize.
* @param props Properties passed via xJCL
*/
public void initialize(Properties props);
/**
* This method is invoked to actually persist the passed object to the database
* using JPA EntityManager
* @param manager
* @param record
*/
public void writeRecord(EntityManager manager, Object record);
}
xJCL 예
<batch-data-streams>
<bds>
<logical-name>outputStream</logical-name>
<props>
<prop name="PATTERN_IMPL_CLASS" value="com.ibm.websphere.batch.samples.tests.bds.EchoWriter"/>
<prop name="PERSISTENT_UNIT" value="mypersistentU"/>
<prop name="debug" value="true"/>
</props>
<impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.JPAWriter</impl-class>
</bds>
</batch-data-streams>