<?xml version="1.0" encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="https://nozaki.me/roller/roller-ui/styles/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom">
    <title type="html">Kohei Nozaki&apos;s blog</title>
    <subtitle type="html">Notes of my experiments</subtitle>
    <id>https://nozaki.me/roller/kyle/feed/entries/atom</id>
            <link rel="self" type="application/atom+xml" href="https://nozaki.me/roller/kyle/feed/entries/atom?cat=JBatch" />
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/" />
        <updated>2024-05-01T08:28:13+00:00</updated>
    <generator uri="http://roller.apache.org" version="5.2.0">Apache Roller</generator>
        <entry>
        <id>https://nozaki.me/roller/kyle/entry/jbatch-examples-bulk-loading-from1</id>
        <title type="html">JBatch examples: bulk loading from database to CSV file</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/jbatch-examples-bulk-loading-from1"/>
        <published>2015-05-24T06:52:00+00:00</published>
        <updated>2015-06-09T08:19:42+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jberet" scheme="http://roller.apache.org/ns/tags/" />
        <category term="wildfly" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;In &lt;a href=&quot;/roller/kyle/entry/jbatch-examples-bulk-loading-from&quot;&gt;previous entry&lt;/a&gt;, we looked how to load data from CSV file to database. in this entry, we will look how to load data from database to CSV file. we’ll use &lt;code&gt;JdbcItemReader&lt;/code&gt; to read data from database and &lt;code&gt;CsvItemWriter&lt;/code&gt; to write data to as a CSV file.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_setup&quot;&gt;Setup&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;In this setup we’ll use WildFly 9.0.0.CR1.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Assume we already have a table &lt;code&gt;forex&lt;/code&gt; and data in H2 database that created and populated in &lt;a href=&quot;/roller/kyle/entry/jbatch-examples-bulk-loading-from&quot;&gt;previous entry&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;For &lt;code&gt;JdbcItemReader&lt;/code&gt;, we need an another datasource which is &lt;strong&gt;Non-JTA&lt;/strong&gt;, references the same database to &lt;strong&gt;JTA&lt;/strong&gt; one. &lt;a href=&quot;https://developer.jboss.org/message/916629&quot;&gt;for detail see this conversation&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;data-source add \
 --name=MyNonJtaDS \
 --driver-name=h2 \
 --jndi-name=java:jboss/datasources/MyNonJtaDS \
 --user-name=sa \
 --password=sa \
 --connection-url=jdbc:h2:/tmp/myds;AUTO_SERVER=TRUE \
 --jta=false&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Next, create job artifacts.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;__src_main_resources_meta_inf_batch_jobs_save_csv_xml&quot;&gt;/src/main/resources/META-INF/batch-jobs/save-csv.xml&lt;/h3&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Note that &lt;code&gt;MyNonJtaDS&lt;/code&gt; is used, not &lt;code&gt;MyDS&lt;/code&gt;. and all of classes that used in the job are supplied within &lt;code&gt;jberet-support&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;job id=&quot;save-csv&quot; version=&quot;1.0&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;&amp;gt;
    &amp;lt;step id=&quot;save&quot;&amp;gt;
        &amp;lt;chunk&amp;gt;
            &amp;lt;reader ref=&quot;jdbcItemReader&quot;&amp;gt;
                &amp;lt;properties&amp;gt;
                    &amp;lt;property name=&quot;dataSourceLookup&quot; value=&quot;java:jboss/datasources/MyNonJtaDS&quot;/&amp;gt;
                    &amp;lt;property name=&quot;sql&quot;
                              value=&quot;SELECT symbol, ts, bid_open, bid_high, bid_low, bid_close, volume FROM forex ORDER BY symbol, ts&quot;/&amp;gt;
                    &amp;lt;property name=&quot;beanType&quot; value=&quot;java.util.List&quot;/&amp;gt;
                &amp;lt;/properties&amp;gt;
            &amp;lt;/reader&amp;gt;
            &amp;lt;writer ref=&quot;csvItemWriter&quot;&amp;gt;
                &amp;lt;properties&amp;gt;
                    &amp;lt;property name=&quot;resource&quot; value=&quot;#{jobParameters[&apos;resource&apos;]}&quot;/&amp;gt;
                    &amp;lt;property name=&quot;header&quot;
                              value=&quot;symbol, ts, bid_open, bid_high, bid_low, bid_close, volume&quot;/&amp;gt;
                    &amp;lt;property name=&quot;beanType&quot; value=&quot;java.util.List&quot;/&amp;gt;
                &amp;lt;/properties&amp;gt;
            &amp;lt;/writer&amp;gt;
        &amp;lt;/chunk&amp;gt;
    &amp;lt;/step&amp;gt;
&amp;lt;/job&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_run_the_job&quot;&gt;Run the job&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Issue following command. this saves a CSV file into &lt;code&gt;/tmp/save.csv&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;curl &apos;http://localhost:8080/jbatch-example-1.0-SNAPSHOT/jbatch/rest/start/save-csv?resource=/tmp/save.csv&apos;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;After job execution is done, check the CSV file is created as expected:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;symbol,ts,bid_open,bid_high,bid_low,bid_close,volume
USDJPY,2015-04-01 00:00:00.0,119.566,119.566,119.551,119.565,0
USDJPY,2015-04-01 00:01:00.0,119.566,119.581,119.565,119.579,0
USDJPY,2015-04-01 00:02:00.0,119.581,119.586,119.581,119.583,0
...&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;The project which used in this entry can be obtained from &lt;a href=&quot;https://github.com/lbtc-xxx/jbatch-example&quot;&gt;my GitHub repository&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_references&quot;&gt;References&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_csv_data/index.html&quot; class=&quot;bare&quot;&gt;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_csv_data/index.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_data_through_jdbc/index.html&quot; class=&quot;bare&quot;&gt;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_data_through_jdbc/index.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/jbatch-examples-bulk-loading-from</id>
        <title type="html">JBatch examples: bulk loading from CSV file to database</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/jbatch-examples-bulk-loading-from"/>
        <published>2015-05-24T06:07:39+00:00</published>
        <updated>2015-06-09T08:20:24+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jberet" scheme="http://roller.apache.org/ns/tags/" />
        <category term="wildfly" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Bulk loading is a typical usecase of batch application. in this entry, I give you a example of bulk loading from a CSV file.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;There is a supplemental package named &lt;code&gt;jberet-support&lt;/code&gt;, which contains many useful classes that implemented &lt;code&gt;ItemReader&lt;/code&gt; or &lt;code&gt;ItemWriter&lt;/code&gt; for common usecases. in this entry, we&amp;#8217;ll use &lt;code&gt;CsvItemReader&lt;/code&gt; to read a CSV file and &lt;code&gt;JdbcItemWriter&lt;/code&gt; to write data to database.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_setup&quot;&gt;Setup&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;In this setup we&amp;#8217;ll use WildFly 9.0.0.CR1.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;First, we need a CSV file, whatever. so we&amp;#8217;ll use a forex historical data which can be downloaded from &lt;a href=&quot;http://www.histdata.com/download-free-forex-historical-data/?/ascii/1-minute-bar-quotes/usdjpy/2015/4&quot; class=&quot;bare&quot;&gt;http://www.histdata.com/download-free-forex-historical-data/?/ascii/1-minute-bar-quotes/usdjpy/2015/4&lt;/a&gt; . download it and unpack, put &lt;code&gt;DAT_ASCII_USDJPY_M1_201504.csv&lt;/code&gt; somewhere in your environment. this file contains data like:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;20150401 000000;119.566000;119.566000;119.551000;119.565000;0
20150401 000100;119.566000;119.581000;119.565000;119.579000;0
20150401 000200;119.581000;119.586000;119.581000;119.583000;0
...&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Next, define a JTA datasource on WildFly. following is an example command which defines a H2 datasource using &lt;code&gt;jboss-cli&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;data-source add \
 --name=MyDS \
 --driver-name=h2 \
 --jndi-name=java:jboss/datasources/MyDS \
 --user-name=sa \
 --password=sa \
 --connection-url=jdbc:h2:/tmp/myds;AUTO_SERVER=TRUE&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;After confirmed outcome was &lt;code&gt;success&lt;/code&gt;, issue following command to test a connection:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;/subsystem=datasources/data-source=MyDS:test-connection-in-pool&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Next, create a table to store dataset. issue following command to start H2 console, in the base directory of your WildFly instance:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;java -cp ./modules/system/layers/base/com/h2database/h2/main/h2*.jar org.h2.tools.Shell -url &quot;jdbc:h2:/tmp/myds;AUTO_SERVER=TRUE&quot; -user sa -password sa&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Execute following DDL:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;CREATE TABLE forex (
    symbol VARCHAR(6) NOT NULL,
    ts TIMESTAMP NOT NULL,
    bid_open NUMERIC(10,3) NOT NULL,
    bid_high NUMERIC(10,3) NOT NULL,
    bid_low NUMERIC(10,3) NOT NULL,
    bid_close NUMERIC(10,3) NOT NULL,
    volume INTEGER NOT NULL,
    PRIMARY KEY(symbol, ts)
);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Next, create a batch application.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;_pom_xml&quot;&gt;pom.xml&lt;/h3&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;You need following dependencies in your &lt;code&gt;pom.xml&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;dependencies&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;javax&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;javaee-api&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;7.0&amp;lt;/version&amp;gt;
        &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.apache.batchee&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;batchee-servlet-embedded&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;0.2-incubating&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.jberet&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;jberet-support&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;1.1.0.Final&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;net.sf.supercsv&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;super-csv&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;2.3.1&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;com.fasterxml.jackson.core&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;jackson-databind&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;2.5.3&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;__src_main_resources_meta_inf_batch_jobs_load_csv_xml&quot;&gt;/src/main/resources/META-INF/batch-jobs/load-csv.xml&lt;/h3&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;The job uses &lt;code&gt;csvItemReader&lt;/code&gt; and &lt;code&gt;jdbcItemWriter&lt;/code&gt; that are supplied within the &lt;code&gt;jberet-support&lt;/code&gt; package.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;job id=&quot;load-csv&quot; version=&quot;1.0&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;&amp;gt;
    &amp;lt;step id=&quot;load&quot;&amp;gt;
        &amp;lt;chunk&amp;gt;
            &amp;lt;reader ref=&quot;csvItemReader&quot;&amp;gt;
                &amp;lt;properties&amp;gt;
                    &amp;lt;property name=&quot;resource&quot; value=&quot;#{jobParameters[&apos;resource&apos;]}&quot;/&amp;gt;
                    &amp;lt;property name=&quot;headerless&quot; value=&quot;true&quot;/&amp;gt;
                    &amp;lt;property name=&quot;delimiterChar&quot; value=&quot;;&quot;/&amp;gt;
                    &amp;lt;property name=&quot;beanType&quot; value=&quot;java.util.List&quot;/&amp;gt;
                &amp;lt;/properties&amp;gt;
            &amp;lt;/reader&amp;gt;
            &amp;lt;processor ref=&quot;forexItemProcessor&quot;&amp;gt;
                &amp;lt;properties&amp;gt;
                    &amp;lt;property name=&quot;symbol&quot; value=&quot;#{jobParameters[&apos;symbol&apos;]}&quot;/&amp;gt;
                &amp;lt;/properties&amp;gt;
            &amp;lt;/processor&amp;gt;
            &amp;lt;writer ref=&quot;jdbcItemWriter&quot;&amp;gt;
                &amp;lt;properties&amp;gt;
                    &amp;lt;property name=&quot;dataSourceLookup&quot; value=&quot;java:jboss/datasources/MyDS&quot;/&amp;gt;
                    &amp;lt;property name=&quot;sql&quot;
                              value=&quot;INSERT INTO forex (symbol, ts, bid_open, bid_high, bid_low, bid_close, volume) values (?, ?, ?, ?, ?, ?, ?)&quot;/&amp;gt;
                    &amp;lt;property name=&quot;beanType&quot; value=&quot;java.util.List&quot;/&amp;gt;
                &amp;lt;/properties&amp;gt;
            &amp;lt;/writer&amp;gt;
        &amp;lt;/chunk&amp;gt;
    &amp;lt;/step&amp;gt;
&amp;lt;/job&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;__src_main_java_jbatch_forexitemprocessor_java&quot;&gt;/src/main/java/jbatch/ForexItemProcessor.java&lt;/h3&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Named
@Dependent
public class ForexItemProcessor implements ItemProcessor {
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(&quot;uuuuMMdd HHmmss&quot;);

    @Inject
    @BatchProperty
    private String symbol;

    @Override
    public Object processItem(final Object item) throws Exception {
        final List items = (List) item;
        return Arrays.asList(symbol,
                Timestamp.valueOf(LocalDateTime.parse((String) items.get(0), FORMATTER)),
                new BigDecimal((String) items.get(1)),
                new BigDecimal((String) items.get(2)),
                new BigDecimal((String) items.get(3)),
                new BigDecimal((String) items.get(4)),
                Integer.valueOf((String) items.get(5)));
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_run_the_batch&quot;&gt;Run the batch&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Example if you put the forex CSV in &lt;code&gt;/tmp/DAT_ASCII_USDJPY_M1_201504.csv&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;curl &apos;http://localhost:8080/jbatch-example-1.0-SNAPSHOT/jbatch/rest/start/load-csv?symbol=USDJPY&amp;amp;resource=/tmp/DAT_ASCII_USDJPY_M1_201504.csv&apos;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;After the job done, check dataset within your database using the H2 CLI:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;sql&amp;gt; select * from forex;
SYMBOL | TS                    | BID_OPEN | BID_HIGH | BID_LOW | BID_CLOSE | VOLUME
USDJPY | 2015-04-01 00:00:00.0 | 119.566  | 119.566  | 119.551 | 119.565   | 0
USDJPY | 2015-04-01 00:01:00.0 | 119.566  | 119.581  | 119.565 | 119.579   | 0
USDJPY | 2015-04-01 00:02:00.0 | 119.581  | 119.586  | 119.581 | 119.583   | 0
...
(31572 rows, 505 ms)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;The project which used in this entry can be obtained from &lt;a href=&quot;https://github.com/lbtc-xxx/jbatch-example&quot;&gt;my GitHub repository&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_references&quot;&gt;References&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_csv_data/index.html&quot; class=&quot;bare&quot;&gt;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_csv_data/index.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_data_through_jdbc/index.html&quot; class=&quot;bare&quot;&gt;http://jberet.gitbooks.io/jberet-user-guide/content/read_and_write_data_through_jdbc/index.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/jbatch-examples-get-started-with</id>
        <title type="html">JBatch examples: get started JBatch with WildFly and batchee-servlet-embedded</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/jbatch-examples-get-started-with"/>
        <published>2015-05-24T03:43:56+00:00</published>
        <updated>2015-05-25T08:13:33+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="batchee" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jberet" scheme="http://roller.apache.org/ns/tags/" />
        <category term="wildfly" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;JSR352 aka JBatch is the standardized batch processing framework for the Java EE platform. it eases tedious work on batch programming such as transaction management of bulk processing, parallel processing, flow control. and it gives well-integrated job information management mechanism, well-designed interfaces that enables us to develop common modules for frequently use. there are some convenient modules aim to be used in typical situation. in this entry, I introduce you some examples to get started.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_setup&quot;&gt;Setup&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Setup WildFly 9.0.0.CR1: download the full distribution from &lt;a href=&quot;http://www.wildfly.org/&quot;&gt;wildfly.org&lt;/a&gt; and unpack.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Next, create a war application contains following resources:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;_pom_xml&quot;&gt;pom.xml&lt;/h3&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;This contains a dependency to &lt;code&gt;batchee-servlet-embedded&lt;/code&gt;. it brings a simple web application which enables us to control batch jobs, also it supplies simple REST style interface.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;jbatch-example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;jbatch-example&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
    &amp;lt;packaging&amp;gt;war&amp;lt;/packaging&amp;gt;

    &amp;lt;properties&amp;gt;
        &amp;lt;maven.compiler.source&amp;gt;1.8&amp;lt;/maven.compiler.source&amp;gt;
        &amp;lt;maven.compiler.target&amp;gt;1.8&amp;lt;/maven.compiler.target&amp;gt;
        &amp;lt;project.build.sourceEncoding&amp;gt;UTF-8&amp;lt;/project.build.sourceEncoding&amp;gt;
        &amp;lt;failOnMissingWebXml&amp;gt;false&amp;lt;/failOnMissingWebXml&amp;gt;
    &amp;lt;/properties&amp;gt;

    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;javax&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;javaee-api&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;7.0&amp;lt;/version&amp;gt;
            &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.apache.batchee&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;batchee-servlet-embedded&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;0.2-incubating&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;

&amp;lt;/project&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;__src_main_java_jbatch_mybatchlet_java&quot;&gt;/src/main/java/jbatch/MyBatchlet.java&lt;/h3&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Named
@Dependent
public class MyBatchlet extends AbstractBatchlet {
    @Override
    public String process() throws Exception {
        System.out.println(&quot;Hello, JBatch&quot;);
        return null;
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;__src_main_resources_meta_inf_batch_jobs_simple_job_xml&quot;&gt;/src/main/resources/META-INF/batch-jobs/simple-job.xml&lt;/h3&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;job id=&quot;simple-job&quot; version=&quot;1.0&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;&amp;gt;
    &amp;lt;step id=&quot;myStep&quot;&amp;gt;
        &amp;lt;batchlet ref=&quot;myBatchlet&quot;/&amp;gt;
    &amp;lt;/step&amp;gt;
&amp;lt;/job&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_deploy_and_run_the_batch&quot;&gt;Deploy and run the batch&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Then deploy the war, and go to &lt;a href=&quot;http://localhost:8080/jbatch-example-1.0-SNAPSHOT/jbatch/&quot; class=&quot;bare&quot;&gt;http://localhost:8080/jbatch-example-1.0-SNAPSHOT/jbatch/&lt;/a&gt; from your browser. you&amp;#8217;ll see following page:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;imageblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;img src=&quot;/roller/kyle/mediaresource/26c69072-c35c-4885-b8ab-cb7c8445c7ac&quot; alt=&quot;26c69072 c35c 4885 b8ab cb7c8445c7ac&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Then click New Batch button. you&amp;#8217;ll be transited to following page. enter &lt;code&gt;simple-job&lt;/code&gt; to the text box, then click &lt;strong&gt;Set Job Name&lt;/strong&gt;, and click &lt;strong&gt;Submit&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;imageblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;img src=&quot;/roller/kyle/mediaresource/41f38684-4e35-4e09-8463-28b81ae49f92&quot; alt=&quot;41f38684 4e35 4e09 8463 28b81ae49f92&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;If the batch executed successfully, you&amp;#8217;ll be transited to following page:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;imageblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;img src=&quot;/roller/kyle/mediaresource/5913a110-1457-483b-878b-d8d08f2520a2&quot; alt=&quot;5913a110 1457 483b 878b d8d08f2520a2&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Also you&amp;#8217;ll see following output in your WildFly console:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;12:23:02,046 INFO  [stdout] (Batch Thread - 2) Hello, JBatch&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;You can see job execution history from the web. click &lt;code&gt;simple-job&lt;/code&gt; in home page and you&amp;#8217;ll be transited following page:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;imageblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;img src=&quot;/roller/kyle/mediaresource/e2f7d3c1-c52b-4261-9727-a3a22c1277ce&quot; alt=&quot;e2f7d3c1 c52b 4261 9727 a3a22c1277ce&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Instead of using web browser, you can launch a job with simple REST style API as follows:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;curl http://localhost:8080/jbatch-example-1.0-SNAPSHOT/jbatch/rest/start/simple-job&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;For details of the REST API, you can see help with following command:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;curl http://localhost:8080/jbatch-example-1.0-SNAPSHOT/jbatch/rest/&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;It shows:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;Known commands are:

* start/ - start a new batch job
  Sample: http://localhost:8080/myapp/jbatch/rest/start/myjobname?param1=x&amp;amp;param2=y
  BatchEE will start the job and immediately return

* status/ - query the current status
  Sample: http://localhost:8080/myapp/jbatch/rest/status/23
  will return the state of executionId 23

* stop/ - stop the job with the given executionId
  Sample: http://localhost:8080/myapp/jbatch/rest/stop/23
  will stop the job with executionId 23

* restart/ - restart the job with the given executionId
  Sample: http://localhost:8080/myapp/jbatch/rest/restart/23
  will restart the job with executionId 23&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;The project which used in this entry can be obtained from &lt;a href=&quot;https://github.com/lbtc-xxx/jbatch-example&quot;&gt;my GitHub repository&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/testing-a-jbatch-job-using</id>
        <title type="html">Testing a JBatch job using Arquillian on remote WildFly</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/testing-a-jbatch-job-using"/>
        <published>2015-03-05T08:14:33+00:00</published>
        <updated>2015-03-05T08:14:33+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="arquillian" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <category term="wildfly" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;I pushed entire project to &lt;a href=&quot;https://github.com/lbtc-xxx/arquillian-jbatch&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/arquillian-jbatch&lt;/a&gt; .&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;While I prefer remote EJB way &lt;a href=&quot;/roller/kyle/entry/lean-example-of-integration-test&quot;&gt;like my previous posting&lt;/a&gt; for JBatch testing, it works well for simple project. but little slower than remote EJB on my environment.&lt;/p&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/using-apache-batchee-s-jax</id>
        <title type="html">Using Apache BatchEE&apos;s server API with JBeret</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/using-apache-batchee-s-jax"/>
        <published>2015-03-04T09:11:04+00:00</published>
        <updated>2015-03-21T13:25:16+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="arquillian" scheme="http://roller.apache.org/ns/tags/" />
        <category term="batchee" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jberet" scheme="http://roller.apache.org/ns/tags/" />
        <category term="wildfly" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;&lt;a href=&quot;http://batchee.incubator.apache.org&quot;&gt;Apache BatchEE&lt;/a&gt; is a fork of the JSR352 reference implementation with many additional features. it has useful REST APIs built on JAX-RS so we can manipulate (start, stop, restart, and so on) batches through REST API. fortunately, it is well modularized so we can use its REST API implementation with other JSR352 implementation such as JBeret.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lbtc-xxx/batcheetest&quot;&gt;I created an example project which works with WildFly 8.2.0.Final and its JSR352 implementation JBeret&lt;/a&gt;. after deploy, issue following command:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;curl -H &apos;Content-Type: application/json&apos; \
     -d &apos;{&quot;entries&quot;: [ {&quot;key&quot;: &quot;myKey1&quot;, &quot;value&quot;: &quot;myValue1&quot;}, {&quot;key&quot;: &quot;myKey2&quot;, &quot;value&quot;: &quot;myValue2&quot;} ]}&apos; \
     http://localhost:8080/batcheetest/jbatch/batchee/execution/start/myjob&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Then you&amp;#8217;ll see following output in WildFly console:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;17:57:18,608 INFO  [stdout] (Batch Thread - 9) Hello world!
17:57:18,609 INFO  [stdout] (Batch Thread - 9) Job Parameters: {myKey2=myValue2, myKey1=myValue1}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;It&amp;#8217;s much better than create a servlet which kicks the batch.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;And I haven&amp;#8217;t tested yet, it also have useful client API for that REST API. we can use &lt;code&gt;JobOperator&lt;/code&gt; transparently thanks to its proxy. for details of REST API and BatchEE, see following URLs:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://batchee.incubator.apache.org/gui.html&quot; class=&quot;bare&quot;&gt;http://batchee.incubator.apache.org/gui.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://batchee.incubator.apache.org/apidocs/org/apache/batchee/jaxrs/server/JBatchResourceImpl.html&quot; class=&quot;bare&quot;&gt;http://batchee.incubator.apache.org/apidocs/org/apache/batchee/jaxrs/server/JBatchResourceImpl.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://events.linuxfoundation.org/sites/events/files/slides/apache_batchee_jbatch_apachecon2014.pdf&quot; class=&quot;bare&quot;&gt;http://events.linuxfoundation.org/sites/events/files/slides/apache_batchee_jbatch_apachecon2014.pdf&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lbtc-xxx/batcheetest/blob/be92f33e7689524733b1d70e355f3fba9b58a09e/src/test/java/myjob/MyJobIT.java&quot;&gt;I added a test case which uses client API of BatchEE&lt;/a&gt;, but it doesn&amp;#8217;t work with released version. you need to apply a patch by hand. for details refer &lt;a href=&quot;https://issues.apache.org/jira/browse/BATCHEE-59&quot; class=&quot;bare&quot;&gt;https://issues.apache.org/jira/browse/BATCHEE-59&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Also I created an example of a test class which uses Arquillian. this won&amp;#8217;t work with 0.2-incubating but will work with future versions.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@RunWith(Arquillian.class)
public class MyJobArquillianIT {
    @ArquillianResource
    private URL url;
    private JobOperator jobOperator;

    @Deployment(testable = false)
    public static Archive&amp;lt;?&amp;gt; war() {
        final File[] files = Maven.configureResolver()
                .loadPomFromFile(&quot;pom.xml&quot;)
                .resolve(&quot;org.apache.batchee:batchee-jaxrs-server&quot;)
                .withTransitivity()
                .asFile();
        return ShrinkWrap.create(WebArchive.class)
                .addClass(HelloBatchlet.class)
                .addAsResource(&quot;META-INF/batch-jobs/myjob.xml&quot;)
                .addAsLibraries(files);
    }

    @Before
    public void before() {
        jobOperator = BatchEEJAXRSClientFactory.newClient(url.toExternalForm() + &quot;jbatch&quot;);
    }

    @Test
    public void test() {
        Properties jobParameters = new Properties();
        jobParameters.setProperty(&quot;someKey&quot;, &quot;someValue&quot;);
        final JobExecution jobExecution = waitForFinish(jobOperator.start(&quot;myjob&quot;, jobParameters));
        Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
    }

    private static final Collection&amp;lt;BatchStatus&amp;gt; BATCH_END_STATUSES
            = EnumSet.of(BatchStatus.COMPLETED, BatchStatus.FAILED, BatchStatus.STOPPED, BatchStatus.ABANDONED);

    private JobExecution waitForFinish(long executionId) {
        JobExecution jobExecution;
        while (!BATCH_END_STATUSES.contains((jobExecution = jobOperator.getJobExecution(executionId)).getBatchStatus())) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return jobExecution;
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_web_frontend&quot;&gt;Web frontend&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Its web-frontend GUI (&lt;code&gt;batchee-servlet-embedded&lt;/code&gt;) works even against JBeret runtime as follows. you can view executions, jobs and its definition, and can start jobs with custom parameters.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;imageblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;img src=&quot;/roller/kyle/mediaresource/42afff86-2c07-4c4f-8a93-9b90f4910b43&quot; alt=&quot;42afff86 2c07 4c4f 8a93 9b90f4910b43&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;It also exposes &lt;code&gt;simple-rest&lt;/code&gt; API which is more useful when issue the command by hand or some cases (e.g. cron job). in case of this example, you can start a job as follows:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;$ curl &apos;http://localhost:8080/batcheetest/jbatch-gui/rest/start/myjob?param1=x&amp;amp;param2=y&apos;
5
OK&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;You can read its help as follows:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;$ curl &apos;http://localhost:8080/batcheetest/jbatch-gui/rest/&apos;
-1
FAILURE
Unknown command:
The returned response if of MIME type text/plain and contains the following information
  {jobExecutionId} (or -1 if no executionId was detected)\n
  OK (or FAILURE)\n
  followed by command specific information

Known commands are:

* start/ - start a new batch job
  Sample: http://localhost:8080/myapp/jbatch/rest/start/myjobname?param1=x&amp;amp;param2=y
  BatchEE will start the job and immediately return

* status/ - query the current status
  Sample: http://localhost:8080/myapp/jbatch/rest/status/23
  will return the state of executionId 23

* stop/ - stop the job with the given executionId
  Sample: http://localhost:8080/myapp/jbatch/rest/stop/23
  will stop the job with executionId 23

* restart/ - restart the job with the given executionId
  Sample: http://localhost:8080/myapp/jbatch/rest/restart/23
  will restart the job with executionId 23&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/jberet-jdbcitemwriter-example-on-ee</id>
        <title type="html">JBeret JdbcItemWriter / JdbcItemReader example on EE environment</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/jberet-jdbcitemwriter-example-on-ee"/>
        <published>2015-02-28T15:11:12+00:00</published>
        <updated>2015-03-01T04:15:24+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jberet" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lbtc-xxx/jberet-support-jdbc-example&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/jberet-support-jdbc-example&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;We need to use non transactional datasource for JdbcItemReader.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_references&quot;&gt;References&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.jboss.org/thread/251794&quot; class=&quot;bare&quot;&gt;https://developer.jboss.org/thread/251794&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.jboss.org/thread/177527?tstart=0&quot; class=&quot;bare&quot;&gt;https://developer.jboss.org/thread/177527?tstart=0&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/jberet-on-java-se-with</id>
        <title type="html">JBeret on Java SE with JDBC chunk oriented processing example</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/jberet-on-java-se-with"/>
        <published>2015-02-28T12:58:40+00:00</published>
        <updated>2015-02-28T13:04:39+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;I pushed an example to &lt;a href=&quot;https://github.com/lbtc-xxx/jberet-se-example&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/jberet-se-example&lt;/a&gt; . but it looks like not comfortable due to lack of automatic injection mechanism or transaction management that available in EE environment. I guess some better approach might be exists but I don&amp;#8217;t know yet. if you know any better way please let me know.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_references&quot;&gt;References&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://stackoverflow.com/questions/25734863/standalone-example-on-jberet-jsr352&quot; class=&quot;bare&quot;&gt;http://stackoverflow.com/questions/25734863/standalone-example-on-jberet-jsr352&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
    </entry>
    <entry>
        <id>https://nozaki.me/roller/kyle/entry/articles-jbatch-hello</id>
        <title type="html">動かしてみる</title>
        <author><name>Kohei Nozaki</name></author>
        <link rel="alternate" type="text/html" href="https://nozaki.me/roller/kyle/entry/articles-jbatch-hello"/>
        <published>2014-01-20T21:40:29+00:00</published>
        <updated>2015-03-01T08:07:33+00:00</updated> 
        <category term="JBatch" label="JBatch" />
        <category term="jbatch" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;p&gt;
jbatch(JSR352)とはJavaEE7から入ったバッチフレームワークの規格です。WildFly8ではGlassFish4とは別の実装が使われています。すごく簡単なのをWildFly8で動かしてみます。
&lt;/p&gt;

&lt;h2&gt;環境&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;WildFly 8.0.0CR1&lt;/li&gt;
  &lt;li&gt;Eclipse等々は&lt;a href=&quot;/roller/kyle/entry/articles-wildfly-servlet&quot; &gt;ここ&lt;/a&gt;で設定した状態&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;CDIの設定をする&lt;/h2&gt;

&lt;p&gt;
プロジェクトの設定を開いてProject Facetsを選びCDIにチェックを入れてOKを押します。
&lt;img src=&quot;/articles-img/jbatch/hello/cdi.png&quot;/&gt;
&lt;/p&gt;

&lt;h2&gt;ジョブXMLファイルを作る&lt;/h2&gt;

&lt;p&gt;
ジョブを起動すると、まずこのXMLファイルがロードされます。JSR352ではアプリ開発者はこのXMLファイルとartifactと呼ばれるクラス群を作る必要があります。まずXMLファイルが読まれ、ここに書かれた通りにartifactが呼び出されます。
&lt;/p&gt;

&lt;p&gt;
作る場所はこのへん．画像では/src/main/javaの下になっていますが，XMLファイル等のJavaソース以外のものは/src/main/resourcesに置くのが望ましいです．war内の位置で言うとclasses/META-INFの下になります。このファイルの名前がバッチの名前になります。
&lt;img src=&quot;/articles-img/jbatch/hello/jobxmllocation.png&quot;/&gt;
&lt;/p&gt;

内容はとりあえずこんな感じ。
&lt;pre class=&quot;brush: xml;&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;job id=&quot;job001&quot; version=&quot;1.0&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;&amp;gt;
	&amp;lt;step id=&quot;step001&quot;&amp;gt;
		&amp;lt;batchlet ref=&quot;testBatchlet&quot;/&amp;gt;
	&amp;lt;/step&amp;gt;
&amp;lt;/job&amp;gt;
&lt;/pre&gt;

&lt;h2&gt;Batchletを作る&lt;/h2&gt;

&lt;p&gt;Batchletは簡単な処理を書くときに使います。バルク処理とかをやるときは、ここで紹介するBatchletではなく、chunk方式と呼ばれるartifactを使ったほうがよいです。作るクラス1つだけで簡単なのでここではBatchletを作ります。XMLファイルとartifactはCDIの名前でひも付けるので、作る場所はどこでも良いです。&lt;/p&gt;

&lt;pre class=&quot;brush: java;&quot;&gt;
package com.example;

import javax.batch.api.AbstractBatchlet;
import javax.inject.Named;

@Named
public class TestBatchlet extends AbstractBatchlet{

	@Override
	public String process() throws Exception {
		System.out.println(&quot;Hello JSR352&quot;);
		return &quot;SUCCESS&quot;;
	}
}
&lt;/pre&gt;

&lt;h2&gt;Servletを作る&lt;/h2&gt;

&lt;p&gt;
バッチを動かす際の起点にします。ブラウザでServletにGETを飛ばすとバッチが動き出す感じです。定時実行とかスケジュール実行がしたければEJBタイマでやることもできます。
&lt;/p&gt;

&lt;pre class=&quot;brush: java;&quot;&gt;
package com.example;

import java.io.IOException;
import java.util.Properties;

import javax.batch.runtime.BatchRuntime;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(&quot;/TestServlet&quot;)
public class TestServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		long executionId = BatchRuntime.getJobOperator().start(&quot;job001&quot;, new Properties());
		response.getWriter().write(&quot;execution id: &quot; + executionId);
	}
}
&lt;/pre&gt;

&lt;h2&gt;動かしてみる&lt;/h2&gt;

&lt;p&gt;デプロイしたらブラウザでアクセスしてみましょう
&lt;img src=&quot;/articles-img/jbatch/hello/run.png&quot;/&gt;
&lt;/p&gt;

&lt;p&gt;
動いているようです。それっぽいログも出ています
&lt;img src=&quot;/articles-img/jbatch/hello/log.png&quot;/&gt;
&lt;/p&gt;

&lt;p&gt;
ジョブを実行するとDB等にかなり詳細な履歴が残せるのですが、WildFly8のデフォルトではインメモリデータベースに格納されるだけになっているようで、後から参照する方法とかは少し調べましたが不明です。DBに残すようにする設定の方法はまた別途調べる予定。
&lt;/p&gt;

&lt;p&gt;
JobOperator#start()で返るのはexecutionIdといって、このIDを使って実行中のバッチを止めたり、途中で死んだバッチを再実行したりできます。バッチの実行ごとに採番されます。リロードすると数字がインクリメントされていきます。
&lt;/p&gt;</content>
    </entry>
</feed>

