<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Java/JEE</title>
	<atom:link href="http://numberformat.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://numberformat.wordpress.com</link>
	<description>Information that Helps!</description>
	<lastBuildDate>Wed, 25 Jan 2012 15:03:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='numberformat.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Java/JEE</title>
		<link>http://numberformat.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://numberformat.wordpress.com/osd.xml" title="Java/JEE" />
	<atom:link rel='hub' href='http://numberformat.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Invoke Server Side Code Using GWT</title>
		<link>http://numberformat.wordpress.com/2012/01/16/invoke-server-side-code-using-gwt/</link>
		<comments>http://numberformat.wordpress.com/2012/01/16/invoke-server-side-code-using-gwt/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:33:19 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5299</guid>
		<description><![CDATA[This page describes how to Invoke Server Side Code to retrieve data from the server side and display the results in a JavaScript pop-up. Background GWT generates JavaScript code that makes a call to server side components thru the Servlet Interface. The Service Implementation class extends the &#8220;RemoteServiceServlet&#8221; class. This allows GWT to respond to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5299&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes how to Invoke Server Side Code to retrieve data from the server side and display the results in a JavaScript pop-up.</p>
<h3>Background</h3>
<p>GWT generates JavaScript code that makes a call to server side components thru the Servlet Interface. The Service Implementation class extends the &#8220;RemoteServiceServlet&#8221; class. This allows GWT to respond to requests made from the GWT generated Javascript.</p>
<h3>Requirements</h3>
<ul>
<li>Maven</li>
<li>Java 5 or above</li>
<li><a href="http://numberformat.wordpress.com/2012/01/14/blank-gwt-template/">Successful completion of my previous post</a></li>
</ul>
<h3>Procedure</h3>
<p>Before we begin we need to create directories.</p>
<p><pre class="brush: bash; gutter: false;">
mkdir -p src/main/java/com/test/server
</pre></p>
<h3>Create the Interface</h3>
<p>First you create a an interface that can be used by the client. Maven generates a client side Interface based this.</p>
<p>vi src/main/java/com/test/client/GreetingService.java<br />
<pre class="brush: java; gutter: false;">
package com.test.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath(&quot;greet&quot;)
public interface GreetingService extends RemoteService {
  String greetServer(String input) throws IllegalArgumentException;
}
</pre></p>
<h3>Create the Implementation</h3>
<p>vi src/main/java/com/test/server/GreetingServiceImpl.java<br />
<pre class="brush: java; gutter: false;">
package com.test.server;

import com.test.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings(&quot;serial&quot;)
public class GreetingServiceImpl extends RemoteServiceServlet implements
    GreetingService {

  public String greetServer(String input) throws IllegalArgumentException {
    String serverInfo = getServletContext().getServerInfo();
    String userAgent = getThreadLocalRequest().getHeader(&quot;User-Agent&quot;);

    return &quot;Hello, &quot; + input + &quot;! I am running &quot; + serverInfo
        + &quot;.It looks like you are using:&quot; + userAgent;
  }
}
</pre></p>
<h3>Define the Servlet</h3>
<p>Add the servlet to the web.xml.</p>
<p>vi src/main/webapp/WEB-INF/web.xml<br />
<pre class="brush: xml; gutter: false;">
  &lt;!-- Servlets --&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;greetServlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.test.server.GreetingServiceImpl&lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;!-- Servlet-Mapping --&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;greetServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/matrix/greet&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
</pre></p>
<h3>Change the EntryPoint</h3>
<p>Make the changes described in the following patch file by hand to the existing file.</p>
<p>vi src/main/java/com/test/client/Matrix.java<br />
<pre class="brush: diff; gutter: false;">
--- src/main/java/com/test/client/Matrix.java
+++ src/main/java/com/test/client/Matrix.java	
@@ -5,15 +5,26 @@
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.RootPanel;
 
 public class Matrix implements EntryPoint {
-
+	private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
+	
 	public void onModuleLoad() {
 		Button button = new Button(&quot;Send&quot;, new ClickHandler() {
 			public void onClick(ClickEvent event) {
-				Window.alert(&quot;Hello World!&quot;);
+		        greetingService.greetServer(&quot;World&quot;, new AsyncCallback&lt;String&gt;() {
+		            public void onFailure(Throwable caught) {
+		              // Show the RPC error message to the user
+		              Window.alert(&quot;Remote Procedure Call - Failure&quot;);
+		            }
+
+		            public void onSuccess(String result) {
+		                Window.alert(result);
+		            }
+		          });
 			}
 		});
 		button.setStyleName(&quot;sendButton&quot;);
</pre></p>
<h3>Test the application</h3>
<p><pre class="brush: bash; gutter: false;">
mvn compile gwt:run
</pre></p>
<p>After clicking the button on the screen a JavaScript alert box will open returning text from the server side. You can use Firefox FireBug plugin to verify the server side communication.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/5299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/5299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/5299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/5299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/5299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/5299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/5299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5299&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/01/16/invoke-server-side-code-using-gwt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Internationalizing a GWT Application</title>
		<link>http://numberformat.wordpress.com/2012/01/16/internationalizing-a-gwt-application/</link>
		<comments>http://numberformat.wordpress.com/2012/01/16/internationalizing-a-gwt-application/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:30:52 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5282</guid>
		<description><![CDATA[This page describes how to setup internationalization in your GWT application. The example on this page builds from the application described here. Requirements Maven Java 5 or above Successful completion of my previous post Project Configuration In order to enable internationalization support you need to add the following &#8220;goal&#8221; and &#8220;i18nMessagesBundle&#8221; elements inside &#8220;gwt-maven-plugin&#8221;: vi [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5282&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes how to setup internationalization in your GWT application. The example on this page builds from the <a href="http://numberformat.wordpress.com/2012/01/14/blank-gwt-template/">application described here</a>.</p>
<h3>Requirements</h3>
<ul>
<li>Maven</li>
<li>Java 5 or above</li>
<li><a href="http://numberformat.wordpress.com/2012/01/14/blank-gwt-template/">Successful completion of my previous post</a></li>
</ul>
<h3>Project Configuration</h3>
<p>In order to enable internationalization support you need to add the following &#8220;goal&#8221; and &#8220;i18nMessagesBundle&#8221; elements inside &#8220;gwt-maven-plugin&#8221;:</p>
<p>vi pom.xml<br />
<pre class="brush: xml; gutter: false; highlight: [9];">
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;gwt-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.4.0&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
            ...
            &lt;goal&gt;i18n&lt;/goal&gt;
            ...
            &lt;/goals&gt;
...
</pre></p>
<p>insert the &#8220;i18nMessagesBundle&#8221; element here:</p>
<p><pre class="brush: xml; gutter: false; highlight: [3];">
        &lt;configuration&gt;
          ...
          &lt;i18nMessagesBundles&gt;
                    &lt;i18nMessagesBundle&gt;com.test.client.Messages&lt;/i18nMessagesBundle&gt;
          &lt;/i18nMessagesBundles&gt;
          ...
        &lt;configuration&gt;
</pre></p>
<p>Externalize the language strings to a property file. </p>
<p>The following message bundle is converted to a Java Class by Maven. In order to specify additional bundles just insert an additional &#8220;i18nMessagesBundle&#8221; tag in the pom.xml file.</p>
<h3>Properties File</h3>
<p>Create the directory that will hold the property file if not done so already: </p>
<p><pre class="brush: bash; gutter: false;">
mkdir -p src/main/resources/com/test/client
</pre></p>
<p>vi src/main/resources/com/test/client/Messages.properties<br />
<pre class="brush: plain; gutter: false;">
sendButton = Send
hello = Hello {0}!
</pre></p>
<h3>Java code Change</h3>
<p>Modify the java code to reference the property values instead of hard-coded strings.</p>
<p><pre class="brush: plain; gutter: false;">
--- matrix-blank/src/main/java/com/test/client/Matrix.java	
+++ matrix/src/main/java/com/test/client/Matrix.java	
@@ -10,10 +10,11 @@
 
 public class Matrix implements EntryPoint {
 
+	private final Messages messages = GWT.create(Messages.class);
 	public void onModuleLoad() {
-		Button button = new Button(&quot;Send&quot;, new ClickHandler() {
+		Button button = new Button(messages.sendButton(), new ClickHandler() {
 			public void onClick(ClickEvent event) {
-				Window.alert(&quot;Hello World!&quot;);
+				Window.alert(messages.hello(&quot;World&quot;));
 			}
 		});
 		button.setStyleName(&quot;sendButton&quot;);
</pre></p>
<h3>Test the Change</h3>
<p><pre class="brush: bash; gutter: false;">
mvn compile gwt:run
</pre></p>
<h3>The French Version</h3>
<p>Creating a French version of the application is simple!. Just Create a copy of the file and append an _fr or the locale you want to support.</p>
<p><pre class="brush: bash; gutter: false;">
cp src/main/resources/com/test/client/Messages.properties \
src/main/resources/com/test/client/Messages_fr.properties
</pre></p>
<p>Modify the file and update the English to French.</p>
<p>vi src/main/resources/com/test/client/Messages_fr.properties<br />
<pre class="brush: plain; gutter: false;">
sendButton = Envoyer
hello = bonjour {0}!
</pre></p>
<h3>Configure</h3>
<p>You can add the following line into the module element of your &#8220;gwt.xml&#8221; file for each locale you want to support:<br />
vi src/main/resources/com/test/Matrix.gwt.xml<br />
<pre class="brush: plain; gutter: false;">
&lt;extend-property name=&quot;locale&quot; values=&quot;fr&quot;/&gt;
</pre></p>
<h3>Start the application</h3>
<p><pre class="brush: bash; gutter: false;">
mvn compile gwt:run
</pre></p>
<h3>Test the Change</h3>
<p>At this point you have 2 options to see the French version of the site:</p>
<ol>
<li>You can put the following line in the host HTML page<br />
<pre class="brush: xml; gutter: false;">
&lt;meta name=&quot;gwt:property&quot; content=&quot;locale=fr&quot;&gt;
</pre></p>
</li>
<li>Append the client property value to the query string of the URL: http://127.0.0.1:8888/Matrix.html?gwt.codesvr=127.0.0.1:9997?locale=fr</li>
</ol>
<p>Either way you will see the French version of the site.</p>
<h3>Reference</h3>
<p><a href="http://code.google.com/webtoolkit/doc/latest/tutorial/i18n.html">http://code.google.com/webtoolkit/doc/latest/tutorial/i18n.html</a></p>
<h3>Appendix</h3>
<p>Creating Keys for place holder parameters, the lines of the property file should look like this:</p>
<p><pre class="brush: plain; gutter: false;">
myString = First parm is {0}, second parm is {1}, third parm is {2}.
</pre></p>
<p>The key &#8220;myString&#8221; can be used in static HTML by wrapping the content with a html tag with an assigned id.</p>
<p><pre class="brush: xml; gutter: false;">
    &lt;h1 id=&quot;myString&quot;&gt;&lt;/h1&gt;
</pre></p>
<p>The id attribute can be used as a handle to replace the text in Java code like this:</p>
<p><pre class="brush: xml; gutter: false;">
    RootPanel.get(&quot;appTitle&quot;).add(new Label(constants.myString(&quot;one&quot;,&quot;two&quot;,&quot;three&quot;)));
</pre></p>
<p>To get the list of locale&#8217;s supported by your JVM just run the following code:</p>
<p><pre class="brush: java; gutter: false;">
	public static void main(String args[]) {
		Locale locales[] = SimpleDateFormat.getAvailableLocales();
		List arrayList = Arrays.asList(locales);
		Collections.sort(arrayList, new Comparator() {
			public int compare(Locale o1, Locale o2) {
				return o1.getDisplayName().compareTo(o2.getDisplayName());
			}
		});
		for (Locale locale : arrayList) {
			System.out.println(locale.toString() + &quot;\t&quot; + locale.getDisplayName());
		}
	}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/5282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/5282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/5282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/5282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/5282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/5282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5282&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/01/16/internationalizing-a-gwt-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Blank GWT Template Starter Application</title>
		<link>http://numberformat.wordpress.com/2012/01/14/blank-gwt-template/</link>
		<comments>http://numberformat.wordpress.com/2012/01/14/blank-gwt-template/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 03:12:29 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5273</guid>
		<description><![CDATA[This page describes the complete end-to-end process of creating and testing a blank &#8220;Hello World&#8221; type Google Web Tool kit (GWT) starter application using Maven. The page takes about 10-15 minutes to complete and have a working GWT application. The application described on this page displays a Send Button on the page. It displays a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5273&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes the complete end-to-end process of creating and testing a blank &#8220;Hello World&#8221; type Google Web Tool kit (GWT) starter application using Maven. The page takes about 10-15 minutes to complete and have a working GWT application. </p>
<p>The application described on this page displays a Send Button on the page. It displays a JavaScript alert() message when the button is clicked.</p>
<h3>Background</h3>
<p>The GWT SDK allows you to generate an application using their generation tool. However I never liked using this tool because the application it generated is useless to me unless I understand how the application is working. The following page breaks down a simple Hello World GWT application step by step and allows the reader to follow along.</p>
<h3>Requirements</h3>
<ul>
<li>Maven</li>
<li>Java 5 or above</li>
</ul>
<p>This page covers GWT version 2.4.0.</p>
<p>The first step is to create directory that will hold your project. The example below uses &#8220;matrix&#8221; as the project name. You can replace each instance of &#8220;matrix&#8221; with whatever you want to call your project.</p>
<p><pre class="brush: bash; gutter: false;">
mkdir matrix
cd matrix
# create some additional directories
mkdir -p src/main/java/com/test/client
mkdir -p src/main/resources/com/test
mkdir -p src/main/webapp/WEB-INF
</pre></p>
<p>vi pom.xml<br />
<pre class="brush: xml; gutter: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&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/maven-v4_0_0.xsd&quot;&gt;

  &lt;!-- POM file generated with GWT webAppCreator --&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.test&lt;/groupId&gt;
  &lt;artifactId&gt;matrix&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;GWT Maven Archetype&lt;/name&gt;

  &lt;properties&gt;
    &lt;!-- Convenience property to set the GWT version --&gt;
    &lt;gwtVersion&gt;2.4.0&lt;/gwtVersion&gt;
    &lt;!-- GWT needs at least java 1.5 --&gt;
    &lt;webappDirectory&gt;${project.build.directory}/${project.build.finalName}&lt;/webappDirectory&gt;
    &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
      &lt;artifactId&gt;gwt-servlet&lt;/artifactId&gt;
      &lt;version&gt;${gwtVersion}&lt;/version&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
      &lt;artifactId&gt;gwt-user&lt;/artifactId&gt;
      &lt;version&gt;${gwtVersion}&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;4.7&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;!-- Generate compiled stuff in the folder used for developing mode --&gt;
    &lt;outputDirectory&gt;${webappDirectory}/WEB-INF/classes&lt;/outputDirectory&gt;
    &lt;plugins&gt;
      &lt;!-- GWT Maven Plugin --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;gwt-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.4.0&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;compile&lt;/goal&gt;
              &lt;goal&gt;test&lt;/goal&gt;
              &lt;goal&gt;generateAsync&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;!-- Plugin configuration. There are many available options, see 
          gwt-maven-plugin documentation at codehaus.org --&gt;
        &lt;configuration&gt;
          &lt;runTarget&gt;Matrix.html&lt;/runTarget&gt;
          &lt;hostedWebapp&gt;${webappDirectory}&lt;/hostedWebapp&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;

      &lt;!-- Copy static web files before executing gwt:run --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.1.1&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;phase&gt;compile&lt;/phase&gt;
            &lt;goals&gt;
              &lt;goal&gt;exploded&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;webappDirectory&gt;${webappDirectory}&lt;/webappDirectory&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.3.2&lt;/version&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.5&lt;/source&gt;
          &lt;target&gt;1.5&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre></p>
<h3>Host HTML Page</h3>
<p>The following is the Host HTML Page. The page imports the generated Javascript and starts the Javascript application. Similar to the &#8220;Entry Point&#8221; main() method of many other programming languages.</p>
<p>vi src/main/webapp/Matrix.html<br />
<pre class="brush: xml; gutter: false;">
&lt;!doctype html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
    &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;Matrix.css&quot;&gt;
    &lt;title&gt;X&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;matrix/matrix.nocache.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;iframe src=&quot;javascript:''&quot; id=&quot;__gwt_historyFrame&quot; tabIndex='-1' style=&quot;position:absolute;width:0;height:0;border:0&quot;&gt;&lt;/iframe&gt;
    &lt;noscript&gt;
      &lt;div style=&quot;width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif&quot;&gt;
        Your web browser must have JavaScript enabled
        in order for this application to display correctly.
      &lt;/div&gt;
    &lt;/noscript&gt;
    &lt;div id=&quot;sendButtonContainer&quot;&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre></p>
<h3>CSS Styles</h3>
<p>GWT components are highly customizable. It makes sense to define sizes, colors, alighment, images, and other visual aspects of the component in CSS.</p>
<p>vi src/main/webapp/Matrix.css<br />
<pre class="brush: css; gutter: false;">
.sendButton {
  display: block;
  font-size: 12pt;
}
</pre></p>
<h3>Web Application Descriptor</h3>
<p>The following is a basic web.xml file for the application.</p>
<p>vi src/main/webapp/WEB-INF/web.xml<br />
<pre class="brush: xml; gutter: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE web-app
    PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
    &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;

&lt;web-app&gt;

  &lt;!-- Servlets --&gt;
  &lt;!-- Servlet-Mapping --&gt;

  &lt;!-- Default page to serve --&gt;
  &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;Matrix.html&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</pre></p>
<p>vi src/main/resources/com/test/Matrix.gwt.xml<br />
<pre class="brush: xml; gutter: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;module rename-to='matrix'&gt;
  &lt;inherits name='com.google.gwt.user.User' /&gt;
  &lt;inherits name='com.google.gwt.user.theme.standard.Standard' /&gt;
  &lt;entry-point class='com.test.client.Matrix' /&gt;
  &lt;source path='client' /&gt;
&lt;/module&gt;
</pre></p>
<p>vi src/main/java/com/test/client/Matrix.java<br />
<pre class="brush: java; gutter: false;">
package com.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

public class Matrix implements EntryPoint {

	public void onModuleLoad() {
		Button button = new Button(&quot;Send&quot;, new ClickHandler() {
			public void onClick(ClickEvent event) {
				Window.alert(&quot;Hello World!&quot;);
			}
		});
		button.setStyleName(&quot;sendButton&quot;);
		RootPanel.get(&quot;sendButtonContainer&quot;).add(button);
	}
}
</pre></p>
<h3>Run the project</h3>
<p><pre class="brush: bash; gutter: false;">
mvn eclipse:clean eclipse:eclipse
mvn clean compile gwt:run
</pre></p>
<h3>What&#8217;s Next?</h3>
<ul>
<li><a href="http://numberformat.wordpress.com/2012/01/16/internationalizing-a-gwt-application/">Internationalize your application</a></li>
<li><a href="http://numberformat.wordpress.com/2012/01/16/invoke-server-side-code-using-gwt/">Invoke Server Side Code Using GWT</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/5273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/5273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/5273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/5273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/5273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/5273/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5273&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/01/14/blank-gwt-template/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Batch Validation</title>
		<link>http://numberformat.wordpress.com/2011/10/17/spring-batch-validation/</link>
		<comments>http://numberformat.wordpress.com/2011/10/17/spring-batch-validation/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 21:49:16 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5026</guid>
		<description><![CDATA[This page demonstrates the process of using Spring Batch and the Apache Commons Validator Framework to validate each record in a flat file. To keep this tutorial brief we will stop processing the file and print out the validation failure message on the first occurrence. Background The Commons Validator Framework is composed of a core [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5026&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page demonstrates the process of using Spring Batch and the Apache Commons Validator Framework to validate each record in a flat file. To keep this tutorial brief we will stop processing the file and print out the validation failure message on the first occurrence.</p>
<h3>Background</h3>
<p>The Commons Validator Framework is composed of a core set of classes responsible for validating data. Since the framework is versatile and does not make assumptions about implementation, you can&#8217;t use it out of the box unless you write wrapper code to adapt it to your needs. </p>
<p>Years ago the popular Struts framework had provided a set of wrapper classes in the &#8220;org.apache.struts.validator&#8221; package. The spring MVC framework had made similar adaptations. I had found it strange that the makers of spring batch did not have a drop in replacement so that had lead me to write this page.</p>
<h3>Requirements</h3>
<ul>
<li>Java 5 or above with Maven 2</li>
<li>Successful completion of the <a href="http://numberformat.wordpress.com/2011/10/01/the-3-rs-of-spring-batch/">example application described here</a>.</li>
</ul>
<p>This tutorial continues from where the previous one left of so please complete the examples in those articles first before proceeding.</p>
<h3>Procedure</h3>
<p>Start by adding the following dependencies into your pom.xml file.</p>
<p>pom.xml<br />
<pre class="brush: xml; light: true;">
&lt;!-- The commons Validator Framework --&gt;
	&lt;dependency&gt;
	    &lt;groupId&gt;commons-validator&lt;/groupId&gt;
	    &lt;artifactId&gt;commons-validator&lt;/artifactId&gt;
	    &lt;version&gt;1.1.4&lt;/version&gt;
	&lt;/dependency&gt;
&lt;!-- Spring Wrapper classes for the Validator Framework --&gt;
        &lt;dependency&gt;
	    &lt;groupId&gt;org.springmodules&lt;/groupId&gt;
	    &lt;artifactId&gt;spring-modules-validation&lt;/artifactId&gt;
	    &lt;version&gt;0.8&lt;/version&gt;
	&lt;/dependency&gt;
</pre></p>
<p>The following is the core class that makes this all happen.</p>
<p>src/main/java/com/test/SpringCommonsValidator.java<br />
<pre class="brush: java; light: true;">
package com.test;

import java.util.List;

import org.springframework.batch.item.validator.ValidationException;
import org.springframework.batch.item.validator.Validator;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;

/**
 * Allows for the commons validation framework to print human readable 
 * validation failure messages. Also its very good at adapting the 
 * Spring Validator Interface to Spring Batch Validator, thus allowing 
 * this class to be used as a Validator in the spring batch framework.
 * 
 * This class delegates most of its work to the spring validator.
 * 
 */
public class SpringCommonsValidator&lt;T&gt; implements Validator&lt;T&gt; {

	private org.springframework.validation.Validator validator;
	private MessageSource messageSource;

	public void validate(T item) throws ValidationException {

		if (!validator.supports(item.getClass())) {
			throw new ValidationException(&quot;Validation failed for &quot; + item + &quot;: &quot; + item.getClass().getName()
					+ &quot; class is not supported by validator.&quot;);
		}

		BeanPropertyBindingResult errors = new BeanPropertyBindingResult(item, &quot;item&quot;);

		validator.validate(item, errors);

		if (errors.hasErrors()) {
			throw new ValidationException(&quot;Validation failed for &quot; + item + &quot;: &quot; + errorsToString(errors));
		}
	}

	private String errorsToString(Errors errors) {
		@SuppressWarnings(&quot;rawtypes&quot;)
		List errorList = errors.getAllErrors();
		StringBuffer buffer = new StringBuffer();
		
		boolean first = true;
		for (Object object : errorList) {
			if(object instanceof MessageSourceResolvable) {
				MessageSourceResolvable r = (MessageSourceResolvable)object;
				if(!first) { buffer.append(&quot;; &quot;); } 
				buffer.append(messageSource.getMessage(r, null));
				first = false;
			}
		}
		return buffer.toString();
	}


	public void setValidator(org.springframework.validation.Validator validator) {
		this.validator = validator;
	}

	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

	public MessageSource getMessageSource() {
		return messageSource;
	}
}
</pre></p>
<h3>Resource Bundle</h3>
<p>The following property file is used to display the error messages. I guess some additional work can be done to internationalize these messages but since batch programs are not end-client facing&#8230; what&#8217;s the point? </p>
<p>On the other hand, having error messages in a property files does have its advantages.</p>
<p>src/main/resources/messages.properties<br />
<pre class="brush: plain; light: true;">
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.
 
errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.
 
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.
</pre></p>
<h3>Configuration</h3>
<p>Modify the spring configuration file to add the validatorFactory, beanValidator and springValidator. These classes allow you to have the ValidatingItemProcessor validate each item that is passed to it.</p>
<p>src/main/resources/simpleJob.xml</p>
<p>Replace the following section<br />
<pre class="brush: xml; light: true;">
&lt;!-- Processor --&gt;
&lt;beans:bean name=&quot;empProcessor&quot; class=&quot;com.test.EmployeeProcessor&quot;&gt;
&lt;/beans:bean&gt;
</pre></p>
<p>with the following<br />
<pre class="brush: xml; light: true;">
&lt;!-- Processor --&gt;
&lt;beans:bean name=&quot;empProcessor&quot; class=&quot;org.springframework.batch.item.validator.ValidatingItemProcessor&quot;&gt;
    &lt;beans:property name=&quot;validator&quot; ref=&quot;springValidator&quot;/&gt;    
&lt;/beans:bean&gt;

&lt;!-- Validator --&gt;
    &lt;beans:bean id=&quot;validatorFactory&quot;
          class=&quot;org.springmodules.validation.commons.DefaultValidatorFactory&quot;&gt;
    &lt;beans:property name=&quot;validationConfigLocations&quot;&gt;
        &lt;beans:list&gt;
          &lt;beans:value&gt;validation.xml&lt;/beans:value&gt;
          &lt;beans:value&gt;validator-rules.xml&lt;/beans:value&gt;
        &lt;/beans:list&gt;
      &lt;/beans:property&gt;
    &lt;/beans:bean&gt;
     
    &lt;beans:bean id=&quot;beanValidator&quot; class=&quot;org.springmodules.validation.commons.DefaultBeanValidator&quot;&gt;
        &lt;beans:property name=&quot;validatorFactory&quot; ref=&quot;validatorFactory&quot;/&gt;
        &lt;beans:property name=&quot;useFullyQualifiedClassName&quot; value=&quot;true&quot;/&gt;
    &lt;/beans:bean&gt; 

    &lt;beans:bean id=&quot;springValidator&quot; class=&quot;com.test.SpringCommonsValidator&quot;&gt;
        &lt;beans:property name=&quot;validator&quot; ref=&quot;beanValidator&quot;/&gt;
        &lt;beans:property name=&quot;messageSource&quot; ref=&quot;resourceBundleMessageSource&quot;/&gt;        
    &lt;/beans:bean&gt; 

    &lt;beans:bean id=&quot;resourceBundleMessageSource&quot; class=&quot;org.springframework.context.support.ResourceBundleMessageSource&quot;&gt;
        &lt;beans:property name=&quot;basename&quot; value=&quot;messages&quot;/&gt;    
    &lt;/beans:bean&gt; 
</pre></p>
<h3>Commons validator configuration</h3>
<p>The following is the validation configuration file used by commons-validator. If you have used the struts framework before then this file may look familiar to you. This file contains some default &#8220;shrink-wrapped&#8221; validation checks that were originally included with struts. There is nothing to customize here for now so please just copy and paste this into your program and continue on.</p>
<p>src/main/resources/validator-rules.xml<br />
<pre class="brush: xml; light: true;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE form-validation PUBLIC
          &quot;-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN&quot;
          &quot;http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd&quot;&gt;
 
&lt;form-validation&gt;
    &lt;global&gt;
        &lt;validator name=&quot;required&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateRequired&quot;
            methodParams=&quot;java.lang.Object,
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.springframework.validation.Errors&quot;
            msg=&quot;errors.required&quot;&gt;
        &lt;/validator&gt;
        &lt;validator name=&quot;requiredif&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateRequiredIf&quot;
            methodParams=&quot;java.lang.Object,
                               org.springframework.validation.ErrorsAction,
                               org.apache.commons.validator.Field,
                               org.springframework.validation.Errors&quot;
            msg=&quot;errors.required&quot; /&gt;
 
        &lt;validator name=&quot;validwhen&quot; msg=&quot;errors.required&quot;
            classname=&quot;org.apache.struts.validator.validwhen.ValidWhen&quot; method=&quot;validateValidWhen&quot;
            methodParams=&quot;java.lang.Object,
                       org.springframework.validation.ErrorsAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot; /&gt;
 
        &lt;validator name=&quot;minlength&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateMinLength&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.minlength&quot;
            jsFunction=&quot;org.apache.commons.validator.javascript.validateMinLength&quot; /&gt;
 
        &lt;validator name=&quot;maxlength&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateMaxLength&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.maxlength&quot;
            jsFunction=&quot;org.apache.commons.validator.javascript.validateMaxLength&quot; /&gt;
 
        &lt;validator name=&quot;mask&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateMask&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.invalid&quot; /&gt;
 
        &lt;validator name=&quot;byte&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateByte&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.byte&quot; jsFunctionName=&quot;ByteValidations&quot; /&gt;
 
        &lt;validator name=&quot;short&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateShort&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.short&quot; jsFunctionName=&quot;ShortValidations&quot; /&gt;
 
        &lt;validator name=&quot;integer&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateInteger&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.integer&quot; jsFunctionName=&quot;IntegerValidations&quot; /&gt;
 
        &lt;validator name=&quot;long&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateLong&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.long&quot; /&gt;
 
        &lt;validator name=&quot;float&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateFloat&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.float&quot; jsFunctionName=&quot;FloatValidations&quot; /&gt;
 
        &lt;validator name=&quot;double&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateDouble&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.double&quot; /&gt;
 
        &lt;validator name=&quot;date&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateDate&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.date&quot; jsFunctionName=&quot;DateValidations&quot; /&gt;
 
        &lt;validator name=&quot;intRange&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateIntRange&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;integer&quot; msg=&quot;errors.range&quot; /&gt;
 
        &lt;validator name=&quot;floatRange&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateFloatRange&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;float&quot; msg=&quot;errors.range&quot; /&gt;
 
        &lt;validator name=&quot;doubleRange&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateDoubleRange&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;double&quot; msg=&quot;errors.range&quot; /&gt;
 
        &lt;validator name=&quot;creditCard&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateCreditCard&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.creditcard&quot; /&gt;
 
        &lt;validator name=&quot;email&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateEmail&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.email&quot; /&gt;
 
        &lt;validator name=&quot;url&quot;
            classname=&quot;org.springmodules.validation.commons.FieldChecks&quot; method=&quot;validateUrl&quot;
            methodParams=&quot;java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.springframework.validation.Errors&quot;
            depends=&quot;&quot; msg=&quot;errors.url&quot; /&gt;
    &lt;/global&gt;
&lt;/form-validation&gt;
</pre></p>
<h3>Validation Rules</h3>
<p>The next file contains the actual validations that need to be performed.</p>
<p>These validations are:</p>
<ol>
<li>last Name is required</li>
<li>last Name must be between 20 and 35 characters in length</li>
<li>rank is required.</li>
</ol>
<p>src/main/resources/validation.xml<br />
<pre class="brush: xml; light: true;">
&lt;!DOCTYPE form-validation PUBLIC
          &quot;-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN&quot;
          &quot;http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd&quot;&gt;
&lt;form-validation&gt;
 
    &lt;formset&gt;
        &lt;form name=&quot;com.test.Employee&quot;&gt;
            &lt;field property=&quot;lastName&quot; depends=&quot;required,minlength,maxlength&quot;&gt;
                &lt;arg0 key=&quot;lastName&quot; /&gt;
                &lt;arg1 name=&quot;minlength&quot; key=&quot;${var:minlength}&quot; resource=&quot;false&quot;/&gt;
                &lt;arg1 name=&quot;maxlength&quot; key=&quot;${var:maxlength}&quot; resource=&quot;false&quot;/&gt;
                &lt;var&gt;
                    &lt;var-name&gt;minlength&lt;/var-name&gt;
                    &lt;var-value&gt;20&lt;/var-value&gt;
                &lt;/var&gt;
                &lt;var&gt;
                    &lt;var-name&gt;maxlength&lt;/var-name&gt;
                    &lt;var-value&gt;35&lt;/var-value&gt;
                &lt;/var&gt;                
            &lt;/field&gt;
            &lt;field property=&quot;rank&quot; depends=&quot;required&quot;&gt;
                &lt;arg key=&quot;rank&quot; /&gt;
            &lt;/field&gt;
        &lt;/form&gt;
    &lt;/formset&gt;
&lt;/form-validation&gt;
</pre></p>
<h3>Run the batch</h3>
<p>Run the batch application by typing the following on the command line.<br />
<pre class="brush: plain; light: true;">
mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<h3>Observe the Results</h3>
<p>The following message should display on the console indicating a validation failure.</p>
<p><pre class="brush: plain; light: true;">
SEVERE: Encountered an error executing the step
org.springframework.batch.item.validator.ValidationException: Validation failed for Employee [empId=7876, lastName=ADAMS, title=CLERK, salary=1100, rank=null]: lastName can not be less than 20 characters.; rank is required.
	at com.test.SpringCommonsValidator.validate(SpringCommonsValidator.java:38)
	at org.springframework.batch.item.validator.ValidatingItemProcessor.process(ValidatingItemProcessor.java:77)
	at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:125)
	at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:288)
</pre></p>
<h3>Next Steps</h3>
<p>The application described here is a quick and dirty approach to illustrate batch validation. In a typical production grade application you will want to allow the job to continue processing the remaining records in a file and send the bad records to a error file. The error file can be reviewed manually and re-processed on the next run.</p>
<p>Comments and feedback are Welcome.</p>
<p>Thanks!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/5026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/5026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/5026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/5026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/5026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/5026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/5026/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5026&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/10/17/spring-batch-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Restartable Jobs With Spring Batch</title>
		<link>http://numberformat.wordpress.com/2011/10/07/restartable-jobs-with-spring-batch/</link>
		<comments>http://numberformat.wordpress.com/2011/10/07/restartable-jobs-with-spring-batch/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 02:41:20 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5004</guid>
		<description><![CDATA[This page demonstrates how spring batch handles job failure and how to recover from them. Background Please review The Domain Language of Spring Batch prior to reading this further. StepExecution In simple terms each &#8220;job&#8221; is broken up into individual &#8220;steps&#8221;. The process of executing a step is called a &#8220;StepExecution&#8221;. Each execution of a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5004&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page demonstrates how spring batch handles job failure and how to recover from them.</p>
<h3>Background</h3>
<p>Please review <a href="http://static.springsource.org/spring-batch/reference/html/domain.html">The Domain Language of Spring Batch</a> prior to reading this further.</p>
<h4>StepExecution</h4>
<p>In simple terms each &#8220;job&#8221; is broken up into individual &#8220;steps&#8221;. The process of executing a step is called a &#8220;StepExecution&#8221;. Each execution of a step can either result in Success or Failure. If individual steps of a larger job fail it would be nice to know where the step left off. The Designers of this framework recognized this and came up with a way to allow steps to resume. The JobRepository allows Readers and Writers to store status, start and end times, exit codes, and count information for each Execution of a step within a Job. This information is stored using the ExecutionContext at each commit interval.</p>
<h4>ExecutionContext</h4>
<p>The &#8220;ExecutionContext&#8221; is a collection of name/value pairs that are persisted to the database. Each instance that a Step is executed by the spring batch framework has its own ExecutionContext. Many of the default Reader/Writer implementations publish information to the ExecutionContext by default.</p>
<h4>Outline of this page</h4>
<p>Here is a breakdown of what will be demonstrated:</p>
<ol>
<li>Simulate a job failure by modifying the EmployeeProcessor.java and throw an exception towards the middle of the file.</li>
<li>Examine the output file and verify that all prior records were written out.</li>
<li>Examine the JobRepository database to verify the ExecutionContext record contains the recovery information.</li>
<li>Modify EmployeeProcessor.java to not throw the test exception.</li>
<li>Examine the output file and verify that all the remaining records were written out.</li>
<li>Note that the Footer of the file is incorrect.</li>
<li>Fix the EmployeeItemWriter.java to read the ExecutionContext and output the correct footer.</li>
</ol>
<p>This page picks up where the last one left of. So if you have not done so already please implement <a href="http://numberformat.wordpress.com/2011/10/01/spring-batch-headers-and-footers/">the example application described here</a>.</p>
<h3>Requirements</h3>
<ul>
<li>Java 5 or above and Maven 2</li>
<li>Spring Batch 2.x</li>
<li>Successful completion of xxx</li>
</ul>
<h3>Inserting An Error</h3>
<p>The below highlighted code stops the process when the record for the &#8220;president&#8221; is processed. </p>
<p><pre class="brush: java; highlight: [8]; light: true;">
package com.test;

import org.springframework.batch.item.ItemProcessor;

public class EmployeeProcessor implements ItemProcessor&lt;Employee, Employee&gt; {

	public Employee process(Employee emp) throws Exception {
		if(&quot;PRESIDENT&quot;.equals(emp.getTitle())) throw new Exception(&quot;test exception: found President&quot;);
		// if salary &gt;= 2500 then set rank as &quot;Director&quot;		
		if(emp.getSalary() &gt;= 2500 ) {
			emp.setRank(&quot;Director&quot;);
		} else {
			emp.setRank(&quot;N/A&quot;);
		}
		return emp;
	}

}
</pre></p>
<p>Run the command:</p>
<p><pre class="brush: plain; light: true;">
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<p>Open the target/output_data.txt file and observe that only 7 records were processed.</p>
<p>Comment out line 8 from EmployeeProcessor.java above and re-run the batch.</p>
<p><pre class="brush: plain; light: true;">
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<p>Open target/output_data.txt one more time and observe that the remaining records were processed however note that the footer information is incorrect. It should say 14 records instead of 7.</p>
<h3>Making Spring Batch Restartable</h3>
<p>If you remember in the previous article we modified the EmployeeItemWriter class to print out a header and footer records. The footer record was generated using state variables (totalAmount, and recordCount). Since the EmployeeItemWriter maintains state, when the batch job restarts the state variables are re-initialized to their original values. Since the second invocation of the job starts from the middle of the input file the writer does not get an opportunity to properly initialize the state variables.</p>
<p>To fix this problem we will use the executionContext. The executionContext gets updated on each commit interval. It is the place where Spring batch keeps information that is important to the currently running job Execution.</p>
<p>We will modify the open() and update() methods of the EmployeeItemWriter to lookup the values from the ExecutionContext.</p>
<p>/src/main/java/com/test/EmployeeItemWriter.java<br />
<pre class="brush: java; light: true;">
	public void open(ExecutionContext executionContext) throws ItemStreamException {
		if(executionContext.containsKey(&quot;current.recordCount&quot;)) {
			recordCount = new Long(executionContext.getLong(&quot;current.recordCount&quot;)).intValue();
		} else {
			recordCount = 0;
		}		
		
		if(executionContext.containsKey(&quot;current.totalAmount&quot;)) {
			totalAmount = new BigDecimal(executionContext.getDouble(&quot;current.totalAmount&quot;));
		} else {
			totalAmount = BigDecimal.ZERO;
		}		
		this.delegate.open(executionContext);
	}

	public void update(ExecutionContext executionContext) throws ItemStreamException {
		executionContext.putLong(&quot;current.recordCount&quot;, recordCount);
		executionContext.putDouble(&quot;current.totalAmount&quot;, totalAmount.doubleValue());
		
		this.delegate.update(executionContext);
	}
</pre></p>
<p>We don&#8217;t need to modify &#8220;empReader&#8221; bean since it is backed by &#8220;FlatFileItemReader&#8221; and it&#8217;s implementation is restartable by default.</p>
<h3>Clear the database</h3>
<p>In order to start fresh again, Delete all files under src/main/resources/db. This is where HSQLDB keeps its database files. Once you delete this the DDLUtils framework will regenerate the database with all the schema information.</p>
<h3>Re-run the job</h3>
<p>Comment IN the EmployeeProcessor.java so that when &#8220;PRESIDENT&#8221; is encountered it throws an exception and re-run the job.</p>
<p><pre class="brush: plain; light: true;">
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<p>Comment OUT the line in EmployeeProcessor.java and re-run the job again.</p>
<p><pre class="brush: plain; light: true;">
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<h3>Verify the output</h3>
<p>Open target/output_data.txt one more time and observe that the remaining records were processed and the count should be 14 records.</p>
<p>That&#8217;s all for now.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/5004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/5004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/5004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/5004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/5004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/5004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/5004/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=5004&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/10/07/restartable-jobs-with-spring-batch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Batch HyperSQL Job Repository</title>
		<link>http://numberformat.wordpress.com/2011/10/02/spring-batch-hypersql-job-repository/</link>
		<comments>http://numberformat.wordpress.com/2011/10/02/spring-batch-hypersql-job-repository/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 05:16:46 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=4946</guid>
		<description><![CDATA[This page describes the process of setting up a semi-permanent job repository that will maintain state between job invocations. No external databases will be necessary since HSQLDB is a pure java implementation of a database. Background The spring batch framework offers an in-memory Repository that does not persist domain objects once the batch job is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4946&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes the process of setting up a semi-permanent job repository that will maintain state between job invocations. No external databases will be necessary since HSQLDB is a pure java implementation of a database.</p>
<h3>Background</h3>
<p>The spring batch framework offers an in-memory Repository that does not persist domain objects once the batch job is complete. This is a severe limitation since:</p>
<ul>
<li>Job restarts will not be possible (resume on restart functionality)</li>
<li>Can not guarantee that two job instances with the same parameters are not launched simultaneously</li>
<li>Not suitable for multi-threaded job invocations</li>
</ul>
<h3>Requirements</h3>
<ul>
<li>Java 5 or above and Maven 2</li>
<li>Successful completion of <a href="http://numberformat.wordpress.com/2010/02/05/hello-world-with-spring-batch/">Hello World with spring batch</a>.</li>
</ul>
<h3>Solution</h3>
<p>In order to have the job repository stored in our application we will be using HSQLDB as our database implementation and and DDLUtils to manage the schema. </p>
<p>Modify the pom.xml and insert the following dependencies.</p>
<p>pom.xml<br />
<pre class="brush: xml; light: true;">
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.ddlutils&lt;/groupId&gt;
        &lt;artifactId&gt;ddlutils&lt;/artifactId&gt;
        &lt;version&gt;1.0&lt;/version&gt;
    &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
            &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
            &lt;version&gt;1.8.0.10&lt;/version&gt;
        &lt;/dependency&gt;
</pre></p>
<h3>DDL</h3>
<p>The following xml file is used by Apache DDLUtils to create the Spring Batch JobRepository database. When the application starts for the first time the tables will be created. Each subsequent invocation will cause the DDLUtils to check the database schema against the xml file. If the database is different then it will make the necessary alters to update the database to reflect the schema represented in the below file. </p>
<p>src/main/resources/ddl.xml<br />
<pre class="brush: xml; light: true;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE database SYSTEM &quot;http://db.apache.org/torque/dtd/database.dtd&quot;&gt;
&lt;database name=&quot;testdb&quot;&gt;

	&lt;table name=&quot;BATCH_JOB_INSTANCE&quot;&gt;
		&lt;column name=&quot;JOB_INSTANCE_ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot;
			autoIncrement=&quot;true&quot;/&gt;
		&lt;column name=&quot;VERSION&quot; type=&quot;BIGINT&quot; /&gt;
		&lt;column name=&quot;JOB_NAME&quot; type=&quot;VARCHAR&quot; size=&quot;100&quot; required=&quot;true&quot; /&gt;
		&lt;column name=&quot;JOB_KEY&quot; type=&quot;VARCHAR&quot; size=&quot;32&quot; required=&quot;true&quot; /&gt;
		&lt;unique name=&quot;JOB_INST_UN&quot;&gt;
		  &lt;unique-column name=&quot;JOB_NAME&quot;/&gt;
		  &lt;unique-column name=&quot;JOB_KEY&quot;/&gt;
		&lt;/unique&gt;
	&lt;/table&gt;

    &lt;table name=&quot;BATCH_JOB_EXECUTION&quot;&gt;
        &lt;column name=&quot;JOB_EXECUTION_ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot;/&gt;
        &lt;column name=&quot;VERSION&quot; type=&quot;BIGINT&quot; /&gt;
	    &lt;column name=&quot;JOB_INSTANCE_ID&quot; type=&quot;BIGINT&quot; required=&quot;true&quot;/&gt;
	    &lt;column name=&quot;CREATE_TIME&quot; type=&quot;TIMESTAMP&quot; required=&quot;true&quot;/&gt;
	    &lt;column name=&quot;START_TIME&quot; type=&quot;TIMESTAMP&quot;/&gt;
	    &lt;column name=&quot;END_TIME&quot; type=&quot;TIMESTAMP&quot;/&gt;
	    &lt;column name=&quot;STATUS&quot; type=&quot;VARCHAR&quot; size=&quot;10&quot;/&gt;
	    &lt;column name=&quot;EXIT_CODE&quot; type=&quot;VARCHAR&quot; size=&quot;20&quot;/&gt;
	    &lt;column name=&quot;EXIT_MESSAGE&quot; type=&quot;VARCHAR&quot; size=&quot;2500&quot;/&gt;
	    &lt;column name=&quot;LAST_UPDATED&quot; type=&quot;TIMESTAMP&quot;/&gt;
	    &lt;foreign-key name=&quot;JOB_INST_EXEC_FK&quot; foreignTable=&quot;BATCH_JOB_INSTANCE&quot;&gt;
	       &lt;reference foreign=&quot;JOB_INSTANCE_ID&quot; local=&quot;JOB_INSTANCE_ID&quot;/&gt;
	    &lt;/foreign-key&gt;
    &lt;/table&gt;

    &lt;table name=&quot;BATCH_JOB_PARAMS&quot;&gt;
        &lt;column name=&quot;JOB_INSTANCE_ID&quot; type=&quot;BIGINT&quot; required=&quot;true&quot;/&gt;
	    &lt;column name=&quot;TYPE_CD&quot; type=&quot;VARCHAR&quot; size=&quot;6&quot; required=&quot;true&quot;/&gt;
	    &lt;column name=&quot;KEY_NAME&quot; type=&quot;VARCHAR&quot; size=&quot;100&quot; required=&quot;true&quot;/&gt; 
	    &lt;column name=&quot;STRING_VAL&quot; type=&quot;VARCHAR&quot; size=&quot;250&quot;/&gt; 
	    &lt;column name=&quot;DATE_VAL&quot; type=&quot;TIMESTAMP&quot;/&gt; 
	    &lt;column name=&quot;LONG_VAL&quot; type=&quot;BIGINT&quot;/&gt;
	    &lt;column name=&quot;DOUBLE_VAL&quot; type=&quot;DOUBLE&quot;/&gt;
        &lt;foreign-key name=&quot;JOB_INST_PARAMS_FK&quot; foreignTable=&quot;BATCH_JOB_INSTANCE&quot;&gt;
           &lt;reference foreign=&quot;JOB_INSTANCE_ID&quot; local=&quot;JOB_INSTANCE_ID&quot;/&gt;
        &lt;/foreign-key&gt;
    &lt;/table&gt;

    &lt;table name=&quot;BATCH_STEP_EXECUTION&quot;&gt;
		&lt;column name=&quot;STEP_EXECUTION_ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot; 
		  autoIncrement=&quot;true&quot; /&gt;
		&lt;column name=&quot;VERSION&quot; type=&quot;BIGINT&quot; required=&quot;true&quot;/&gt;
		&lt;column name=&quot;STEP_NAME&quot; type=&quot;VARCHAR&quot; size=&quot;100&quot; required=&quot;true&quot;/&gt;
		&lt;column name=&quot;JOB_EXECUTION_ID&quot; type=&quot;BIGINT&quot; required=&quot;true&quot; /&gt;
		&lt;column name=&quot;START_TIME&quot; type=&quot;TIMESTAMP&quot; required=&quot;true&quot;/&gt; 
		&lt;column name=&quot;END_TIME&quot; type=&quot;TIMESTAMP&quot;/&gt;  
		&lt;column name=&quot;STATUS&quot; type=&quot; VARCHAR&quot; size=&quot;10&quot;/&gt;
		&lt;column name=&quot;COMMIT_COUNT&quot; type=&quot;BIGINT&quot;/&gt; 
		&lt;column name=&quot;READ_COUNT&quot; type=&quot;BIGINT&quot;/&gt;
		&lt;column name=&quot;FILTER_COUNT&quot; type=&quot;BIGINT&quot;/&gt;
		&lt;column name=&quot;WRITE_COUNT&quot; type=&quot;BIGINT&quot;/&gt;
		&lt;column name=&quot;READ_SKIP_COUNT&quot; type=&quot;BIGINT&quot;/&gt;
		&lt;column name=&quot;WRITE_SKIP_COUNT&quot; type=&quot;BIGINT&quot;/&gt;
		&lt;column name=&quot;PROCESS_SKIP_COUNT&quot; type=&quot;BIGINT&quot;/&gt;
		&lt;column name=&quot;ROLLBACK_COUNT&quot; type=&quot;BIGINT&quot;/&gt; 
		&lt;column name=&quot;EXIT_CODE&quot; type=&quot;VARCHAR&quot; size=&quot;20&quot;/&gt;
		&lt;column name=&quot;EXIT_MESSAGE&quot; type=&quot;VARCHAR&quot; size=&quot;2500&quot;/&gt;
		&lt;column name=&quot;LAST_UPDATED&quot; type=&quot;TIMESTAMP&quot;/&gt;
        &lt;foreign-key name=&quot;JOB_EXEC_STEP_FK&quot; foreignTable=&quot;BATCH_JOB_EXECUTION&quot;&gt;
           &lt;reference foreign=&quot;JOB_EXECUTION_ID&quot; local=&quot;JOB_EXECUTION_ID&quot;/&gt;
        &lt;/foreign-key&gt;
    &lt;/table&gt;

    &lt;table name=&quot;BATCH_STEP_EXECUTION_CONTEXT&quot;&gt;
	    &lt;column name=&quot;STEP_EXECUTION_ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot;/&gt;
	    &lt;column name=&quot;SHORT_CONTEXT&quot; type=&quot;VARCHAR&quot; size=&quot;2500&quot; required=&quot;true&quot;/&gt;
	    &lt;column name=&quot;SERIALIZED_CONTEXT&quot; type=&quot;VARCHAR&quot; /&gt;
        &lt;foreign-key name=&quot;STEP_EXEC_CTX_FK&quot; foreignTable=&quot;BATCH_STEP_EXECUTION&quot;&gt;
           &lt;reference foreign=&quot;STEP_EXECUTION_ID&quot; local=&quot;STEP_EXECUTION_ID&quot;/&gt;
        &lt;/foreign-key&gt;
    &lt;/table&gt;

    &lt;table name=&quot;BATCH_JOB_EXECUTION_CONTEXT&quot;&gt;
		&lt;column name=&quot;JOB_EXECUTION_ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot;/&gt;
		&lt;column name=&quot;SHORT_CONTEXT&quot; type=&quot;VARCHAR&quot; size=&quot;2500&quot; required=&quot;true&quot;/&gt;
		&lt;column name=&quot;SERIALIZED_CONTEXT&quot; type=&quot;VARCHAR&quot;/&gt; 
        &lt;foreign-key name=&quot;JOB_EXEC_CTX_FK&quot; foreignTable=&quot;BATCH_JOB_EXECUTION&quot;&gt;
           &lt;reference foreign=&quot;JOB_EXECUTION_ID&quot; local=&quot;JOB_EXECUTION_ID&quot;/&gt;
        &lt;/foreign-key&gt;        
    &lt;/table&gt;
	&lt;table name=&quot;BATCH_STEP_EXECUTION_SEQ&quot;&gt;
		&lt;column name=&quot;ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot; autoIncrement=&quot;true&quot; /&gt;
	&lt;/table&gt;
	&lt;table name=&quot;BATCH_JOB_EXECUTION_SEQ&quot;&gt;
		&lt;column name=&quot;ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot; autoIncrement=&quot;true&quot; /&gt;
	&lt;/table&gt;
	&lt;table name=&quot;BATCH_JOB_SEQ&quot;&gt;
		&lt;column name=&quot;ID&quot; type=&quot;BIGINT&quot; primaryKey=&quot;true&quot; autoIncrement=&quot;true&quot; /&gt;
	&lt;/table&gt;
    
&lt;/database&gt;
</pre></p>
<h3>Java Code</h3>
<p>The following file initializes the Job Repository and creates the schema based on a DDL contained in an xml configuration file. It also allows the system to gracefully shut-down the database and persist the in-memory data back to the file system after batch job completion.</p>
<p>src/main/java/com/test/JobRepositoryInitializer.java<br />
<pre class="brush: java; light: true;">
package com.test;

import java.io.InputStreamReader;

import javax.sql.DataSource;

import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Database;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class JobRepositoryInitializer {
	private DataSource dataSource;
	private String configFile;
	
	/**
	 * This method reads the schema from an xml file and determines
	 * if it needs to issue DDL statements to create or modify tables
	 * already in the database.
	 * 
	 * @throws Exception
	 */
	public void checkDDL() throws Exception {
        Platform platform = PlatformFactory
        .createNewPlatformInstance(dataSource);

        // Apache DDLUtils framework is used to create/modify schema.
		Database database = new DatabaseIO().read(new InputStreamReader(
		        getClass().getResourceAsStream(configFile)));
		
		platform.alterTables(database, false);
		System.out.println(&quot;HSQLDB is ready: &quot; + platform);
	}

	public void shutdownDatabase() {
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(dataSource);
        template.update(&quot;SHUTDOWN;&quot;);
        System.out.println(&quot;HSQLDB was gracefully shutdown. &quot;);
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public DataSource getDataSource() {
		return dataSource;
	}

	public void setConfigFile(String configFile) {
		this.configFile = configFile;
	}

	public String getConfigFile() {
		return configFile;
	}	
}
</pre></p>
<h3>Configuration</h3>
<p>In order to get the application to use HSQLDB and generate the JobRepository DDL Schema you need to do the following.</p>
<h4>Configure the database</h4>
<p>The following bean allows you to define a dataSource that will be used to connect to the HSQLDB database. The database files will be located in the src/main/resources/db folder. (This is specified in the database URL property)</p>
<p>src/main/resources/applicationContext.xml<br />
<pre class="brush: xml; light: true;">
&lt;bean name=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;org.hsqldb.jdbcDriver&quot;/&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:hsqldb:file:src/main/resources/db/testdb&quot;/&gt;
        &lt;property name=&quot;username&quot; value=&quot;sa&quot;/&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot;/&gt;
&lt;/bean&gt;
</pre></p>
<h4>Job Repository Configuration</h4>
<p>Update the configuration for the job repository to look like this:</p>
<p>src/main/resources/applicationContext.xml<br />
<pre class="brush: xml; light: true;">
    &lt;beans:bean id=&quot;jobRepository&quot;
        class=&quot;org.springframework.batch.core.repository.support.JobRepositoryFactoryBean&quot;&gt;
        &lt;beans:property name=&quot;databaseType&quot; value=&quot;HSQL&quot;/&gt;
        &lt;beans:property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;/&gt;
        &lt;beans:property name=&quot;transactionManager&quot; ref=&quot;transactionManager&quot; /&gt;
    &lt;/beans:bean&gt;
</pre></p>
<h4>Apache DDLUtil Configuration</h4>
<p>When the application starts for the first time the system will need to create the JobRepository tables. The following Spring Bean initializes the job repository and creates tables that are defined in the<br />
src/main/resources/applicationContext.xml<br />
<pre class="brush: xml; light: true;">
	&lt;beans:bean id=&quot;jobRepositoryInitializer&quot; class=&quot;com.test.JobRepositoryInitializer&quot;
		init-method=&quot;checkDDL&quot; destroy-method=&quot;shutdownDatabase&quot;&gt;
		&lt;beans:property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;
		&lt;beans:property name=&quot;configFile&quot; value=&quot;/ddl.xml&quot; /&gt;
	&lt;/beans:bean&gt;
</pre></p>
<h3>Run the application</h3>
<p>To run the job from the command line type the following:</p>
<p><pre class="brush: bash; light: true;">
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<p>You will notice that if you run the job again the console will print the following:</p>
<blockquote><p>SEVERE: Job Terminated in error: A job instance already exists and is complete for parameters={}.  If you want to run this job again, change the parameters.<br />
org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={}.  If you want to run this job again, change the parameters.
</p></blockquote>
<p>This is a <strong><font color="green">successful</font></strong> indication that the HSQLDB is working persisting the data. Spring Batch framework is indicating that the helloWorld job invocation has already happened. More than one invocation with the same parameters is not allowed. If you want to read more about this then <a href="http://numberformat.wordpress.com/2010/02/07/multiple-batch-runs-with-spring-batch/">please read the following article</a>.</p>
<p>You can also read the database script file located here: </p>
<p>src/main/resources/db/testdb.script<br />
<pre class="brush: plain; light: true;">
INSERT INTO BATCH_JOB_INSTANCE VALUES(0,0,'helloWorldJob','d41d8cd98f00b204e9800998ecf8427e')
INSERT INTO BATCH_JOB_EXECUTION VALUES(0,2,0,'2011-10-02 19:53:54.601000000','2011-10-02 19:53:54.617000000','2011-10-02 19:53:54.642000000','COMPLETED','COMPLETED','','2011-10-02 19:53:54.642000000')
INSERT INTO BATCH_STEP_EXECUTION VALUES(0,3,'step1',0,'2011-10-02 19:53:54.626000000','2011-10-02 19:53:54.639000000','COMPLETED',1,0,0,0,0,0,0,0,'COMPLETED','','2011-10-02 19:53:54.639000000')
INSERT INTO BATCH_STEP_EXECUTION_CONTEXT VALUES(0,'{&quot;map&quot;:&quot;&quot;}',NULL)
INSERT INTO BATCH_JOB_EXECUTION_CONTEXT VALUES(0,'{&quot;map&quot;:&quot;&quot;}',NULL)
INSERT INTO BATCH_STEP_EXECUTION_SEQ VALUES(0)
INSERT INTO BATCH_JOB_EXECUTION_SEQ VALUES(0)
INSERT INTO BATCH_JOB_SEQ VALUES(0)
</pre></p>
<p>HSQLDB uses this file to persist data to the file system in-between batch invocations.</p>
<p>That&#8217;s all for now!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/4946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/4946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/4946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/4946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/4946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/4946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/4946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/4946/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4946&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/10/02/spring-batch-hypersql-job-repository/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Batch Headers and Footers</title>
		<link>http://numberformat.wordpress.com/2011/10/01/spring-batch-headers-and-footers/</link>
		<comments>http://numberformat.wordpress.com/2011/10/01/spring-batch-headers-and-footers/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 03:07:10 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=4934</guid>
		<description><![CDATA[This page describes the process of creating running a Spring Batch job that creates an output file with header and footer information. Background In prior articles we created a batch job that read information and outputted the result to another file. The output file was missing a header and footer lines. In this article we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4934&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes the process of creating running a Spring Batch job that creates an output file with header and footer information.</p>
<h3>Background</h3>
<p>In prior articles we created a batch job that read information and outputted the result to another file. The output file was missing a header and footer lines. In this article we will look into generating this information.</p>
<h3>Requirements</h3>
<ul>
<li>Java 5</li>
<li>Maven 2</li>
<li>This page picks up where the following page left off. Please Review and Implement <a href="http://numberformat.wordpress.com/2011/10/01/the-3-rs-of-spring-batch/">the following article</a>.</li>
</ul>
<h3>Header</h3>
<p>The header of the will simply contain the filename and the timestamp.</p>
<p>fileName,Timestamp</p>
<h3>Footer</h3>
<p>The footer contained in the output be composed of 2 fields.</p>
<p>#ofRecords,salarySum</p>
<p>where:<br />
#ofRecords &#8211; Count of the number of records in the output<br />
salarySum &#8211; Sum of all values in the salary field</p>
<h3>Solution</h3>
<p>Create a Item Writer that will wrap the &#8220;FlatFileItemWriter&#8221;. The &#8220;headerCallback&#8221; and &#8220;footerCallback&#8221; methods of the ItemWriter will be called at the beginning and ending of the file. This allows developers to implement code that will allow them to write information to the header and footer of the output file.</p>
<p>src/main/java/com/test/EmployeeItemWriter.java<br />
<pre class="brush: java; gutter: false;">
package com.test;

import java.io.IOException;
import java.io.Writer;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.file.FlatFileFooterCallback;
import org.springframework.batch.item.file.FlatFileHeaderCallback;
import org.springframework.batch.item.file.FlatFileItemWriter;

public class EmployeeItemWriter implements ItemWriter&lt;Employee&gt;,
		FlatFileFooterCallback, FlatFileHeaderCallback, ItemStream {

    private FlatFileItemWriter&lt;Employee&gt; delegate;

    private BigDecimal totalAmount = BigDecimal.ZERO;

	private int recordCount = 0;
    
    public void writeFooter(Writer writer) throws IOException {
        writer.write(&quot;&quot;+recordCount + &quot;,&quot; + totalAmount);
    }
	public void writeHeader(Writer writer) throws IOException {
        writer.write(&quot;output_file.txt&quot; + &quot;,&quot; + new Date());
	}
    public void write(List&lt;? extends Employee&gt; items) throws Exception {
        BigDecimal chunkTotal = BigDecimal.ZERO;
        int chunkRecord = 0;
        for (Employee employee : items) {
            chunkRecord++;
            chunkTotal = chunkTotal.add(new BigDecimal(employee.getSalary()));
        }
        delegate.write(items);
        // After successfully writing all items
        totalAmount = totalAmount.add(chunkTotal);
        recordCount += chunkRecord;
	}
    
    public void setDelegate(FlatFileItemWriter&lt;Employee&gt; delegate) {
		this.delegate = delegate;
	}

	public void close() throws ItemStreamException {
		this.delegate.close();
	}

	public void open(ExecutionContext arg0) throws ItemStreamException {
		this.delegate.open(arg0);
	}

	public void update(ExecutionContext arg0) throws ItemStreamException {
		this.delegate.update(arg0);
	}
}
</pre></p>
<h3>Batch XML Configuration</h3>
<p>The following xml will allow the ItemWriter to wrap the FlatFileItemWriter and maintain a running total.</p>
<p>The highlighted lines are the changes from the prior version.</p>
<p>/src/main/resources/simpleJob.xml<br />
<pre class="brush: java; gutter: false; highlight: [56,57,60,61,62,70];">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/batch&quot;
     xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;
     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
     xsi:schemaLocation=&quot;
 
http://www.springframework.org/schema/batch
 
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd

http://www.springframework.org/schema/beans
 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot;&gt;
 
    &lt;beans:import resource=&quot;applicationContext.xml&quot;/&gt;
 
&lt;!-- Tokenizer - Converts a delimited string into a Set of Fields --&gt;
&lt;beans:bean name=&quot;defaultTokenizer&quot; 
    class=&quot;org.springframework.batch.item.file.transform.DelimitedLineTokenizer&quot;/&gt;

&lt;!-- FieldSetMapper - Populates a bean's attributes with using the FieldSet --&gt;
&lt;beans:bean name=&quot;employeeFieldSetMapper&quot; class=&quot;com.test.EmployeeFieldSetMapper&quot;/&gt;

&lt;!-- LineMapper - Uses the tokenizer and Mapper to create instances of a Bean. --&gt;
&lt;beans:bean name=&quot;employeeLineMapper&quot; class=&quot;org.springframework.batch.item.file.mapping.DefaultLineMapper&quot;&gt;
    &lt;beans:property name=&quot;lineTokenizer&quot; ref=&quot;defaultTokenizer&quot;/&gt;    
    &lt;beans:property name=&quot;fieldSetMapper&quot; ref=&quot;employeeFieldSetMapper&quot;/&gt;        
&lt;/beans:bean&gt;

&lt;!-- Reader - used by the tasklet to process one Item from the input. --&gt;
&lt;beans:bean name=&quot;empReader&quot; class=&quot;org.springframework.batch.item.file.FlatFileItemReader&quot;&gt;
    &lt;beans:property name=&quot;lineMapper&quot; ref=&quot;employeeLineMapper&quot;/&gt;
    
    &lt;!-- use spring integrations for the following, but for now filename is hard coded --&gt;
    &lt;beans:property name=&quot;resource&quot; value=&quot;input_data.txt&quot;/&gt;    
&lt;/beans:bean&gt;

&lt;!-- Processor --&gt;

&lt;beans:bean name=&quot;empProcessor&quot; class=&quot;com.test.EmployeeProcessor&quot;&gt;
&lt;/beans:bean&gt;

&lt;!-- Writer --&gt;
&lt;beans:bean id=&quot;empWriter&quot; class=&quot;org.springframework.batch.item.file.FlatFileItemWriter&quot;&gt;
    &lt;beans:property name=&quot;resource&quot; value=&quot;file:target/output_data.txt&quot; /&gt;
    &lt;beans:property name=&quot;lineAggregator&quot;&gt;
        &lt;beans:bean class=&quot;org.springframework.batch.item.file.transform.DelimitedLineAggregator&quot;&gt;
            &lt;beans:property name=&quot;delimiter&quot; value=&quot;,&quot;/&gt;
            &lt;beans:property name=&quot;fieldExtractor&quot;&gt;
                &lt;beans:bean class=&quot;org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor&quot;&gt;
                    &lt;beans:property name=&quot;names&quot; value=&quot;empId,lastName,title,salary,rank&quot;/&gt;
                &lt;/beans:bean&gt;
            &lt;/beans:property&gt;
        &lt;/beans:bean&gt;
    &lt;/beans:property&gt;
    &lt;beans:property name=&quot;footerCallback&quot; ref=&quot;empHeaderFooterWriter&quot; /&gt;
    &lt;beans:property name=&quot;headerCallback&quot; ref=&quot;empHeaderFooterWriter&quot; /&gt;
&lt;/beans:bean&gt;

&lt;beans:bean id=&quot;empHeaderFooterWriter&quot; class=&quot;com.test.EmployeeItemWriter&quot;&gt;
    &lt;beans:property name=&quot;delegate&quot; ref=&quot;empWriter&quot;/&gt;
&lt;/beans:bean&gt;

&lt;job id=&quot;helloWorldJob&quot;&gt;
    &lt;step id=&quot;step1&quot; next=&quot;step2&quot;&gt;
        &lt;tasklet ref=&quot;helloWorldTasklet&quot; /&gt;
    &lt;/step&gt;
    &lt;step id=&quot;step2&quot;&gt;
        &lt;tasklet&gt;
            &lt;chunk reader=&quot;empReader&quot; processor=&quot;empProcessor&quot; writer=&quot;empHeaderFooterWriter&quot; commit-interval=&quot;1&quot;/&gt;
        &lt;/tasklet&gt;
    &lt;/step&gt;
&lt;/job&gt;
 
&lt;beans:bean name=&quot;helloWorldTasklet&quot; class=&quot;com.test.HelloWorldTasklet&quot;/&gt;
 
&lt;!--
To run the job from the command line type the following:
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
 --&gt;
&lt;/beans:beans&gt;
</pre></p>
<h3>Execute the job</h3>
<p>Go to the command line and type the following:</p>
<p><pre class="brush: bash; gutter: false;">
mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<h3>View the results</h3>
<p>The output file will appear in the target/ folder of the project.</p>
<p>The file should look like this:</p>
<p><pre class="brush: plain; light: true;">
output_file.txt,Sat Oct 01 22:50:17 EDT 2011
7876,ADAMS,CLERK,1100,N/A
7499,ALLEN,SALESMAN,1600,N/A
7698,BLAKE,MANAGER,2850,Director
7782,CLARK,MANAGER,2450,N/A
7902,FORD,ANALYST,3000,Director
7900,JAMES,CLERK,950,N/A
7566,JONES,MANAGER,2975,Director
7839,KING,PRESIDENT,5000,Director
7654,MARTIN,SALESMAN,1250,N/A
7934,MILLER,CLERK,1300,N/A
7788,SCOTT,ANALYST,3000,Director
7369,SMITH,CLERK,800,N/A
7844,TURNER,SALESMAN,1500,N/A
7521,WARD,SALESMAN,1250,N/A
14,29025
</pre></p>
<p>That&#8217;s all for now!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/4934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/4934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/4934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/4934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/4934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/4934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/4934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/4934/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4934&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/10/01/spring-batch-headers-and-footers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>The 3 R&#8217;s of Spring Batch</title>
		<link>http://numberformat.wordpress.com/2011/10/01/the-3-rs-of-spring-batch/</link>
		<comments>http://numberformat.wordpress.com/2011/10/01/the-3-rs-of-spring-batch/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 00:36:14 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=4893</guid>
		<description><![CDATA[This page describes how you can Read, wRrite and perform aRithmetic on flat files using The Spring Batch Framework. We will take a comma separated file (csv) that contain employee information, add some information to it, and write it back to the file system. Background The basic building blocks of any batch process is Reading [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4893&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes how you can <strong>R</strong>ead, w<strong>R</strong>rite and perform a<strong>R</strong>ithmetic on flat files using The Spring Batch Framework. We will take a comma separated file (csv) that contain employee information, add some information to it, and write it back to the file system.</p>
<h3>Background</h3>
<p>The basic building blocks of any batch process is </p>
<ol>
<li>Reading a Item</li>
<li>Performing an operation on it</li>
<li>Writing the Item back</li>
</ol>
<p>Please take some time to review <a href="http://static.springsource.org/spring-batch/reference/html/domain.html">The Domain Language of Batch</a> before proceeding. It covers much of the fundamental concepts we will be covering here.</p>
<h3>Batch Steps</h3>
<p>This page is focused on an individual step of the batch process. </p>
<p>The following is from the spring batch documentation</p>
<blockquote><p>A Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing. This is a necessarily vague description because the contents of any given Step are at the discretion of the developer writing a Job. A Step can be as simple or complex as the developer desires. A simple Step might load data from a file into the database, requiring little or no code. (depending upon the implementations used) A more complex Step may have complicated business rules that are applied as part of the processing. </p></blockquote>
<h3>Step Processing types</h3>
<p>There are 2 ways a step can process data, </p>
<h4>Tasklet</h4>
<p>If the step requires only to execute a single task then you can use a tasklet. Typical use case for this is when you need to run a stored procedure, or copy a file from one location to the other. In the &#8220;Hello World&#8221; example we used a Tasklet to print the message to the console.</p>
<h4>Chunk oriented</h4>
<p>Chunk oriented processing involves specifying a reader, processor and writer. The input is read one item at a time in sequence and passed to the processor and eventually to the writer in chunks within a transaction boundary. Once the commit interval is reached the items are committed to the writer. Chunk oriented processing is what we will cover on this page.</p>
<h3>Requirements</h3>
<ul>
<li>Java 5</li>
<li>Maven 2</li>
<li>Review and implementation of <a href="http://numberformat.wordpress.com/2010/02/05/hello-world-with-spring-batch/">the following article</a>.</li>
<li>And this one: <a href="http://numberformat.wordpress.com/2011/10/01/hello-world-with-spring-batch-2-1-x/">http://numberformat.wordpress.com/2011/10/01/hello-world-with-spring-batch-2-1-x/</a></li>
</ul>
<h3>Project Setup</h3>
<p>We will be modifying an existing project so please review the articles listed in the section above.</p>
<h3>Input Data</h3>
<p>The following is the input csv file that will be read. Please create the following file in the projects resource directory.</p>
<p>src/main/resources/input_data.txt<br />
<pre class="brush: plain; gutter: false;">
7876,ADAMS,CLERK,1100
7499,ALLEN,SALESMAN,1600
7698,BLAKE,MANAGER,2850
7782,CLARK,MANAGER,2450
7902,FORD,ANALYST,3000
7900,JAMES,CLERK,950
7566,JONES,MANAGER,2975
7839,KING,PRESIDENT,-5000
7654,MARTIN,SALESMAN,1250
7934,MILLER,CLERK,1300
7788,SCOTT,ANALYST,3000
7369,SMITH,CLERK,800
7844,TURNER,SALESMAN,1500
7521,WARD,SALESMAN,1250
</pre></p>
<h3>Employee Bean</h3>
<p>This is a simple bean that represents a single Employee.</p>
<p>src/main/java/com/test/Employee.java<br />
<pre class="brush: java; gutter: false;">
package com.test;

public class Employee {

	private Integer empId;
	private String lastName;
	private String title;
	private Integer salary;
	private String rank;
	
	public Integer getEmpId() {
		return empId;
	}
	public void setEmpId(Integer empId) {
		this.empId = empId;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public Integer getSalary() {
		return salary;
	}
	public void setSalary(Integer salary) {
		this.salary = salary;
	}
	public void setRank(String rank) {
		this.rank = rank;
	}
	public String getRank() {
		return rank;
	}
	@Override
	public String toString() {
		return &quot;Employee [empId=&quot; + empId + &quot;, lastName=&quot; + lastName
				+ &quot;, title=&quot; + title + &quot;, salary=&quot; + salary + &quot;, rank=&quot; + rank
				+ &quot;]&quot;;
	}	
}
</pre></p>
<h3>Reading</h3>
<p>In order to read data from a file we will only need to write the FieldSetMapper class that takes a FieldSet object and maps its contents into an bean.</p>
<p>src/main/java/com/test/EmployeeFieldSetMapper.java<br />
<pre class="brush: java; gutter: false;">
package com.test;

import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;

public class EmployeeFieldSetMapper implements FieldSetMapper&lt;Employee&gt; {

	public Employee mapFieldSet(FieldSet fieldSet) throws BindException {
		if(fieldSet == null) return null;
		
		Employee emp = new Employee();	
		// unlike jdbc the index is 0 based	
		emp.setEmpId(fieldSet.readInt(0)); 
		emp.setLastName(fieldSet.readString(1));
		emp.setTitle(fieldSet.readString(2));
		emp.setSalary(fieldSet.readInt(3));
		
		return emp;
	}

}
</pre></p>
<h3>Arithmetic</h3>
<p>Not really! All we are doing is assigning a Rank based on the salary amount. The item processor takes an input Bean and converts it to an output bean. In this case the beans are the same but they don&#8217;t have to be.</p>
<p>src/main/java/com/test/EmployeeProcessor.java<br />
<pre class="brush: java; gutter: false;">
package com.test;

import org.springframework.batch.item.ItemProcessor;

public class EmployeeProcessor implements ItemProcessor&lt;Employee, Employee&gt; {

	public Employee process(Employee emp) throws Exception {
		// if salary &gt;= 2500 then set rank as &quot;Director&quot;		
		if(emp.getSalary() &gt;= 2500 ) {
			emp.setRank(&quot;Director&quot;);			
		} else {
			emp.setRank(&quot;N/A&quot;);
		}
		return emp;
	}

}
</pre></p>
<h3>Writing</h3>
<p>All the objects needed for writing the file are configured using xml. See the xml file below for more details.</p>
<h3>Job Configuration</h3>
<p>Modify the job xml file to define the new beans.</p>
<p>src/main/resources/simpleJob.xml<br />
<pre class="brush: xml; gutter: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/batch&quot;
     xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;
     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
     xsi:schemaLocation=&quot;
 
http://www.springframework.org/schema/batch
 
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd

http://www.springframework.org/schema/beans
 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot;&gt;
 
    &lt;beans:import resource=&quot;applicationContext.xml&quot;/&gt;
 
&lt;!-- Tokenizer - Converts a delimited string into a Set of Fields --&gt;
&lt;beans:bean name=&quot;defaultTokenizer&quot; 
    class=&quot;org.springframework.batch.item.file.transform.DelimitedLineTokenizer&quot;/&gt;

&lt;!-- FieldSetMapper - Populates a bean's attributes with using the FieldSet --&gt;
&lt;beans:bean name=&quot;employeeFieldSetMapper&quot; class=&quot;com.test.EmployeeFieldSetMapper&quot;/&gt;

&lt;!-- LineMapper - Uses the tokenizer and Mapper to create instances of a Bean. --&gt;
&lt;beans:bean name=&quot;employeeLineMapper&quot; class=&quot;org.springframework.batch.item.file.mapping.DefaultLineMapper&quot;&gt;
    &lt;beans:property name=&quot;lineTokenizer&quot; ref=&quot;defaultTokenizer&quot;/&gt;    
    &lt;beans:property name=&quot;fieldSetMapper&quot; ref=&quot;employeeFieldSetMapper&quot;/&gt;        
&lt;/beans:bean&gt;

&lt;!-- Reader - used by the tasklet to process one Item from the input. --&gt;
&lt;beans:bean name=&quot;empReader&quot; class=&quot;org.springframework.batch.item.file.FlatFileItemReader&quot;&gt;
    &lt;beans:property name=&quot;lineMapper&quot; ref=&quot;employeeLineMapper&quot;/&gt;
    
    &lt;!-- use spring integrations for the following, but for now filename is hard coded --&gt;
    &lt;beans:property name=&quot;resource&quot; value=&quot;input_data.txt&quot;/&gt;    
&lt;/beans:bean&gt;

&lt;!-- Processor --&gt;

&lt;beans:bean name=&quot;empProcessor&quot; class=&quot;com.test.EmployeeProcessor&quot;&gt;
&lt;/beans:bean&gt;

&lt;!-- Writer --&gt;
&lt;beans:bean id=&quot;empWriter&quot; class=&quot;org.springframework.batch.item.file.FlatFileItemWriter&quot;&gt;
    &lt;beans:property name=&quot;resource&quot; value=&quot;file:target/output_data.txt&quot; /&gt;
    &lt;beans:property name=&quot;lineAggregator&quot;&gt;
        &lt;beans:bean class=&quot;org.springframework.batch.item.file.transform.DelimitedLineAggregator&quot;&gt;
            &lt;beans:property name=&quot;delimiter&quot; value=&quot;,&quot;/&gt;
            &lt;beans:property name=&quot;fieldExtractor&quot;&gt;
                &lt;beans:bean class=&quot;org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor&quot;&gt;
                    &lt;beans:property name=&quot;names&quot; value=&quot;empId,lastName,title,salary,rank&quot;/&gt;
                &lt;/beans:bean&gt;
            &lt;/beans:property&gt;
        &lt;/beans:bean&gt;
    &lt;/beans:property&gt;
&lt;/beans:bean&gt;

&lt;job id=&quot;helloWorldJob&quot;&gt;
    &lt;step id=&quot;step1&quot; next=&quot;step2&quot;&gt;
        &lt;tasklet ref=&quot;helloWorldTasklet&quot; /&gt;
    &lt;/step&gt;
    &lt;step id=&quot;step2&quot;&gt;
        &lt;tasklet&gt;
            &lt;chunk reader=&quot;empReader&quot; processor=&quot;empProcessor&quot; writer=&quot;empWriter&quot; commit-interval=&quot;1&quot;/&gt;
        &lt;/tasklet&gt;
    &lt;/step&gt;
&lt;/job&gt;
 
&lt;beans:bean name=&quot;helloWorldTasklet&quot; class=&quot;com.test.HelloWorldTasklet&quot;/&gt;
 
&lt;!--
To run the job from the command line type the following:
mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
 --&gt;
&lt;/beans:beans&gt;
</pre></p>
<h3>Execute the job</h3>
<p>Go to the command line and type the following:</p>
<p><pre class="brush: bash; gutter: false;">
mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<h3>View the Results</h3>
<p>The output file will appear in the target/ folder of the project.</p>
<h3>Further Reading</h3>
<p>To keep things simple we were reading and writing files located in the project own folders. There are many enterprise design patterns that describe the best practices for feeding data into the batch programs. For further reading on this topic please see the <a href="http://www.springsource.org/spring-integration">Spring Integrations Framework Homepage</a>. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/4893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/4893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/4893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/4893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/4893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/4893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/4893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/4893/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4893&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/10/01/the-3-rs-of-spring-batch/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello World With Spring Batch 2.1.x</title>
		<link>http://numberformat.wordpress.com/2011/10/01/hello-world-with-spring-batch-2-1-x/</link>
		<comments>http://numberformat.wordpress.com/2011/10/01/hello-world-with-spring-batch-2-1-x/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 14:30:05 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=4896</guid>
		<description><![CDATA[This page describes how convert the spring hello world example application to work using spring batch 2.1.x. Background The Hello World With Spring Batch was written a while ago. Since then there was a new version of spring batch released. Instead of changing the original article, I chose to write a new one just describing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4896&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes how convert the spring hello world example application to work using spring batch 2.1.x.</p>
<h3>Background</h3>
<p>The Hello World With Spring Batch was written a while ago. Since then there was a new version of spring batch released. Instead of changing the original article, I chose to write a new one just describing the changes needed to get the application described there to work.</p>
<p><strong>The original article is located here: </strong></p>
<p><a href="http://numberformat.wordpress.com/2010/02/05/hello-world-with-spring-batch/">http://numberformat.wordpress.com/2010/02/05/hello-world-with-spring-batch/</a></p>
<h3>Step 1</h3>
<p>Update the pom.xml dependency for spring-batch-core.</p>
<p>pom.xml<br />
<pre class="brush: xml; gutter: false;">
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.batch&lt;/groupId&gt;
            &lt;artifactId&gt;spring-batch-core&lt;/artifactId&gt;
            &lt;version&gt;2.1.8.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
</pre></p>
<h3>Step 2</h3>
<p>update the xml: </p>
<p>src/main/resources/simpleJob.xml<br />
<pre class="brush: xml; gutter: false;">
http://www.springframework.org/schema/batch/spring-batch-2.0.xsd&quot;&gt;
</pre></p>
<p>with<br />
<pre class="brush: xml; gutter: false;">
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd&quot;&gt;
</pre></p>
<p>Finally Run the command just like before:</p>
<p><pre class="brush: bash; gutter: false;">
mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args=&quot;simpleJob.xml helloWorldJob&quot;
</pre></p>
<p>That&#8217;s all for now!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/4896/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/4896/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/4896/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/4896/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/4896/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/4896/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/4896/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/4896/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4896&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/10/01/hello-world-with-spring-batch-2-1-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Live Search Functionality using ExtJS</title>
		<link>http://numberformat.wordpress.com/2011/07/24/live-search-functionality-using-extjs/</link>
		<comments>http://numberformat.wordpress.com/2011/07/24/live-search-functionality-using-extjs/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 05:20:13 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[hsqldb]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=4786</guid>
		<description><![CDATA[This page describes the process of developing a live search page Extjs and Java Servlets. This is similar to the live search / type ahead functionality offered by google. This page contains instructions on how to create a complete working example in about a 1/2 hour using jetty servlet engine and the Java HyperSQL in-memory [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4786&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This page describes the process of developing a live search page Extjs and Java Servlets. This is similar to the live search / type ahead functionality offered by google. This page contains instructions on how to create a complete working example in about a 1/2 hour using jetty servlet engine and the Java HyperSQL in-memory database.</p>
<h3>Requirements</h3>
<ul>
<li>Maven 2</li>
<li>Java 5 or above</li>
</ul>
<h3>Background</h3>
<p>Type ahead functionality allows users to obtain a list of possible options as they type. Chances that the item the user is looking for increases with each keystroke. </p>
<p>A <strong>static</strong> working example is <a href="http://www.vermatech.com/extjs/sandbox/type-ahead/">located here</a>.</p>
<p>Live search results are typically displayed in combo boxes. A combo boxes are a mix between a drop down box and a text field. The ext-js framework enhances the basic HTML drop down to allow for type ahead functionality.</p>
<h4>Simple Database Driven Search</h4>
<p>Next we will take the example presented above and enhance it to retrieve results from a servlet invocation. The servlet will call the database to return results. </p>
<h4>Smarter Database Driven Search</h4>
<p>The data returned after you start to type may sometimes overwhelm the user. A better way to return results is to display them based on ranking. Each word in our sample table also has a rank column. We will start to use this to get smarter search results.</p>
<h4>Pagination</h4>
<p>The example implemented here uses pagination. The user is able to page thru search results. This capability is enabled by sending back &#8220;totalCount&#8221; value that represents the total search results available from the database. The &#8220;start&#8221; and &#8220;limit&#8221; parameters passed to the servlet help the system &#8220;window&#8221; the results so that only the required rows get sent to the browser.</p>
<p>In the example below, in order to get the &#8220;totalCount&#8221; I had to execute the query 2 times. Once to get the count and the other time to get the actual data.</p>
<p>Not all databases support &#8220;start&#8221; and &#8220;limit&#8221; fields. Check with your database vendor for availability.</p>
<h3>Implementation</h3>
<p>The project described here is composed of:</p>
<ol>
<li>index.jsp that displays the extjs component</li>
<li>Servlet that does the search against the database and return JSON</li>
<li>HSQLDB (HyperSQL) In memory database to hold the data</li>
<li>Spring Framework so that we can use the SimpleJdbcTemplate</li>
</ol>
<h4>Start a new Project</h4>
<p>We will be creating this project using Maven2. If you have not used maven before please see my maven2 tutorial on the right nav of this site.</p>
<p><pre class="brush: bash; gutter: false;">
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
</pre></p>
<p>groupId: com.test<br />
artifactId: live-search</p>
<p>Answer the rest of the questions with defaults “Just hit the enter key”,</p>
<p>cd to the project base folder.</p>
<p>cd live-search</p>
<p>Create the necessary directories.<br />
<pre class="brush: bash; gutter: false;">
mkdir -p src/main/java/com/test
mkdir -p src/main/resources/com/test
mkdir -p src/main/resources/db
</pre><br />
Modify the project Configuration</p>
<p>The pom.xml file should look something like this.</p>
<p>pom.xml<br />
<pre class="brush: xml; gutter: false;">
&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/maven-v4_0_0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.test&lt;/groupId&gt;
  &lt;artifactId&gt;live-search&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;live-search Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;3.8.1&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.json&lt;/groupId&gt;
            &lt;artifactId&gt;json&lt;/artifactId&gt;
            &lt;version&gt;20090211&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.ibatis&lt;/groupId&gt;
            &lt;artifactId&gt;ibatis-sqlmap&lt;/artifactId&gt;
            &lt;version&gt;2.3.4.726&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring&lt;/artifactId&gt;
            &lt;version&gt;2.5.6&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;mysql&lt;/groupId&gt;
        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
        &lt;version&gt;5.1.9&lt;/version&gt;
    &lt;/dependency&gt;        
        &lt;dependency&gt;
            &lt;groupId&gt;log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j&lt;/artifactId&gt;
            &lt;version&gt;1.2.14&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
            &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
            &lt;version&gt;2.2.4&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.ddlutils&lt;/groupId&gt;
            &lt;artifactId&gt;ddlutils&lt;/artifactId&gt;
            &lt;version&gt;1.0&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
            &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
            &lt;version&gt;2.5&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
            &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
            &lt;version&gt;2.0&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
    &lt;finalName&gt;live-search&lt;/finalName&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;version&gt;2.0.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;source&gt;1.6&lt;/source&gt;
                    &lt;target&gt;1.6&lt;/target&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
                &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
				&lt;version&gt;7.0.0.v20091005&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;scanIntervalSeconds&gt;2&lt;/scanIntervalSeconds&gt;
                    &lt;webAppConfig&gt;
                        &lt;contextPath&gt;/&lt;/contextPath&gt;
                    &lt;/webAppConfig&gt;
                    &lt;stopKey&gt;s&lt;/stopKey&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;

</pre></p>
<p>Each key press initiates an Ajax request to the server. The server sends back a small list of possible options. </p>
<h4>Servlet</h4>
<p>The following servlet runs queries against the database and returns results to the caller. In a standard web application you would follow the MVC design pattern. To keep the example short I have done it all in the servlet.</p>
<p>src/main/java/com/test/SearchServlet.java<br />
<pre class="brush: java; gutter: false;">
package com.test;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private SimpleJdbcTemplate jdbcTemplate;

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		ApplicationContext context = WebApplicationContextUtils
			.getRequiredWebApplicationContext(config.getServletContext());
		
		jdbcTemplate = (SimpleJdbcTemplate) context.getBean(&quot;jdbcTemplate&quot;);		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String query = req.getParameter(&quot;query&quot;);		
		if(query==null || &quot;&quot;.equals(query.trim())) return;		
		int offset = 0, limit = 0;
		
		try {
			offset = Integer.parseInt(req.getParameter(&quot;start&quot;));
		} catch (Exception ex) {}
		try {
			limit = Integer.parseInt(req.getParameter(&quot;limit&quot;));
		} catch (Exception ex) {}

		if(limit &lt;=0 ) { limit = 20; }
		
		// get the overall total count
		final List&lt;JSONObject&gt; resultList = new ArrayList&lt;JSONObject&gt;();
		jdbcTemplate.&lt;JSONObject&gt; query(
				&quot;SELECT distinct word_x FROM word_lemmatised &quot; +
				&quot;WHERE word_x like ? order by word_x limit ? offset ?;&quot;,
				new ParameterizedRowMapper&lt;JSONObject&gt;() {
					public JSONObject mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						JSONObject jsonWord = new JSONObject();
						try {
							jsonWord.put(&quot;word_x&quot;, rs.getString(1));
							resultList.add(jsonWord);
						} catch (JSONException e) {}
						return jsonWord;
					}
				}, query+&quot;%&quot;, limit, offset);
		
		int totalCount = jdbcTemplate.queryForInt(
				&quot;SELECT count(distinct word_x) FROM word_lemmatised &quot;
						+ &quot;WHERE word_x like ?&quot;, query + &quot;%&quot;);
		boolean success = true;
		
		
		JSONObject response = new JSONObject();		
		try {
			response.put(&quot;success&quot;, success);
			response.put(&quot;totalCount&quot;, totalCount);
			response.put(&quot;records&quot;, resultList);			
		} catch (JSONException e) {}
		resp.getWriter().print(response.toString());
	}

	public void setJdbcTemplate(SimpleJdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public SimpleJdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
}
</pre></p>
<p>src/main/webapp/WEB-INF/web.xml</p>
<p><pre class="brush: xml; gutter: false;">
&lt;!DOCTYPE web-app PUBLIC
 &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
 &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot; &gt;

&lt;web-app&gt;
	&lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;

	&lt;context-param&gt;
		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
		&lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;
	&lt;/context-param&gt;

	&lt;listener&gt;
		&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
	&lt;/listener&gt;
    &lt;listener&gt;
        &lt;listener-class&gt;com.test.DBLifecycleContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    
	&lt;servlet&gt;
		&lt;servlet-name&gt;searchServlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;com.test.SearchServlet&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;searchServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/app/searchServlet&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</pre></p>
<h4>Infrastructure classes</h4>
<p>The following classes and configuration files support the application.</p>
<p>src/main/java/com/test/DBLifecycleContextListener.java<br />
<pre class="brush: java; gutter: false;">
package com.test;
 
import java.io.InputStreamReader;
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;
 
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Database;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
 
/**
 * This listener initializes or gracefully shuts down the database based on
 * events from the web application.
 */
public class DBLifecycleContextListener implements ServletContextListener {
    private DataSource dataSource = null;
    private WebApplicationContext springContext = null;
 
    public void contextDestroyed(ServletContextEvent event) {
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(dataSource);
        template.update(&quot;SHUTDOWN;&quot;);
        System.out.println(&quot;HSQLDB was shutdown. &quot;);
    }
 
    public void contextInitialized(ServletContextEvent event) {
        springContext = WebApplicationContextUtils
                .getWebApplicationContext(event.getServletContext());
        dataSource = (DataSource) springContext.getBean(&quot;dataSource&quot;);
 
        Platform platform = PlatformFactory
                .createNewPlatformInstance(dataSource);
 
        Database database = new DatabaseIO().read(new InputStreamReader(
                getClass().getResourceAsStream(&quot;/ddl.xml&quot;)));
 
        System.out.println(database);
 
        platform.alterTables(database, false);
 
        System.out.println(&quot;HSQLDB is ready: &quot; + platform);
 
    }
 
}
</pre></p>
<h4>HyperSQL in memory database Setup</h4>
<p>The following defines the schema that will be used to create the in-memory tables in the Java HyperSQL database.</p>
<p>src/main/resources/ddl.xml<br />
<pre class="brush: xml; gutter: false;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE database SYSTEM &quot;http://db.apache.org/torque/dtd/database.dtd&quot;&gt;
&lt;database name=&quot;liveSearch&quot;&gt;
  &lt;table name=&quot;word_lemmatised&quot;&gt;
    &lt;column name=&quot;word_x&quot;
            type=&quot;VARCHAR&quot;
            primaryKey=&quot;true&quot;
            size=&quot;255&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;wordClass&quot;
            type=&quot;VARCHAR&quot;
            primaryKey=&quot;true&quot;
            size=&quot;10&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;frequency&quot;
            type=&quot;INTEGER&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;sortOrder&quot;
            type=&quot;INTEGER&quot;
            required=&quot;true&quot;/&gt;            

    &lt;index name=&quot;word_lemmatised_frequency&quot;&gt;
	&lt;index-column name=&quot;frequency&quot;/&gt;
    &lt;/index&gt;
    &lt;index name=&quot;word_lemmatised_sortOrder&quot;&gt;
	&lt;index-column name=&quot;sortOrder&quot;/&gt;
    &lt;/index&gt;

  &lt;/table&gt;
 
&lt;/database&gt;
</pre></p>
<p>The following data is the word list used to populate the in-memory table. This table will be queried by the servlet so it can return json back to the extjs component.</p>
<p>Copy the contents of this file into:</p>
<p>src/main/resources/db/liveSearch.script<br />
<pre class="brush: sql; gutter: false;">
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE MEMORY TABLE WORD_LEMMATISED(WORD_X VARCHAR(255) NOT NULL,WORDCLASS VARCHAR(10) NOT NULL,FREQUENCY INTEGER NOT NULL,SORTORDER INTEGER NOT NULL,PRIMARY KEY(WORD_X,WORDCLASS))
CREATE INDEX WORD_LEMMATISED_FREQUENCY ON WORD_LEMMATISED(FREQUENCY)
CREATE INDEX WORD_LEMMATISED_SORTORDER ON WORD_LEMMATISED(SORTORDER)
CREATE USER SA PASSWORD &quot;&quot;
GRANT DBA TO SA
SET WRITE_DELAY 10
SET SCHEMA PUBLIC
INSERT INTO WORD_LEMMATISED VALUES('a','det',2186369,5)
INSERT INTO WORD_LEMMATISED VALUES('abandon','v',4249,2107)
INSERT INTO WORD_LEMMATISED VALUES('abbey','n',1110,5204)
INSERT INTO WORD_LEMMATISED VALUES('ability','n',10468,966)
INSERT INTO WORD_LEMMATISED VALUES('able','a',30454,321)
INSERT INTO WORD_LEMMATISED VALUES('abnormal','a',809,6277)
INSERT INTO WORD_LEMMATISED VALUES('abolish','v',1744,3862)
INSERT INTO WORD_LEMMATISED VALUES('abolition','n',1154,5085)
INSERT INTO WORD_LEMMATISED VALUES('abortion','n',1471,4341)
INSERT INTO WORD_LEMMATISED VALUES('about','adv',52561,179)
INSERT INTO WORD_LEMMATISED VALUES('about','prep',144554,69)
INSERT INTO WORD_LEMMATISED VALUES('above','a',2139,3341)
INSERT INTO WORD_LEMMATISED VALUES('abroad','adv',3941,2236)
INSERT INTO WORD_LEMMATISED VALUES('abruptly','adv',1146,5106)
INSERT INTO WORD_LEMMATISED VALUES('absence','n',5949,1602)
INSERT INTO WORD_LEMMATISED VALUES('absent','a',1504,4266)
INSERT INTO WORD_LEMMATISED VALUES('absolute','a',3489,2435)
INSERT INTO WORD_LEMMATISED VALUES('absolutely','adv',5782,1651)
INSERT INTO WORD_LEMMATISED VALUES('absorb','v',2684,2907)
INSERT INTO WORD_LEMMATISED VALUES('absorption','n',932,5769)
INSERT INTO WORD_LEMMATISED VALUES('abstract','a',1605,4083)
INSERT INTO WORD_LEMMATISED VALUES('absurd','a',966,5655)
INSERT INTO WORD_LEMMATISED VALUES('abuse','n',3428,2461)
INSERT INTO WORD_LEMMATISED VALUES('abuse','v',1364,4570)
INSERT INTO WORD_LEMMATISED VALUES('academic','a',4594,1974)
INSERT INTO WORD_LEMMATISED VALUES('academy','n',1025,5453)
INSERT INTO WORD_LEMMATISED VALUES('accelerate','v',1114,5188)
INSERT INTO WORD_LEMMATISED VALUES('accent','n',1842,3707)
INSERT INTO WORD_LEMMATISED VALUES('accept','v',20373,507)
INSERT INTO WORD_LEMMATISED VALUES('acceptable','a',3647,2351)
INSERT INTO WORD_LEMMATISED VALUES('acceptance','n',2702,2895)
INSERT INTO WORD_LEMMATISED VALUES('access','n',10099,997)
INSERT INTO WORD_LEMMATISED VALUES('access','v',1389,4516)
INSERT INTO WORD_LEMMATISED VALUES('accessible','a',1637,4024)
INSERT INTO WORD_LEMMATISED VALUES('accident','n',8374,1207)
INSERT INTO WORD_LEMMATISED VALUES('accommodate','v',2065,3418)
INSERT INTO WORD_LEMMATISED VALUES('accommodation','n',4305,2085)
INSERT INTO WORD_LEMMATISED VALUES('accompany','v',4885,1892)
INSERT INTO WORD_LEMMATISED VALUES('accomplish','v',968,5648)
INSERT INTO WORD_LEMMATISED VALUES('accord','n',947,5723)
INSERT INTO WORD_LEMMATISED VALUES('accord','v',976,5613)
INSERT INTO WORD_LEMMATISED VALUES('accordance','n',2042,3443)
INSERT INTO WORD_LEMMATISED VALUES('according','prep',15722,646)
INSERT INTO WORD_LEMMATISED VALUES('accordingly','adv',2288,3214)
INSERT INTO WORD_LEMMATISED VALUES('account','n',19260,536)
INSERT INTO WORD_LEMMATISED VALUES('account','v',6130,1562)
INSERT INTO WORD_LEMMATISED VALUES('accountability','n',1184,5011)
INSERT INTO WORD_LEMMATISED VALUES('accountant','n',2199,3289)
INSERT INTO WORD_LEMMATISED VALUES('accounting','a',1640,4018)
INSERT INTO WORD_LEMMATISED VALUES('accumulate','v',1084,5279)
INSERT INTO WORD_LEMMATISED VALUES('accumulation','n',987,5570)
INSERT INTO WORD_LEMMATISED VALUES('accuracy','n',1692,3934)
INSERT INTO WORD_LEMMATISED VALUES('accurate','a',2928,2743)
INSERT INTO WORD_LEMMATISED VALUES('accurately','adv',1423,4436)
INSERT INTO WORD_LEMMATISED VALUES('accusation','n',1153,5088)
INSERT INTO WORD_LEMMATISED VALUES('accuse','v',4047,2190)
INSERT INTO WORD_LEMMATISED VALUES('accused','a',1387,4521)
INSERT INTO WORD_LEMMATISED VALUES('achieve','v',16628,611)
INSERT INTO WORD_LEMMATISED VALUES('achievement','n',4586,1980)
INSERT INTO WORD_LEMMATISED VALUES('acid','n',5897,1613)
INSERT INTO WORD_LEMMATISED VALUES('acknowledge','v',4151,2139)
INSERT INTO WORD_LEMMATISED VALUES('acquaintance','n',920,5809)
INSERT INTO WORD_LEMMATISED VALUES('acquire','v',6354,1512)
INSERT INTO WORD_LEMMATISED VALUES('acquisition','n',3245,2546)
INSERT INTO WORD_LEMMATISED VALUES('acre','n',2150,3327)
INSERT INTO WORD_LEMMATISED VALUES('across','adv',3439,2457)
INSERT INTO WORD_LEMMATISED VALUES('across','prep',21763,474)
INSERT INTO WORD_LEMMATISED VALUES('act','n',22657,455)
INSERT INTO WORD_LEMMATISED VALUES('act','v',15620,654)
INSERT INTO WORD_LEMMATISED VALUES('action','n',26894,371)
INSERT INTO WORD_LEMMATISED VALUES('activate','v',1293,4708)
INSERT INTO WORD_LEMMATISED VALUES('active','a',7290,1332)
INSERT INTO WORD_LEMMATISED VALUES('actively','adv',1493,4294)
INSERT INTO WORD_LEMMATISED VALUES('activist','n',1285,4736)
INSERT INTO WORD_LEMMATISED VALUES('activity','n',23105,440)
INSERT INTO WORD_LEMMATISED VALUES('actor','n',3540,2413)
INSERT INTO WORD_LEMMATISED VALUES('actress','n',1051,5376)
INSERT INTO WORD_LEMMATISED VALUES('actual','a',6849,1414)
INSERT INTO WORD_LEMMATISED VALUES('actually','adv',25990,385)
INSERT INTO WORD_LEMMATISED VALUES('acute','a',2294,3205)
INSERT INTO WORD_LEMMATISED VALUES('adapt','v',2687,2906)
INSERT INTO WORD_LEMMATISED VALUES('adaptation','n',1132,5153)
INSERT INTO WORD_LEMMATISED VALUES('add','v',27367,363)
INSERT INTO WORD_LEMMATISED VALUES('added','a',1334,4624)
INSERT INTO WORD_LEMMATISED VALUES('addition','n',10664,949)
INSERT INTO WORD_LEMMATISED VALUES('additional','a',7364,1319)
INSERT INTO WORD_LEMMATISED VALUES('address','n',6112,1566)
INSERT INTO WORD_LEMMATISED VALUES('address','v',5872,1625)
INSERT INTO WORD_LEMMATISED VALUES('adequate','a',3571,2397)
INSERT INTO WORD_LEMMATISED VALUES('adequately','adv',1149,5097)
INSERT INTO WORD_LEMMATISED VALUES('adjacent','a',1624,4047)
INSERT INTO WORD_LEMMATISED VALUES('adjective','n',1012,5496)
INSERT INTO WORD_LEMMATISED VALUES('adjust','v',2697,2898)
INSERT INTO WORD_LEMMATISED VALUES('adjustment','n',2114,3370)
INSERT INTO WORD_LEMMATISED VALUES('administer','v',1795,3769)
INSERT INTO WORD_LEMMATISED VALUES('administration','n',6865,1409)
INSERT INTO WORD_LEMMATISED VALUES('administrative','a',3548,2407)
INSERT INTO WORD_LEMMATISED VALUES('administrator','n',1483,4314)
INSERT INTO WORD_LEMMATISED VALUES('admiration','n',966,5654)
INSERT INTO WORD_LEMMATISED VALUES('admire','v',2168,3312)
INSERT INTO WORD_LEMMATISED VALUES('admission','n',2742,2861)
INSERT INTO WORD_LEMMATISED VALUES('admit','v',10905,925)
INSERT INTO WORD_LEMMATISED VALUES('adopt','v',8549,1186)
INSERT INTO WORD_LEMMATISED VALUES('adoption','n',1544,4191)
INSERT INTO WORD_LEMMATISED VALUES('adult','a',1547,4182)
INSERT INTO WORD_LEMMATISED VALUES('adult','n',6855,1411)
INSERT INTO WORD_LEMMATISED VALUES('advance','n',5055,1840)
INSERT INTO WORD_LEMMATISED VALUES('advance','v',3032,2683)
INSERT INTO WORD_LEMMATISED VALUES('advanced','a',3183,2583)
INSERT INTO WORD_LEMMATISED VALUES('advantage','n',10285,981)
INSERT INTO WORD_LEMMATISED VALUES('adventure','n',1993,3491)
INSERT INTO WORD_LEMMATISED VALUES('adverse','a',1184,5010)
INSERT INTO WORD_LEMMATISED VALUES('advertise','v',2099,3386)
INSERT INTO WORD_LEMMATISED VALUES('advertisement','n',2136,3344)
INSERT INTO WORD_LEMMATISED VALUES('advertising','n',3582,2392)
INSERT INTO WORD_LEMMATISED VALUES('advice','n',10437,971)
INSERT INTO WORD_LEMMATISED VALUES('advise','v',5055,1839)
INSERT INTO WORD_LEMMATISED VALUES('adviser','n',3191,2580)
INSERT INTO WORD_LEMMATISED VALUES('advisory','a',1500,4277)
INSERT INTO WORD_LEMMATISED VALUES('advocate','n',911,5848)
INSERT INTO WORD_LEMMATISED VALUES('advocate','v',1636,4029)
INSERT INTO WORD_LEMMATISED VALUES('aesthetic','a',1027,5444)
INSERT INTO WORD_LEMMATISED VALUES('affair','n',10561,954)
INSERT INTO WORD_LEMMATISED VALUES('affect','v',12867,789)
INSERT INTO WORD_LEMMATISED VALUES('affection','n',1601,4092)
INSERT INTO WORD_LEMMATISED VALUES('affinity','n',847,6101)
INSERT INTO WORD_LEMMATISED VALUES('afford','v',5346,1769)
INSERT INTO WORD_LEMMATISED VALUES('afraid','a',5967,1596)
INSERT INTO WORD_LEMMATISED VALUES('after','conj',30855,312)
INSERT INTO WORD_LEMMATISED VALUES('after','prep',85939,111)
INSERT INTO WORD_LEMMATISED VALUES('afternoon','n',8934,1128)
INSERT INTO WORD_LEMMATISED VALUES('afterwards','adv',4544,1991)
INSERT INTO WORD_LEMMATISED VALUES('again','adv',59829,160)
INSERT INTO WORD_LEMMATISED VALUES('against','prep',56208,169)
INSERT INTO WORD_LEMMATISED VALUES('age','n',25340,399)
INSERT INTO WORD_LEMMATISED VALUES('age','v',1565,4142)
INSERT INTO WORD_LEMMATISED VALUES('aged','prep',3096,2641)
INSERT INTO WORD_LEMMATISED VALUES('agency','n',9579,1054)
INSERT INTO WORD_LEMMATISED VALUES('agenda','n',2427,3069)
INSERT INTO WORD_LEMMATISED VALUES('agent','n',8100,1233)
INSERT INTO WORD_LEMMATISED VALUES('aggregate','a',1078,5294)
INSERT INTO WORD_LEMMATISED VALUES('aggression','n',1243,4845)
INSERT INTO WORD_LEMMATISED VALUES('aggressive','a',1925,3581)
INSERT INTO WORD_LEMMATISED VALUES('ago','adv',19808,522)
INSERT INTO WORD_LEMMATISED VALUES('agony','n',1017,5475)
INSERT INTO WORD_LEMMATISED VALUES('agree','v',23497,428)
INSERT INTO WORD_LEMMATISED VALUES('agreed','a',1106,5218)
INSERT INTO WORD_LEMMATISED VALUES('agreement','n',15627,651)
INSERT INTO WORD_LEMMATISED VALUES('agricultural','a',3162,2593)
INSERT INTO WORD_LEMMATISED VALUES('agriculture','n',3858,2265)
INSERT INTO WORD_LEMMATISED VALUES('ahead','adv',8809,1145)
INSERT INTO WORD_LEMMATISED VALUES('aid','n',7903,1249)
INSERT INTO WORD_LEMMATISED VALUES('aid','v',2086,3398)
INSERT INTO WORD_LEMMATISED VALUES('aids','n',2463,3042)
INSERT INTO WORD_LEMMATISED VALUES('aim','n',7460,1306)
INSERT INTO WORD_LEMMATISED VALUES('aim','v',7638,1281)
INSERT INTO WORD_LEMMATISED VALUES('air','n',19046,544)
INSERT INTO WORD_LEMMATISED VALUES('aircraft','n',6200,1548)
INSERT INTO WORD_LEMMATISED VALUES('airline','n',1982,3500)
INSERT INTO WORD_LEMMATISED VALUES('airport','n',2756,2855)
INSERT INTO WORD_LEMMATISED VALUES('alarm','n',2322,3169)
INSERT INTO WORD_LEMMATISED VALUES('alarm','v',1222,4914)
INSERT INTO WORD_LEMMATISED VALUES('albeit','conj',1406,4477)
INSERT INTO WORD_LEMMATISED VALUES('album','n',2581,2957)
INSERT INTO WORD_LEMMATISED VALUES('alcohol','n',3066,2662)
INSERT INTO WORD_LEMMATISED VALUES('alert','a',810,6273)
INSERT INTO WORD_LEMMATISED VALUES('alert','v',1125,5170)
INSERT INTO WORD_LEMMATISED VALUES('alien','a',868,6003)
INSERT INTO WORD_LEMMATISED VALUES('alike','adv',1270,4773)
INSERT INTO WORD_LEMMATISED VALUES('alive','a',4254,2103)
INSERT INTO WORD_LEMMATISED VALUES('all','adv',55704,171)
INSERT INTO WORD_LEMMATISED VALUES('all','det',230737,43)
INSERT INTO WORD_LEMMATISED VALUES('allegation','n',2124,3360)
INSERT INTO WORD_LEMMATISED VALUES('allege','v',1820,3731)
INSERT INTO WORD_LEMMATISED VALUES('alleged','a',1728,3887)
INSERT INTO WORD_LEMMATISED VALUES('allegedly','adv',1041,5398)
INSERT INTO WORD_LEMMATISED VALUES('alliance','n',3518,2422)
INSERT INTO WORD_LEMMATISED VALUES('allied','a',972,5630)
INSERT INTO WORD_LEMMATISED VALUES('allocate','v',2445,3060)
INSERT INTO WORD_LEMMATISED VALUES('allocation','n',2305,3193)
INSERT INTO WORD_LEMMATISED VALUES('allow','v',33687,279)
INSERT INTO WORD_LEMMATISED VALUES('allowance','n',3411,2472)
INSERT INTO WORD_LEMMATISED VALUES('ally','n',2381,3105)
INSERT INTO WORD_LEMMATISED VALUES('almost','adv',31588,300)
INSERT INTO WORD_LEMMATISED VALUES('alone','a',7088,1365)
INSERT INTO WORD_LEMMATISED VALUES('alone','adv',6262,1528)
INSERT INTO WORD_LEMMATISED VALUES('along','adv',8081,1235)
INSERT INTO WORD_LEMMATISED VALUES('along','prep',16233,627)
INSERT INTO WORD_LEMMATISED VALUES('alongside','prep',2720,2883)
INSERT INTO WORD_LEMMATISED VALUES('aloud','adv',999,5533)
INSERT INTO WORD_LEMMATISED VALUES('already','adv',34292,275)
INSERT INTO WORD_LEMMATISED VALUES('alright','a',3592,2386)
INSERT INTO WORD_LEMMATISED VALUES('alright','adv',4777,1926)
INSERT INTO WORD_LEMMATISED VALUES('also','adv',124884,81)
INSERT INTO WORD_LEMMATISED VALUES('altar','n',969,5643)
INSERT INTO WORD_LEMMATISED VALUES('alter','v',4061,2183)
INSERT INTO WORD_LEMMATISED VALUES('alteration','n',1527,4226)
INSERT INTO WORD_LEMMATISED VALUES('alternative','a',5098,1828)
INSERT INTO WORD_LEMMATISED VALUES('alternative','n',5228,1797)
INSERT INTO WORD_LEMMATISED VALUES('alternatively','adv',1723,3894)
INSERT INTO WORD_LEMMATISED VALUES('although','conj',43635,215)
INSERT INTO WORD_LEMMATISED VALUES('altogether','adv',3218,2558)
INSERT INTO WORD_LEMMATISED VALUES('aluminium','n',995,5546)
INSERT INTO WORD_LEMMATISED VALUES('always','adv',46228,201)
INSERT INTO WORD_LEMMATISED VALUES('amateur','a',1025,5452)
INSERT INTO WORD_LEMMATISED VALUES('amateur','n',900,5879)
INSERT INTO WORD_LEMMATISED VALUES('amazing','a',1873,3658)
INSERT INTO WORD_LEMMATISED VALUES('ambassador','n',1264,4788)
INSERT INTO WORD_LEMMATISED VALUES('ambiguity','n',1058,5345)
INSERT INTO WORD_LEMMATISED VALUES('ambiguous','a',837,6146)
INSERT INTO WORD_LEMMATISED VALUES('ambition','n',2319,3177)
INSERT INTO WORD_LEMMATISED VALUES('ambitious','a',1526,4228)
INSERT INTO WORD_LEMMATISED VALUES('ambulance','n',1690,3936)
INSERT INTO WORD_LEMMATISED VALUES('amend','v',1386,4525)
INSERT INTO WORD_LEMMATISED VALUES('amendment','n',2574,2960)
INSERT INTO WORD_LEMMATISED VALUES('amid','prep',1096,5243)
INSERT INTO WORD_LEMMATISED VALUES('among','prep',22864,450)
INSERT INTO WORD_LEMMATISED VALUES('amongst','prep',4552,1989)
INSERT INTO WORD_LEMMATISED VALUES('amount','n',16138,629)
INSERT INTO WORD_LEMMATISED VALUES('amount','v',3633,2358)
INSERT INTO WORD_LEMMATISED VALUES('amp','n',878,5960)
INSERT INTO WORD_LEMMATISED VALUES('ample','a',822,6211)
INSERT INTO WORD_LEMMATISED VALUES('amuse','v',1093,5255)
INSERT INTO WORD_LEMMATISED VALUES('amusement','n',1027,5443)
INSERT INTO WORD_LEMMATISED VALUES('an','det',343063,33)
INSERT INTO WORD_LEMMATISED VALUES('analogy','n',1098,5238)
INSERT INTO WORD_LEMMATISED VALUES('analyse','v',4106,2166)
INSERT INTO WORD_LEMMATISED VALUES('analysis','n',14149,732)
INSERT INTO WORD_LEMMATISED VALUES('analyst','n',1586,4109)
INSERT INTO WORD_LEMMATISED VALUES('ancestor','n',1249,4821)
INSERT INTO WORD_LEMMATISED VALUES('ancient','a',4981,1860)
INSERT INTO WORD_LEMMATISED VALUES('and','conj',2687863,4)
INSERT INTO WORD_LEMMATISED VALUES('angel','n',1897,3616)
INSERT INTO WORD_LEMMATISED VALUES('anger','n',3291,2530)
INSERT INTO WORD_LEMMATISED VALUES('anger','v',892,5902)
INSERT INTO WORD_LEMMATISED VALUES('angle','n',3644,2352)
INSERT INTO WORD_LEMMATISED VALUES('angrily','adv',1093,5254)
INSERT INTO WORD_LEMMATISED VALUES('angry','a',4282,2095)
INSERT INTO WORD_LEMMATISED VALUES('animal','n',15250,671)
INSERT INTO WORD_LEMMATISED VALUES('ankle','n',1363,4573)
INSERT INTO WORD_LEMMATISED VALUES('anniversary','n',2144,3332)
INSERT INTO WORD_LEMMATISED VALUES('announce','v',12582,815)
INSERT INTO WORD_LEMMATISED VALUES('announcement','n',2758,2852)
INSERT INTO WORD_LEMMATISED VALUES('annoy','v',1116,5186)
INSERT INTO WORD_LEMMATISED VALUES('annual','a',7785,1265)
INSERT INTO WORD_LEMMATISED VALUES('annually','adv',1092,5258)
INSERT INTO WORD_LEMMATISED VALUES('anonymous','a',1112,5194)
INSERT INTO WORD_LEMMATISED VALUES('another','det',60182,159)
INSERT INTO WORD_LEMMATISED VALUES('answer','n',12596,810)
INSERT INTO WORD_LEMMATISED VALUES('answer','v',10140,989)
INSERT INTO WORD_LEMMATISED VALUES('ant','n',998,5539)
INSERT INTO WORD_LEMMATISED VALUES('antibody','n',1528,4221)
INSERT INTO WORD_LEMMATISED VALUES('anticipate','v',2316,3184)
INSERT INTO WORD_LEMMATISED VALUES('anticipation','n',835,6155)
INSERT INTO WORD_LEMMATISED VALUES('anxiety','n',3129,2616)
INSERT INTO WORD_LEMMATISED VALUES('anxious','a',3088,2645)
INSERT INTO WORD_LEMMATISED VALUES('any','det',123655,83)
INSERT INTO WORD_LEMMATISED VALUES('anybody','pron',4952,1872)
INSERT INTO WORD_LEMMATISED VALUES('anyone','pron',14956,686)
INSERT INTO WORD_LEMMATISED VALUES('anything','pron',28321,347)
INSERT INTO WORD_LEMMATISED VALUES('anyway','adv',12232,837)
INSERT INTO WORD_LEMMATISED VALUES('anywhere','adv',4105,2167)
INSERT INTO WORD_LEMMATISED VALUES('apart','adv',10040,1004)
INSERT INTO WORD_LEMMATISED VALUES('apartment','n',1901,3612)
INSERT INTO WORD_LEMMATISED VALUES('apologise','v',1057,5353)
INSERT INTO WORD_LEMMATISED VALUES('apology','n',1195,4984)
INSERT INTO WORD_LEMMATISED VALUES('appalling','a',1027,5442)
INSERT INTO WORD_LEMMATISED VALUES('apparatus','n',1099,5236)
INSERT INTO WORD_LEMMATISED VALUES('apparent','a',5306,1782)
INSERT INTO WORD_LEMMATISED VALUES('apparently','adv',7696,1272)
INSERT INTO WORD_LEMMATISED VALUES('appeal','n',10020,1006)
INSERT INTO WORD_LEMMATISED VALUES('appeal','v',4764,1930)
INSERT INTO WORD_LEMMATISED VALUES('appear','v',30595,319)
INSERT INTO WORD_LEMMATISED VALUES('appearance','n',6606,1462)
INSERT INTO WORD_LEMMATISED VALUES('appendix','n',1884,3643)
INSERT INTO WORD_LEMMATISED VALUES('appetite','n',1055,5363)
INSERT INTO WORD_LEMMATISED VALUES('apple','n',2996,2704)
INSERT INTO WORD_LEMMATISED VALUES('applicable','a',1419,4443)
INSERT INTO WORD_LEMMATISED VALUES('applicant','n',2179,3305)
INSERT INTO WORD_LEMMATISED VALUES('application','n',16281,623)
INSERT INTO WORD_LEMMATISED VALUES('applied','a',1155,5081)
INSERT INTO WORD_LEMMATISED VALUES('apply','v',18982,547)
INSERT INTO WORD_LEMMATISED VALUES('appoint','v',6407,1500)
INSERT INTO WORD_LEMMATISED VALUES('appointed','a',1606,4080)
INSERT INTO WORD_LEMMATISED VALUES('appointment','n',5911,1610)
INSERT INTO WORD_LEMMATISED VALUES('appraisal','n',1092,5257)
INSERT INTO WORD_LEMMATISED VALUES('appreciate','v',4312,2082)
INSERT INTO WORD_LEMMATISED VALUES('appreciation','n',1329,4640)
INSERT INTO WORD_LEMMATISED VALUES('approach','n',16331,621)
INSERT INTO WORD_LEMMATISED VALUES('approach','v',7432,1310)
INSERT INTO WORD_LEMMATISED VALUES('appropriate','a',11010,917)
INSERT INTO WORD_LEMMATISED VALUES('appropriately','adv',891,5905)
INSERT INTO WORD_LEMMATISED VALUES('approval','n',4050,2187)
INSERT INTO WORD_LEMMATISED VALUES('approve','v',5312,1780)
INSERT INTO WORD_LEMMATISED VALUES('approved','a',911,5847)
INSERT INTO WORD_LEMMATISED VALUES('approximately','adv',2837,2798)
INSERT INTO WORD_LEMMATISED VALUES('aquarium','n',912,5843)
INSERT INTO WORD_LEMMATISED VALUES('arbitrary','a',1091,5262)
INSERT INTO WORD_LEMMATISED VALUES('arc','n',842,6125)
INSERT INTO WORD_LEMMATISED VALUES('arch','n',1248,4825)
INSERT INTO WORD_LEMMATISED VALUES('archaeological','a',826,6187)
INSERT INTO WORD_LEMMATISED VALUES('archbishop','n',1109,5206)
INSERT INTO WORD_LEMMATISED VALUES('architect','n',2572,2961)
INSERT INTO WORD_LEMMATISED VALUES('architectural','a',885,5929)
INSERT INTO WORD_LEMMATISED VALUES('architecture','n',3018,2688)
INSERT INTO WORD_LEMMATISED VALUES('archive','n',1124,5172)
INSERT INTO WORD_LEMMATISED VALUES('area','n',58449,162)
INSERT INTO WORD_LEMMATISED VALUES('arena','n',952,5704)
INSERT INTO WORD_LEMMATISED VALUES('argue','v',14196,728)
INSERT INTO WORD_LEMMATISED VALUES('argument','n',12125,843)
INSERT INTO WORD_LEMMATISED VALUES('arise','v',8860,1139)
INSERT INTO WORD_LEMMATISED VALUES('arm','n',20089,513)
INSERT INTO WORD_LEMMATISED VALUES('arm','v',1533,4214)
INSERT INTO WORD_LEMMATISED VALUES('armchair','n',886,5924)
INSERT INTO WORD_LEMMATISED VALUES('armed','a',3344,2505)
INSERT INTO WORD_LEMMATISED VALUES('army','n',12379,826)
INSERT INTO WORD_LEMMATISED VALUES('around','adv',23106,439)
INSERT INTO WORD_LEMMATISED VALUES('around','prep',22180,461)
INSERT INTO WORD_LEMMATISED VALUES('arouse','v',1308,4675)
INSERT INTO WORD_LEMMATISED VALUES('arrange','v',7021,1379)
INSERT INTO WORD_LEMMATISED VALUES('arrangement','n',9054,1113)
INSERT INTO WORD_LEMMATISED VALUES('array','n',1258,4803)
INSERT INTO WORD_LEMMATISED VALUES('arrest','n',2095,3391)
INSERT INTO WORD_LEMMATISED VALUES('arrest','v',4059,2185)
INSERT INTO WORD_LEMMATISED VALUES('arrival','n',3815,2278)
INSERT INTO WORD_LEMMATISED VALUES('arrive','v',14093,735)
INSERT INTO WORD_LEMMATISED VALUES('arrow','n',1621,4058)
INSERT INTO WORD_LEMMATISED VALUES('art','n',20168,509)
INSERT INTO WORD_LEMMATISED VALUES('article','n',9710,1037)
INSERT INTO WORD_LEMMATISED VALUES('articulate','v',821,6218)
INSERT INTO WORD_LEMMATISED VALUES('artificial','a',1901,3611)
INSERT INTO WORD_LEMMATISED VALUES('artist','n',8105,1232)
INSERT INTO WORD_LEMMATISED VALUES('artistic','a',1553,4170)
INSERT INTO WORD_LEMMATISED VALUES('as','adv',101583,98)
INSERT INTO WORD_LEMMATISED VALUES('as','conj',364164,31)
INSERT INTO WORD_LEMMATISED VALUES('as','prep',201968,48)
INSERT INTO WORD_LEMMATISED VALUES('ascertain','v',842,6124)
INSERT INTO WORD_LEMMATISED VALUES('ash','n',1051,5375)
INSERT INTO WORD_LEMMATISED VALUES('ashamed','a',1100,5233)
INSERT INTO WORD_LEMMATISED VALUES('aside','adv',3607,2375)
INSERT INTO WORD_LEMMATISED VALUES('ask','v',60879,154)
INSERT INTO WORD_LEMMATISED VALUES('asleep','a',2463,3041)
INSERT INTO WORD_LEMMATISED VALUES('aspect','n',11643,871)
INSERT INTO WORD_LEMMATISED VALUES('aspiration','n',1269,4777)
INSERT INTO WORD_LEMMATISED VALUES('assault','n',2395,3094)
INSERT INTO WORD_LEMMATISED VALUES('assault','v',919,5814)
INSERT INTO WORD_LEMMATISED VALUES('assemble','v',1621,4057)
INSERT INTO WORD_LEMMATISED VALUES('assembly','n',5847,1630)
INSERT INTO WORD_LEMMATISED VALUES('assert','v',2012,3477)
INSERT INTO WORD_LEMMATISED VALUES('assertion','n',1119,5180)
INSERT INTO WORD_LEMMATISED VALUES('assess','v',6088,1570)
INSERT INTO WORD_LEMMATISED VALUES('assessment','n',7602,1290)
INSERT INTO WORD_LEMMATISED VALUES('asset','n',5721,1663)
INSERT INTO WORD_LEMMATISED VALUES('assign','v',1778,3802)
INSERT INTO WORD_LEMMATISED VALUES('assignment','n',1707,3919)
INSERT INTO WORD_LEMMATISED VALUES('assist','v',4021,2202)
INSERT INTO WORD_LEMMATISED VALUES('assistance','n',4344,2064)
INSERT INTO WORD_LEMMATISED VALUES('assistant','a',1745,3860)
INSERT INTO WORD_LEMMATISED VALUES('assistant','n',2655,2921)
INSERT INTO WORD_LEMMATISED VALUES('associate','n',1047,5383)
INSERT INTO WORD_LEMMATISED VALUES('associate','v',8743,1156)
INSERT INTO WORD_LEMMATISED VALUES('associated','a',1447,4391)
INSERT INTO WORD_LEMMATISED VALUES('association','n',13471,757)
INSERT INTO WORD_LEMMATISED VALUES('assume','v',11044,912)
INSERT INTO WORD_LEMMATISED VALUES('assumption','n',5554,1705)
INSERT INTO WORD_LEMMATISED VALUES('assurance','n',2100,3384)
INSERT INTO WORD_LEMMATISED VALUES('assure','v',3116,2625)
INSERT INTO WORD_LEMMATISED VALUES('astonishing','a',848,6096)
INSERT INTO WORD_LEMMATISED VALUES('asylum','n',974,5620)
INSERT INTO WORD_LEMMATISED VALUES('at','prep',534162,19)
INSERT INTO WORD_LEMMATISED VALUES('athlete','n',812,6264)
INSERT INTO WORD_LEMMATISED VALUES('atmosphere','n',4902,1889)
INSERT INTO WORD_LEMMATISED VALUES('atom','n',1473,4331)
INSERT INTO WORD_LEMMATISED VALUES('atomic','a',1106,5217)
INSERT INTO WORD_LEMMATISED VALUES('attach','v',4821,1915)
INSERT INTO WORD_LEMMATISED VALUES('attachment','n',959,5677)
INSERT INTO WORD_LEMMATISED VALUES('attack','n',9963,1012)
INSERT INTO WORD_LEMMATISED VALUES('attack','v',6586,1464)
INSERT INTO WORD_LEMMATISED VALUES('attacker','n',919,5813)
INSERT INTO WORD_LEMMATISED VALUES('attain','v',1182,5016)
INSERT INTO WORD_LEMMATISED VALUES('attainment','n',948,5717)
INSERT INTO WORD_LEMMATISED VALUES('attempt','n',11877,857)
INSERT INTO WORD_LEMMATISED VALUES('attempt','v',9873,1022)
INSERT INTO WORD_LEMMATISED VALUES('attempted','a',849,6090)
INSERT INTO WORD_LEMMATISED VALUES('attend','v',8801,1148)
INSERT INTO WORD_LEMMATISED VALUES('attendance','n',1889,3633)
INSERT INTO WORD_LEMMATISED VALUES('attention','n',13968,740)
INSERT INTO WORD_LEMMATISED VALUES('attitude','n',10758,938)
INSERT INTO WORD_LEMMATISED VALUES('attract','v',6410,1498)
INSERT INTO WORD_LEMMATISED VALUES('attraction','n',2366,3124)
INSERT INTO WORD_LEMMATISED VALUES('attractive','a',5152,1814)
INSERT INTO WORD_LEMMATISED VALUES('attribute','n',1260,4798)
INSERT INTO WORD_LEMMATISED VALUES('attribute','v',2311,3187)
INSERT INTO WORD_LEMMATISED VALUES('auction','n',1466,4352)
INSERT INTO WORD_LEMMATISED VALUES('audience','n',6500,1480)
INSERT INTO WORD_LEMMATISED VALUES('audit','n',2136,3343)
INSERT INTO WORD_LEMMATISED VALUES('auditor','n',1679,3955)
INSERT INTO WORD_LEMMATISED VALUES('aunt','n',1536,4211)
INSERT INTO WORD_LEMMATISED VALUES('author','n',6852,1413)
INSERT INTO WORD_LEMMATISED VALUES('authorise','v',968,5647)
INSERT INTO WORD_LEMMATISED VALUES('authority','n',31231,303)
INSERT INTO WORD_LEMMATISED VALUES('automatic','a',2245,3242)
INSERT INTO WORD_LEMMATISED VALUES('automatically','adv',2787,2832)
INSERT INTO WORD_LEMMATISED VALUES('autonomous','a',1073,5305)
INSERT INTO WORD_LEMMATISED VALUES('autonomy','n',1788,3783)
INSERT INTO WORD_LEMMATISED VALUES('autumn','n',3917,2250)
INSERT INTO WORD_LEMMATISED VALUES('availability','n',1912,3602)
INSERT INTO WORD_LEMMATISED VALUES('available','a',27184,367)
INSERT INTO WORD_LEMMATISED VALUES('avenue','n',943,5736)
INSERT INTO WORD_LEMMATISED VALUES('average','a',5922,1607)
INSERT INTO WORD_LEMMATISED VALUES('average','n',4104,2168)
INSERT INTO WORD_LEMMATISED VALUES('aviation','n',925,5794)
INSERT INTO WORD_LEMMATISED VALUES('avoid','v',11750,866)
INSERT INTO WORD_LEMMATISED VALUES('await','v',1958,3536)
INSERT INTO WORD_LEMMATISED VALUES('awake','a',1040,5404)
INSERT INTO WORD_LEMMATISED VALUES('awake','v',825,6193)
INSERT INTO WORD_LEMMATISED VALUES('award','n',13274,764)
INSERT INTO WORD_LEMMATISED VALUES('award','v',6625,1458)
INSERT INTO WORD_LEMMATISED VALUES('aware','a',10764,936)
INSERT INTO WORD_LEMMATISED VALUES('awareness','n',3516,2424)
INSERT INTO WORD_LEMMATISED VALUES('away','adv',50294,188)
INSERT INTO WORD_LEMMATISED VALUES('awful','a',2960,2731)
INSERT INTO WORD_LEMMATISED VALUES('awkward','a',1489,4301)
INSERT INTO WORD_LEMMATISED VALUES('axis','n',1019,5469)
INSERT INTO WORD_LEMMATISED VALUES('aye','interjecti',5166,1811)
INSERT INTO WORD_LEMMATISED VALUES('baby','n',11503,883)
INSERT INTO WORD_LEMMATISED VALUES('back','a',2335,3160)
INSERT INTO WORD_LEMMATISED VALUES('back','adv',75494,118)
INSERT INTO WORD_LEMMATISED VALUES('back','n',24095,415)
INSERT INTO WORD_LEMMATISED VALUES('back','v',4391,2048)
INSERT INTO WORD_LEMMATISED VALUES('background','n',6923,1398)
INSERT INTO WORD_LEMMATISED VALUES('backing','n',1887,3636)
INSERT INTO WORD_LEMMATISED VALUES('backwards','adv',1802,3757)
INSERT INTO WORD_LEMMATISED VALUES('bacon','n',1037,5411)
INSERT INTO WORD_LEMMATISED VALUES('bacteria','n',1265,4786)
INSERT INTO WORD_LEMMATISED VALUES('bad','a',25608,393)
INSERT INTO WORD_LEMMATISED VALUES('badly','adv',4329,2072)
INSERT INTO WORD_LEMMATISED VALUES('bag','n',6955,1389)
INSERT INTO WORD_LEMMATISED VALUES('bail','n',811,6268)
INSERT INTO WORD_LEMMATISED VALUES('bake','v',930,5773)
INSERT INTO WORD_LEMMATISED VALUES('balance','n',8601,1179)
INSERT INTO WORD_LEMMATISED VALUES('balance','v',2361,3132)
INSERT INTO WORD_LEMMATISED VALUES('balanced','a',898,5884)
INSERT INTO WORD_LEMMATISED VALUES('balcony','n',1127,5165)
INSERT INTO WORD_LEMMATISED VALUES('ball','n',8636,1170)
INSERT INTO WORD_LEMMATISED VALUES('ballet','n',1340,4614)
INSERT INTO WORD_LEMMATISED VALUES('balloon','n',1030,5436)
INSERT INTO WORD_LEMMATISED VALUES('ballot','n',1055,5362)
INSERT INTO WORD_LEMMATISED VALUES('ban','n',2468,3037)
INSERT INTO WORD_LEMMATISED VALUES('ban','v',2851,2791)
INSERT INTO WORD_LEMMATISED VALUES('banana','n',924,5797)
INSERT INTO WORD_LEMMATISED VALUES('band','n',9003,1117)
INSERT INTO WORD_LEMMATISED VALUES('bang','n',980,5597)
INSERT INTO WORD_LEMMATISED VALUES('bang','v',1197,4976)
INSERT INTO WORD_LEMMATISED VALUES('bank','n',20946,491)
INSERT INTO WORD_LEMMATISED VALUES('banker','n',1348,4602)
INSERT INTO WORD_LEMMATISED VALUES('banking','n',1681,3950)
INSERT INTO WORD_LEMMATISED VALUES('bankruptcy','n',1066,5321)
INSERT INTO WORD_LEMMATISED VALUES('banner','n',857,6051)
INSERT INTO WORD_LEMMATISED VALUES('bar','n',9969,1011)
INSERT INTO WORD_LEMMATISED VALUES('bar','v',1210,4947)
INSERT INTO WORD_LEMMATISED VALUES('bare','a',2291,3211)
INSERT INTO WORD_LEMMATISED VALUES('barely','adv',2293,3206)
INSERT INTO WORD_LEMMATISED VALUES('bargain','n',1229,4886)
INSERT INTO WORD_LEMMATISED VALUES('bargain','v',893,5898)
INSERT INTO WORD_LEMMATISED VALUES('barn','n',1465,4356)
INSERT INTO WORD_LEMMATISED VALUES('barrel','n',1411,4464)
INSERT INTO WORD_LEMMATISED VALUES('barrier','n',3011,2691)
INSERT INTO WORD_LEMMATISED VALUES('base','n',9410,1070)
INSERT INTO WORD_LEMMATISED VALUES('base','v',18742,556)
INSERT INTO WORD_LEMMATISED VALUES('basement','n',852,6077)
INSERT INTO WORD_LEMMATISED VALUES('basic','a',10860,928)
INSERT INTO WORD_LEMMATISED VALUES('basically','adv',3116,2624)
INSERT INTO WORD_LEMMATISED VALUES('basin','n',1314,4661)
INSERT INTO WORD_LEMMATISED VALUES('basis','n',14420,715)
INSERT INTO WORD_LEMMATISED VALUES('basket','n',1658,3983)
INSERT INTO WORD_LEMMATISED VALUES('bass','n',1036,5416)
INSERT INTO WORD_LEMMATISED VALUES('bastard','n',1841,3709)
INSERT INTO WORD_LEMMATISED VALUES('bat','n',1249,4820)
INSERT INTO WORD_LEMMATISED VALUES('batch','n',977,5609)
INSERT INTO WORD_LEMMATISED VALUES('bath','n',3484,2439)
INSERT INTO WORD_LEMMATISED VALUES('bathroom','n',2792,2828)
INSERT INTO WORD_LEMMATISED VALUES('battery','n',2050,3433)
INSERT INTO WORD_LEMMATISED VALUES('battle','n',7063,1372)
INSERT INTO WORD_LEMMATISED VALUES('battle','v',983,5583)
INSERT INTO WORD_LEMMATISED VALUES('bay','n',2097,3387)
INSERT INTO WORD_LEMMATISED VALUES('be','v',4239632,2)
INSERT INTO WORD_LEMMATISED VALUES('beach','n',4125,2154)
INSERT INTO WORD_LEMMATISED VALUES('beam','n',1540,4205)
INSERT INTO WORD_LEMMATISED VALUES('bean','n',1767,3824)
INSERT INTO WORD_LEMMATISED VALUES('bear','n',1786,3788)
INSERT INTO WORD_LEMMATISED VALUES('bear','v',17461,592)
INSERT INTO WORD_LEMMATISED VALUES('beard','n',980,5596)
INSERT INTO WORD_LEMMATISED VALUES('bearing','n',1466,4351)
INSERT INTO WORD_LEMMATISED VALUES('beast','n',1232,4877)
INSERT INTO WORD_LEMMATISED VALUES('beat','n',1425,4430)
INSERT INTO WORD_LEMMATISED VALUES('beat','v',8106,1231)
INSERT INTO WORD_LEMMATISED VALUES('beautiful','a',8670,1162)
INSERT INTO WORD_LEMMATISED VALUES('beautifully','adv',1241,4849)
INSERT INTO WORD_LEMMATISED VALUES('beauty','n',4445,2027)
INSERT INTO WORD_LEMMATISED VALUES('because','conj',103003,96)
INSERT INTO WORD_LEMMATISED VALUES('become','v',67219,130)
INSERT INTO WORD_LEMMATISED VALUES('bed','n',17947,578)
INSERT INTO WORD_LEMMATISED VALUES('bedroom','n',5865,1626)
INSERT INTO WORD_LEMMATISED VALUES('bee','n',1237,4859)
INSERT INTO WORD_LEMMATISED VALUES('beef','n',1516,4243)
INSERT INTO WORD_LEMMATISED VALUES('beer','n',3762,2307)
INSERT INTO WORD_LEMMATISED VALUES('before','adv',6285,1522)
INSERT INTO WORD_LEMMATISED VALUES('before','conj',30731,314)
INSERT INTO WORD_LEMMATISED VALUES('before','prep',51259,185)
INSERT INTO WORD_LEMMATISED VALUES('beg','v',1885,3642)
INSERT INTO WORD_LEMMATISED VALUES('begin','v',43740,214)
INSERT INTO WORD_LEMMATISED VALUES('beginning','n',8018,1240)
INSERT INTO WORD_LEMMATISED VALUES('behalf','n',4012,2206)
INSERT INTO WORD_LEMMATISED VALUES('behave','v',3082,2650)
INSERT INTO WORD_LEMMATISED VALUES('behaviour','n',12853,793)
INSERT INTO WORD_LEMMATISED VALUES('behind','adv',2795,2823)
INSERT INTO WORD_LEMMATISED VALUES('behind','prep',20694,498)
INSERT INTO WORD_LEMMATISED VALUES('being','n',3732,2324)
INSERT INTO WORD_LEMMATISED VALUES('belief','n',7509,1302)
INSERT INTO WORD_LEMMATISED VALUES('believe','v',34603,273)
INSERT INTO WORD_LEMMATISED VALUES('bell','n',2758,2851)
INSERT INTO WORD_LEMMATISED VALUES('belly','n',959,5676)
INSERT INTO WORD_LEMMATISED VALUES('belong','v',5716,1664)
INSERT INTO WORD_LEMMATISED VALUES('below','adv',8587,1182)
INSERT INTO WORD_LEMMATISED VALUES('below','prep',5748,1656)
INSERT INTO WORD_LEMMATISED VALUES('belt','n',2328,3163)
INSERT INTO WORD_LEMMATISED VALUES('bench','n',2320,3173)
INSERT INTO WORD_LEMMATISED VALUES('bend','n',881,5946)
INSERT INTO WORD_LEMMATISED VALUES('bend','v',3453,2454)
INSERT INTO WORD_LEMMATISED VALUES('beneath','prep',4917,1883)
INSERT INTO WORD_LEMMATISED VALUES('beneficial','a',1375,4544)
INSERT INTO WORD_LEMMATISED VALUES('beneficiary','n',876,5973)
INSERT INTO WORD_LEMMATISED VALUES('benefit','n',15251,670)
INSERT INTO WORD_LEMMATISED VALUES('benefit','v',4262,2101)
INSERT INTO WORD_LEMMATISED VALUES('beside','prep',5785,1649)
INSERT INTO WORD_LEMMATISED VALUES('besides','adv',1765,3830)
INSERT INTO WORD_LEMMATISED VALUES('besides','prep',848,6095)
INSERT INTO WORD_LEMMATISED VALUES('best','adv',9790,1027)
INSERT INTO WORD_LEMMATISED VALUES('bet','n',950,5710)
INSERT INTO WORD_LEMMATISED VALUES('bet','v',2292,3209)
INSERT INTO WORD_LEMMATISED VALUES('betray','v',1310,4670)
INSERT INTO WORD_LEMMATISED VALUES('better','adv',15626,652)
INSERT INTO WORD_LEMMATISED VALUES('between','prep',91141,105)
INSERT INTO WORD_LEMMATISED VALUES('beyond','adv',1062,5333)
INSERT INTO WORD_LEMMATISED VALUES('beyond','prep',10705,945)
INSERT INTO WORD_LEMMATISED VALUES('bias','n',1372,4548)
INSERT INTO WORD_LEMMATISED VALUES('bible','n',2075,3408)
INSERT INTO WORD_LEMMATISED VALUES('bicycle','n',1134,5144)
INSERT INTO WORD_LEMMATISED VALUES('bid','n',3316,2521)
INSERT INTO WORD_LEMMATISED VALUES('bid','v',1756,3843)
INSERT INTO WORD_LEMMATISED VALUES('big','a',33300,282)
INSERT INTO WORD_LEMMATISED VALUES('bike','n',2224,3266)
INSERT INTO WORD_LEMMATISED VALUES('bile','n',1228,4892)
INSERT INTO WORD_LEMMATISED VALUES('bill','n',10125,993)
INSERT INTO WORD_LEMMATISED VALUES('bin','n',1040,5403)
INSERT INTO WORD_LEMMATISED VALUES('bind','v',6517,1472)
INSERT INTO WORD_LEMMATISED VALUES('binding','a',1246,4832)
INSERT INTO WORD_LEMMATISED VALUES('biography','n',988,5567)
INSERT INTO WORD_LEMMATISED VALUES('biological','a',1965,3523)
INSERT INTO WORD_LEMMATISED VALUES('biology','n',1029,5440)
INSERT INTO WORD_LEMMATISED VALUES('bird','n',9021,1115)
INSERT INTO WORD_LEMMATISED VALUES('birth','n',5889,1615)
INSERT INTO WORD_LEMMATISED VALUES('birthday','n',3352,2500)
INSERT INTO WORD_LEMMATISED VALUES('biscuit','n',1552,4172)
INSERT INTO WORD_LEMMATISED VALUES('bishop','n',3620,2366)
INSERT INTO WORD_LEMMATISED VALUES('bit','n',30675,315)
INSERT INTO WORD_LEMMATISED VALUES('bitch','n',1006,5510)
INSERT INTO WORD_LEMMATISED VALUES('bite','n',887,5920)
INSERT INTO WORD_LEMMATISED VALUES('bite','v',2885,2765)
INSERT INTO WORD_LEMMATISED VALUES('bitter','a',2384,3103)
INSERT INTO WORD_LEMMATISED VALUES('bitterly','adv',1097,5240)
INSERT INTO WORD_LEMMATISED VALUES('bizarre','a',1054,5369)
INSERT INTO WORD_LEMMATISED VALUES('black','a',20609,502)
INSERT INTO WORD_LEMMATISED VALUES('black','n',2310,3189)
INSERT INTO WORD_LEMMATISED VALUES('blade','n',1442,4400)
INSERT INTO WORD_LEMMATISED VALUES('blame','n',852,6076)
INSERT INTO WORD_LEMMATISED VALUES('blame','v',4248,2108)
INSERT INTO WORD_LEMMATISED VALUES('blank','a',1499,4279)
INSERT INTO WORD_LEMMATISED VALUES('blanket','n',1545,4184)
INSERT INTO WORD_LEMMATISED VALUES('blast','n',975,5616)
INSERT INTO WORD_LEMMATISED VALUES('blast','v',866,6009)
INSERT INTO WORD_LEMMATISED VALUES('bleak','a',916,5825)
INSERT INTO WORD_LEMMATISED VALUES('bleed','v',896,5889)
INSERT INTO WORD_LEMMATISED VALUES('bless','v',1228,4891)
INSERT INTO WORD_LEMMATISED VALUES('blessing','n',938,5754)
INSERT INTO WORD_LEMMATISED VALUES('blind','a',2674,2912)
INSERT INTO WORD_LEMMATISED VALUES('blink','v',896,5888)
INSERT INTO WORD_LEMMATISED VALUES('block','n',5705,1669)
INSERT INTO WORD_LEMMATISED VALUES('block','v',2688,2904)
INSERT INTO WORD_LEMMATISED VALUES('bloke','n',1597,4095)
INSERT INTO WORD_LEMMATISED VALUES('blonde','a',912,5842)
INSERT INTO WORD_LEMMATISED VALUES('blood','n',10176,986)
INSERT INTO WORD_LEMMATISED VALUES('bloody','a',5261,1791)
INSERT INTO WORD_LEMMATISED VALUES('bloody','adv',2016,3470)
INSERT INTO WORD_LEMMATISED VALUES('blow','n',2372,3118)
INSERT INTO WORD_LEMMATISED VALUES('blow','v',5013,1856)
INSERT INTO WORD_LEMMATISED VALUES('blue','a',9089,1109)
INSERT INTO WORD_LEMMATISED VALUES('blue','n',2455,3053)
INSERT INTO WORD_LEMMATISED VALUES('board','n',17878,581)
INSERT INTO WORD_LEMMATISED VALUES('board','v',850,6086)
INSERT INTO WORD_LEMMATISED VALUES('boast','v',1179,5026)
INSERT INTO WORD_LEMMATISED VALUES('boat','n',7373,1317)
INSERT INTO WORD_LEMMATISED VALUES('bodily','a',817,6240)
INSERT INTO WORD_LEMMATISED VALUES('body','n',32231,294)
INSERT INTO WORD_LEMMATISED VALUES('boil','v',1148,5101)
INSERT INTO WORD_LEMMATISED VALUES('boiler','n',878,5959)
INSERT INTO WORD_LEMMATISED VALUES('bold','a',1430,4419)
INSERT INTO WORD_LEMMATISED VALUES('bolt','n',1281,4748)
INSERT INTO WORD_LEMMATISED VALUES('bomb','n',3703,2333)
INSERT INTO WORD_LEMMATISED VALUES('bomb','v',1202,4960)
INSERT INTO WORD_LEMMATISED VALUES('bomber','n',1003,5524)
INSERT INTO WORD_LEMMATISED VALUES('bond','n',3753,2313)
INSERT INTO WORD_LEMMATISED VALUES('bone','n',4665,1955)
INSERT INTO WORD_LEMMATISED VALUES('bonus','n',1364,4569)
INSERT INTO WORD_LEMMATISED VALUES('book','n',37675,252)
INSERT INTO WORD_LEMMATISED VALUES('book','v',1894,3623)
INSERT INTO WORD_LEMMATISED VALUES('booking','n',1391,4510)
INSERT INTO WORD_LEMMATISED VALUES('booklet','n',1210,4946)
INSERT INTO WORD_LEMMATISED VALUES('boom','n',1491,4297)
INSERT INTO WORD_LEMMATISED VALUES('boost','n',978,5603)
INSERT INTO WORD_LEMMATISED VALUES('boost','v',1739,3873)
INSERT INTO WORD_LEMMATISED VALUES('boot','n',3930,2240)
INSERT INTO WORD_LEMMATISED VALUES('border','n',5028,1853)
INSERT INTO WORD_LEMMATISED VALUES('bored','a',1040,5402)
INSERT INTO WORD_LEMMATISED VALUES('boring','a',1531,4217)
INSERT INTO WORD_LEMMATISED VALUES('borough','n',2243,3246)
INSERT INTO WORD_LEMMATISED VALUES('borrow','v',3353,2499)
INSERT INTO WORD_LEMMATISED VALUES('boss','n',3739,2320)
INSERT INTO WORD_LEMMATISED VALUES('both','adv',27644,358)
INSERT INTO WORD_LEMMATISED VALUES('both','det',41162,227)
INSERT INTO WORD_LEMMATISED VALUES('bother','v',4048,2188)
INSERT INTO WORD_LEMMATISED VALUES('bottle','n',5872,1624)
INSERT INTO WORD_LEMMATISED VALUES('bottom','a',2301,3198)
INSERT INTO WORD_LEMMATISED VALUES('bottom','n',5441,1742)
INSERT INTO WORD_LEMMATISED VALUES('bounce','v',977,5608)
INSERT INTO WORD_LEMMATISED VALUES('boundary','n',4416,2036)
INSERT INTO WORD_LEMMATISED VALUES('bourgeois','a',929,5782)
INSERT INTO WORD_LEMMATISED VALUES('bow','n',1357,4585)
INSERT INTO WORD_LEMMATISED VALUES('bow','v',1359,4578)
INSERT INTO WORD_LEMMATISED VALUES('bowel','n',1441,4404)
INSERT INTO WORD_LEMMATISED VALUES('bowl','n',2631,2935)
INSERT INTO WORD_LEMMATISED VALUES('bowl','v',1020,5466)
INSERT INTO WORD_LEMMATISED VALUES('bowler','n',997,5541)
INSERT INTO WORD_LEMMATISED VALUES('box','n',11292,900)
INSERT INTO WORD_LEMMATISED VALUES('boxing','n',902,5872)
INSERT INTO WORD_LEMMATISED VALUES('boy','n',21205,486)
INSERT INTO WORD_LEMMATISED VALUES('boyfriend','n',1285,4735)
INSERT INTO WORD_LEMMATISED VALUES('bracket','n',1017,5474)
INSERT INTO WORD_LEMMATISED VALUES('brain','n',5586,1698)
INSERT INTO WORD_LEMMATISED VALUES('brake','n',974,5619)
INSERT INTO WORD_LEMMATISED VALUES('branch','n',8456,1196)
INSERT INTO WORD_LEMMATISED VALUES('brand','n',1819,3733)
INSERT INTO WORD_LEMMATISED VALUES('brandy','n',959,5675)
INSERT INTO WORD_LEMMATISED VALUES('brass','n',1433,4416)
INSERT INTO WORD_LEMMATISED VALUES('brave','a',1760,3838)
INSERT INTO WORD_LEMMATISED VALUES('breach','n',3407,2474)
INSERT INTO WORD_LEMMATISED VALUES('bread','n',3780,2294)
INSERT INTO WORD_LEMMATISED VALUES('break','n',4271,2099)
INSERT INTO WORD_LEMMATISED VALUES('break','v',19512,532)
INSERT INTO WORD_LEMMATISED VALUES('breakdown','n',1591,4104)
INSERT INTO WORD_LEMMATISED VALUES('breakfast','n',4314,2080)
INSERT INTO WORD_LEMMATISED VALUES('breast','n',2648,2926)
INSERT INTO WORD_LEMMATISED VALUES('breath','n',5347,1768)
INSERT INTO WORD_LEMMATISED VALUES('breathe','v',3372,2492)
INSERT INTO WORD_LEMMATISED VALUES('breed','n',1745,3859)
INSERT INTO WORD_LEMMATISED VALUES('breed','v',1974,3513)
INSERT INTO WORD_LEMMATISED VALUES('breeding','n',1403,4488)
INSERT INTO WORD_LEMMATISED VALUES('breeze','n',1455,4376)
INSERT INTO WORD_LEMMATISED VALUES('brewery','n',1012,5495)
INSERT INTO WORD_LEMMATISED VALUES('brick','n',2675,2911)
INSERT INTO WORD_LEMMATISED VALUES('bride','n',1111,5201)
INSERT INTO WORD_LEMMATISED VALUES('bridge','n',5367,1761)
INSERT INTO WORD_LEMMATISED VALUES('brief','a',4977,1861)
INSERT INTO WORD_LEMMATISED VALUES('briefly','adv',3280,2531)
INSERT INTO WORD_LEMMATISED VALUES('brigade','n',1245,4839)
INSERT INTO WORD_LEMMATISED VALUES('bright','a',6190,1552)
INSERT INTO WORD_LEMMATISED VALUES('brilliant','a',3498,2432)
INSERT INTO WORD_LEMMATISED VALUES('bring','v',43894,211)
INSERT INTO WORD_LEMMATISED VALUES('broad','a',6447,1488)
INSERT INTO WORD_LEMMATISED VALUES('broadcast','n',946,5726)
INSERT INTO WORD_LEMMATISED VALUES('broadcast','v',1116,5185)
INSERT INTO WORD_LEMMATISED VALUES('broadly','adv',1602,4091)
INSERT INTO WORD_LEMMATISED VALUES('brochure','n',1176,5037)
INSERT INTO WORD_LEMMATISED VALUES('broken','a',2479,3027)
INSERT INTO WORD_LEMMATISED VALUES('broker','n',1100,5232)
INSERT INTO WORD_LEMMATISED VALUES('bronze','n',1209,4951)
INSERT INTO WORD_LEMMATISED VALUES('brother','n',11757,864)
INSERT INTO WORD_LEMMATISED VALUES('brow','n',1194,4986)
INSERT INTO WORD_LEMMATISED VALUES('brown','a',4300,2088)
INSERT INTO WORD_LEMMATISED VALUES('brush','n',1686,3941)
INSERT INTO WORD_LEMMATISED VALUES('brush','v',2115,3369)
INSERT INTO WORD_LEMMATISED VALUES('bubble','n',843,6120)
INSERT INTO WORD_LEMMATISED VALUES('bucket','n',1401,4490)
INSERT INTO WORD_LEMMATISED VALUES('budget','n',9311,1078)
INSERT INTO WORD_LEMMATISED VALUES('build','v',23931,418)
INSERT INTO WORD_LEMMATISED VALUES('builder','n',1795,3768)
INSERT INTO WORD_LEMMATISED VALUES('building','n',20770,496)
INSERT INTO WORD_LEMMATISED VALUES('bulb','n',1030,5435)
INSERT INTO WORD_LEMMATISED VALUES('bulk','n',2056,3424)
INSERT INTO WORD_LEMMATISED VALUES('bull','n',1257,4807)
INSERT INTO WORD_LEMMATISED VALUES('bullet','n',1227,4894)
INSERT INTO WORD_LEMMATISED VALUES('bulletin','n',861,6036)
INSERT INTO WORD_LEMMATISED VALUES('bump','v',817,6239)
INSERT INTO WORD_LEMMATISED VALUES('bunch','n',1344,4610)
INSERT INTO WORD_LEMMATISED VALUES('bundle','n',881,5945)
INSERT INTO WORD_LEMMATISED VALUES('burden','n',2988,2710)
INSERT INTO WORD_LEMMATISED VALUES('bureau','n',1636,4028)
INSERT INTO WORD_LEMMATISED VALUES('bureaucracy','n',1509,4256)
INSERT INTO WORD_LEMMATISED VALUES('bureaucratic','a',927,5789)
INSERT INTO WORD_LEMMATISED VALUES('burial','n',1052,5373)
INSERT INTO WORD_LEMMATISED VALUES('burn','n',904,5868)
INSERT INTO WORD_LEMMATISED VALUES('burn','v',5091,1829)
INSERT INTO WORD_LEMMATISED VALUES('burning','a',1252,4813)
INSERT INTO WORD_LEMMATISED VALUES('burst','n',936,5761)
INSERT INTO WORD_LEMMATISED VALUES('burst','v',2476,3030)
INSERT INTO WORD_LEMMATISED VALUES('bury','v',2987,2713)
INSERT INTO WORD_LEMMATISED VALUES('bus','n',6761,1428)
INSERT INTO WORD_LEMMATISED VALUES('bush','n',1933,3567)
INSERT INTO WORD_LEMMATISED VALUES('business','n',38204,244)
INSERT INTO WORD_LEMMATISED VALUES('businessman','n',1895,3621)
INSERT INTO WORD_LEMMATISED VALUES('busy','a',5221,1801)
INSERT INTO WORD_LEMMATISED VALUES('but','conj',459622,23)
INSERT INTO WORD_LEMMATISED VALUES('butter','n',2044,3439)
INSERT INTO WORD_LEMMATISED VALUES('butterfly','n',1136,5132)
INSERT INTO WORD_LEMMATISED VALUES('button','n',2503,3012)
INSERT INTO WORD_LEMMATISED VALUES('buy','v',25582,394)
INSERT INTO WORD_LEMMATISED VALUES('buyer','n',4285,2092)
INSERT INTO WORD_LEMMATISED VALUES('by','adv',2898,2760)
INSERT INTO WORD_LEMMATISED VALUES('by','prep',517171,20)
INSERT INTO WORD_LEMMATISED VALUES('bye','interjecti',1626,4042)
</pre></p>
<p>The following is the spring application configuration file. If you are using mySQL to connect then just comment out the HSQLDB and comment in the mysql Configuration entry.</p>
<p>src/main/resources/applicationContext.xml<br />
<pre class="brush: xml; gutter: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
    xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 
http://www.springframework.org/schema/context
 
http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;&gt;


	&lt;!-- Use the following for the HSQLDB in memory Java database (default) --&gt;
	&lt;bean name=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
	    &lt;property name=&quot;driverClassName&quot; value=&quot;org.hsqldb.jdbcDriver&quot;/&gt;
	    &lt;property name=&quot;url&quot; value=&quot;jdbc:hsqldb:file:src/main/resources/db/liveSearch&quot;/&gt;
	    &lt;property name=&quot;username&quot; value=&quot;sa&quot;/&gt;
	    &lt;property name=&quot;password&quot; value=&quot;&quot;/&gt;
	&lt;/bean&gt;
 
    &lt;!-- uncomment this to use mySQL and comment out the HSQLDB above
	&lt;bean name=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
	    &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt;
	    &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://xxxx:3306/xxxx&quot;/&gt;
	    &lt;property name=&quot;username&quot; value=&quot;xxxx&quot;/&gt;
	    &lt;property name=&quot;password&quot; value=&quot;xxx&quot;/&gt;
	&lt;/bean&gt;
 	--&gt;
	 
	&lt;bean name=&quot;jdbcTemplate&quot; class=&quot;org.springframework.jdbc.core.simple.SimpleJdbcTemplate&quot;&gt;
	    &lt;constructor-arg&gt;&lt;ref bean=&quot;dataSource&quot;/&gt;&lt;/constructor-arg&gt;
	&lt;/bean&gt;
&lt;/beans&gt;
</pre></p>
<h4>Homepage</h4>
<p>The following page presents the user with an extjs combo box that makes ajax calls to the servlet to get search results.</p>
<p>src/main/webapp/index.jsp<br />
<pre class="brush: xml; gutter: false;">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;ComboBox - Live Search&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot;
        href=&quot;http://dev.sencha.com/deploy/ext-3.3.1/resources/css/ext-all.css&quot;/&gt;
 
    &lt;script type=&quot;text/javascript&quot;
        src=&quot;http://dev.sencha.com/deploy/ext-3.3.1/adapter/ext/ext-base-debug.js&quot;&gt;
    &lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;
        src=&quot;http://dev.sencha.com/deploy/ext-3.3.1/ext-all-debug.js&quot;&gt;
    &lt;/script&gt;

	&lt;script type=&quot;text/javascript&quot;&gt;
		Ext.onReady(function(){
		 
			// This reader helps process search result data being 
			// returned after the search.
			var myReader = new Ext.data.JsonReader({
				root: 'records',
				totalProperty: 'totalCount',
				fields: [
				        {name: 'word_x', type: 'string'}
				    ]
			});
		 
			// This represents the URL that returns the search results.
			var myStore = new Ext.data.Store({
				// url : 'response.do' // url: uses POST by default
				proxy: new Ext.data.HttpProxy({  // force it to use GET method
					url:    '/app/searchServlet',
					method: 'GET'
				}),
			    reader : myReader
			});
			// Custom rendering Template
			var resultTpl = new Ext.XTemplate(
				'&lt;tpl for=&quot;.&quot;&gt;&lt;div class=&quot;search-item&quot;&gt;',
				    '&lt;h3&gt;{word_x}&lt;/h3&gt;',
				'&lt;/div&gt;&lt;/tpl&gt;'
			);

			var search = new Ext.form.ComboBox({			
				store: myStore,
				displayField:'title',
				typeAhead: false,
				loadingText: 'Searching...',
				width: 570,
				minChars: 2,
				pageSize:5,
				hideTrigger:true,
				tpl: resultTpl,
				applyTo: 'search',
				itemSelector: 'div.search-item',
				onSelect: function(record){ 
					alert(record.data.word_x + ' was selected...');
					// override default onSelect to do redirect
//				    window.location =
//				        String.format('http://extjs.com/forum/showthread.php?t={0}&amp;p={1}', 
//				        	record.data.topicId, record.id);
				}
			});
		});	
	&lt;/script&gt;

    &lt;style type=&quot;text/css&quot;&gt;
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    &lt;/style&gt;     
&lt;/head&gt;
 
&lt;body&gt;
&lt;p&gt;
    &lt;b&gt;Combo with Templates and Ajax&lt;/b&gt;&lt;br /&gt;
	
	Type any word that begins with the letters &quot;a&quot; or &quot;b&quot;. for example &quot;ab&quot;, &quot;be&quot; ...
	
&lt;/p&gt;

&lt;!-- The box wrap markup embedded instead of using Element.boxWrap() --&gt;
&lt;div style=&quot;width:600px;&quot;&gt;
    &lt;div class=&quot;x-box-tl&quot;&gt;&lt;div class=&quot;x-box-tr&quot;&gt;&lt;div class=&quot;x-box-tc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
    &lt;div class=&quot;x-box-ml&quot;&gt;&lt;div class=&quot;x-box-mr&quot;&gt;&lt;div class=&quot;x-box-mc&quot;&gt;
        &lt;h3 style=&quot;margin-bottom:5px;&quot;&gt;Search the Ext Forums&lt;/h3&gt;
        &lt;input type=&quot;text&quot; size=&quot;40&quot; name=&quot;search&quot; id=&quot;search&quot; /&gt;
        &lt;div style=&quot;padding-top:4px;&quot;&gt;
            Live search requires a minimum of 2 characters.
        &lt;/div&gt;
 
    &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
    &lt;div class=&quot;x-box-bl&quot;&gt;&lt;div class=&quot;x-box-br&quot;&gt;&lt;div class=&quot;x-box-bc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<h4>Test the application</h4>
<p>To test the application we will start the jetty servlet engine.</p>
<p><pre class="brush: bash; gutter: false;">
mvn clean compile jetty:run
</pre></p>
<p>Navigate to the page and start typing. Search results should start to show.</p>
<p>http://localhost:8080/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/4786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/numberformat.wordpress.com/4786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/numberformat.wordpress.com/4786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/numberformat.wordpress.com/4786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/numberformat.wordpress.com/4786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/numberformat.wordpress.com/4786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/numberformat.wordpress.com/4786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/numberformat.wordpress.com/4786/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&amp;blog=7605784&amp;post=4786&amp;subd=numberformat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2011/07/24/live-search-functionality-using-extjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
	</channel>
</rss>
