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

<channel>
	<title>Daniel Rosowski&#039;s Techblog</title>
	<atom:link href="http://rosowski.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rosowski.wordpress.com</link>
	<description>Grails/Groovy and Java related topics</description>
	<lastBuildDate>Tue, 23 Aug 2011 08:04:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rosowski.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Daniel Rosowski&#039;s Techblog</title>
		<link>http://rosowski.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rosowski.wordpress.com/osd.xml" title="Daniel Rosowski&#039;s Techblog" />
	<atom:link rel='hub' href='http://rosowski.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using Google App Engine with Grails</title>
		<link>http://rosowski.wordpress.com/2011/08/19/using-google-app-engine-with-grails/</link>
		<comments>http://rosowski.wordpress.com/2011/08/19/using-google-app-engine-with-grails/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 08:05:24 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=94</guid>
		<description><![CDATA[Using a Platform-as-a-Service (PaaS) provider has many advantages over rigging up your own server and maintaining your application yourself. First you don&#8217;t have to worry about the server infrastructure (OS, Security Patches, Networking etc.). But PaaS goes one step further and provides the hosting platform too. This means you should be able to just upload [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=94&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Using a Platform-as-a-Service (PaaS) provider has many advantages over rigging up your own server and maintaining your application yourself. First you don&#8217;t have to worry about the server infrastructure (OS, Security Patches, Networking etc.). But PaaS goes one step further and provides the hosting platform too. This means you should be able to just upload your application to the PaaS provider and your application is ready and accessible. Additionally there are even providers which offer their services free-of-charge in a limited setting (see <a href="http://code.google.com/intl/de-DE/appengine/kb/billing.html#freequota" title="GAE quota" target="_blank">http://code.google.com/intl/de-DE/appengine/kb/billing.html#freequota</a>). Having a free hosting solution sounded great, so I gave GAE a shot.</p>
<p>First thing to check when trying something new with Grails: Is there already a plugin? Well, <a href="http://www.grails.org/plugin/app-engine" target="_blank">there is</a>. And its pretty good too. You get up to speed in no time and don&#8217;t have to worry much about your dependency on GAE. The plugin handles the removal of the hibernate plugin (which you can&#8217;t use anymore, since GAE persistence is done using datanucleus), the creation of the needed configuration files and the deployment of your application.</p>
<p>In my situation I already had a pretty complete application which I &#8220;just&#8221; wanted to make available in the cloud. What I had to do was add annotations controlling the persistence behaviour to my domain classes (if you&#8217;re developing on a windows box, you need to check this as well: <a href="http://www.morkeleb.com/2009/07/27/grails-and-google-appengine-on-windows/" target="_blank">http://www.morkeleb.com/2009/07/27/grails-and-google-appengine-on-windows/</a>). You&#8217;ll end up having something similar to this:</p>
<p><pre class="brush: java;">
import javax.jdo.annotations.PersistenceCapable
import javax.jdo.annotations.IdentityType
import javax.jdo.annotations.Key
import javax.jdo.annotations.IdGeneratorStrategy
import javax.jdo.annotations.Persistent
import javax.jdo.annotations.PrimaryKey

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = &quot;true&quot;)
class Location {

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  Key key

  @Persistent
  String name

  @Persistent
  String address

  @Persistent
  String city

  @Persistent
  String region
...
}
</pre></p>
<p>Now comes the tricky part. I mentioned that I already had a pretty complete application which, of course, was using a handful of plugins. It turns out you cannot use plugins which depend on hibernate. I had two plugins installed which depend on hibernate, searchable and commentable. Well, I didn&#8217;t use the searchable plugin extensively, I could have replaced it with some simple calls to findBy. The commentable plugin was not much of a loss either, I could have replaced it with some hours effort.</p>
<p>The next thing I stumbled upon was the restrictions on java classes which GAE allows. I was using the excellent groovy httpbuilder in my application which in turn is using HttpsURLConnection, which is a restricted class in GAE. At this point I didn&#8217;t continue with this experiment. Due to the restrictions GAE lays upon its users, it was not a viable solution for me.</p>
<p>The conclusion is of course to thoroughly read through the documentation which comes for GAE and especially for <a href="http://code.google.com/intl/de-DE/appengine/docs/java/runtime.html#The_Sandbox" target="_blank">the JVM sandbox</a> and the <a href="http://code.google.com/intl/de-DE/appengine/docs/java/jrewhitelist.html" target="_blank">JRE white list</a>, for all classes which you are allowed to use in your GAE application.</p>
<p>Other PaaS solutions include Amazons <a href="http://aws.amazon.com/de/elasticbeanstalk/" target="_blank">Elastic Beanstalk</a> which makes a very good impression. But the pricing model is no alternative to GAE, since my application would be non-profit. VMWares <a href="http://www.cloudfoundry.com/" target="_blank">CloudFoundry</a> would be the most &#8220;native&#8221; PaaS solution for Grails apps, but the pricing is not available yet, plus you can only get on the platform by invitation. I will definitely keep an eye on both solutions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=94&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2011/08/19/using-google-app-engine-with-grails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding custom constraints per AST transformation</title>
		<link>http://rosowski.wordpress.com/2011/06/16/adding-custom-constraints-per-ast-transformation/</link>
		<comments>http://rosowski.wordpress.com/2011/06/16/adding-custom-constraints-per-ast-transformation/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 09:15:15 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=67</guid>
		<description><![CDATA[While developing a Grails plugin (https://github.com/drosowski/grails-concurrent-update) I needed to add a custom constraint to all domain classes which are annotated with a custom annotation. Looking for ways to accomplish this I stumbled upon AST transformations. AST transformations can be thought of as metaprogramming at compile time. There are already quite a few articles on this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=67&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While developing a Grails plugin (<a href="https://github.com/drosowski/grails-concurrent-update" title="grails-concurrent-update">https://github.com/drosowski/grails-concurrent-update</a>) I needed to add a custom constraint to all domain classes which are annotated with a custom annotation. Looking for ways to accomplish this I stumbled upon AST transformations. AST transformations can be thought of as metaprogramming at compile time. There are already quite a few articles on this issue, so I won&#8217;t cover the basics here.</p>
<p>o The official groovy user guide covers this <a href="http://groovy.codehaus.org/Compile-time+Metaprogramming+-+AST+Transformations" title="AST transformations user guide">topic</a>.<br />
o or an <a href="http://hamletdarcy.blogspot.com/2010/01/groovy-ast-transformations-by-example.html" title="AST transformations by example">article</a> by Hamlet D&#8217;Arcy.</p>
<p>Also there are already some plugins where I recklessly copy&amp;pasted some of the code (like the excellent multi-tenant plugin). But I could only find code to insert pre defined constraints like nullable, not custom constraints. So I needed</p>
<ol>
<li>a custom annotation, and</li>
<li>the corresponding class which performs the AST transformation</li>
</ol>
<p>The annotation was the easy part. You just have to define an interface in Grails&#8217; src directory, looking something like this.<br />
<pre class="brush: java;">
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@GroovyASTTransformationClass(&quot;com.rosowski.grails.plugin.ConcurrentUpdateASTTransformation&quot;)
public @interface ConcurrentUpdate {
}
</pre></p>
<p>The next thing we need is the class which performs the AST transformation, as stated in the annotation of the interface. Please have a look at the <a href="https://github.com/drosowski/grails-concurrent-update/blob/ce91c28707aae393fe49bb32d7f570392ba6a421/src/java/com/rosowski/grails/plugin/ConcurrentUpdateASTTransformation.java" title="Sourcecode for ConcurrentUpdateASTTransformation.java">sourcecode</a> hosted at github for details, since I will only cover the building of the custom validator.</p>
<p>I decided to use AstBuilder, because it lets you build ASTNodes from String input, which is pretty convenient. So I declared my custom validator as a String, looking like this.<br />
<pre class="brush: java;">
    private static final String checkVersion = &quot;version(validator: { Long value, object -&gt;\n&quot; +
            &quot;      if (value != null) {\n&quot; +
            &quot;        def storedVersion = object.getPersistentValue('version')\n&quot; +
            &quot;        if (storedVersion &gt; value) {\n&quot; +
            &quot;          object.version = storedVersion\n&quot; +
            &quot;          object.isLocked = true\n&quot; +
            &quot;          return ['optimistic.locking.failure']\n&quot; +
            &quot;        }\n&quot; +
            &quot;        else {\n&quot; +
            &quot;          object.isLocked = false\n&quot; +
            &quot;          return true\n&quot; +
            &quot;        }\n&quot; +
            &quot;      }\n&quot; +
            &quot;      return true\n&quot; +
            &quot;    })&quot;;
</pre><br />
Granted, it does look pretty clumsy and is hard to read. First I tried using a class which provided the constraint as a closure, but that didn&#8217;t work. Somehow the call getField on the classNode always returned null.</p>
<p>The corresponding code to transform the string into an ASTNode is done in the method getCheckVersion().<br />
<pre class="brush: java;">
    private Expression getCheckVersion() {
        List&lt;ASTNode&gt; nodes = new AstBuilder().buildFromString(checkVersion);
        if (nodes != null &amp;&amp; nodes.size() &gt; 0) {
            BlockStatement block = (BlockStatement) nodes.get(0);
            List&lt;Statement&gt; statements = block.getStatements();
            if (statements != null &amp;&amp; statements.size() &gt; 0) {
                ReturnStatement returnStatement = (ReturnStatement) statements.get(0);
                return returnStatement.getExpression();
            }
        }
        return null;
    }
</pre></p>
<p>Next I can just add the resulting expression to the existing constraints closure found in the annotated class.<br />
<pre class="brush: java;">
    private void addVersionConstraint(ClassNode classNode, Expression checkVersion) {
        FieldNode constraints = classNode.getField(&quot;constraints&quot;);
        ClosureExpression closure = (ClosureExpression) constraints.getInitialExpression();
        BlockStatement block = (BlockStatement) closure.getCode();
        block.addStatement(new ExpressionStatement(checkVersion));
        LOG.info(&quot;[OptimisticLockASTTransformation] Added constraint [version] to class [&quot; + classNode.getName() + &quot;]&quot;);
    }
</pre></p>
<p>And this way I have a custom constraint added to all classes annotated with @ConcurrentUpdate. Sweet, isn&#8217;t it? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I would be glad to hear about your comments or improvements!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=67&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2011/06/16/adding-custom-constraints-per-ast-transformation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>Upcoming Grails and Groovy content</title>
		<link>http://rosowski.wordpress.com/2011/06/16/upcoming-grails-and-groovy-content/</link>
		<comments>http://rosowski.wordpress.com/2011/06/16/upcoming-grails-and-groovy-content/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 07:56:38 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=64</guid>
		<description><![CDATA[Well, its been quite a while since my last post on this blog. I could say I didn&#8217;t have the time or the energy to blog, but to be honest I just didn&#8217;t have to say much. And according to my grandma its best to shut up if you don&#8217;t have anything important to say. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=64&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, its been quite a while since my last post on this blog. I could say I didn&#8217;t have the time or the energy to blog, but to be honest I just didn&#8217;t have to say much. And according to my grandma its best to shut up if you don&#8217;t have anything important to say. My focus at work changed from using plain JEE and OFBiz to Grails. And with that I learned a lot which I would like to share. So hopefully the upcoming articles will be useful to somebody.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=64&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2011/06/16/upcoming-grails-and-groovy-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>YUI &#8211; Howto build an editable dropdown box</title>
		<link>http://rosowski.wordpress.com/2009/04/17/yui-howto-build-an-editable-dropdown-box/</link>
		<comments>http://rosowski.wordpress.com/2009/04/17/yui-howto-build-an-editable-dropdown-box/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 06:05:00 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=56</guid>
		<description><![CDATA[I&#8217;ve been playing around with Yahoo&#8217;s UI lately. I think it has some pretty nice features (autocomplete, calendar etc.) plus it integrates well with Grails. For a personal project of mine, I had the requirement to display a list of suggestions to the user, but he/she should still be able to define their own values. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=56&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with Yahoo&#8217;s UI lately. I think it has some pretty nice features (autocomplete, calendar etc.) plus it integrates well with Grails. For a personal project of mine, I had the requirement to display a list of suggestions to the user, but he/she should still be able to define their own values. I remembered an editable dropdown box which I saw on some desktop application.</p>
<p><pre class="brush: jscript;">
&lt;div id=&quot;gameTypeBox&quot;&gt;
  &lt;input type=&quot;text&quot; id=&quot;gameType&quot; name=&quot;gameType&quot; value=&quot;${fieldValue(bean:game,field:'gameType')}&quot; /&gt;
  &lt;div id=&quot;gameTypeList&quot;&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  var myDataSource = new YAHOO.util.XHRDataSource('${createLink(controller:'game', action:'listGameTypes')}');
  myDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
  myDataSource.responseSchema = {resultsList : &quot;types&quot;};

  var myAutoComp = new YAHOO.widget.AutoComplete('gameType','gameTypeList', myDataSource);
  myAutoComp.minQueryLength = 0;
  myAutoComp.queryDelay = 0;

  //show suggestions
  var showContainer = function(myAutoComp) {
    this.sendQuery('');
  };
  myAutoComp.textboxFocusEvent.subscribe(showContainer);
&lt;/script&gt;
</pre></p>
<p>First of all, don&#8217;t get confused by the ${} constructs, they are Grails specific. As you can see it&#8217;s pretty straightforward. First you define your datasource. In this example its a XHR request returning a list of all gametypes in JSON format.The minQueryLength and queryDelay are both set to 0, since the suggestions should pop up as soon as the textfield is on focus. This is done in the next part, where we send an empty XHR query, so the corresponding method in the controller gets triggered and we get the list of gametypes. Next you subscribe the function to the textboxFocusEvent and you&#8217;re done. Of course you can still autocomplete the users text input, but this has to be done in the controller. In this example I first show all suggestions to the user. After that the list gets filtered by the users input.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=56&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2009/04/17/yui-howto-build-an-editable-dropdown-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>Relocating a tomcat webapp to another server</title>
		<link>http://rosowski.wordpress.com/2009/01/22/relocating-a-tomcat-webapp-to-another-server/</link>
		<comments>http://rosowski.wordpress.com/2009/01/22/relocating-a-tomcat-webapp-to-another-server/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 11:33:22 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=42</guid>
		<description><![CDATA[Today I want to show you a little trick I used to relocate a tomcat webapplication to another server running with a new IP. The webapp is already running on the new server, but the hostname still points to the old server. I don&#8217;t want the users to have to wait until the DNS entry [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=42&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I want to show you a little trick I used to relocate a tomcat webapplication to another server running with a new IP. The webapp is already running on the new server, but the hostname still points to the old server. I don&#8217;t want the users to have to wait until the DNS entry spread its way across the internet. So I decided to redirect all traffic from the old server to the new server. Ideally you have configured an apache webserver in front of your tomcat (for security, performance etc., see <a href="http://people.apache.org/~mturk/docs/article/ftwai.html" target="_blank">here</a>). The article is a bit outdated, but it still has some valid points especially for the reasons on why you should put a webserver in front of your tomcat. Of course you would use mod_proxy_ajp nowadays for this task instead of mod_jk as recommended in the article.<br />
Ok, back to the problem. In order to connect the webserver with tomcat they talk via ajp usually on port 8009. So what I did is just forward this port using ssh to the new server like this:</p>
<p><em><strong>ssh -N -L 8009:192.168.1.2:8009 user@192.168.1.2</strong></em></p>
<p>where 192.168.1.2 is the new servers IP address. This way the user doesn&#8217;t recognize he/she has been redirected. Sweet, isn&#8217;t it?<br />
The apache on the new server is already configured to listen to HTTP requests and redirects them to localhost:8009 (where tomcat is listening). So when the hostname is switched to the new IP address the webserver running on the new server is forwarding the requests to tomcat. By using this trick we have a seamless transition during the server switch which is absolutely transparent for the user.</p>
<p>What other options can you think of?  I bet there are a hundred ways to do it with apache <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=42&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2009/01/22/relocating-a-tomcat-webapp-to-another-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>I love CollectionUtils</title>
		<link>http://rosowski.wordpress.com/2008/12/18/i-love-collectionutils/</link>
		<comments>http://rosowski.wordpress.com/2008/12/18/i-love-collectionutils/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 15:13:19 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=32</guid>
		<description><![CDATA[I just love the CollectionUtils. Today I was facing a problem, where I was iterating through a map and wanted to check if the key partially matches one element from a list of values. Still following? I think it gets much clearer when I go straight to the code. Let me just say this: CollectionUtils.exists  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=32&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just love the CollectionUtils. Today I was facing a problem, where I was iterating through a map and wanted to check if the key partially matches one element from a list of values. Still following? I think it gets much clearer when I go straight to the code. Let me just say this: CollectionUtils.exists  kicks ass! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><pre class="brush: java;">
        final List&lt;String&gt; prefixes = UtilMisc.toList(&quot;first_&quot;, &quot;second_&quot;, &quot;third_&quot;);

        for (Map.Entry entry : context.entrySet()) {
            String value = null;
            String mapKey = null;
            String afterPrefix = null;
            if (entry.getKey() instanceof String) {
                final String key = (String) entry.getKey();
                if (CollectionUtils.exists(prefixes, new Predicate() {

                    public boolean evaluate(Object arg0) {
                        String element = (String) arg0;
                        if (key.startsWith(element)) {
                            return true;
                        }
                        return false;
                    }
                })) {
                    String[] strArr = key.split(&quot;_&quot;);
                    mapKey = strArr[0];
                    afterPrefix = strArr[1];
                    value = (String) entry.getValue();
                }
            }
        }
</pre></p>
<p>*EDIT: I should have mentioned that I&#8217;m talking about the Commons CollectionUtils. They can be found <a title="here" href="http://commons.apache.org/collections/" target="_blank">here</a>.</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=32&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2008/12/18/i-love-collectionutils/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>Subversion over https &#8211; PITA</title>
		<link>http://rosowski.wordpress.com/2008/11/19/subversion-over-https-pita/</link>
		<comments>http://rosowski.wordpress.com/2008/11/19/subversion-over-https-pita/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 16:08:23 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=29</guid>
		<description><![CDATA[I&#8217;ve been using subversion for a long time. Recently I reconfigured the server to use https to have the subversion traffic encrypted. When you have a large codebase with many files and you&#8217;re following subversion best practices and branch your project for big changes you will have a problem. Over http/https the merging process will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=29&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using subversion for a long time. Recently I reconfigured the server to use https to have the subversion traffic encrypted. When you have a large codebase with many files and you&#8217;re following subversion best practices and branch your project for big changes you will have a problem. Over http/https the merging process will take forever. Well, this is of course exaggerated to make my point, but it is really slow. Compared to svn+ssh which I&#8217;m using now, https is a real performance killer.</p>
<p>At some point I read about turning off the path based checks for mod_authz_dav using &#8220;SVNPathAuthz Off&#8221;, but that helped little. I think the big overhead is the http protocol, which just isn&#8217;t meant for things like that.</p>
<p>My tip for everyone making extensive use of subversions branching and merging capabilities: Use svn+ssh over https for encrypted subversion traffic. It will speed things up significantly!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=29&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2008/11/19/subversion-over-https-pita/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>Lucene &#8211; scoring direct hits</title>
		<link>http://rosowski.wordpress.com/2008/10/15/lucene-scoring-direct-hits/</link>
		<comments>http://rosowski.wordpress.com/2008/10/15/lucene-scoring-direct-hits/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 13:10:01 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=23</guid>
		<description><![CDATA[This post is dealing with the scoring algorithm used in Lucene. I guess most people who are using Lucene came to the point where they want to score direct matches higher than wildcard matches. For example if we have the searchphrase &#8220;cup&#8221; and we have several documents in our index which contain the searchphrase like: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=23&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post is dealing with the scoring algorithm used in Lucene.</p>
<p>I guess most people who are using Lucene came to the point where they want to score direct matches higher than wildcard matches. For example if we have the searchphrase &#8220;cup&#8221; and we have several documents in our index which contain the searchphrase like:</p>
<ul>
<li><strong>doc 4711</strong>: name: cupholder</li>
<li><strong>doc 4712</strong>: name: cup</li>
</ul>
<p>In most use-cases people want the direct match, in this case doc 4712 to appear as the first hit. Because cup is contained in both names, you get both documents as matches, but doc 4712 as the first match. So far so good. If you add more complexity to the documents perhaps by giving them a description, you might end up with a messed up scoring. This can have different causes (perhaps &#8220;cup&#8221; appears in the description of doc 4711 but not in 4712). Check out the Similarity class in Lucene and call searcher.explain() on your document to find out the reason for the score. What you want to do is to boost a direct match. Here is how I did it:</p>
<p><pre class="brush: java;">
//where fieldName is 'name' or 'description'
Query tmpQuery = new TermQuery(new Term(fieldName, searchString));
//boost the direct match
tmpQuery.setBoost(2.0f);
query.add(tmpQuery, BooleanClause.Occur.SHOULD);

//search for other occurences
tmpQuery = new WildcardQuery(new Term(fieldName, &quot;*&quot; + searchString + &quot;*&quot;));
query.add(tmpQuery, BooleanClause.Occur.SHOULD);
</pre></p>
<p>I hope that helped somebody on his or her Lucene journey. Have a nice day.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=23&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2008/10/15/lucene-scoring-direct-hits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>OFBiz services: entity-auto execution engine</title>
		<link>http://rosowski.wordpress.com/2008/07/29/entity-auto-service-execution-engine/</link>
		<comments>http://rosowski.wordpress.com/2008/07/29/entity-auto-service-execution-engine/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 12:39:23 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[OFBiz]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=19</guid>
		<description><![CDATA[For those of you who are not on the developer mailinglist. David Jones added a cool new feature to the service engine which enables automated CRUD operations on entities. David added some examples in the example application in OFBiz. Here is an excerpt from the services.xml showing the usage of the new execution engine: Note [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=19&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For those of you who are not on the developer mailinglist. David Jones added a <a href="http://www.nabble.com/The-fancy-new-entity-auto-service-execution-engine-to18674040.html">cool new feature</a> to the service engine which enables automated CRUD operations on entities.</p>
<p>David added some examples in the example application in OFBiz. Here is an excerpt from the services.xml showing the usage of the new execution engine:<br />
<pre class="brush: xml;">
    &lt;service name=&quot;createExample&quot; default-entity-name=&quot;Example&quot; engine=&quot;entity-auto&quot; invoke=&quot;create&quot; auth=&quot;true&quot;&gt;
        &lt;description&gt;Create a Example&lt;/description&gt;
        &lt;permission-service service-name=&quot;exampleGenericPermission&quot; main-action=&quot;CREATE&quot;/&gt;
        &lt;auto-attributes include=&quot;pk&quot; mode=&quot;OUT&quot; optional=&quot;false&quot;/&gt;
        &lt;auto-attributes include=&quot;nonpk&quot; mode=&quot;IN&quot; optional=&quot;true&quot;/&gt;
        &lt;override name=&quot;exampleTypeId&quot; optional=&quot;false&quot;/&gt;
        &lt;override name=&quot;statusId&quot; optional=&quot;false&quot;/&gt;
        &lt;override name=&quot;exampleName&quot; optional=&quot;false&quot;/&gt;
    &lt;/service&gt;
</pre><br />
Note the usage of engine type &#8220;entity-auto&#8221; and the new attribute &#8220;invoke&#8221;. This one calls the create operation on the example entity. Check out the class org.ofbiz.service.engine.EntityAutoEngine. This is where the action is happening.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rosowski.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rosowski.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=19&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2008/07/29/entity-auto-service-execution-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
		<item>
		<title>Lucene &#8211; using the HitCollector</title>
		<link>http://rosowski.wordpress.com/2008/07/29/lucene-using-the-hitcollector/</link>
		<comments>http://rosowski.wordpress.com/2008/07/29/lucene-using-the-hitcollector/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 10:47:56 +0000</pubDate>
		<dc:creator>danielrosowski</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://rosowski.wordpress.com/?p=3</guid>
		<description><![CDATA[This post is about the Lucene search engine. Lucene is available for many different programming languages and is host to another handful of subprojects. Check out their website at http://lucene.apache.org. But you found your way here so I guess you already know what Lucene is. So let&#8217;s get down to business&#8230; To get a grasp [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=3&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post is about the Lucene search engine. Lucene is available for many different programming languages and is host to another handful of subprojects. Check out their website at <a href="http://lucene.apache.org">http://lucene.apache.org</a>. But you found your way here so I guess you already know what Lucene is. So let&#8217;s get down to business&#8230;</p>
<p>To get a grasp of what I&#8217;m talking about here, you should already have a general understanding of the basic Lucene concepts. There are some pretty good tutorials which cover the basics. Be sure to at least check out the <a href="http://lucene.apache.org/java/2_2_0/gettingstarted.html">introduction</a> to the demo application which comes with Lucene. A very good <a href="http://www.ibm.com/developerworks/library/wa-lucene/index.html">tutorial</a> about indexing has been written by Deng Peng Zhou.</p>
<p>As I started working with Lucene, I usually went with the standard search routine:</p>
<p><pre class="brush: java;">
Hits result = searcher.search(query);
</pre></p>
<p>I&#8217;m running a webshop where products are assigned to categories. Soon there was the requirement to count the search hits in specific categories. An easy task with the Lucene HitCollector. Here&#8217;s my HitCollector</p>
<p><pre class="brush: java;">
public class CountCollector extends TopFieldDocCollector {

    private Searcher searcher = null;
    private Map countMap = new HashMap();

    public CountCollector(Searcher searcher, IndexReader reader, Sort sorter, int maxSearchResults) throws IOException {
        super(reader, sorter, maxSearchResults);
        this.searcher = searcher;
    }

    public void collect(int doc, float score) {
        super.collect(doc, score);

        try {
            Document document = searcher.doc(doc);
            if (document != null) {
                    Field[] categoriesDoc = document.getFields(&quot;categories&quot;);
                    if (categoriesDoc != null &amp;&amp; categoriesDoc.length &gt; 0) {
                        for (int i = 0; i &lt; categoriesDoc.length; i++) {
                            if (countMap.containsKey(categoriesDoc[i].stringValue())) {
                                countMap.put(categoriesDoc[i].stringValue(), new Long(countMap.get(categoriesDoc[i].stringValue()) + 1));
                            } else {
                                countMap.put(categoriesDoc[i].stringValue(), new Long(&quot;1&quot;));
                            }
                        }
                   }
             }
        }
        catch (CorruptIndexException e) {
            System.err.println(&quot;ERROR: &quot; + e.getMessage());
        }
        catch (IOException e) {
            System.err.println(&quot;ERROR: &quot; + e.getMessage());
        }
    }
}
</pre><br />
First, I extended TopFieldDocCollector which collects the top-sorting documents, returning them as TopFieldDocs. I override the collect method so it counts every hit per category for the search result. Note that the collect method gets called once for every hit. The next question is how to call the search with the custom HitCollector<br />
<pre class="brush: java;">
CountHitCollector collector = new CountHitCollector(searcher, indexReader, sorter, maxSearchResults);
searcher.search(finalQuery, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
</pre><br />
The search method returns no Hits Object. The result documents are saved in the HitCollector. Next you can just step through the ScoreDoc array and do<br />
<pre class="brush: java;">
Document doc = searcher.doc(hits[i].doc);
</pre><br />
for each document and put it in a custom result object.</p>
<p>This post showed just one example for the usage of the HitCollector. There are many more cases for which it might come in handy. Tell me if this post was useful to you and perhaps for which case you used the HitCollector.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rosowski.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rosowski.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rosowski.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rosowski.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rosowski.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rosowski.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rosowski.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rosowski.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rosowski.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rosowski.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rosowski.wordpress.com&amp;blog=4190303&amp;post=3&amp;subd=rosowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rosowski.wordpress.com/2008/07/29/lucene-using-the-hitcollector/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d4d634d6ab49965ecbfb240590c5333?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danielrosowski</media:title>
		</media:content>
	</item>
	</channel>
</rss>
