<?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/"
	>

<channel>
	<title>We Heart Code</title>
	<atom:link href="http://www.weheartcode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weheartcode.com</link>
	<description>A discourse on programming</description>
	<lastBuildDate>Sun, 17 Jan 2010 02:16:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oracle Delete Taking a Long Time</title>
		<link>http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/</link>
		<comments>http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 02:16:15 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/?p=62</guid>
		<description><![CDATA[ It may look like your delete statement is hung, but ff your table has foreign keys in another table without indexes on that column Oracle will full table scan that other table for every row that you&#8217;re deleting. Hopefully this saves someone some time.
Bookmark to:
]]></description>
			<content:encoded><![CDATA[<p> It may look like your delete statement is hung, but ff your table has foreign keys in another table without indexes on that column Oracle will full table scan that other table for every row that you&#8217;re deleting. Hopefully this saves someone some time.</p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/&amp;title=Oracle+Delete+Taking+a+Long+Time" title="Add 'Oracle Delete Taking a Long Time' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Oracle Delete Taking a Long Time' to Del.icio.us" alt="Add 'Oracle Delete Taking a Long Time' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/&amp;title=Oracle+Delete+Taking+a+Long+Time" title="Add 'Oracle Delete Taking a Long Time' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Oracle Delete Taking a Long Time' to digg" alt="Add 'Oracle Delete Taking a Long Time' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Oracle+Delete+Taking+a+Long+Time&amp;u=http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/" title="Add 'Oracle Delete Taking a Long Time' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Oracle Delete Taking a Long Time' to FURL" alt="Add 'Oracle Delete Taking a Long Time' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/&amp;title=Oracle+Delete+Taking+a+Long+Time" title="Add 'Oracle Delete Taking a Long Time' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Oracle Delete Taking a Long Time' to reddit" alt="Add 'Oracle Delete Taking a Long Time' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/" title="Add 'Oracle Delete Taking a Long Time' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Oracle Delete Taking a Long Time' to Technorati" alt="Add 'Oracle Delete Taking a Long Time' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/&amp;title=Oracle+Delete+Taking+a+Long+Time" title="Add 'Oracle Delete Taking a Long Time' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Oracle Delete Taking a Long Time' to Google Bookmarks" alt="Add 'Oracle Delete Taking a Long Time' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2010/01/16/oracle-delete-taking-a-long-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Luhn Digit Generation Oracle PL/SQL Implementation</title>
		<link>http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/</link>
		<comments>http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 11:27:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/?p=51</guid>
		<description><![CDATA[Here's how to generate a Luhn Mod-10 Check Digit. It's implemented as a function in oracle PL/SQL. I spent 2 hours looking for this online, then decided to implement it myself since it's not that hard. Anyway, I thought I'd post it here for the next person trolling google for it. This is useful for [...]]]></description>
			<content:encoded><![CDATA[<p>Here's how to generate a Luhn Mod-10 Check Digit. It's implemented as a function in oracle PL/SQL. I spent 2 hours looking for this online, then decided to implement it myself since it's not that hard. Anyway, I thought I'd post it here for the next person trolling google for it. This is useful for generating credit card numbers or any other place you need a check digit.</p>
<p>This algorithm works by doing the same thing as the validation algorithm, but shifted over one character (the equivalent of adding a zero to a number, generating the sum &#038; subtracting 10).</p>
<p><strong>*EDIT - there was a bug in this code, i just fixed it on 12/4/2009, the old code returned 10 instead of zero. It also was only working on even numbers, sorry about that! </strong></p>
<div class="syntax_hilite">
<div id="sql-2">
<div class="sql"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> generate_luhn <span style="color:#006600; font-weight:bold;">&#40;</span>togen <span style="color: #993333; font-weight: bold;">IN</span> varchar<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">RETURN</span> number<br />
<span style="color: #993333; font-weight: bold;">IS</span><br />
&nbsp; &nbsp; curval NUMBER := <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; total NUMBER := <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; everyother NUMBER := <span style="color: #cc66cc;">1</span>;</p>
<p>BEGIN<br />
&nbsp; <span style="color: #993333; font-weight: bold;">IF</span><span style="color:#006600; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp;togen <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#41;</span> then<br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">0</span>;<br />
&nbsp; end <span style="color: #993333; font-weight: bold;">IF</span>;</p>
<p>&nbsp; <br />
&nbsp; <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> reverse <span style="color: #cc66cc;">1</span> .. LENGTH<span style="color:#006600; font-weight:bold;">&#40;</span>togen<span style="color:#006600; font-weight:bold;">&#41;</span> loop<br />
&nbsp; &nbsp; curval:=SUBSTR<span style="color:#006600; font-weight:bold;">&#40;</span>togen, i, <span style="color: #cc66cc;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span> everyother = <span style="color: #cc66cc;">1</span> then<br />
&nbsp; &nbsp; &nbsp; &nbsp;everyother := <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; curval := curval * <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span><span style="color:#006600; font-weight:bold;">&#40;</span>curval&gt; <span style="color: #cc66cc;">9</span><span style="color:#006600; font-weight:bold;">&#41;</span> then<br />
&nbsp; &nbsp; &nbsp; &nbsp; curval:=curval-<span style="color: #cc66cc;">9</span>;<br />
&nbsp; &nbsp; &nbsp; end <span style="color: #993333; font-weight: bold;">IF</span>;<br />
&nbsp; &nbsp; &nbsp;else<br />
&nbsp; &nbsp; &nbsp; &nbsp;everyother := <span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp; end <span style="color: #993333; font-weight: bold;">IF</span>;</p>
<p>&nbsp; &nbsp;<br />
&nbsp; &nbsp; total := total + curval;<br />
&nbsp; end loop;<br />
&nbsp; <span style="color: #993333; font-weight: bold;">IF</span> MOD<span style="color:#006600; font-weight:bold;">&#40;</span>total, <span style="color: #cc66cc;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> = <span style="color: #cc66cc;">0</span> THEN<br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; ELSE<br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">10</span> - MOD<span style="color:#006600; font-weight:bold;">&#40;</span>total, <span style="color: #cc66cc;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; END <span style="color: #993333; font-weight: bold;">IF</span>;<br />
END generate_luhn;<br />
/</div>
</div>
</div>
<p></p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/&amp;title=Luhn+Digit+Generation+Oracle+PL%2FSQL+Implementation" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Del.icio.us" alt="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/&amp;title=Luhn+Digit+Generation+Oracle+PL%2FSQL+Implementation" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to digg" alt="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Luhn+Digit+Generation+Oracle+PL%2FSQL+Implementation&amp;u=http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to FURL" alt="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/&amp;title=Luhn+Digit+Generation+Oracle+PL%2FSQL+Implementation" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to reddit" alt="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Technorati" alt="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/&amp;title=Luhn+Digit+Generation+Oracle+PL%2FSQL+Implementation" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Google Bookmarks" alt="Add 'Luhn Digit Generation Oracle PL/SQL Implementation' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2009/10/06/luhn-digit-generation-oracle-plsql-implementation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Capturing Uncaught Java Exceptions in a Bash Shell Script</title>
		<link>http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/</link>
		<comments>http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/#comments</comments>
		<pubDate>Wed, 13 May 2009 16:53:28 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/</guid>
		<description><![CDATA[I was burned one to many times by chaining dependent java programs together in a bash script.
By default the java executable will return zero if the program exited manually, and 1 if there was an uncaught RuntimeException.
Let's say test.sh runs a java program, we want to run it 3 times, but if it fails during [...]]]></description>
			<content:encoded><![CDATA[<p>I was burned one to many times by chaining dependent java programs together in a bash script.</p>
<p>By default the java executable will return zero if the program exited manually, and 1 if there was an uncaught RuntimeException.</p>
<p>Let's say test.sh runs a java program, we want to run it 3 times, but if it fails during any of the runs we want to abort our run.</p>
<div class="syntax_hilite">
<div id="code-6">
<div class="code">#!/usr/bin/bash<br />
java Test<br />
exitval=$?<br />
echo <span style="color:#CC0000;">"exit val: ${exitval}"</span><br />
exit $exitval</div>
</div>
</div>
<p></p>
<p>Then in our shell script to run test.sh each time we'd do something like this.</p>
<div class="syntax_hilite">
<div id="code-7">
<div class="code">#!/usr/bin/bash</p>
<p>./test.<span style="">sh</span><br />
step1=$?</p>
<p>if <span style="color:#006600; font-weight:bold;">&#91;</span> $step1 -eq <span style="color:#CC0000;">"0"</span> <span style="color:#006600; font-weight:bold;">&#93;</span> ; then<br />
&nbsp; ./test.<span style="">sh</span><br />
&nbsp; step2=$?<br />
&nbsp; if <span style="color:#006600; font-weight:bold;">&#91;</span> $step2 -eq <span style="color:#CC0000;">"0"</span> <span style="color:#006600; font-weight:bold;">&#93;</span> ; then<br />
&nbsp; &nbsp; ./test.<span style="">sh</span><br />
&nbsp; &nbsp; step3=$?<br />
&nbsp; &nbsp; if <span style="color:#006600; font-weight:bold;">&#91;</span> $step3 -eq <span style="color:#CC0000;">"0"</span> <span style="color:#006600; font-weight:bold;">&#93;</span> ; then<br />
&nbsp; &nbsp; &nbsp; echo <span style="color:#CC0000;">"Finished successfully."</span><br />
&nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp;echo <span style="color:#CC0000;">"Step 3 failed."</span><br />
&nbsp; &nbsp; fi<br />
&nbsp; else<br />
&nbsp; &nbsp; echo <span style="color:#CC0000;">"Step 2 failed with ${step2}"</span><br />
&nbsp; fi<br />
else<br />
&nbsp; echo <span style="color:#CC0000;">"Step 1 Failed. with ${step1}"</span><br />
fi</div>
</div>
</div>
<p></p>
<p>To test my script I made a little java class that will error out half the time that looks like this:</p>
<div class="syntax_hilite">
<div id="java-8">
<div class="java"><span style="color: #a1a100;">import java.util.Random;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test<br />
<span style="color: #66cc66;">&#123;</span></p>
<p><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
<a href="http://www.google.com/search?q=allinurl%3ARandom+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Random</span></a> gen = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ARandom+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Random</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>gen.<span style="color: #006600;">nextInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>&gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
<a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"I Win!"</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #b1b100;">else</span><br />
<span style="color: #66cc66;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ARuntimeException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">RuntimeException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"I Fail!"</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/&amp;title=Capturing+Uncaught+Java+Exceptions+in+a+Bash+Shell+Script" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Del.icio.us" alt="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/&amp;title=Capturing+Uncaught+Java+Exceptions+in+a+Bash+Shell+Script" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to digg" alt="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Capturing+Uncaught+Java+Exceptions+in+a+Bash+Shell+Script&amp;u=http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to FURL" alt="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/&amp;title=Capturing+Uncaught+Java+Exceptions+in+a+Bash+Shell+Script" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to reddit" alt="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Technorati" alt="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/&amp;title=Capturing+Uncaught+Java+Exceptions+in+a+Bash+Shell+Script" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Google Bookmarks" alt="Add 'Capturing Uncaught Java Exceptions in a Bash Shell Script' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2009/05/13/capturing-uncaught-java-exceptions-in-a-bash-shell-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mylyn + Trac + wsgi</title>
		<link>http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/</link>
		<comments>http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 13:16:22 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/</guid>
		<description><![CDATA[I am using mod_wsgi instead of mod_python for my trac .11 install.
I'm also using the AccountManager plugin for authentication, and don't have anonymous access setup.
Anyway, authentication wasn't working (through XML RPC) hence mylyn didn't have the perms to do anything, and was silently defaulting to anon mode. even though I had the XML RPC plugin [...]]]></description>
			<content:encoded><![CDATA[<p>I am using mod_wsgi instead of mod_python for my trac .11 install.</p>
<p>I'm also using the AccountManager plugin for authentication, and don't have anonymous access setup.</p>
<p>Anyway, authentication wasn't working (through XML RPC) hence mylyn didn't have the perms to do anything, and was silently defaulting to anon mode. even though I had the XML RPC plugin installed and permissions set up.</p>
<p>Here's the steps to get them all playing nice (this was harder than it looked to figure out):</p>
<ol>
<li>Install/Enable the <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">XML RPC Plugin</a> for trac</li>
<li>Give your authenticated group the XML_RPC permission</li>
<li>Install/Enable the <a href="http://trac-hacks.org/wiki/HttpAuthPlugin">HttpAuth Plugin</a></li>
<li>Add this line to your apache config for your site: WSGIPassAuthorization On</li>
</ol>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/&amp;title=Mylyn+%2B+Trac+%2B+wsgi" title="Add 'Mylyn + Trac + wsgi' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Mylyn + Trac + wsgi' to Del.icio.us" alt="Add 'Mylyn + Trac + wsgi' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/&amp;title=Mylyn+%2B+Trac+%2B+wsgi" title="Add 'Mylyn + Trac + wsgi' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Mylyn + Trac + wsgi' to digg" alt="Add 'Mylyn + Trac + wsgi' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Mylyn+%2B+Trac+%2B+wsgi&amp;u=http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/" title="Add 'Mylyn + Trac + wsgi' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Mylyn + Trac + wsgi' to FURL" alt="Add 'Mylyn + Trac + wsgi' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/&amp;title=Mylyn+%2B+Trac+%2B+wsgi" title="Add 'Mylyn + Trac + wsgi' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Mylyn + Trac + wsgi' to reddit" alt="Add 'Mylyn + Trac + wsgi' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/" title="Add 'Mylyn + Trac + wsgi' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Mylyn + Trac + wsgi' to Technorati" alt="Add 'Mylyn + Trac + wsgi' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/&amp;title=Mylyn+%2B+Trac+%2B+wsgi" title="Add 'Mylyn + Trac + wsgi' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Mylyn + Trac + wsgi' to Google Bookmarks" alt="Add 'Mylyn + Trac + wsgi' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2009/02/19/mylyn-trac-wsgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily Creating Fixed Length Flat Files With Groovy</title>
		<link>http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/</link>
		<comments>http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 13:42:27 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/</guid>
		<description><![CDATA[Here's an (I think elegant) way to create flat files with Groovy.
I want this script to be easy to read by future developers. So if someone wants to know what the format of the file is they can see it just by opening the script.
Classes We'll Use
Groovy:

SQL: We'll use this library to access the database, [...]]]></description>
			<content:encoded><![CDATA[<p>Here's an (I think elegant) way to create flat files with Groovy.</p>
<p>I want this script to be easy to read by future developers. So if someone wants to know what the format of the file is they can see it just by opening the script.</p>
<h2>Classes We'll Use</h2>
<p>Groovy:</p>
<ul>
<li><a href="http://docs.codehaus.org/display/GROOVY/Tutorial+6+-+Groovy+SQL">SQL</a>: We'll use this library to access the database, it has some nice closure methods like eachRow which make iterating over results easy.</li>
<li><a href="http://groovy.codehaus.org/groovy-jdk/java/lang/String.html">String</a>: Groovy includes a string class that has some nice methods like padRight and padLeft, handy for making fixed length files.</li>
</ul>
<p>Java:</p>
<ul>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileWriter.html">File Writer</a>: The easiest way to create files in java.</li>
</ul>
<h2>The Plan</h2>
<p>Define our file in a map at the top of the file, it will be SQL Alias Name : Length.</p>
<p>Execute our SQL, for each row iterate through our file definition map and pad each value by the appropriate length.</p>
<h2>The Code</h2>
<p>Pretty self explanatory -- a few neat groovy things we use in this script:</p>
<ul>
<li>Triple quotes for a multiline string (our sql)</li>
<li>The format method to easily format a date (bye bye simple date format) for the file name</li>
<li>The elvis operator <code>?:</code> makes the results null safe so we can call padRight.</li>
<li>The each method on Groovy's Map that accepts a closure, we use that to iterate through our file definition.</li>
</ul>
<div class="syntax_hilite">
<div id="java-10">
<div class="java"><span style="color: #a1a100;">import groovy.sql.Sql</span></p>
<p><span style="color: #a1a100;">import java.io.File;</span><br />
<span style="color: #a1a100;">import java.io.FileWriter;</span></p>
<p>&nbsp; &nbsp; def fileName = <span style="color: #ff0000;">"FLATFILE"</span> + <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a>.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'%tY%&lt;tm%&lt;td'</span>,<span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ADate+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">".txt"</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; def sql = Sql.<span style="color: #006600;">newInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"jdbc:oracle:thin:@localhost:1521:midb01"</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"xxx"</span>,<span style="color: #ff0000;">"xxx"</span>, <span style="color: #808080; font-style: italic;">//user,pass</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"oracle.jdbc.driver.OracleDriver"</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">//jdbc driver</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AFileWriter+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">FileWriter</span></a> writer = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AFileWriter+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">FileWriter</span></a><span style="color: #66cc66;">&#40;</span>fileName<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//this map defines the field length based on alias id from the SQL</span><br />
&nbsp; &nbsp; def fileDef = <span style="color: #66cc66;">&#91;</span>COLUMN1:<span style="color: #cc66cc;">14</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; COLUMN2:<span style="color: #cc66cc;">9</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; COLUMN3:<span style="color: #cc66cc;">5</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; COLUMN4:<span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; def qry = <span style="color: #ff0000;">""</span><span style="color: #ff0000;">"SELECT column1,column2,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column3,column4 FROM OurTable"</span><span style="color: #ff0000;">""</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; def test = sql.<span style="color: #006600;">eachRow</span><span style="color: #66cc66;">&#40;</span>qry<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>row -&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; fileDef.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#123;</span> k,v-&gt; writer.<span style="color: #006600;">append</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>row<span style="color: #66cc66;">&#91;</span>k<span style="color: #66cc66;">&#93;</span> ?: <span style="color: #ff0000;">" "</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">padRight</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006600;">append</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; writer.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</div>
</div>
<p></p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/&amp;title=Easily+Creating+Fixed+Length+Flat+Files+With+Groovy" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Del.icio.us" alt="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/&amp;title=Easily+Creating+Fixed+Length+Flat+Files+With+Groovy" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to digg" alt="Add 'Easily Creating Fixed Length Flat Files With Groovy' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Easily+Creating+Fixed+Length+Flat+Files+With+Groovy&amp;u=http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to FURL" alt="Add 'Easily Creating Fixed Length Flat Files With Groovy' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/&amp;title=Easily+Creating+Fixed+Length+Flat+Files+With+Groovy" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to reddit" alt="Add 'Easily Creating Fixed Length Flat Files With Groovy' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Technorati" alt="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/&amp;title=Easily+Creating+Fixed+Length+Flat+Files+With+Groovy" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Google Bookmarks" alt="Add 'Easily Creating Fixed Length Flat Files With Groovy' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2009/01/21/easily-creating-fixed-length-flat-files-with-groovy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing Portable Groovy Scripts with A Magic Runnable Jar</title>
		<link>http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/</link>
		<comments>http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 14:24:57 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/</guid>
		<description><![CDATA[I've found myself using Java as a "scripting" language lately due to the necessity of working in mixed *nix and windows environments where I can't count on a standard scripting language being installed like python,perl, or ruby. What's more I either don't have the rights to install a binary of said scripting languages or don't [...]]]></description>
			<content:encoded><![CDATA[<p>I've found myself using Java as a "scripting" language lately due to the necessity of working in mixed *nix and windows environments where I can't count on a standard scripting language being installed like python,perl, or ruby. What's more I either don't have the rights to install a binary of said scripting languages or don't want to go through the bureaucracy to request the installation.</p>
<p>The benefits of using Java in these environments is I can package my program as a Runnable Jar easily through Eclipse's Export functionality. I also have a wonderful wealth of libraries for doing almost anything I want -- from FTP libraries, to any Database driver I can dream of. Anyone who's had to deal with the freetds library in perl to connect to a MS SQL database knows what a huge boon being able to use JDBC is.</p>
<p>The cons of using Java is my code is not as terse as it could be, and for common scripting tasks like reading and writing files and database records a simple task now becomes tons of boiler plate exception handling and JDBC calls. I also have to re-compile and re-package my entire program if I want to make a simple change.</p>
<p>What if we could harness the power of any Java Library we wanted, no hassle deployment, but marry the simplicity of a scripting language and flexibility of an interpreted language? </p>
<h2>Enter Groovy</h2>
<p><span id="more-47"></span></p>
<p>Hello world in groovy:</p>
<div class="syntax_hilite">
<div id="java-15">
<div class="java">println <span style="color: #ff0000;">"Hello, I'm a portable Groovy Script!"</span></div>
</div>
</div>
<p></p>
<p>Iterating over an oracle record set in Groovy:</p>
<div class="syntax_hilite">
<div id="java-16">
<div class="java"><span style="color: #a1a100;">import groovy.sql.Sql</span></p>
<p>
def sql = Sql.<span style="color: #006600;">newInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"jdbc:oracle:thin:@localhost:1521:MYSID"</span>,<span style="color: #ff0000;">"xxx"</span>,<span style="color: #ff0000;">"xxx"</span>,<span style="color: #ff0000;">"oracle.jdbc.driver.OracleDriver"</span><span style="color: #66cc66;">&#41;</span></p>
<p>sql.<span style="color: #006600;">eachRow</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Select * from employees"</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> employee-&gt;<br />
println employee<br />
<span style="color: #66cc66;">&#125;</span></p>
<p>sql.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</div>
</div>
<p></p>
<p>I don't want to go into the groovy language, that's another topic, but I think it's obvious that for simple tasks Groovy is superior to Java.</p>
<p>There are many ways to <a href="http://groovy.codehaus.org/Running">Run Groovy Scripts</a>. However, I want a way to run a script without having to install the Groovy Runtime.</p>
<p>Ideal situation:</p>
<ul>
<li>Develop Groovy script in Eclipse</li>
<li>Export Groovy Runtime as Runnable Jar from Eclipse Project</li>
<li>Upload Runnable Jar and Groovy Script to Any Server with a JRE</li>
<li>Run runnable jar server, by specifying path to groovy script</li>
</ul>
<p>This gives me the flexibility of being able to use my favorite IDE, and easily run <em>and change</em> my script on any other machine with a JRE.</p>
<p>If you'd like you can also download the finished <a href="http://www.weheartcode.com/GroovyLauncher.zip">GroovyLauncher</a> eclipse project.</p>
<p><strong>Developing Groovy Scripts in Eclipse</strong><br />
You'll should have a recent version of Eclipse and the <a href="http://groovy.codehaus.org/Eclipse+Plugin">Groovy Plugin</a>.  To create a new project, simply start a new Java Project, then create a new Groovy Class to add any classes/scripts you want to your project. It's important that you add one groovy script to this project even if it's just a simple hello world script, that will prompt Eclipse to add the Groovy Libraries jars to the build path of your project.</p>
<p>Now to run a groovy script in eclipse you just right click on the .groovy file and do "Run as Groovy Script", done and done. However, in order to run our script from a runnable jar we are going to need a Java Class with a Main method. </p>
<p><strong>Launching A Groovy Script with the Groovy Shell</strong></p>
<p>The <a href="http://groovy.codehaus.org/api/groovy/lang/GroovyShell.html">GroovyShell</a> class is a handy Java Class that can run any Groovy Script passed into it's Main method. We're going to wrap this  class in our own Main class called GroovyLauncher.</p>
<p>So I just make a new Java Class called GroovyLauncher and tell eclipse to create a main method for it.</p>
<p>The class looks like this:</p>
<div class="syntax_hilite">
<div id="java-17">
<div class="java"><span style="color: #a1a100;">import groovy.lang.GroovyShell;</span></p>
<p><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GroovyLauncher <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GroovyShell.<span style="color: #006600;">main</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So this class will be the Main Class we tell Eclipse to use when creating an exportable jar. This class does nothing inside of eclipse, because it expects the path to a groovy script to be passed into it from the command line. We'll only use this Main class when launching from our deployed location. </p>
<p>In order to create a Runnable Jar from an Eclipse Project we need to create a LaunchConfiguration, the quickest way to do that is just to right click on our GroovyLauncher class and do Run as Java Application. When run it will display some GroovyShell error messages because we didn't pass in any arguments. That's fine, we just want Eclilpse to create a default Launch Configuration for the class.</p>
<p>Now right click on your project and select "Export" in the next dialog choose Runnable Jar.</p>
<p>In the next dialog we need to select the Launch Configuration to use (this is the Main class that the Jar will use when run).</p>
<p><img src="http://content.screencast.com/users/lil-dice/folders/Jing/media/ee0701e8-163f-48d2-8b38-ec692e39ef11/2009-01-14_0910.png" alt="Export Dialog" /></p>
<p>Pull down the drop down and you should see your GroovyLauncher Run Configuration that was created automatically by Eclipse when we tried to run our GroovyLauncher class.</p>
<p>Now just specify the file name for the jar and we're done. What eclipse does during the next step is repackage all the classes from your Build Path into one single jar file. So if we included mysql jdbc drivers in our build path, they'd be repackaged into our own jar. This is a legal gray area, but it's damn cool and simple. We don't have to worry about classpaths anymore when we launch our jar! We just run it with "java -jar filename.jar"</p>
<p>So now to test our GroovyLauncher jar we can run it on our machine or another by running:</p>
<div class="syntax_hilite">
<div id="code-18">
<div class="code">java -jar GroovyLauncher.<span style="">jar</span> ourscript.<span style="">groovy</span></div>
</div>
</div>
<p></p>
<p>Now we can pass in ANY groovy script we want using this same launcher jar, it can reference any Java class that was in our BuildPath of our eclipse project. If you didn't add anything other than the Groovy Libraries you'll just have access to the core Groovy Libraries + the Java API's, if you want to be able to do SQL and other fun stuff you'll need to add the appropriate jars to your Eclipse Project just like normal.</p>
<p><strong>Conclusion</strong><br />
You might make a couple different Runnable Jars based on different needs. You could create a project that just included the Groovy Libraries and the GroovyLauncher class and maybe export that as GroovyLauncherLight.jar and make another project that has your favorite JDBC drivers plus any other common libraries and export that project as GroovyLauncherFull.jar</p>
<p>A word of warning, I haven't benchmarked using the GroovyShell versus the GroovyLauncher, however most of your swiss army type scripts don't need to be blazing fast, they just need to be easily changed and easy to run.</p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/&amp;title=Writing+Portable+Groovy+Scripts+with+A+Magic+Runnable+Jar" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Del.icio.us" alt="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/&amp;title=Writing+Portable+Groovy+Scripts+with+A+Magic+Runnable+Jar" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to digg" alt="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Writing+Portable+Groovy+Scripts+with+A+Magic+Runnable+Jar&amp;u=http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to FURL" alt="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/&amp;title=Writing+Portable+Groovy+Scripts+with+A+Magic+Runnable+Jar" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to reddit" alt="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Technorati" alt="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/&amp;title=Writing+Portable+Groovy+Scripts+with+A+Magic+Runnable+Jar" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Google Bookmarks" alt="Add 'Writing Portable Groovy Scripts with A Magic Runnable Jar' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2009/01/14/writing-portable-groovy-scripts-with-a-magic-runnable-jar/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Regular Expression to Replace System.out.println with Log4j</title>
		<link>http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/</link>
		<comments>http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 14:32:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/</guid>
		<description><![CDATA[This is nothing fancy, but may help some of you log4j newbies.
I found myself replacing a project's hideous System.out.println statements with log4j log calls.
Just do a File Search in eclipse , tick the regular expression box and do a Replace:


Find: System\.out\.println\&#40;"(.+?)"\&#41;;
Replace: log.info&#40;"\1"&#41;;



Now you just have to go in and add your imports and your log [...]]]></description>
			<content:encoded><![CDATA[<p>This is nothing fancy, but may help some of you log4j newbies.</p>
<p>I found myself replacing a project's hideous System.out.println statements with log4j log calls.</p>
<p>Just do a File Search in eclipse , tick the regular expression box and do a Replace:</p>
<div class="syntax_hilite">
<div id="code-20">
<div class="code">Find: System\.<span style="">out</span>\.<span style="">println</span>\<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"(.+?)"</span>\<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
Replace: log.<span style="">info</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\1</span>"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>Now you just have to go in and add your imports and your log field variable to your classes.</p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/&amp;title=Regular+Expression+to+Replace+System.out.println+with+Log4j" title="Add 'Regular Expression to Replace System.out.println with Log4j' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Regular Expression to Replace System.out.println with Log4j' to Del.icio.us" alt="Add 'Regular Expression to Replace System.out.println with Log4j' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/&amp;title=Regular+Expression+to+Replace+System.out.println+with+Log4j" title="Add 'Regular Expression to Replace System.out.println with Log4j' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Regular Expression to Replace System.out.println with Log4j' to digg" alt="Add 'Regular Expression to Replace System.out.println with Log4j' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Regular+Expression+to+Replace+System.out.println+with+Log4j&amp;u=http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/" title="Add 'Regular Expression to Replace System.out.println with Log4j' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Regular Expression to Replace System.out.println with Log4j' to FURL" alt="Add 'Regular Expression to Replace System.out.println with Log4j' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/&amp;title=Regular+Expression+to+Replace+System.out.println+with+Log4j" title="Add 'Regular Expression to Replace System.out.println with Log4j' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Regular Expression to Replace System.out.println with Log4j' to reddit" alt="Add 'Regular Expression to Replace System.out.println with Log4j' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/" title="Add 'Regular Expression to Replace System.out.println with Log4j' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Regular Expression to Replace System.out.println with Log4j' to Technorati" alt="Add 'Regular Expression to Replace System.out.println with Log4j' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/&amp;title=Regular+Expression+to+Replace+System.out.println+with+Log4j" title="Add 'Regular Expression to Replace System.out.println with Log4j' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Regular Expression to Replace System.out.println with Log4j' to Google Bookmarks" alt="Add 'Regular Expression to Replace System.out.println with Log4j' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2008/12/29/regular-expression-to-replace-systemoutprintln-with-log4j/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reusing Annotation Based Controllers in Spring MVC</title>
		<link>http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/</link>
		<comments>http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 17:36:52 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[j2ee]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/</guid>
		<description><![CDATA[I was a late comer to the wonderful world of Spring. Seeing that I hate XML, I am very keen on using annotations everywhere! Everything I read said that using annotation based controllers wasn't a good idea because they were hard to re-use due to their very fluid rules for method signatures.
The first thing I [...]]]></description>
			<content:encoded><![CDATA[<p>I was a late comer to the wonderful world of <a href="http://springframework.org/">Spring</a>. Seeing that I hate XML, I am very keen on using annotations everywhere! Everything I read said that using annotation based controllers wasn't a good idea because they were hard to re-use due to their very fluid rules for method signatures.</p>
<p>The first thing I did in <a href="http://static.springframework.org/spring/docs/2.0.x/reference/mvc.html">Spring MVC</a> was to write the perennial CRUD application. After I was done the code was fairly clean but still contained plenty of boilerplate java code. So I wanted to make it generic so I could churn out CRUD's for maintenance tables.</p>
<p>Goals:</p>
<ol>
<li>Only write code that's specific to the Entity I am dealing with in the controller.</li>
<li>Make use of &lt;Generics&gt; so I don't have to cast stuff like a caveman from 1997.</li>
<li>Have spring figure out URI mapping based on controller names.</li>
<li>Write <strong>zero</strong> bean specific xml.</li>
</ol>
<p><span id="more-45"></span><br />
Anotomy of a CRUD Controller.<br />
Your classic CRUD (Create Update Delete) Controller works with one domain type and needs to do a few things:</p>
<ol>
<li>List items</li>
<li>Create items</li>
<li>Update items</li>
<li>Delete items</li>
</ol>
<p>As far as controller methods go, you'll generally need to do a few things:</p>
<ul>
<li>Set up your backing domain object for your form on creations and edits</li>
<li>Validate and save results from the form on submission.</li>
<li>List items from your data store.</li>
</ul>
<h3>The Old Way</h3>
<p>Let's look at how we'd accomplish <em>listing </em>items with Spring MVC.</p>
<div class="syntax_hilite">
<div id="java-35">
<div class="java">@RequestMapping<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"/employee/list"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ModelMap list<span style="color: #66cc66;">&#40;</span>ModelMap model<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; model.<span style="color: #006600;">addAttribute</span><span style="color: #66cc66;">&#40;</span>dao.<span style="color: #006600;">selectAll</span><span style="color: #66cc66;">&#40;</span>Employee.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> model;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So this method uses my dao to run a query. (Your DAO Service implementation will be different depending on how you access your database.)</p>
<p>It then takes the results of that query and throws it in the ModelMap. Recall the ModelMap is smart and will come up with the correct attribute name. So if selectAll returns a List of Employees it will be added to the model as employeeList. Great. Now we use the @RequestMapping annotation to set our URL mapping to employee/list.</p>
<h3>The New Way</h3>
<p>Let's look at how we could make this list method generic. We've got two things that explicitly reference our Employee domain object. The URL mapping and the .class we pass to our DAO service.</p>
<p><b>Solving the URL problem</b><br />
If we define a generic list method in our abstract controller one option for configuring the specific url in the extending class would be something like this.</p>
<div class="syntax_hilite">
<div id="java-36">
<div class="java">@RequestMapping<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"department/list"</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> ModelMap list<span style="color: #66cc66;">&#40;</span>ModelMap map<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
super<span style="color: #66cc66;">&#40;</span>map<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>I don't like this method, it assumes the person implementing the super class will know that they must override the list method just to set a request mapping.  A better method would be if Spring was able to infer the URL map from the implementing controller's class name. ControllerClassNameHandlerMapping to the rescue!</p>
<p>Spring's ControllerClassNameHandlerMapping will take a controller's class name and map it to a URL. I like to mix this with the SimpleUrlHandlerMapping to map views the same way.</p>
<p>Here's how I configure these beans:</p>
<div class="syntax_hilite">
<div id="xml-37">
<div class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"order"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"defaultHandler"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If no @Controller match, map path to a view to render; e.g. the<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;/intro&quot; path would map to the view named &quot;intro&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"org.springframework.web.servlet.mvc.UrlFilenameViewController"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Maps all other request URLs to views --&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"urlMapping"</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"defaultHandler"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Selects view names to render based on the request URI: e.g. /index<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selects &quot;index&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"org.springframework.web.servlet.mvc.UrlFilenameViewController"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"order"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"2"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</div>
</div>
<p></p>
<p>So what all this means is that if someone requests: /department/list it will automatically map to a Controller called DepartmentController and the @RequestMapping annotated method called list. There's no need to define a URL mapping in our @RequestMapping annotation, we'll just define a request type instead.</p>
<h3>Dynamic entity/domain class</h3>
<p>There are many ways we can take care of the problem. The coolest way is to use some neat <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208860">reflection tricks</a> like so:</p>
<div class="syntax_hilite">
<div id="java-38">
<div class="java">@SuppressWarnings<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"unchecked"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> Class&lt;T&gt; getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>Class&lt;T&gt;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>ParameterizedType<span style="color: #66cc66;">&#41;</span> getClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getGenericSuperclass</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getActualTypeArguments</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So now we have a generic list method:</p>
<div class="syntax_hilite">
<div id="java-39">
<div class="java">@RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">GET</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ModelMap list<span style="color: #66cc66;">&#40;</span>ModelMap model<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; model.<span style="color: #006600;">addAttribute</span><span style="color: #66cc66;">&#40;</span>dao.<span style="color: #006600;">selectAll</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> model;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<h3>Creating/Updating</h3>
<p>The normal pattern for doing creating and updating in Spring MVC controllers consists of a few methods.</p>
<p>Methods to display the initial form:<br />
These methods simply show the same form view.</p>
<p>I implemented them like this, we assume the view name from the Domain object (entity)'s name:</p>
<div class="syntax_hilite">
<div id="java-40">
<div class="java">@RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">GET</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> create<span style="color: #66cc66;">&#40;</span>ModelMap model, WebRequest request<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/form"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; @RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">GET</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> update<span style="color: #66cc66;">&#40;</span>ModelMap model<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/form"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>Now before the form is submitted we need to tell Spring to bind our form to a @ModelAttribute. This is the same as a FormBackingObject in classic Spring MVC.</p>
<p>The way it works is any method annotated with @ModelAttribute will be executed and the returned object bound to any matching forms in a view.</p>
<p>In this view I do one of two things. If we're going to be doing a create I return a new Domain object. This domain object may have some default values set to get initially bound in to the form. If we're doing an update I need to look up the Domain  Object from the DAO Service.</p>
<p>Since our @ModelAttribute annotated method will be called on each request I need a way to tell if this is an update request or a create request. An easy way is just to check if our Primary Key parameter is set in the WebRequest.</p>
<p>Here's what a generic @ModelAttribute method looks like:</p>
<div class="syntax_hilite">
<div id="java-41">
<div class="java">@ModelAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"crudObj"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> T setupModel<span style="color: #66cc66;">&#40;</span>WebRequest request<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> pk = request.<span style="color: #006600;">getParameter</span><span style="color: #66cc66;">&#40;</span>getPkParam<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>pk == <span style="color: #000000; font-weight: bold;">null</span> || org.<span style="color: #006600;">apache</span>.<span style="color: #006600;">commons</span>.<span style="color: #006600;">lang</span>.<span style="color: #006600;">StringUtils</span>.<span style="color: #006600;">isEmpty</span><span style="color: #66cc66;">&#40;</span>pk<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> getEntityInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span>dao.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Long</span></a>.<span style="color: #006600;">parseLong</span><span style="color: #66cc66;">&#40;</span>pk<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So we need another abstract method called getPkParam that returns the String representing the domain property that the Primary Key is stored in.<br />
If on your database the primary key is always called "id" then you could certainly implement getPkParam to return "id" every time in the superclass.</p>
<p>So far we have implemented methods that do the following in our superclass: Forward a request to the correct form view and setup the model object to make it available for automatic binding in our view.</p>
<p>The next step is to define what happens when a form is submitted. When a form is submitted we'll have to do 2 things, weather and update or an insert we need to Validate the form and persist the Domain object to the database if validation passes.</p>
<p>Due to the @ModelAttribute annotation the model object will now be available in your view as {$crudObj}. Ideally we would make it available based on the type name so the view was more readable, but that's one of the limitations we have when using annotations is the inability to add dynamic values as parameters.</p>
<p>Let's look at a generic save method:</p>
<div class="syntax_hilite">
<div id="java-42">
<div class="java">@RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">POST</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> save<span style="color: #66cc66;">&#40;</span>@ModelAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"crudObj"</span><span style="color: #66cc66;">&#41;</span> T entity, BindingResult bindingResult<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//validate entity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; getValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">validate</span><span style="color: #66cc66;">&#40;</span>entity, bindingResult<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//return to form if we had errors</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bindingResult.<span style="color: #006600;">hasErrors</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/form"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//merge into datasource</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dao.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>entity<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//return to list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">"redirect:/"</span> + ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/list.html"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>We have a new abstract method called getValidator(Object obj,BindingResult res) that will return the validator for your Domain class.</p>
<h3>Implementation</h3>
<p>We now have all the pieces in place.</p>
<p><strong>Finished CrudController&lt;T&gt;</strong></p>
<div class="syntax_hilite">
<div id="java-43">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> CrudController&lt;T&gt; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//Bring in a generic DAO that can handle crud operations.</span><br />
&nbsp; &nbsp; @Autowired <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> SimpleDao dao;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> CrudController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; super<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">protected</span> Validator getValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @SuppressWarnings<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"unchecked"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> Class&lt;T&gt; getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>Class&lt;T&gt;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>ParameterizedType<span style="color: #66cc66;">&#41;</span> getClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getGenericSuperclass</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getActualTypeArguments</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @SuppressWarnings<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"unchecked"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> T getEntityInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006600;">forName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">newInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AInstantiationException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">InstantiationException</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ARuntimeException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">RuntimeException</span></a><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AIllegalAccessException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">IllegalAccessException</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ARuntimeException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">RuntimeException</span></a><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AClassNotFoundException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">ClassNotFoundException</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ARuntimeException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">RuntimeException</span></a><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;&nbsp; <span style="color: #808080; font-style: italic;">//assume the primary key property is going to be the Entity Class plus Seq</span><br />
&nbsp; &nbsp;&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getPkParam<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;&nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortNameAsProperty</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"Seq"</span>;<br />
&nbsp; &nbsp;&nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">GET</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ModelMap list<span style="color: #66cc66;">&#40;</span>ModelMap model<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; model.<span style="color: #006600;">addAttribute</span><span style="color: #66cc66;">&#40;</span>dao.<span style="color: #006600;">selectAll</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> model;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; @RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">GET</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> create<span style="color: #66cc66;">&#40;</span>ModelMap model, WebRequest request<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/form"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; @RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">GET</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> update<span style="color: #66cc66;">&#40;</span>ModelMap model<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/form"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">POST</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> save<span style="color: #66cc66;">&#40;</span>@ModelAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"crudObj"</span><span style="color: #66cc66;">&#41;</span> T entity, BindingResult bindingResult<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//validate entity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; getValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">validate</span><span style="color: #66cc66;">&#40;</span>entity, bindingResult<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//return to form if we had errors</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bindingResult.<span style="color: #006600;">hasErrors</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/form"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//merge into datasource</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dao.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>entity<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//return to list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">"redirect:/"</span> + ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/list.html"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @RequestMapping<span style="color: #66cc66;">&#40;</span>method = RequestMethod.<span style="color: #006600;">POST</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> delete<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> isInsert, @ModelAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"crudObj"</span><span style="color: #66cc66;">&#41;</span> T entity, BindingResult bindingResult<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//delete</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dao.<span style="color: #006600;">delete</span><span style="color: #66cc66;">&#40;</span>entity<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//return to list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">"redirect:/"</span> + ClassUtils.<span style="color: #006600;">getShortName</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">"/list.html"</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @ModelAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"crudObj"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> T setupModel<span style="color: #66cc66;">&#40;</span>WebRequest request<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> pk = request.<span style="color: #006600;">getParameter</span><span style="color: #66cc66;">&#40;</span>getPkParam<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>pk == <span style="color: #000000; font-weight: bold;">null</span> || org.<span style="color: #006600;">apache</span>.<span style="color: #006600;">commons</span>.<span style="color: #006600;">lang</span>.<span style="color: #006600;">StringUtils</span>.<span style="color: #006600;">isEmpty</span><span style="color: #66cc66;">&#40;</span>pk<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> getEntityInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span>dao.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span>getEntityClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Long</span></a>.<span style="color: #006600;">parseLong</span><span style="color: #66cc66;">&#40;</span>pk<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//Set up any custom editors, adds a custom one for java.sql.date by default</span><br />
&nbsp; &nbsp; @InitBinder<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> initBinder<span style="color: #66cc66;">&#40;</span>WebDataBinder binder<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASimpleDateFormat+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">SimpleDateFormat</span></a> dateFormat = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ASimpleDateFormat+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">SimpleDateFormat</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"yyyy-MM-dd"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; dateFormat.<span style="color: #006600;">setLenient</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; binder.<span style="color: #006600;">registerCustomEditor</span><span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3ADate+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Date</span></a>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000000; font-weight: bold;">new</span> CustomSqlDateEditor<span style="color: #66cc66;">&#40;</span>dateFormat, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p>
Now if I want to add another CRUD to my application I simply have to do the following:</p>
<p>Implement my abstract CrudController for the Domain class I want to edit. So let's say we wanted a department controller.</p>
<p>It's definition would look like this:</p>
<div class="syntax_hilite">
<div id="java-44">
<div class="java">@Controller<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DepartmentController <span style="color: #000000; font-weight: bold;">extends</span> CrudController&lt;Department&gt; <span style="color: #66cc66;">&#123;</span></p>
<p>&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> Validator getValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> DepartmentValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>Next I'd define my validator class, it might look something like this:</p>
<div class="syntax_hilite">
<div id="java-45">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DepartmentValidator <span style="color: #000000; font-weight: bold;">implements</span> Validator <span style="color: #66cc66;">&#123;</span></p>
<p>&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">boolean</span> supports<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> departmentClass<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// TODO Auto-generated method stub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> Department.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>departmentClass<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> validate<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> healthScope, Errors errors<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ValidationUtils.<span style="color: #006600;">rejectIfEmptyOrWhitespace</span><span style="color: #66cc66;">&#40;</span>errors, <span style="color: #ff0000;">"departmentName"</span>,<span style="color: #ff0000;">"departmentName"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p><b>View set up</b><br />
If you notice sometimes I pull the view name from the Domain class, this method is obviously assuming a certain directory structure on your view side:</p>
<p>Here's what my view directory looks like:</p>
<div class="syntax_hilite">
<div id="code-46">
<div class="code">WEB-INF<br />
&nbsp; /jsp<br />
&nbsp; &nbsp; /department<br />
&nbsp; &nbsp; &nbsp; form.<span style="">jsp</span><br />
&nbsp; &nbsp; &nbsp; list.<span style="">jsp</span></div>
</div>
</div>
<p></p>
<p>The last thing I'd do is define my jsp's like this: (<em>You can make your jsp's however you want, i'm just showing some example ones for completeness.</em>)</p>
<p><strong>list.jsp</strong><br />
This page just lists our data using the handy <a href="http://displaytag.sourceforge.net/11/">DisplayTag</a> library.</p>
<div class="syntax_hilite">
<div id="java-47">
<div class="java">&lt;html&gt;<br />
&lt;%@ page language=<span style="color: #ff0000;">"java"</span> contentType=<span style="color: #ff0000;">"text/html; charset=EUC-KR"</span><br />
&nbsp; &nbsp; pageEncoding=<span style="color: #ff0000;">"UTF-8"</span>%&gt;<br />
&lt;%@ taglib prefix=<span style="color: #ff0000;">"c"</span> uri=<span style="color: #ff0000;">"http://java.sun.com/jsp/jstl/core"</span>%&gt;<br />
&lt;%@ taglib uri=<span style="color: #ff0000;">"http://displaytag.sf.net"</span> prefix=<span style="color: #ff0000;">"display"</span> %&gt;<br />
&lt;!DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #ff0000;">"-//W3C//DTD HTML 4.01 Transitional//EN"</span> <span style="color: #ff0000;">"http://www.w3.org/TR/html4/loose.dtd"</span>&gt;<br />
&lt;html&gt;<br />
&lt;c:<span style="color: #a1a100;">import url=&quot;/WEB-INF/jsp/header.jsp&quot; /&gt;</span><br />
&lt;body&gt;<br />
&lt;div id=<span style="color: #ff0000;">"content"</span>&gt;<br />
&nbsp; &nbsp; &lt;br /&gt;<br />
&nbsp; &nbsp; &lt;h3&gt;Departments&lt;/h3&gt;<br />
&nbsp; &nbsp; &lt;span <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">"pagebanner"</span>&gt;&lt;a href=<span style="color: #ff0000;">"&lt;c:url value="</span>create.<span style="color: #006600;">html</span><span style="color: #ff0000;">" /&gt;"</span>&gt;<span style="color: #66cc66;">&#91;</span>Create <span style="color: #000000; font-weight: bold;">New</span><span style="color: #66cc66;">&#93;</span>&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &lt;display:table name=<span style="color: #ff0000;">"departmentList"</span> requestURI=<span style="color: #ff0000;">"list.html"</span> pagesize=<span style="color: #ff0000;">"25"</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;display:column href=<span style="color: #ff0000;">"update.html"</span>&nbsp; paramId=<span style="color: #ff0000;">"departmentSeq"</span> paramProperty=<span style="color: #ff0000;">"departmentSeq"</span>/&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;display:column title=<span style="color: #ff0000;">"Department Name"</span> property=<span style="color: #ff0000;">"departmentName"</span>/&gt;<br />
&nbsp; &nbsp; &lt;/display:table&gt;<br />
&lt;/div&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</div>
</div>
</div>
<p></p>
<p><strong>form.jsp</strong><br />
Displays a form for both a new and edit. Notice this pulls from the command object "crudObj" that was set up in the @ModelAttribute("crudObj") annotated method.</p>
<div class="syntax_hilite">
<div id="java-48">
<div class="java">&lt;%@ page language=<span style="color: #ff0000;">"java"</span> contentType=<span style="color: #ff0000;">"text/html; charset=EUC-KR"</span><br />
&nbsp; &nbsp; pageEncoding=<span style="color: #ff0000;">"UTF-8"</span>%&gt;<br />
&lt;%@ taglib prefix=<span style="color: #ff0000;">"c"</span> uri=<span style="color: #ff0000;">"http://java.sun.com/jsp/jstl/core"</span> %&gt;<br />
&lt;%@ taglib prefix=<span style="color: #ff0000;">"form"</span> uri=<span style="color: #ff0000;">"http://www.springframework.org/tags/form"</span> %&gt;<br />
&lt;%@ taglib prefix=<span style="color: #ff0000;">"spring"</span> uri=<span style="color: #ff0000;">"http://www.springframework.org/tags"</span> %&gt;<br />
&lt;%@ taglib prefix=<span style="color: #ff0000;">"fmt"</span> uri=<span style="color: #ff0000;">"http://java.sun.com/jsp/jstl/fmt"</span> %&gt;</p>
<p>&lt;!DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #ff0000;">"-//W3C//DTD HTML 4.01 Transitional//EN"</span> <span style="color: #ff0000;">"http://www.w3.org/TR/html4/loose.dtd"</span>&gt;<br />
&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;div id=<span style="color: #ff0000;">"content"</span>&gt;<br />
&nbsp; &nbsp; Create/Edit Department<br />
&nbsp; &nbsp; &lt;form:form action=<span style="color: #ff0000;">"save.html"</span> commandName=<span style="color: #ff0000;">"crudObj"</span>&gt;<br />
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.google.com/search?q=allinurl%3AName+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Name</span></a>:&nbsp; &lt;form:input path=<span style="color: #ff0000;">"departmentName"</span>/&gt; &lt;form:errors path=<span style="color: #ff0000;">"departmentName"</span> cssClass=<span style="color: #ff0000;">"error"</span>/&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &lt;form:hidden path=<span style="color: #ff0000;">"departmentSeq"</span>/&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span style="color: #ff0000;">"submit"</span> value=<span style="color: #ff0000;">"Submit"</span>/&gt;<br />
&nbsp; &nbsp; &lt;/form:form&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div>
</div>
</div>
<p></p>
<h3>Summary</h3>
<p> Let's review:</p>
<ul>
<li>By using a generic templated base class we reap the benefits of Spring's "configuration by convention" and our controller is more specific and easy to use.</li>
<li>We take advantage of Configuration by Convention again to automatically have meaningful url's without having to explicitly configure them thanks to Spring's ControllerClassNameHandlerMapping.</li>
</ul>
<p>The way I created an abstract controller above was just one way to do it, however I believe I've shown that just because your controller classes don't extend an old-style Spring controller class doesn't mean <b>you</b> can't take advantage of inheritance to make your own life easier, even when using annotations.<!-- ~ --><!-- ~ --></p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/&amp;title=Reusing+Annotation+Based+Controllers+in+Spring+MVC" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to Del.icio.us" alt="Add 'Reusing Annotation Based Controllers in Spring MVC' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/&amp;title=Reusing+Annotation+Based+Controllers+in+Spring+MVC" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to digg" alt="Add 'Reusing Annotation Based Controllers in Spring MVC' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Reusing+Annotation+Based+Controllers+in+Spring+MVC&amp;u=http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to FURL" alt="Add 'Reusing Annotation Based Controllers in Spring MVC' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/&amp;title=Reusing+Annotation+Based+Controllers+in+Spring+MVC" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to reddit" alt="Add 'Reusing Annotation Based Controllers in Spring MVC' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to Technorati" alt="Add 'Reusing Annotation Based Controllers in Spring MVC' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/&amp;title=Reusing+Annotation+Based+Controllers+in+Spring+MVC" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Reusing Annotation Based Controllers in Spring MVC' to Google Bookmarks" alt="Add 'Reusing Annotation Based Controllers in Spring MVC' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2008/10/16/reusing-annotation-based-controllers-in-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eclipselink in J2SE RCP Applications</title>
		<link>http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/</link>
		<comments>http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 14:03:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[eclipselink]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/</guid>
		<description><![CDATA[In this article I'll go over integrating EclipseLink into an RCP application. I will not explain every detail of the JPA specification however. The source code this article is partially based off of is currently pending IP Review for inclusion in the official EclipseLink project, however you may download it now from here. You can [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I'll go over integrating EclipseLink into an RCP application. I will not explain every detail of the JPA specification however. The source code this article is partially based off of is currently pending IP Review for inclusion in the official EclipseLink project, however you may <a href="http://weheartcode.com/comics_crud_el.zip">download it now from here</a>. You can follow the inclusion status on the official <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=226361">bug report</a>. If you just want to browse the source, check out the org.eclipse.* projects in <a href="http://weecode.com/EclipseLinkRcpCrud/trunk/">our anon SVN</a>. This example requires the OSGi branch of EclipseLink, which <a href="http://www.eclipse.org/eclipselink/downloads/">you can get here</a>.</p>
<p>It requires a derby database which <a href="http://weheartcode.com/derby_with_comics_db.zip">you can download from here</a>, simply run the startNetworkServer.bat in the bin directory to start it.</p>
<h2>Introduction</h2>
<p><a href="http://www.eclipse.org/eclipselink/">Eclipselink</a> is a part of the Eclipse Project. It's an ORM that implements the <a href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/">JPA 1.0 specification</a>, the main commiters on the project are Oracle employees, and Eclipselink is based on the mature <a href="http://www.oracle.com/technology/products/ias/toplink/index.html">Toplink</a> library, in fact Toplink is being renamed Eclipselink for future releases.</p>
<h3>Why use JPA?</h3>
<p>JPA is the official persistence specification for <a href="http://java.sun.com/products/ejb/">EJB 3</a>, it's not going anywhere and you're going to have an easier time finding other developers who are familiar with the JPA specification. What's even better is the EclipseLink implementation is the JPA 2.0 reference specification, so there's a good chance some features you enjoy in the EclipseLink implementation will be present in the JPA 2 specification as well.</p>
<h3>Why bother with an ORM?</h3>
<p>When you're coding an <a href="http://wiki.eclipse.org/index.php/Rich_Client_Platform">RCP application</a>, chances are you're already passing around Java Beans that represent your data model. If you could have the mapping take place automatically from your database to java beans, it just makes your life that much easier. Once you add the power of libraries like Jface Databinding it's hard to go back to any other method of data access.</p>
<h3>Death to XML</h3>
<p>Thankfully EclipseLink does not require much XML,  the only xml file I create is a persistence.xml that simply lists all my entity classes. A nice editor is included with the JPA Tools plugin that makes managing it simple. All other configuration can be done via annotations.</p>
<p>Tons more after the Jump!<br />
<span id="more-44"></span></p>
<h2>High Level Plug-in Architecture</h2>
<p>I like to split my project into 2 main parts. You could put it all in one plugin, but this is how I do it.</p>
<h3>UI</h3>
<p>This plugin contains all my UI code. Views, Perspectices, Editors, etc. No data access code should occur here though. Instead we'll just use our model plugin. This isn't an RCP tutorial, so I'm going to assume you know your way around the base RCP classes and project set up.</p>
<h3>The Model</h3>
<p>The model plugin is where all the data access work takes place, from here we can separate 3 main concerns.</p>
<p><strong>Connection Set Up (EntityManagerFactory)</strong><br />
The EclipseLink class that takes care of creating database connection, configuring pooling, or re-using an exisiting datasource as a connection is the EntityManagerFactory.</p>
<p>Configuring your EntityManagerFactory involves specificing the connection, and setting options. Once we're done, you guessed it, we can create EntityManagers!</p>
<p>The call to createEntityManagerFactory takes the name of your "persistence unit", it must match the name you put in your persistence.xml, so in this case it's "comics".</p>
<p>Here's the EntityManagerFactory I created for the Comics example:</p>
<div class="syntax_hilite">
<div id="java-58">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> ComicsEntityManagerFactory <span style="color: #66cc66;">&#123;</span></p>
<p>&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> EntityManagerFactory emf = <span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> Map&lt;String, Object&gt; properties = <span style="color: #000000; font-weight: bold;">new</span> HashMap&lt;String, Object&gt;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">TARGET_DATABASE</span>, <span style="color: #ff0000;">"Derby"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">JDBC_DRIVER</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"org.apache.derby.jdbc.ClientDriver"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">JDBC_URL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"jdbc:derby://localhost:1527/sample;create=true"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">JDBC_USER</span>, <span style="color: #ff0000;">"app"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">JDBC_PASSWORD</span>, <span style="color: #ff0000;">"app"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">JDBC_READ_CONNECTIONS_MIN</span>, <span style="color: #ff0000;">"1"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">JDBC_WRITE_CONNECTIONS_MIN</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"1"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">BATCH_WRITING</span>, <span style="color: #ff0000;">"JDBC"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">CLASSLOADER</span>, ComicsEntityManagerFactory.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006600;">getClassLoader</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"eclipselink.logging.level"</span>, <span style="color: #ff0000;">"FINE"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"eclipselink.logging.timestamp"</span>, <span style="color: #ff0000;">"false"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"eclipselink.logging.session"</span>, <span style="color: #ff0000;">"false"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"eclipselink.logging.thread"</span>, <span style="color: #ff0000;">"false"</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; emf = <span style="color: #000000; font-weight: bold;">new</span> PersistenceProvider<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">createEntityManagerFactory</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"comics"</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; properties<span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Creates a new ComicsEntityManager object.<br />
&nbsp; &nbsp;&nbsp; *<br />
&nbsp; &nbsp;&nbsp; * @return the entity manager<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> EntityManager createEntityManager<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>emf == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> emf.<span style="color: #006600;">createEntityManager</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p><strong>Models (EntityManager Usage)</strong><br />
Once we have an EntityManagerFactory we can use that EntityManagerFactory to create an EntityManager. An EntityManager has it's own cache, handles all data access (selects/inserts/updates) and also can manage your transactions (commit/rollback).</p>
<p>I've found that I wrote the same code quite a bit: Obtain an EntityManager from my EntityManagerFactory, begin a transaction, commit a transaction, etc. Rather than write this same code over and over again I find it much easier to simply put this code in a base "Model" class.</p>
<p>I use two types of "Models", one type is your standard Read Only model, I call this class BaseModel, it has some convience methods like selectAll and getNamedQueryResults. The next type of Model I call an "EditorModel" (Because I mostly use it in editors). It has transaction management methods as well as a method called isDirty which can tell me if I have any changes pending to go in the current transaction. This is very useful for editors  and any other place you want to do read/write stuff.</p>
<p>I either use these two classes on their own or I extend them to put business specific methods in them -- things like getAllEmployees(), etc.</p>
<p><strong>Entities</strong><br />
An entity represents a persistent object in your database (usually a table or a view). In java terms they are  POJO's (Plain Old Java Objects). I usually add<a href="http://java.sun.com/docs/books/tutorial/javabeans/properties/bound.html"> property change support</a> to them for use with the <a href="http://wiki.eclipse.org/index.php/JFace_Data_Binding">JFace Databinding</a> library, but that's not required.</p>
<p>Example Entity (this one implements property change support, that's why I'm extending BaseEntityObject) :</p>
<div class="syntax_hilite">
<div id="java-59">
<div class="java">@<a href="http://www.google.com/search?q=allinurl%3AEntity+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Entity</span></a><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Publisher <span style="color: #000000; font-weight: bold;">extends</span> BaseEntityObject <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?q=allinurl%3ASerializable+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Serializable</span></a> <span style="color: #66cc66;">&#123;</span></p>
<p>&nbsp; &nbsp; @Id<br />
&nbsp; &nbsp; @GeneratedValue<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> id;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> name;</p>
<p>&nbsp; &nbsp; @OneToMany<span style="color: #66cc66;">&#40;</span>mappedBy = <span style="color: #ff0000;">"publisher"</span>, cascade = CascadeType.<span style="color: #006600;">PERSIST</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List&lt;Title&gt; titles;</p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Instantiates a new publisher.<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Publisher<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Instantiates a new publisher.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @param name the name<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Publisher<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">name</span> = name;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Gets the name.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @return Returns the name.<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> name;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Sets the name.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @param name The name to set.<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setName<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">name</span> != <span style="color: #000000; font-weight: bold;">null</span> || name != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firePropertyChange<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"name"</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">name</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">name</span> = name<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Gets the id.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @return Returns the id.<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> getId<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> id;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Sets the id.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @param id the new id</p>
<p>&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setId<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; firePropertyChange<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"id"</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">id</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">id</span> = id<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* (non-Javadoc)<br />
&nbsp; &nbsp;&nbsp; * @see java.lang.Object#toString()<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> getName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Gets the titles.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @return the titles<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> List&lt;Title&gt; getTitles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> titles;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Sets the titles.<br />
&nbsp; &nbsp;&nbsp; * <br />
&nbsp; &nbsp;&nbsp; * @param titles the new titles<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setTitles<span style="color: #66cc66;">&#40;</span>List&lt;Title&gt; titles<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">titles</span> != <span style="color: #000000; font-weight: bold;">null</span> || titles != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firePropertyChange<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"titles"</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">titles</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">titles</span> = titles<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>Rememeber: Every entity defined in your model project must be referenced in your persistence.xml.</p>
<p><strong>Generating Entities</strong><br />
The best way to generate your entities is with the <a href="http://www.eclipse.org/webtools/dali/main.php">Dali JPA Tools plugin</a>, it's available on the standard eclipse update site. After you get Dali make sure you configure your drivers &#038; connections for whatever platform your database uses - oracle,mysql, etc. </p>
<p>You cannot just use the JPA Tools plugin on any ol' project however. Though in the future this limitation will go away. First you must create a special "JPA Project" and immediately converting it to a plugin project. </p>
<p>Then you can then generate your entities by right clicking <strong> on your project</strong> and selecting JPA Tools->Generate Entities.</p>
<p><strong>Common Gotcha - sharing Entities</strong><br />
When we're talking about OSGi, Entities can not pass the class loader boundry, so you cannot (at this time: September 2008) re-use entities between bundles. This just means the EntityManager you persist an entity with, must be in the same bundle. So I couldn't take common entities and put them in their own bundle, then expect to persist/select to them with an EntityManager defined in another bundle.</p>
<p>This isn't as much of a deal breaker as it sounds at first, you just have to violate DRY for Entity Classes, which aren't all that interesting in the first place. There's nothing stopping you from defining common interfaces or Abstract classes that entities from multiple bundles share.</p>
<h3>Selects/Inserts/Updates/Deletes</h3>
<p>So how do you <em>do stuff</em> with EclipseLink? Turns out, it's pretty simple. However there are so many different ways to do things, I don't have the room here to go over it. Please read this <a href="http://wiki.eclipse.org/Developing_Applications_Using_EclipseLink_JPA_(ELUG)">excellent wiki article</a> to quickly get up to speed. Also any JPA Tutorial will get you caught up on the basics.  I'd like to go over how all of this stuff pertains to your run of the mill RCP applications.</p>
<h3>Editor Use Case</h3>
<p>A common usage scenario with a database driven app is to use a FormEditor to modify a collection of entities. Thanks to EclipseLink we get lots of stuff for free, let's take a look at an example editor class.</p>
<p><strong>Editor Initialization</strong><br />
The init method, here we want to get whatever entities we want to set up our Model, remember our Model basically wraps our EntityManager and contains some convenience methods for dealing with transactions, etc. We need to obtain all of our entities from the entity manager, usually through a simple select query.</p>
<div class="syntax_hilite">
<div id="java-60">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> init<span style="color: #66cc66;">&#40;</span>IEditorSite site, IEditorInput input<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> PartInitException <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; PublishersEditorInput myInput = <span style="color: #66cc66;">&#40;</span>PublishersEditorInput<span style="color: #66cc66;">&#41;</span> input;<br />
&nbsp; &nbsp; &nbsp; &nbsp; model = <span style="color: #000000; font-weight: bold;">new</span> PublisherEditorModel<span style="color: #66cc66;">&#40;</span>myInput.<span style="color: #006600;">getPublisher</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; publisher = model.<span style="color: #006600;">getPublisher</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; setSite<span style="color: #66cc66;">&#40;</span>site<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; setInput<span style="color: #66cc66;">&#40;</span>input<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So we create a new PublisherEditorModel, which is a simple class I created that handles starting my transaction, then we get our Publisher entity from the model, let's peak inside the PublisherEditorModel class, here we use call the find method on our entity manager, that method takes the class of our Entity and it's primary key. </p>
<div class="syntax_hilite">
<div id="java-61">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> Publisher getPublisher<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; publisher = em.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span>Publisher.<span style="color: #000000; font-weight: bold;">class</span>, publisher.<span style="color: #006600;">getId</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> publisher;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So now we've got our Publisher Entity, but it's one we obtained from our EntityManager, that means any changes we make to the entity will be followed by the EntityManager. So if we changed a field, then called save on the EntityManager, an update statement would be sent to the database!</p>
<p>You could of course skip the convention of a model class all together and deal with getting the EntityManager directly from your plugin's EntityManagerFactory yourself, but it's much easier to just write that code once.</p>
<p><strong>Checking for changes</strong><br />
One feature of an editor is a dirty state -- you change something, the editor is marked as dirty (A star is added to the editor title). If you save the changes, they go through, if not they're discarded. By using EclipseLink we get this functionality for free. No matter how complicated our model is. In basically one line of code we take care of what used to be a gigantic chore. Now figuring out exactly what the differences are is a bit more complicated, but for our case this works great.</p>
<div class="syntax_hilite">
<div id="java-62">
<div class="java">@Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">boolean</span> isDirty<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></p>
<p>&nbsp; &nbsp; UnitOfWork uow = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>EntityManagerImpl<span style="color: #66cc66;">&#41;</span> model.<span style="color: #006600;">getEntityManager</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getUnitOfWork</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> uow.<span style="color: #006600;">hasChanges</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p><strong>Saving Changes</strong><br />
To save our changes we simply commit our transaction, then start a new one (so editing can continue). Once again, we haven't had to write a single line of SQL. This simple commit will handle, updates, inserts, deletes!  This step used to cause me many hours of grief for each new editor, troubleshooting what sort of SQL I had to generate, and in what order. Don't get me wrong, sometimes EclipseLink doesn't generate the SQL you think it should, but it's usually fairly easy to debug what went wrong.</p>
<div class="syntax_hilite">
<div id="java-63">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> doSave<span style="color: #66cc66;">&#40;</span>IProgressMonitor monitor<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; model.<span style="color: #006600;">getEntityManager</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getTransaction</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">commit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; model.<span style="color: #006600;">getEntityManager</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getTransaction</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">begin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; firePropertyChange<span style="color: #66cc66;">&#40;</span>PROP_DIRTY<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>So, our entities we got from our entity manager we expose to our FormPages in the editor, we then bind those very entities to UI controls, either using JFace databinding or by hand -- whichever way you prefer.</p>
<p><strong>Review</strong><br />
That's really all there is to tying a simple editor to a database. Let's review:</p>
<ol>
<li>Obtain an EntityManager and begin a transaction</li>
<li>Obtain all the entities you need from the EntityManager, either through the find method, a JPQL query or a Native SQL Query, or combination of these methods.</li>
<li>Leverage EclipseLink's UnitOfWork class in your isDirty method.</li>
<li>In your form pages, bind Entities to UI controls.</li>
<li>Commit your transaction when save is called.</li>
</ol>
<h3>Caching in a Thick Client</h3>
<p>Traditionally one of the major benefits you get when using an ORM library and with EclipseLink especially is the ability to have a shared in memory cache. The benefits in a server side web application are immense, when we're dealing with a client side thick application. Caching just gets in our way in most cases. The reason for this is obvious: In a web application EntityManagers across users sessions can all easily share the same cache, since they all reside on the same server (usually).</p>
<p> However in a thick client each user is an island. When I make an update to the database, I update my very own Shared Cache, however Mary who is sitting 2 cubes over still has her own cache that's oblivious to my changes. It's imperative that she receive fresh data all the time!</p>
<p><strong>Fresh data from a find call</strong><br />
Calling find on the EntityManager is the easiest way to get a handle on an Entity. However, you're not gauranteed to hit the database on this call. After our find we just need to call refresh to refresh the Entity from the database. I created a method called findFresh that I put in my Base Model class, here's how it looks:</p>
<div class="syntax_hilite">
<div id="java-64">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> &lt;T&gt; T findFresh<span style="color: #66cc66;">&#40;</span>Class&lt;T&gt; entityClass, <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> primaryKey<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; T result =&nbsp; getEntityManager<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span>entityClass, primaryKey<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>result == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; getEntityManager<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">refresh</span><span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> result;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p><strong>In EntityManager Setup</strong><br />
You can turn off the Shared Cache EntityManager wide, to stop regular JPQL queries from hitting the shared cache, this is called putting your EntityManager in "Isolated Mode", just set it in the properties map you pass to the createEntityManagerFactory method.</p>
<p>I just set the property like this:</p>
<div class="syntax_hilite">
<div id="java-65">
<div class="java">properties.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>PersistenceUnitProperties.<span style="color: #006600;">CACHE_SHARED_DEFAULT</span>, <span style="color: #ff0000;">"false"</span><span style="color: #66cc66;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p><strong>Fresh results from Queries</strong><br />
Just to be sure when I execute any Query - Native or otherwise I set the Query Hint to not use the cache, I created a little helper method I through in a util class like this:</p>
<div class="syntax_hilite">
<div id="java-66">
<div class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> setNoCacheHints<span style="color: #66cc66;">&#40;</span>Query q<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; q.<span style="color: #006600;">setHint</span><span style="color: #66cc66;">&#40;</span>QueryHints.<span style="color: #006600;">REFRESH</span>, HintValues.<span style="color: #000000; font-weight: bold;">TRUE</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>When dealing with NamedQueries you can use the @CacheHint annotation to set the hint.</p>
<h2>Conclusion</h2>
<p>Before using EclipseLink in my business critical RCP applications, we were using all home grown DAO. We successfully ported our old applications to EclipseLink in a matter of months and that was using alpha code. Looking back all the developers agree we couldn't live with out it.  It's amazing what the simplicity of being able to focus on your actual business logic and not SQL generation can do to you, coding is fun again. Thanks EclipseLink!</p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/&amp;title=Eclipselink+in+J2SE+RCP+Applications" title="Add 'Eclipselink in J2SE RCP Applications' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Eclipselink in J2SE RCP Applications' to Del.icio.us" alt="Add 'Eclipselink in J2SE RCP Applications' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/&amp;title=Eclipselink+in+J2SE+RCP+Applications" title="Add 'Eclipselink in J2SE RCP Applications' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Eclipselink in J2SE RCP Applications' to digg" alt="Add 'Eclipselink in J2SE RCP Applications' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Eclipselink+in+J2SE+RCP+Applications&amp;u=http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/" title="Add 'Eclipselink in J2SE RCP Applications' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Eclipselink in J2SE RCP Applications' to FURL" alt="Add 'Eclipselink in J2SE RCP Applications' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/&amp;title=Eclipselink+in+J2SE+RCP+Applications" title="Add 'Eclipselink in J2SE RCP Applications' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Eclipselink in J2SE RCP Applications' to reddit" alt="Add 'Eclipselink in J2SE RCP Applications' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/" title="Add 'Eclipselink in J2SE RCP Applications' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Eclipselink in J2SE RCP Applications' to Technorati" alt="Add 'Eclipselink in J2SE RCP Applications' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/&amp;title=Eclipselink+in+J2SE+RCP+Applications" title="Add 'Eclipselink in J2SE RCP Applications' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Eclipselink in J2SE RCP Applications' to Google Bookmarks" alt="Add 'Eclipselink in J2SE RCP Applications' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Easily Add PropertyChangeSupport to Beans in Eclipse</title>
		<link>http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/</link>
		<comments>http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 18:58:53 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/</guid>
		<description><![CDATA[If you plan on using JFace Databinding in SWT you will have to implement Property Change Support on all your Java Beans, (barf). I wasn't able to find a plugin that would do this in one click to  a class so I came up with two ways to do it.
Here's a code template you [...]]]></description>
			<content:encoded><![CDATA[<p>If you plan on using JFace Databinding in SWT you will have to implement Property Change Support on all your Java Beans, (barf). I wasn't able to find a plugin that would do this in one click to  a class so I came up with two ways to do it.</p>
<p>Here's a code template you can use based on the cool trick I learned at <a href="http://stuffthathappens.com/blog/2007/12/15/javabeans-propertychangesupport-trick/">Stuff That Happens</a> </p>
<p><code>firePropertyChange("${enclosing_method_arguments}", this.${enclosing_method_arguments}, ${line_selection});</code></p>
<p>Just select the assignment part of your setter and use this template.</p>
<p>If you're really lazy you can use a regex find and replace (With the File Search Dialog) </p>
<p>Your Find string will be:<br />
<code>(this.+) = (\w+);</code></p>
<p>And your replace string will be:<br />
<code>firePropertyChange("$2", $1, $1 = $2);</code></p>
<p>Both of these solutions assume you use an Abstract BaseClass to set up your firePropertyChange stuff, then extend for each bean.</p>
<p>Mine looks like this:</p>
<div class="syntax_hilite">
<div id="java-68">
<div class="java">package com.<span style="color: #006600;">weheartcode</span>;</p>
<p><span style="color: #a1a100;">import java.beans.PropertyChangeListener;</span><br />
<span style="color: #a1a100;">import java.beans.PropertyChangeSupport;</span></p>
<p><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> BaseEntity <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">transient</span> <a href="http://www.google.com/search?q=allinurl%3APropertyChangeSupport+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PropertyChangeSupport</span></a> propertyChangeSupport = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3APropertyChangeSupport+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PropertyChangeSupport</span></a><span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Adds the property change listener.<br />
&nbsp; &nbsp;&nbsp; *<br />
&nbsp; &nbsp;&nbsp; * @param listener the listener<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> addPropertyChangeListener<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3APropertyChangeListener+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PropertyChangeListener</span></a> listener<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyChangeSupport.<span style="color: #006600;">addPropertyChangeListener</span><span style="color: #66cc66;">&#40;</span>listener<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Adds the property change listener.<br />
&nbsp; &nbsp;&nbsp; *<br />
&nbsp; &nbsp;&nbsp; * @param propertyName the property name<br />
&nbsp; &nbsp;&nbsp; * @param listener the listener<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> addPropertyChangeListener<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> propertyName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3APropertyChangeListener+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PropertyChangeListener</span></a> listener<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyChangeSupport.<span style="color: #006600;">addPropertyChangeListener</span><span style="color: #66cc66;">&#40;</span>propertyName, listener<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Removes the property change listener.<br />
&nbsp; &nbsp;&nbsp; *<br />
&nbsp; &nbsp;&nbsp; * @param listener the listener<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> removePropertyChangeListener<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3APropertyChangeListener+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PropertyChangeListener</span></a> listener<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyChangeSupport.<span style="color: #006600;">removePropertyChangeListener</span><span style="color: #66cc66;">&#40;</span>listener<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Removes the property change listener.<br />
&nbsp; &nbsp;&nbsp; *<br />
&nbsp; &nbsp;&nbsp; * @param propertyName the property name<br />
&nbsp; &nbsp;&nbsp; * @param listener the listener<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> removePropertyChangeListener<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> propertyName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3APropertyChangeListener+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PropertyChangeListener</span></a> listener<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyChangeSupport.<span style="color: #006600;">removePropertyChangeListener</span><span style="color: #66cc66;">&#40;</span>propertyName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp;&nbsp; * Fire property change.<br />
&nbsp; &nbsp;&nbsp; *<br />
&nbsp; &nbsp;&nbsp; * @param propertyName the property name<br />
&nbsp; &nbsp;&nbsp; * @param oldValue the old value<br />
&nbsp; &nbsp;&nbsp; * @param newValue the new value<br />
&nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #993333;">void</span> firePropertyChange<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> propertyName, <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> oldValue,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> newValue<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyChangeSupport.<span style="color: #006600;">firePropertyChange</span><span style="color: #66cc66;">&#40;</span>propertyName, oldValue,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newValue<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/&amp;title=Easily+Add+PropertyChangeSupport+to+Beans+in+Eclipse" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Del.icio.us" alt="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/&amp;title=Easily+Add+PropertyChangeSupport+to+Beans+in+Eclipse" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to digg" alt="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Easily+Add+PropertyChangeSupport+to+Beans+in+Eclipse&amp;u=http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to FURL" alt="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/&amp;title=Easily+Add+PropertyChangeSupport+to+Beans+in+Eclipse" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to reddit" alt="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Technorati" alt="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/&amp;title=Easily+Add+PropertyChangeSupport+to+Beans+in+Eclipse" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Google Bookmarks" alt="Add 'Easily Add PropertyChangeSupport to Beans in Eclipse' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2008/04/29/easily-add-propertychangesupport-to-beans-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
