Uploaded image for project: 'JBeret'
  1. JBeret
  2. JBERET-308

Implement JdbcBatchlet to execute sql statements in a batchlet

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Major Major
    • 1.3.0.Beta5
    • 1.3.0.Beta4
    • jberet-support
    • None

      Need to implement a batchlet that executes the specified sql statements, e.g., create, delete, drop, or update.

      User should be able to specify multiple sql statements separated by ;

      User should be able to specify whether to commit each statement immediately, or group all statements into one transaction. For example, have a batch property autoCommit = true | false. This property should be used if:

      • there are multiple sql statements;
      • the connection is obtained from DriverManager

      Usage examples:

      <?xml version="1.0" encoding="UTF-8"?>
      <job id="JdbcBatchletTest" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
          <step id="step1">
              <batchlet ref="jdbcBatchlet">
                  <properties>
      
                      <!-- run 2 sqls -->
                      <property name="sqls" value="
      insert into STOCK_TRADE (TRADEDATE, TRADETIME, OPEN, HIGH, LOW, CLOSE, VOLUMN) 
      VALUES('2017-02-17','15:51',122.25,122.44,122.25,122.44,16800.0);
      delete from STOCK_TRADE
                       "/>
                      <property name="url"  value="jdbc:h2:/Users/cfang/dev/jsr352/jberet-support/target/JdbcReaderWriterTest"/>
                  </properties>
              </batchlet>
          </step>
      </job>
      

      Run a stored procedure with jdbcBatchlet:

      <?xml version="1.0" encoding="UTF-8"?>
      <job id="JdbcBatchletTest" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
          <step id="step1">
              <batchlet ref="jdbcBatchlet">
                  <properties>
      
                      <!-- run the stored procedure sp2, which has already been created in the target db -->
                      <!-- in h2 database, it is defined as -->
                      <!--
                      CREATE ALIAS IF NOT EXISTS sp2 AS $$
                      void sp2(Connection conn) throws SQLException {
                          conn.createStatement().executeUpdate("delete from STOCK_TRADE");
                      }$$;
                      -->
                      <property name="sqls" value="{ call sp2() }"/>
                      <property name="url"  value="jdbc:h2:/Users/cfang/dev/jsr352/jberet-support/target/JdbcReaderWriterTest"/>
                  </properties>
              </batchlet>
          </step>
      </job>
      

              cfang@redhat.com Cheng Fang
              cfang@redhat.com Cheng Fang
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: