+

Search Tips   |   Advanced Search

JPAWriterPattern

The JPAWriterPattern 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.

properties. The table includes the name and value of
Property name Value
PATTERN_IMPL_CLASS Class implementing JPAWriterPattern interface
PERSISTENT_UNIT The OpenJPA persistent unit name
JPA properties set on the EntityManager class The value of these properties


Optional properties

The following properties are optional for the pattern.

properties. The table includes the name, value, and description
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 we 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


Related concepts

  • Batch data stream framework and patterns


    Related tasks

  • Use the batch data stream framework

  • JDBCReaderPattern
  • JPAReaderPattern
  • ByteReaderPattern
  • ByteWriterPattern
  • FileReaderPattern
  • FileWriterPattern

    (zos) RecordOrientedDatasetReaderPattern

    (zos) RecordOrientedDataSetWriterPattern