<?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 &#187; eclipse</title>
	<atom:link href="http://www.weheartcode.com/category/eclipse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weheartcode.com</link>
	<description>A discourse on programming</description>
	<lastBuildDate>Thu, 12 May 2011 23:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<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-5">
<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-6">
<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-7">
<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-8">
<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>7</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 [...]]]></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-10">
<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>2</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-20">
<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-21">
<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-22">
<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-23">
<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-24">
<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-25">
<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-26">
<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-27">
<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-28">
<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>7</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-30">
<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>7</slash:comments>
		</item>
		<item>
		<title>Automatically Add JavaDoc Comments in Eclipse</title>
		<link>http://www.weheartcode.com/2008/04/11/automatically-add-javadoc-comments-in-eclipse/</link>
		<comments>http://www.weheartcode.com/2008/04/11/automatically-add-javadoc-comments-in-eclipse/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 13:05:44 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[code generation]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2008/04/11/automatically-add-javadoc-comments-in-eclipse/</guid>
		<description><![CDATA[Recently while preparing to contribute some code to Eclipse I had to add a copyright comment to the top of every class. Enter JAutodoc it will go through and add Javadoc comments and other automated comments, the update site is: http://jautodoc.sourceforge.net/update/ Screenshot: Bookmark to:]]></description>
			<content:encoded><![CDATA[<p>Recently while preparing to contribute some code to <a href="http://www.eclipse.org">Eclipse</a> I had to add a copyright comment to the top of every class. Enter <a href="http://jautodoc.sourceforge.net/">JAutodoc</a> it will go through and add Javadoc comments and other automated comments, the update site is: </p>
<p>http://jautodoc.sourceforge.net/update/</p>
<p>Screenshot:<br />
<img src="http://jautodoc.sourceforge.net/images/preferences.gif" alt="JAutodoc Preferences" /></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/11/automatically-add-javadoc-comments-in-eclipse/&amp;title=Automatically+Add+JavaDoc+Comments+in+Eclipse" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to Del.icio.us" alt="Add 'Automatically Add JavaDoc Comments 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/11/automatically-add-javadoc-comments-in-eclipse/&amp;title=Automatically+Add+JavaDoc+Comments+in+Eclipse" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to digg" alt="Add 'Automatically Add JavaDoc Comments 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=Automatically+Add+JavaDoc+Comments+in+Eclipse&amp;u=http://www.weheartcode.com/2008/04/11/automatically-add-javadoc-comments-in-eclipse/" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to FURL" alt="Add 'Automatically Add JavaDoc Comments 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/11/automatically-add-javadoc-comments-in-eclipse/&amp;title=Automatically+Add+JavaDoc+Comments+in+Eclipse" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to reddit" alt="Add 'Automatically Add JavaDoc Comments 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/11/automatically-add-javadoc-comments-in-eclipse/" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to Technorati" alt="Add 'Automatically Add JavaDoc Comments 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/11/automatically-add-javadoc-comments-in-eclipse/&amp;title=Automatically+Add+JavaDoc+Comments+in+Eclipse" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Automatically Add JavaDoc Comments in Eclipse' to Google Bookmarks" alt="Add 'Automatically Add JavaDoc Comments in Eclipse' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2008/04/11/automatically-add-javadoc-comments-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

