<?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>ibananti&#039;s blog &#187; java</title>
	<atom:link href="http://blog.boyandi.net/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.boyandi.net</link>
	<description>notes about ui, web development, visualization. links, tips and tricks</description>
	<lastBuildDate>Tue, 29 Jun 2010 15:11:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Picback</title>
		<link>http://blog.boyandi.net/2009/06/22/picback/</link>
		<comments>http://blog.boyandi.net/2009/06/22/picback/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:45:55 +0000</pubDate>
		<dc:creator>Ilya Boyandin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[my projects]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[swing]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.boyandi.net/?p=55</guid>
		<description><![CDATA[This weekend the weather was not that great so I spent it at home. Also my laptop almost run out of disk space, so I decided to do something about it. I had 50 Gb of photos in my Picasa albums (it&#8217;s because I mostly shoot RAW, I guess) which I always wanted to archive [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend the weather was not that great so I spent it at home. Also my laptop almost run out of disk space, so I decided to do something about it. I had 50 Gb of photos in my Picasa albums (it&#8217;s because I mostly shoot RAW, I guess) which I always wanted to archive on an external drive keeping only the starred photos on the laptop, so that I can always have the best photos with me. But there is no easy way to do it in Picasa. Well, of course you can do it manually, but in my case it was not an option, because I had <em>so many</em> photos on my laptop.</p>
<p>Just improving the python script which I had been using for few years for backing up Picasa albums would not be an option, because this new tool would need a UI. The user needs first to have an overview over the albums and the disk space they consume, and then decide which one to archive. </p>
<p>So I decided to make a tool which would help me with it. On Saturday evening I started to code and have fun with the good old Swing, and finished it late on Sunday. And then the tool helped me to remove tens of thousands of non-starred photos which I didn&#8217;t want to have on my laptop (after backing them up) and free precious gigabytes just in few minutes.</p>
<p>Here it is: <a href="http://code.google.com/p/picback/">Picback</a>. If you are an extensive Picasa user and photographer, I hope it can be useful for you too.</p>
<p><a href="http://code.google.com/p/picback/"><img border="0" src="http://www.boyandi.net/images/works/PicBack/thumb/backup_progress.png" alt="Picback - A tool for Picasa users for making backups of photo albums and saving disk space" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boyandi.net/2009/06/22/picback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems with Hibernate</title>
		<link>http://blog.boyandi.net/2009/02/17/problems-with-hibernate/</link>
		<comments>http://blog.boyandi.net/2009/02/17/problems-with-hibernate/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 14:17:06 +0000</pubDate>
		<dc:creator>Ilya Boyandin</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.boyandi.net/?p=15</guid>
		<description><![CDATA[After 8 months of development of a new project with extensive use of Hibernate I can now tell about my experiences with it. In general, Hibernate is a very useful tool. It saves a lot of time, because you don&#8217;t have to write SQL queries. If you make changes, you usually don&#8217;t have to rewrite [...]]]></description>
			<content:encoded><![CDATA[<p>After 8 months of development of a new project with extensive use of Hibernate I can now tell about my experiences with it. In general, Hibernate is a very useful tool. It saves a lot of time, because you don&#8217;t have to write SQL queries. If you make changes, you usually don&#8217;t have to rewrite queries, because there are only a few of them. The configuration using annotations is simple and powerful (and I personally prefer it to writing mappings in XML). Hibernate is able to generate database tables from mapped classes automatically and even update them as you add new fields to a class. Hibernate caching facilities are very useful. Finally, Hibernate allows to develop database vendor indepentent applications.</p>
<p>But there are few problems which I experienced:</p>
<ol>
<li>The most frustrating is in fact <a href="http://www.hibernate.org/hib_docs/reference/en/html/performance.html#performance-fetching-proxies">described in the Hibernate docs</a>. An object returned by session.load() isn&#8217;t necessarily an object of the expected class:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Cat cat <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Cat<span style="color: #009900;">&#41;</span> session.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span>Cat.<span style="color: #000000; font-weight: bold;">class</span>, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// instantiate a proxy (does not hit the db)</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cat.<span style="color: #006633;">isDomesticCat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>                  <span style="color: #666666; font-style: italic;">// hit the db to initialize the proxy</span>
    DomesticCat dc <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DomesticCat<span style="color: #009900;">&#41;</span> cat<span style="color: #339933;">;</span>       <span style="color: #666666; font-style: italic;">// Error!</span>
    ....
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li>No inheritance mapping for value objects: here is the <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-1152">JIRA issue</a> that never gets fixed, and a <a href="http://priyanshugoyal.wordpress.com/2007/11/15/hibernate-component-value-object-inheritance-mapping/">workaround</a>.</li>
<li>The strong <a href="http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#entity-mapping-association-collections">suggestion in the Hibernate documentation</a> to use a join table for every unidirectional one-to-many association (in the section 2.2.5.3.2.2. &#8220;Unidirectional&#8221;). Another suggestion <a href="http://forum.hibernate.org/viewtopic.php?t=954178&amp;highlight=unidirectional+null+foriegn+foreign+key">is discussed here</a>.</li>
<li>2nd level caching should be used with caution: after deleting an object the stale version can still stay in cache which can lead to an ObjectNotFoundException. I found no other solution except disabling the 2nd level cache for the class.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.boyandi.net/2009/02/17/problems-with-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CGVis is available under GPL</title>
		<link>http://blog.boyandi.net/2008/09/17/cgvis-is-available-under-gpl/</link>
		<comments>http://blog.boyandi.net/2008/09/17/cgvis-is-available-under-gpl/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 13:12:17 +0000</pubDate>
		<dc:creator>Ilya Boyandin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[my projects]]></category>
		<category><![CDATA[piccolo]]></category>
		<category><![CDATA[swing]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://blog.boyandi.net/?p=14</guid>
		<description><![CDATA[The CGVis project, our visualization tool for multidimensional data, is finally open-sourced. Hurrrah!

]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/p/cgvis/">CGVis project</a>, our visualization tool for multidimensional data, is finally open-sourced. Hurrrah!</p>
<p><a href="http://code.google.com/p/cgvis/"><img src="http://www.boyandi.net/images/works/CGVis/cgvis_onmac7_mid.png" title="CGVis: visualization tool for exploring multidimensional data" alt="CGVis: visualization tool for exploring multidimensional data" width="263" height="183" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boyandi.net/2008/09/17/cgvis-is-available-under-gpl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSP recursion</title>
		<link>http://blog.boyandi.net/2007/11/21/jsp-recursion/</link>
		<comments>http://blog.boyandi.net/2007/11/21/jsp-recursion/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 15:44:14 +0000</pubDate>
		<dc:creator>Ilya Boyandin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.boyandi.net/?p=11</guid>
		<description><![CDATA[If you need to render a tree-like structure here&#8217;s a way of implementing recursion in JSP/JSTL:

${node.title}
&#60;div class=&#34;children&#34;&#62;
&#60;c:forEach var=&#34;node&#34; items=&#34;${node.children}&#34;&#62;
	&#60;c:set var=&#34;node&#34; value=&#34;${node}&#34; scope=&#34;request&#34;/&#62;
	&#60;jsp:include page=&#34;node.jsp&#34;/&#62;
&#60;/c:forEach&#62;
&#60;/div&#62;

The tricky thing is that when you use jsp:include (and for recursion you have to use the dynamic inclusion), normally, you loose all the variables defined in the parent JSP. But if you [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to render a tree-like structure here&#8217;s a way of implementing recursion in JSP/JSTL:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">${node.title}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;children&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;c:forEach</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;node&quot;</span> <span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;${node.children}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;c:set</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;node&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${node}&quot;</span> <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;request&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jsp:include</span> <span style="color: #000066;">page</span>=<span style="color: #ff0000;">&quot;node.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/c:forEach<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The tricky thing is that when you use jsp:include (and for recursion you have to use the dynamic inclusion), normally, you loose all the variables defined in the parent JSP. But if you redefine the variables you need in the &#8220;request&#8221; scope, then they will be visible in the included JSP too. I assumed that this very JSP is named &#8220;node.jsp&#8221; and omitted the declarations. Surprisingly, I found neither this nor any other solution on the Web, so I had to invent one.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boyandi.net/2007/11/21/jsp-recursion/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Restrictive locale resolver</title>
		<link>http://blog.boyandi.net/2007/09/15/7/</link>
		<comments>http://blog.boyandi.net/2007/09/15/7/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 18:14:55 +0000</pubDate>
		<dc:creator>Ilya Boyandin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.boyandi.net/?p=7</guid>
		<description><![CDATA[If you make a web application that supports several languages with Spring you are definitely familiar with the handy locale resolvers Spring provides. Unfortunately, none of them allows to restrict the number of locales that can be set. We needed such restriction, because some of our database queries depended on the locale. So I wrote [...]]]></description>
			<content:encoded><![CDATA[<p>If you make a web application that supports several languages with Spring you are definitely familiar with the handy locale resolvers Spring provides. Unfortunately, none of them allows to restrict the number of locales that can be set. We needed such restriction, because some of our database queries depended on the locale. So I wrote a wrapper locale resolver for it:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Locale</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.LocaleResolver</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * A wrapper for LocaleResolver. Allows to set only one of the predefined set of locales.
 *
 * @author Ilya Boyandin
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RestrictiveLocaleResolver <span style="color: #000000; font-weight: bold;">implements</span> LocaleResolver <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> LocaleResolver localeResolver<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Locale</span> defaultLocale<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Locale<span style="color: #339933;">&gt;</span> supportedLocales<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> RestrictiveLocaleResolver<span style="color: #009900;">&#40;</span>
			LocaleResolver localeResolver, <span style="color: #003399;">Locale</span> defaultLocale,
			Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> supportedLocales<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">localeResolver</span> <span style="color: #339933;">=</span> localeResolver<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">defaultLocale</span> <span style="color: #339933;">=</span> defaultLocale<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Locale<span style="color: #339933;">&gt;</span> locales <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Locale<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> loc <span style="color: #339933;">:</span> supportedLocales<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			locales.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Locale</span><span style="color: #009900;">&#40;</span>loc<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">supportedLocales</span> <span style="color: #339933;">=</span> locales<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> LocaleResolver getLocaleResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> localeResolver<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Locale</span> getDefaultLocale<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> defaultLocale<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Collection<span style="color: #339933;">&lt;</span>Locale<span style="color: #339933;">&gt;</span> getSupportedLocales<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">unmodifiableCollection</span><span style="color: #009900;">&#40;</span>supportedLocales<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Locale</span> resolveLocale<span style="color: #009900;">&#40;</span>HttpServletRequest request<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Locale</span> resolved <span style="color: #339933;">=</span> localeResolver.<span style="color: #006633;">resolveLocale</span><span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Locale</span> supported <span style="color: #339933;">=</span> findSupportedLocale<span style="color: #009900;">&#40;</span>resolved<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	 <span style="color: #666666; font-style: italic;">// this ensures that a locale with one</span>
																 <span style="color: #666666; font-style: italic;">// of the predefined names will be used</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>supported <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> supported<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> defaultLocale<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLocale<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response, <span style="color: #003399;">Locale</span> locale<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Locale</span> supported <span style="color: #339933;">=</span> findSupportedLocale<span style="color: #009900;">&#40;</span>locale<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// this ensures that a locale with one</span>
																<span style="color: #666666; font-style: italic;">// of the predefined names will be used</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>supported <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			localeResolver.<span style="color: #006633;">setLocale</span><span style="color: #009900;">&#40;</span>request, response, supported<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			localeResolver.<span style="color: #006633;">setLocale</span><span style="color: #009900;">&#40;</span>request, response, defaultLocale<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Locale</span> findSupportedLocale<span style="color: #009900;">&#40;</span><span style="color: #003399;">Locale</span> locale<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>, len <span style="color: #339933;">=</span> supportedLocales.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Locale</span> loc <span style="color: #339933;">=</span> supportedLocales.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>loc.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>locale<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> loc<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And then you must have something like this in your config file (of course, you can use any other locale resolver instead of <span><span class="attribute-value">SessionLocaleResolver here)</span></span>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;localeResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.fhj.joanna.web.utils.RestrictiveLocaleResolver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.i18n.SessionLocaleResolver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;de&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;set<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>de<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>en<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/set<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.boyandi.net/2007/09/15/7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL parameters and query optimization</title>
		<link>http://blog.boyandi.net/2007/09/03/6/</link>
		<comments>http://blog.boyandi.net/2007/09/03/6/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 07:23:37 +0000</pubDate>
		<dc:creator>Ilya Boyandin</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.boyandi.net/?p=6</guid>
		<description><![CDATA[Few days ago we found out that passing in SQL parameters to a PreparedStatement can affect query optimization when we ran into a problem querying the database from our web app. We constantly got the following error from SQL Server: Adding a value to a &#8216;datetime&#8217; column caused overflow. In the WHERE clause of the [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago we found out that passing in SQL parameters to a PreparedStatement can affect query optimization when we ran into a problem querying the database from our web app. We constantly got the following error from SQL Server: <em>Adding a value to a &#8216;datetime&#8217; column caused overflow</em>. In the WHERE clause of the query we had something like DATEADD(month, 2, exam_date) and it went wrong, because there was an invalid exam_date entry in the database table (something like 0095-01-10).</p>
<p>The funny thing is that when we tried to run the very same query in Microsoft Query Analyzer it worked without an error. Then I wrote a short test that queried the database directly using PreparedStatement without Spring and iBatis to localize the problem and found out that when I passed parameters to it the error came, when I put the parameter values into the query itself it didn&#8217;t. So it seems that <em>passing the parameters affected the order in which the conditions in the WHERE clause were evaluated</em>: without the parameters another condition was evaluated first so that the errorneous date entry  was filtered out before coming to the condition which used DATEADD.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boyandi.net/2007/09/03/6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
