<?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>REVERT TO CONSOLE &#187; Grails</title>
	<atom:link href="http://www.reverttoconsole.com/blog/category/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reverttoconsole.com</link>
	<description>for f in *;do echo &#124; sed 'i\rtc' &#62;&#62; $f;done;</description>
	<lastBuildDate>Sat, 10 Jul 2010 12:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Developing Grails Apps in Eclipse</title>
		<link>http://www.reverttoconsole.com/blog/grails/developing-grails-apps-in-eclipse/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/developing-grails-apps-in-eclipse/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:11:53 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=368</guid>
		<description><![CDATA[This was a post I was planning on linking to; a colleague of mine was going to write a post about it, but he hasn&#8217;t yet and I&#8217;ve just spent an extra hour trying to get this to work and am frustrated- and so here is the post you&#8217;ve all been waiting for. There are [...]]]></description>
			<content:encoded><![CDATA[<p>This was a post I was planning on linking to; a colleague of mine was going to write a post about it, but he hasn&#8217;t yet and I&#8217;ve just spent an extra hour trying to get this to work and am frustrated- and so here is the post you&#8217;ve all been waiting for.</p>
<p>There are lots of holes in the existing documentation about setting up eclipse to work with grails.</p>
<p>First off, you will want to generate groovy class files to a directory, like bin-groovy. It&#8217;s not just for debugging, it&#8217;s also for running unit tests. Running unit tests from eclipse is a lot faster than running them from the command line, because eclipse will generate the class files needed as you develop. It&#8217;s really nice to have.</p>
<p>Here&#8217;s where the fun starts- let&#8217;s assume you want to use a plugin. It&#8217;s a reasonable assumption, since there are so many cool plugins available. The first thing you need to know is where plugins download and install to. These go to a plugin directory in your .grails directory, which is normally in your home folder. You&#8217;ll need the jars from these plugins in your eclipse classpath, so you&#8217;ll need to unzip them and add them as external jars. Then, you&#8217;ll also need the source from those plugins in your classpath. For this, I added an External Class Folder to my Java Build Path- the folder was located in .grails/projects/<my project>/classes.</p>
<p>While you&#8217;ll want to uncheck the Disable Groovy Compiler Generating Class File checkbox, you&#8217;ll want to enable the Disable Check Package Matches Source Directory, otherwise you&#8217;ll have a compiler error from resources.groovy.</p>
<p>Finally, add bin-groovy as a class folder to your java build path libraries tab.</p>
<p><a href="http://enterprisejavatechblog.blogspot.com/2008/12/unit-testing-grails-in-eclipse.html">This entry was a big help</a>.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/developing-grails-apps-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Grails and HtmlUnit</title>
		<link>http://www.reverttoconsole.com/blog/grails/grails-and-htmlunit/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/grails-and-htmlunit/#comments</comments>
		<pubDate>Sat, 09 May 2009 18:56:14 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[UnitTest]]></category>
		<category><![CDATA[Useful Links]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=360</guid>
		<description><![CDATA[I was struggling to add HtmlUnit to Grails to do some testing when I came upon this. The solution was to remove the HtmlUnit included jar, xml-apis-1.3.04. The error looked like this: loader constraint violation: loader (instance of &#38;amp;amp;lt;bootloader&#38;amp;amp;gt;) previously initiated loading for a different type with name &#38;quot;org/w3c/dom/NamedNodeMap&#38;quot; java.lang.LinkageError: loader constraint violation: loader (instance of ) [...]]]></description>
			<content:encoded><![CDATA[<p>I was struggling to add HtmlUnit to Grails to do some testing <a href="http://jira.codehaus.org/browse/GROOVY-3356">when I came upon this</a>.</p>
<p>The solution was to remove the HtmlUnit included jar, xml-apis-1.3.04.</p>
<p>The error looked like this:</p>
<pre class="brush: php">
loader constraint violation: loader (instance of &amp;amp;amp;lt;bootloader&amp;amp;amp;gt;) previously initiated loading for a different type with name &amp;quot;org/w3c/dom/NamedNodeMap&amp;quot;
java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name &amp;quot;org/w3c/dom/NamedNodeMap&amp;quot;
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getMethod0(Class.java:2670)
at java.lang.Class.getMethod(Class.java:1603)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.isDom3Present(ContextFactory.java:301)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.getE4xImplementationFactory(ContextFactory.java:328)
at net.sourceforge.htmlunit.corejs.javascript.Context.getE4xImplementationFactory(Context.java:2175)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.initStandardObjects(ScriptRuntime.java:222)
at net.sourceforge.htmlunit.corejs.javascript.Context.initStandardObjects(Context.java:1069)
at net.sourceforge.htmlunit.corejs.javascript.Context.initStandardObjects(Context.java:1036)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.init(JavaScriptEngine.java:157)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$000(JavaScriptEngine.java:68)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.run(JavaScriptEngine.java:130)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize(JavaScriptEngine.java:141)
at com.gargoylesoftware.htmlunit.WebClient.initialize(WebClient.java:1107)
at com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage(WebWindowImpl.java:99)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:127)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:442)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:371)
at UIUnitTests.setUp(UIUnitTests.groovy:12)
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:202)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:146)
at _GrailsTest_groovy$_run_closure1_closure19.doCall(_GrailsTest_groovy:112)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:95)
at TestApp$_run_closure1.doCall(TestApp:66)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
</pre>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-and-htmlunit%2F&amp;title=Grails+and+HtmlUnit" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/grails-and-htmlunit/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>New Google Code Project</title>
		<link>http://www.reverttoconsole.com/blog/ajax/new-google-code-project/</link>
		<comments>http://www.reverttoconsole.com/blog/ajax/new-google-code-project/#comments</comments>
		<pubDate>Fri, 08 May 2009 01:41:40 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=356</guid>
		<description><![CDATA[I&#8217;ve started a new google code project, tuneshost, for a presentation I&#8217;m giving this week. It&#8217;s a bare minimal start, and in the short term I&#8217;m not going to be making many enhancements- I&#8217;ll just be using it to demonstrate htmlunit and selenium testing. It&#8217;s built on the grails platform, and uses extjs for the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/tuneshost/">I&#8217;ve started a new google code project, tuneshost</a>, for a presentation I&#8217;m giving this week. It&#8217;s a bare minimal start, and in the short term I&#8217;m not going to be making many enhancements- I&#8217;ll just be using it to demonstrate htmlunit and selenium testing.</p>
<p>It&#8217;s built on the grails platform, and uses extjs for the UI. Communication is predominantly done in a restful fashion, with json. I&#8217;m using the <a href="http://www.grails.org/AcegiSecurity+Plugin">acegi</a> and <a href="http://www.grails.org/Searchable+Plugin">searchable</a> plugins. (btw, searchable is a @#$!@# awesome plugin!!!)</p>
<p>The concept is that you search through your media (it supports music right now, but the plan is to support all media), a la google style. I&#8217;m tired of importing 4 gigs into iTunes over my home network and having to wait 2 hours for it to finish. I&#8217;m also tired of syncing my ipod. So it&#8217;s streaming media for me all the way, and smart searching.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fnew-google-code-project%2F&amp;title=New+Google+Code+Project" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/ajax/new-google-code-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grails Multiple Datasource Plugin</title>
		<link>http://www.reverttoconsole.com/blog/grails/grails-multiple-datasource-plugin/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/grails-multiple-datasource-plugin/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 20:34:39 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Useful Links]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=224</guid>
		<description><![CDATA[Burt Beckwith discusses his new plugin &#8211; one I&#8217;ve been needing for a while!]]></description>
			<content:encoded><![CDATA[<p><a href="http://burtbeckwith.com/blog/?p=70">Burt Beckwith discusses his new plugin</a> &#8211; one I&#8217;ve been needing for a while!</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fgrails-multiple-datasource-plugin%2F&amp;title=Grails+Multiple+Datasource+Plugin" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/grails-multiple-datasource-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails Extended ManyToMany GORM Example</title>
		<link>http://www.reverttoconsole.com/blog/grails/grails-manytomany-gorm-example/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/grails-manytomany-gorm-example/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 02:51:47 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/194</guid>
		<description><![CDATA[This is a variation on this article. Having never been a big fan of writing XML, I&#8217;ll gladly opt for the XML-less version. The first example online I found has some formatting issues and just seems a little hard to follow. My step by step example follows after the jump. Call it the &#8220;Grails extended [...]]]></description>
			<content:encoded><![CDATA[<p>This is a variation on <a href="http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML">this article</a>. Having never been a big fan of writing XML, I&#8217;ll gladly opt for the XML-less version. <a href="http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML">The first example online</a> I found has some formatting issues and just seems a little hard to follow.</p>
<p>My step by step example follows after the jump. Call it the &#8220;Grails extended many-to-many step-by-step guide using the grails console, for dummies&#8221;.</p>
<p><span id="more-164"></span></p>
<p>Let&#8217;s start with a very simple example:</p>
<blockquote><p>A person has one or more characteristics. A characteristic can be applied to more than one person. A PersonCharacteristic relationship has an assignedValue.</p></blockquote>
<p>Here&#8217;s what I did:</p>
<pre>
<code>
grails create-domain-class person

grails create-domain-class characteristic

grails create-domain-class personCharacteristic
</code>
</pre>
<p>First I fleshed out Person:</p>
<pre class="brush: java">
class Person {

	static hasMany = [characteristics:PersonCharacteristic]

	String firstName
	String lastName

	List characteristics() {
		return characteristics.collect{it.characteristic}
	}

	List addCharacteristic(Characteristic characteristic) {
		return addCharacteristic(characteristic, new Integer(1))
	}

	List addCharacteristic(Characteristic characteristic, Integer assignedValue) {
		PersonCharacteristic.link(this, characteristic, assignedValue)
		return characteristics()
	}

	List removeFromCharacteristics(Characteristic characteristic) {
		PersonCharacteristic.unlink(this, characteristic)
		return characteristics()
	}

}
</pre>
<p>and Characteristic is pretty similar</p>
<pre class="brush: java">
class Characteristic {

	static hasMany = [people:PersonCharacteristic,employers:EmployerCharacteristic]

	String name
	String description
	Integer systemWeight = new Integer(1)

	List people() {
		return people.collect{it.person}
	}

	List employers() {
		return employers.collect{it.employer}
	}

	List addToEmployers(Employer employer) {
		EmployerCharacteristic.link(employer, this)
		return employers()
	}

	List addToPeople(Person person) {
		PersonCharacteristic.link(person, this)
		return people()
	}

	List removeFromEmployers(Employer employer) {
		EmployerCharacteristic.unlink(employer, this)
		return employers()
	}

	List removeFromPeople(Person person) {
		PersonCharacteristic.unlink(person, this)
		return people()
	}
}
</pre>
<p>and finally, PersonCharacteristic</p>
<pre class="brush: java">
class PersonCharacteristic {

	def Person person
	def Characteristic characteristic
	def Integer assignedValue

	static PersonCharacteristic link(Person person, Characteristic characteristic) {

		return link(person, characteristic, new Integer(1))
	}

	static PersonCharacteristic link(Person person, Characteristic characteristic, Integer assignedValue ) {
		def pc = PersonCharacteristic.findByPersonAndCharacteristic(person, characteristic)
		if (!pc) {
			pc = new PersonCharacteristic(userWeight:1)
			pc.person = person
			pc.characteristic = characteristic
			pc.assignedValue = assignedValue
			person?.addToCharacteristics(pc)
			characteristic?.addToPeople(pc)
			pc.save()
		}
		return pc
	}

	static void unlink(Person person, Characteristic characteristic) {
		def pc = PersonCharacteristic.findByPersonAndCharacteristic(person, characteristic)
		if (pc) {
			person?.removeFromCharacteristics(pc)
			characteristic?.removeFromPeople(pc)
			pc.delete()
		}
	}
}
</pre>
<p><strong>Note:</strong> if you want an explanation of this class <a href="http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML">look here</a> and read the section <em>The Many-to-Many map</em>.</p>
<p>Now, with any luck we&#8217;ll be able to do this with the console&#8230;</p>
<p>(I would assume you know this but just in case&#8230; go to your project base dir and type&#8230;</p>
<pre>
grails console
</pre>
<p>Now here are some people and characteristics. This is the easy part.</p>
<pre class="brush: java">
def a = new Person(firstName: &quot;Jeff&quot;, lastName: &quot;Revert&quot;)
a.save()
def b = new Person(firstName: &quot;Priyatam&quot;, lastName: &quot;Console&quot;)
b.save()
def c = new Characteristic(name: &quot;Stupid&quot;, description: &quot;slow of mind&quot;)
c.save()
def d = new Characteristic(name: &quot;Handsome&quot;, description: &quot;a pleasing appearance&quot;)
d.save()
</pre>
<p>you should see this output if you&#8217;re following along correctly:</p>
<blockquote><p>
Result: Characteristic : 2
</p></blockquote>
<p>But why take my word for it? Test it!</p>
<pre class="brush: java">
def jeff = Person.findByFirstName(&#039;Jeff&#039;)
def priyatam = Person.findByFirstName(&#039;Priyatam&#039;)
def stupid = Characteristic.findByName(&#039;Stupid&#039;)
def handsome = Characteristic.findByName(&#039;Handsome&#039;)
if(jeff) {
    println &quot;Found Jeff&quot;
}
if(priyatam) {
    println &quot;Found Priyatam&quot;
}
if(stupid) {
    println &quot;Found Stupid&quot;
}
if(handsome) {
    println &quot;Found Handsome&quot;
}
</pre>
<p>You should see this output:</p>
<blockquote><p>
Found Jeff<br />
Found Priyatam<br />
Found Stupid<br />
Found Handsome
</p></blockquote>
<p>Next we need to add our characteristics to our people.</p>
<pre class="brush: java">
def person = Person.findByFirstName(&#039;Jeff&#039;)
def characteristic = Characteristic.findByName(&#039;Stupid&#039;)
person.addCharacteristic(characteristic)
</pre>
<p>and the resulting output:</p>
<blockquote><p>
Result: [Characteristic : 1]
</p></blockquote>
<p>I should be set with my many to many relationship!</p>
<p>Not convinced? I know how you feel&#8230;</p>
<p>One problem with Grails default database config is that you can&#8217;t easily go there and check out the schema. Well, I don&#8217;t know how to anyway, and I&#8217;m guessing I&#8217;m not alone. In my real world job I always check out the database. It&#8217;s like a security blanket, only with a penchant for evil. Anyway, it&#8217;s not that <a href="http://hsqldb.org/">HSQLDB</a> can&#8217;t provide it, it&#8217;s that the config isn&#8217;t running an in-memory database capable of connecting to. So change the development datasource url to this:</p>
<pre>
url = "jdbc:hsqldb:hsql://localhost:9001/devDB"
</pre>
<p>Open a new shell, go to your grails install directory, and run this:</p>
<pre>
java -cp ./lib/hsqldb-1.8.0.5.jar org.hsqldb.Server -database.0 mem:devDB -dbname.0 devDB
</pre>
<p>This will run an in memory database server that you can connect to with your favorite database exploring app. Now fire up the grails console again, and let&#8217;s add this stuff again.<br />
After adding the people and characteristics, and adding the PersonCharacteristic, check out the tables. I see PERSON, CHARACTERISTIC, and PERSON_CHARACTERISTIC.</p>
<pre>
select * from person_characteristic
</pre>
<p>and this shows I&#8217;ve got a PERSON_CHARACTERISTIC table with an ID, VERSION, CHARACTERISTIC_ID, PERSON_ID, and ASSIGNED_VALUE columns with values 1,0,1,1,1. So you get exactly what you&#8217;d expect. Not bad!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/grails-manytomany-gorm-example/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>GORM Relationships in the Grails Console</title>
		<link>http://www.reverttoconsole.com/blog/grails/gorm-relationships-in-the-grails-console/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/gorm-relationships-in-the-grails-console/#comments</comments>
		<pubDate>Fri, 30 May 2008 02:10:03 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/187</guid>
		<description><![CDATA[I&#8217;ve just started scratching the surface with Grails. A good starting point seems to be understanding GORM or Grails Object Relational Mapping, which is based on Hibernate3. In looking at the Grails tutorials online, you might be inclined to start using Grails via scaffolding and generating controllers and views. And this is fine, but another [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started scratching the surface with Grails. A good starting point seems to be understanding <a href="http://docs.codehaus.org/display/GRAILS/GORM">GORM </a>or Grails Object Relational Mapping, which is based on <a href="http://www.hibernate.org/">Hibernate3</a>.</p>
<p>In looking at the Grails tutorials online, you might be inclined to start using Grails via scaffolding and generating controllers and views. And this is fine, but another perhaps smaller step alternative is to start with the <a href="http://grails.org/doc/1.0.x/ref/Command%20Line/console.html">Grails Console</a> and mess around with the relationships you&#8217;re likely to form in the database.</p>
<p>I found that diving in with some of the tutorials, it isn&#8217;t always obvious why you&#8217;d dynamically scaffold versus performing a static scaffold, or you might not pick up on the power of groovy pages immediately. So I found working with the grails console and GORM to start with eliminated some of the mystery, and provided a solid foundation for further learning. <a href="http://reverttoconsole.com/archives/186">In my previous post</a> I discussed some of the subtle, perhaps unexpected, issues with persisting domain objects in the grails console. Here&#8217;s how I added relationships (after the jump).</p>
<p><span id="more-159"></span></p>
<p>Let&#8217;s start with person and characteristic domain objects:</p>
<pre>
grails create-domain-class person
grails create-domain-class characteristic
</pre>
<p>This will create domain class Person, which we will edit to look like:</p>
<pre class="brush: java">
class Person {
        static hasMany = [characteristics:Characteristic]
	static optionals = [&#039;middleInitial&#039;]
        static constraints = {middleInitial(maxLength:1)}
	String firstName
	String lastName
	String middleInitial
}
</pre>
<p>and the Characteristic class:</p>
<pre class="brush: java">
class Characteristic {

	static belongsTo = Person
	static optionals = [&#039;displayName&#039;]
	String name
	String displayName
	Integer systemLevel
}
</pre>
<p>Now fire up the grails console, you can persist the relationship as follows:</p>
<p>[/java]<br />
def c = new Characteristic(name: &#8220;lazy&#8221;, displayName: &#8220;exudes laziness&#8221;, systemLevel: 1)<br />
def p = new Person(firstName: &#8220;Jeff&#8221;, lastName: &#8220;Smith&#8221;, middleInitial: &#8220;S&#8221;,<br />
characteristics:[c])<br />
p.save()<br />
[/java]</p>
<p>After executing, this should display:</p>
<pre>
Result: Person : 1
</pre>
<p>And how about some built-in querying?</p>
<p>Domain object plus .get(id) will retrieve by identifier:</p>
<pre class="brush: java">
def newGuy = Person.get(1)

if(newGuy) {
println newGuy.firstName
} else {
println &quot;No new guy was found!&quot;
}
</pre>
<p>You should see &#8220;Jeff&#8221; as the output.</p>
<p><a href="http://grails.org/doc/1.0.x/guide/single.html#5.4.1%20Dynamic%20Finders">Dynamic finders</a> are where you really see some interesting things:</p>
<pre class="brush: java">
def f = Person.findByFirstName(&#039;Jeff&#039;)
if(f) {
  println f.lastName
  println f.characteristics.each{ println it.name }
} else {
  println &quot;No Person with the first name of Jeff was found!&quot;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/gorm-relationships-in-the-grails-console/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
