Network Deployment (Distributed operating systems), v8.0 > Reference > Developer detailed usage information


JPAWriterPattern

This pattern is used to write data to a database using a Java Persistence API (JPA) connection.


Support classes

The JPAWriter class implements the basic JPA operations of obtaining an EntityManager class and joining, beginning, and committing transactions. By default the JPAWriter joins an existing global transaction.

Package a persistence.xml file that sets the transaction-type attribute to JTA and declares a jta-data-source element. Optionally configure the JPAWriter class to begin and commit transactions in synchronization with the global transactions. These transactions are used with non-jta-data-source elements and connection URLs. In this case the persistence.xml file sets the transaction-type to RESOURCE_LOCAL and declare a non-jta-data-source element or connection URLs.


Required properties

The following properties are required for the pattern.

Required properties. The table includes the name and value of each required property for the pattern.

Property name Value
PATTERN_IMPL_CLASS Class implementing JPAWriterPattern interface
PERSISTENT_UNIT The OpenJPA persistent unit name
JPA properties that you set on the EntityManager class The value of these properties


Optional properties

The following properties are optional for the pattern.

Optional properties. The table includes the name, value, and description of each optional property for the pattern.

Property name Value Description
debug true or false (The default is false.) Enables detailed tracing on this batch data stream.
use_JTA_transactions true or false (The default is true.) If you use the non-jta-data-source element or connection URLs, set the value to false.
EnablePerformanceMeasurement true or false (The default is false.) Calculates the total time spent in the batch data-streams and the processRecord method, if you are using the GenericXDBatchStep.


Interface definition

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 example

<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>

Batch data stream framework and patterns
Use the batch data stream (BDS) framework
JDBCReaderPattern
JPAReaderPattern
ByteReaderPattern
ByteWriterPattern
FileReaderPattern
FileWriterPattern

+

Search Tips   |   Advanced Search