<?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>Virtage Devblog</title>
	<atom:link href="http://devblog.virtage.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.virtage.com</link>
	<description>Blogs and tutorials mostly on Java client-side (Java SE) and server-side (Java EE) and Ubuntu Linux.</description>
	<lastBuildDate>Sun, 05 Feb 2012 08:43:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>cs: Účetnictví FlexiBee &#8211; tipy pro provoz v Ubuntu</title>
		<link>http://devblog.virtage.com/2012/01/cs-ucetnictvi-flexibee-tipy-pro-provoz-v-ubuntu/</link>
		<comments>http://devblog.virtage.com/2012/01/cs-ucetnictvi-flexibee-tipy-pro-provoz-v-ubuntu/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 10:49:14 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Etc.]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=462</guid>
		<description><![CDATA[Ekonomický systém FlexiBee (dříve WinStrom) je zřejmě jediné funkční účetnictví pro Linux. Díky tomu, že je napsané Javě (milujeme Javu ) lze provozovat i na MacOS a Windows. Jako databázi používá PostreSQL. Díky skvělé podpoře Linuxu a Javě bylo jasnou volbou. Přesto lze ještě trochu vylepšit jeho vzhled a fungování. Všechny informace jsem získal a [...]]]></description>
			<content:encoded><![CDATA[	<p>Ekonomický systém <a href="http://www.flexibee.eu">FlexiBee</a> (dříve WinStrom) je zřejmě jediné funkční účetnictví pro Linux. Díky tomu, že je napsané Javě (milujeme Javu <img src='http://devblog.virtage.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) lze provozovat i na MacOS a Windows. Jako <br />
databázi používá PostreSQL. Díky skvělé podpoře Linuxu a Javě bylo jasnou volbou. </p>

	<p><!-- more --></p>

	<p>Přesto lze ještě trochu vylepšit jeho vzhled a fungování. Všechny informace jsem získal a vyzkoušel na mém Ubuntu 11.10 (Oneiric) 32bit.</p>

	<div id="toc_container" class="toc_wrap_right toc_light_blue no_bullets"><p class="toc_title">Table of Contents</p><ul class="toc_list"><li><a href="#Lep_vzhled">1 Lepší vzhled</a></li><li><a href="#Reinstalace">2 Reinstalace</a></li><li><a href="#Nastaven_vlastn_JRE">3 Nastavení vlastní JRE</a></li></ul></div>
<h2><span id="Lep_vzhled">Lepší vzhled</span></h2>

	<p>Největším šokem je vzhled. Upřímně dost odporný. Defaultně používá vzhled (Look &#038; Feel &#8211; <span class="caps">LAF</span>) GTKLookAndFeel, tedy nativní vzhled v Gnome 2/3 a Xfce (sorry <span class="caps">KDE</span>). Hned jsem chtěl nastavit vzhled <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/otherFeatures/nimbus_laf.html">Nimbus</a> bohužel se pak v tom případě text nevešli do vyhraženého místa na dialogu. To je jednoznačně chyba FlexiBee, nikoli Javy. Sami se zaměřujeme na Swing a <a href="http://platform.netbeans.org">NetBeans Platform</a> (na Swingu postavený) a změna vzhledu neovlivní dialogy.</p>

	<p>Všechno nastavení FlexiBee najdete ve spuštěcím skriptu <code>/usr/bin/flexibee</code>. Otevřeme tedy v editoru skript:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ gksudo gedit <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>flexibee</pre></div></div>


	<p>Jediný použitelný <span class="caps">LAF</span> je Metal. Ten sice není příliš &#8220;sexy&#8221;, ale ještě to jde. Aniž bych moc pátral zkusil jsem jestli stačí nastavit standardní Swingovské systémové proměnné</p>

	<ul>
		<li><code>swing.defaultlaf = javax.swing.plaf.metal.MetalLookAndFeel</code> &#8212; třída vzhledu</li>
		<li><code>swing.boldMetal = false</code> &#8212; Metal netučné písmo. Tučné, které se opět nevejde do vymezeného místa.</li>
	</ul>

	<p>do proměnné <code>FLEXIBEE_JAVA_ARGS</code> konfiguračního souboru. Ovšem aby námi nastavené <span class="caps">LAF</span> FlexiBee neignorovalo musíte ještě do <code>FLEXIBEE_ARGS</code> musíte doplnit <code>--no-laf</code>. Ve výsledku tedy: (zaskrolujte až úplně do prava)</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">FLEXIBEE_ARGS</span>=<span style="color: #ff0000;">&quot;--no-laf&quot;</span>
<span style="color: #007800;">FLEXIBEE_JAVA_ARGS</span>=<span style="color: #ff0000;">&quot;-Xmx512m -client -XX:MaxPermSize=128m  -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:-OmitStackTraceInFastThrow -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel -Dswing.boldMetal=false&quot;</span></pre></div></div>


	<h2><span id="Reinstalace">Reinstalace</span></h2>

	<p>Když zapomenete heslo, ale nevadí vám přijít o data (máte totiž zálohu&#8230; <img src='http://devblog.virtage.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> )), pak v manálu píší, že musíte odinstalovat a nainstalovat znovu.</p>

	<p>Jen toto mi nepomohlo. Musíte ještě vymazat skytou složku <code>.winstrom</code> ve svém domovském adresáři. Tepre poté se objeví průvodce prvního spuštění a umožní vytvořit novou databázi.</p>

	<h2><span id="Nastaven_vlastn_JRE">Nastavení vlastní <span class="caps">JRE</span></span></h2>

	<p>Pokud máte na PC více Java Runtime a FlexiBee nenašlo tu správnou (jakou používá zjistíte v dialogu O aplikaci) není nic jednodušší, než ji nastavit ručně: (např. Oracle <span class="caps">JDK</span> 7)</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">FLEXIBEE_JAVA</span>=<span style="color: #ff0000;">&quot;/usr/lib/jvm/jdk1.7.0_01/jre/bin/java&quot;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2012/01/cs-ucetnictvi-flexibee-tipy-pro-provoz-v-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JUnit &#8211; a better way how to test intentional exception throws</title>
		<link>http://devblog.virtage.com/2011/09/junit-better-way-how-to-test-intentional-exception-throws/</link>
		<comments>http://devblog.virtage.com/2011/09/junit-better-way-how-to-test-intentional-exception-throws/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 13:54:45 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=407</guid>
		<description><![CDATA[From time to time during writing JUnit testing (you&#8217;are writing test, aren&#8217;t you ) you will need to test that do throw an exception. Have a look at methods to test such intentional expected behaviour. In past, only way how to an exception throw will not fail complete test was to label test method with [...]]]></description>
			<content:encoded><![CDATA[	<p>From time to time during writing JUnit testing (you&#8217;are writing test, aren&#8217;t you <img src='http://devblog.virtage.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) you will need to test that do throw an exception. Have a look at methods to test such intentional expected behaviour.</p>

	<p><span id="more-407"></span></p>

	<p>In past, only way how to an exception throw will not fail complete test was to label test method with  <code>@Test(expected=SomeExpectedException.class)</code>  annotation.</p>

	<p>From JUnit 4.7 we have much richer tool to test if only certain method or methods call inside your test method throw an exception that we expect. This ability is called <a href="http://www.infoq.com/news/2009/07/junit-4.7-rules">rules</a>.</p>

	<p>Pre JUnit 4.7 way:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Test<span style="color: #009900;">&#40;</span>expected<span style="color: #339933;">=</span><span style="color: #003399;">IndexOutOfBoundsException</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testIndexOutOfBoundsException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">ArrayList</span> emptyList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Object</span> o <span style="color: #339933;">=</span> emptyList.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


	<p>JUnit 4.7+ way:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BagRoundTest <span style="color: #009900;">&#123;</span>
    @Rule
    <span style="color: #000000; font-weight: bold;">public</span> ExpectedException exception <span style="color: #339933;">=</span> ExpectedException.<span style="color: #006633;">none</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> bagRound<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Add expected exception to expected exception list</span>
        exception.<span style="color: #006633;">expect</span><span style="color: #009900;">&#40;</span>ValidactionException.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        methodThatIntentionallyThowsValidationException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #666666; font-style: italic;">// In the rest of test method no more ValidactionException.class is expected</span>
        exception <span style="color: #339933;">=</span> ExpectedException.<span style="color: #006633;">none</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


	<p>Other more advanced techniques are discussed here for example in this StackOverflow <a href="http://stackoverflow.com/questions/156503/how-to-assert-that-a-certain-exception-is-thrown-in-junit4-5-tests">question</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/junit-better-way-how-to-test-intentional-exception-throws/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Etiquette</title>
		<link>http://devblog.virtage.com/2011/09/coding-etiquette/</link>
		<comments>http://devblog.virtage.com/2011/09/coding-etiquette/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 13:45:03 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=398</guid>
		<description><![CDATA[Easy to follow rules improving overall code legibility and later maintenance. Table of Contents1 Editor settings2 GUI naming3 Tasks in comments4 Field naming Editor settings Indentation is usually 1 tab with 4 spaces width. Trailing whitespaces should be removed before commiting to SCM. In NetBeans go to Tools / Options / Editor tab and set [...]]]></description>
			<content:encoded><![CDATA[	<p>Easy to follow rules improving overall code legibility and later maintenance.</p>

	<p><span id="more-398"></span></p>

	<p></p>

	<h2>Editor settings</h2>

	<ul>
		<li><strong>Indentation</strong> is usually 1 tab with 4 spaces width.</li>
		<li><strong>Trailing whitespaces</strong> should be removed before commiting to <span class="caps">SCM</span>.</li>
	</ul>

	<p><a href="http://devblog.virtage.com/wp-content/uploads/2011/09/Selection_002.png"><img src="http://devblog.virtage.com/wp-content/uploads/2011/09/Selection_002-288x300.png" alt="" title="NetBeans IDE remove whitespace dialog" width="288" height="300" class="alignright size-medium wp-image-401" style="float: right" /></a>In NetBeans go to Tools / Options / Editor tab and set Remove Trailing Whitespace to Always.</p>

	<h2><span class="caps">GUI</span> naming</h2>

	<ul>
		<li><strong>txtXXX</strong> &#8211; JText field</li>
		<li><strong>btnXXX</strong> &#8211; JButton</li>
		<li><strong>lblXXX</strong> &#8211; JLabel</li>
	</ul>

	<h2>Tasks in comments</h2>

	<p>We tried to standardize commonly used tasks hard-written in source code comments. Although every &#8220;larger then small&#8221; or important bug/feature should always also be filed in <a href="http://www.redmine.org/">bugtracker</a>.</p>

	<ul>
		<li><strong><span class="caps">TODO</span></strong> &#8211; must be done</li>
		<li><strong><span class="caps">BUG</span></strong> &#8211; needs to be fixed</li>
		<li><strong><span class="caps">ENH</span></strong> &#8211; nice to have enhancement</li>
		<li><strong><span class="caps">MAYBE</span></strong> &#8211; maybe/sometime or never</li>
		<li><strong><span class="caps">ASK</span></strong> &#8211; question or point to analyse in detail</li>
	</ul>

	<h2>Field naming</h2>

	<p>JavaBeans standard:</p>

	<ul>
		<li><strong>setField</strong></li>
		<li><strong>getField</strong></li>
		<li><strong>addListener</strong></li>
		<li><strong>removeListener</strong></li>
	</ul>

	<p>When you don&#8217;t want to unintentionally create JavaBean field by using set/get convention is necessity to use different prefixes:</p>

	<ul>
		<li><strong>specField</strong> instead of <strong>setField</strong></li>
		<li><strong>giveField</strong> instead of <strong>getField</strong></li>
	</ul>]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/coding-etiquette/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to change look &amp; feel of NetBeans IDE and application</title>
		<link>http://devblog.virtage.com/2011/09/how-to-change-look-feel-of-netbeans-ide-and-application/</link>
		<comments>http://devblog.virtage.com/2011/09/how-to-change-look-feel-of-netbeans-ide-and-application/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 13:33:23 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=387</guid>
		<description><![CDATA[Standard GUI toolkit of Java is Swing. NetBeans IDE and Platform is written in Swing. It&#8217;s widely used and accepted. It&#8217;s cross-platform and it&#8217;s doesn&#8217;t look very well under (GTK+) Linux. NetBeans IDE or NetBeans Platform app In NetBeans IDE installation directory under Ubuntu it&#8217;s /home/libor/dev/netbeans/ under Windows it&#8217;s C:\Program Files\NetBeans\ Find etc directory and [...]]]></description>
			<content:encoded><![CDATA[	<p>Standard <span class="caps">GUI</span> toolkit of Java is Swing. NetBeans <span class="caps">IDE</span> and Platform is written in Swing. It&#8217;s widely used and accepted. It&#8217;s cross-platform and it&#8217;s doesn&#8217;t look very well under (<span class="caps">GTK</span>+) Linux.</p>

	<p><span id="more-387"></span></p>

	<h2>NetBeans <span class="caps">IDE</span> or NetBeans Platform app</h2>

	<ol>
		<li>In NetBeans <span class="caps">IDE</span> installation directory
	<ul>
		<li>under Ubuntu it&#8217;s <code>/home/libor/dev/netbeans/</code></li>
		<li>under Windows it&#8217;s <code>C:\Program Files\NetBeans\</code></li>
	</ul></li>
	</ol>

	<ol>
		<li>Find <code>etc</code> directory and <code>netbeans.conf</code> file</li>
	</ol>

	<ol>
		<li>Add to the end of line beginning with <code>netbeans_default_options</code> parameter</li>
	</ol>


<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">--laf path.to.your.laf</pre></div></div>


	<p>e.g. <code>--laf javax.swing.plaf.nimbus.NimbusLookAndFeel</code></p>

	<p>On my Ubuntu 11.10 and Oracle <span class="caps">JDK</span> 7 I have available:</p>


<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">javax.swing.plaf.metal.MetalLookAndFeel
javax.swing.plaf.nimbus.NimbusLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.gtk.GTKLookAndFeel</pre></div></div>


	<p>Please note that GTKLookAndFeel is not available in Windows.</p>

	<ul>
		<li><code>--laf Nimbus</code> for Nimbus L&#038;F</li>
		<li><code>--laf javax.swing.plaf.metal.MetalLookAndFeel</code> for Metal L&#038;F</li>
		<li><code>--laf Gtk</code> for Metal L&#038;F</li>
		<li><code>--laf path.to.your.laf</code> for any other L&#038;F</li>
	</ul>

	<p>Notice that I am using fully qualified class with package name or just class. If class is available to NetBeans launcher script (<span class="caps">JDK</span> standard <span class="caps">LAF</span>s), you can abbreviate to class name.</p>

	<p>So complete line can looks like this (text wrapped for better legibility):</p>


<div class="wp_syntax"><div class="code"><pre class="properties" style="font-family:monospace;"><span style="color: #000080; font-weight:bold;">netbeans_default_options</span><span style="color: #000000;">=</span><span style="color: #933;">&quot;-J-client -J-Xss2m -J-Xms32m 
-J-XX:PermSize=32m -J-XX:MaxPermSize=384m 
-J-Dapple.laf.useScreenMenuBar=true 
-J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true 
-J-DuseSystemAAFontSettings=lcd -J-Dswing.aatext=true --laf Gtk&quot;</span></pre></div></div>


	<h2>NetBeans Platform apps</h2>

	<p>If you want the same for your NetBeans Platform application add to project (suite) <code>project.properties</code> file this line:</p>


<div class="wp_syntax"><div class="code"><pre class="properties" style="font-family:monospace;"><span style="color: #000080; font-weight:bold;">run.args.extra</span><span style="color: #000000;">=</span><span style="color: #008000; font-weight:bold;">--laf Nimbus</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/how-to-change-look-feel-of-netbeans-ide-and-application/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Average user&#8217;s top reasons why Ubuntu rocks</title>
		<link>http://devblog.virtage.com/2011/09/average-users-top-reasons-why-ubuntu-rocks/</link>
		<comments>http://devblog.virtage.com/2011/09/average-users-top-reasons-why-ubuntu-rocks/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 14:48:17 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=315</guid>
		<description><![CDATA[What the pop-music bands, hockey starts and famous actors have in common? Fans. Me, as I big Ubuntu fan, I&#8217;m always ready to argue a lots of reasons why average user should think about Ubuntu Linux. I&#8217;ve tried to list it in this post with hope that it can be useful for not-yet-Ubuntu-fans. Reason #1: [...]]]></description>
			<content:encoded><![CDATA[	<p><em>What the pop-music bands, hockey starts and famous actors have in common? Fans. Me, as I big Ubuntu fan, I&#8217;m always ready to argue a lots of reasons why <a href="http://www.demystifyingusability.com/2006/04/designing_for_t.html">average user</a> should think about Ubuntu Linux. I&#8217;ve tried to list it in this post with hope that it can be useful for not-yet-Ubuntu-fans.</em></p>

	<p><span id="more-315"></span></p>

	<h2>Reason #1: Price and legality</h2>

	<ul>
		<li>Always and forever free</li>
		<li>Copy, distribute, share as you want</li>
	</ul>

	<h2>Reason #2: Perfection of basis</h2>

	<ul>
		<li>Robustness, stability &#8211; features that made Linux famous</li>
		<li>Speed &#8211; 10 seconds to login screen, ready to work immediately after pressing &#8220;Sign in&#8221;, installation takes not more than 15 minutes</li>
		<li>Tab support of Nautilus (file and folder explorer)</li>
		<li>Seamless remote folder working</li>
		<li>True and complete uninstall &#8211; you system never get clutter</li>
		<li>Unified updating of installed application</li>
	</ul>

	<h2>Reason #3: Everything already included</h2>

	<p>Count yourself how much time you spend with installing what is in Ubuntu already included in 700 MB installation CD.</p>

	<ul>
		<li>Out-of-box printing to <span class="caps">PDF</span></li>
		<li><span class="caps">PDF</span> viewer</li>
		<li>LibreOffice office package (formerly OpenOffice)</li>
		<li>Zip/unzipper</li>
		<li>Bittorrent client</li>
		<li>screenshot taking</li>
	</ul>

	<h2>Reason #4: Everybody&#8217;s friend</h2>

	<ul>
		<li>playing well with rest of world</li>
		<li>support plenty of hardware &#8211; typically sound, network, wifi, bluetooth works out of the box</li>
		<li>printing on Windows shared printer</li>
		<li>every existing filesystem support</li>
	</ul>

	<h2>Reason #5: Thinking of you</h2>

	<ul>
		<li>Resume from last position during playback</li>
		<li>Always-on-top everywhere.</li>
		<li>Multiple screens</li>
		<li>Playing any format &#8211; &#8220;Whoops I don&#8217;t have this codec, should I download it?&#8221;</li>
		<li>Thumbnails of everything &#8211; images, movies, <span class="caps">PDF</span>s, text and <span class="caps">HTML</span> files</li>
		<li>Audio is played just with placing mouse over it.</li>
	</ul>

	<h2>Reason #6: Accessibility</h2>

	<ul>
		<li>Super zooming with Super (aka Windows key) + mouse wheel.</li>
		<li>Chaning color of mouse cursor to white or black according to background to be still visible.</li>
		<li>Different sets of icons for visual impaired users</li>
	</ul>]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/average-users-top-reasons-why-ubuntu-rocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JPQL in examples</title>
		<link>http://devblog.virtage.com/2011/09/jpql-in-examples/</link>
		<comments>http://devblog.virtage.com/2011/09/jpql-in-examples/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 13:17:14 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=355</guid>
		<description><![CDATA[Quick brief example driven guide to Java Persistence Query Language (JPQL) Select Basic select: select e from Holiday e Select everything never than: select e from Holiday e where e.date &#62; {d &#39;2020-05-15&#39;} Select everything between dates: select e from Holiday e where e.date between {d &#39;2020-05-15&#39;} and {d &#39;2020-05-18&#39;} Select exact date or time: [...]]]></description>
			<content:encoded><![CDATA[	<p><em>Quick brief example driven guide to Java Persistence Query Language (<span class="caps">JPQL</span>)</em></p>

	<p><span id="more-355"></span></p>

	<h2>Select</h2>

	<p>Basic select:<br />
<code>select e from Holiday e</code></p>

	<p>Select everything never than:<br />
<code>select e from Holiday e where e.date &gt; {d &#39;2020-05-15&#39;}</code></p>

	<p>Select everything between dates:<br />
<code>select e from Holiday e where e.date between {d &#39;2020-05-15&#39;} and {d &#39;2020-05-18&#39;}</code></p>

	<p>Select exact date or time:<br />
<code>select e from Holiday e where e.date like {d &#39;2011-01-01&#39;}</code></p>

	<h2>Parametrized queries</h2>

	<p>Numbered paramaters:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">EM.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select h from Holiday h where h.date = ?1&quot;</span>, Holiday.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
   .<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">GregorianCalendar</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2011</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   .<span style="color: #006633;">getSingleResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/jpql-in-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabling any selection ListSelectionModel for JTable</title>
		<link>http://devblog.virtage.com/2011/09/disabling-any-selection-listselectionmodel-for-jtable/</link>
		<comments>http://devblog.virtage.com/2011/09/disabling-any-selection-listselectionmodel-for-jtable/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 08:29:28 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=337</guid>
		<description><![CDATA[Unfortunatelly there&#8217;s no easy way how to disable any selection in JTable. Setting on JTable: jtable.setColumnSelectionAllowed&#40;false&#41;; jtable.setRowSelectionAllowed&#40;true&#41;; jtable.setCellSelectionAllowed&#40;true&#41;; is not equivalent to disable any selection. My despair of lacking this quite imporant feature of JTable was ended by the idea of Brian Cole posted at one forum thread at CodeRanch. class NullSelectionModel implements ListSelectionModel &#123; [...]]]></description>
			<content:encoded><![CDATA[	<p><em>Unfortunatelly there&#8217;s no easy way how to disable any selection in JTable.</em></p>

	<p><span id="more-337"></span></p>

	<p>Setting on JTable:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">jtable.<span style="color: #006633;">setColumnSelectionAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jtable.<span style="color: #006633;">setRowSelectionAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jtable.<span style="color: #006633;">setCellSelectionAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


	<p>is not equivalent to disable any selection. My despair of lacking this quite imporant feature of JTable was ended by the idea of Brian Cole posted at one forum thread at <a href="http://www.coderanch.com/t/346552/GUI/java/Disable-Selection-JTable">CodeRanch</a>.</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> NullSelectionModel <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">ListSelectionModel</span> <span style="color: #009900;">&#123;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isSelectionEmpty<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: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isSelectedIndex<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getMinSelectionIndex<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: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getMaxSelectionIndex<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: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getLeadSelectionIndex<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: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getAnchorSelectionIndex<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: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSelectionInterval<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index0, <span style="color: #000066; font-weight: bold;">int</span> index1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLeadSelectionIndex<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAnchorSelectionIndex<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addSelectionInterval<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index0, <span style="color: #000066; font-weight: bold;">int</span> index1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> insertIndexInterval<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index, <span style="color: #000066; font-weight: bold;">int</span> length, <span style="color: #000066; font-weight: bold;">boolean</span> before<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> clearSelection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removeSelectionInterval<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index0, <span style="color: #000066; font-weight: bold;">int</span> index1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removeIndexInterval<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index0, <span style="color: #000066; font-weight: bold;">int</span> index1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSelectionMode<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> selectionMode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getSelectionMode<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> SINGLE_SELECTION<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addListSelectionListener<span style="color: #009900;">&#40;</span><span style="color: #003399;">ListSelectionListener</span> lsl<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removeListSelectionListener<span style="color: #009900;">&#40;</span><span style="color: #003399;">ListSelectionListener</span> lsl<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setValueIsAdjusting<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> valueIsAdjusting<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> getValueIsAdjusting<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: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/disabling-any-selection-listselectionmodel-for-jtable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Persistence API in non-JEE environment</title>
		<link>http://devblog.virtage.com/2011/09/java-persistence-api-in-non-jee-environment/</link>
		<comments>http://devblog.virtage.com/2011/09/java-persistence-api-in-non-jee-environment/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 19:50:25 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=308</guid>
		<description><![CDATA[JPA, as a one of the most useful technology from JEE world, is commonly overlooked in Java SE enviroments. There is a lot of documentation, manuals, tutorials but most of them are aimed to JEE enviroments. Unfortunatelly some of essential concepts is different if used outside JEE. Fortunatelly most of things are simpler. In this [...]]]></description>
			<content:encoded><![CDATA[	<p><em><span class="caps">JPA</span>, as a one of the most useful technology from <span class="caps">JEE</span> world, is commonly overlooked in Java SE enviroments. There is a lot of documentation, manuals, tutorials but most of them are aimed to <span class="caps">JEE</span> enviroments. Unfortunatelly some of essential concepts is different if used outside <span class="caps">JEE</span>. Fortunatelly most of things are simpler. In this post I would like to briefly introduce you into <span class="caps">JPA</span> 2.0 for Java SE heavily based on official <span class="caps">JPA</span> 2.0 specification in simplified “destilled” form.</em><br />
<span id="more-308"></span></p>

	<h2>Overview</h2>

	<p>This is not introduction for absolute beginners. Please refer to  books or tutorials on this topic. Firstly, I would like to summary terms and relationships among them.</p>

	<p><a href="http://devblog.virtage.com/wp-content/uploads/2011/09/JPA-in-non-JEE-relationships.png" style="border-style: none;"><img  src="http://devblog.virtage.com/wp-content/uploads/2011/09/JPA-in-non-JEE-relationships-300x269.png" alt="" title="JPA in non-JEE relationships" width="300" height="269" class="alignright size-medium wp-image-368" /></a></p>

	<h2>Persistence Unit</h2>

	<p>A persistence unit is a logical grouping that includes:</p>

	<ul>
		<li>Entity manager factory and its entity managers + their configuration information</li>
		<li>Set of entity classes</li>
		<li>Mapping metadata (annotations or <span class="caps">XML</span> file) that specifies mapping of the classes to the database.</li>
	</ul>

	<p>PU is represented by persistence.xml file in <code>META-INF</code> folder of <span class="caps">JAR</span> file or application.</p>

	<h3>Example of persistence.xml</h3>

	<p>Here I present typical example of peristence.xml file using Eclipselink and MySQL as a backend datastore.</p>

	<p>You can see <em>name of persistence unit</em>, <em>type of transaction</em>, <em>list of entity classes</em>, <em>connection setting</em>, and Eclipselink <em>provider-specific properties</em>.</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;persistence</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence&quot;</span></span>
<span style="color: #009900;"> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;persistence-unit</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.virtage.plexflow&quot;</span> <span style="color: #000066;">transaction-type</span>=<span style="color: #ff0000;">&quot;RESOURCE_LOCAL&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.persistence.jpa.PersistenceProvider<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/provider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.virtage.plexflow.Document<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.virtage.plexflow.WorkflowRule<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.virtage.plexflow.DocumentProperties<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;eclipselink.logging.level&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;FINE&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;javax.persistence.jdbc.driver&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;javax.persistence.jdbc.url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost/plexflow_trunk&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;javax.persistence.jdbc.user&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;plexflow_trunk&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;javax.persistence.jdbc.password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;very_strong_password&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;eclipselink.logging.level&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;INFO&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/persistence-unit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/persistence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


	<h2>Persistence Context</h2>

	<p>Definition found in <span class="caps">JPA</span> specification chapter 7.1:<br />
<em>A persistence context is a set of managed entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed by the entity manager.</em></p>

	<p>In <span class="caps">JEE</span> environment we persistence context is always managed automatically and is propagated with <span class="caps">JTA</span> transaction.</p>

	<ul>
		<li><strong>transaction scoped persistence context</strong> &#8211; lifetime of transaction is scoped to a single transaction. After transaction completes (TO <span class="caps">CONFIRM</span> no matter how whether with success or failure), persistence contexts die.</li></li>
		<li><strong>extended persistence context</strong> &#8211; extended lifetime that can spans multiple transactions</li>
	</ul>

	<p>In <span class="caps">JSE</span> environment exists only application-managed persistence contexts (because we have only application-managed entity managers) we always create a new isolated extended persistence context. Lifecycle is managed by <code>EntityManager.close()</code> method that closes entity manager to release its persistence context and other resources.</p>

	<p>Type of persistence context is depending on the PersistenceContextType specified when its entity manager is created.</p>

	<p>Persistence contexts are always associated with an entity manager factory. Entity manager instances obtained from different entity manager factories never share the same persistence context.</p>

	<p>TO <span class="caps">ASK</span> V <span class="caps">JSE</span> je jen transaction-scoped PC? Je to tak? Jelikož v <span class="caps">JPA</span> spec (7.6.2 a 7.6.3) je jen container-managed transaction-scoped a extended PC.</p>

	<p>In <span class="caps">JSE</span> we recognize these PCs: (<span class="caps">JPA</span> 7.7)</p>

	<p>(<span class="caps">JPA</span> spec 7.6:)</p>

	<ul>
		<li><strong>Container-managed persistence contexts</strong> (<span class="caps">JPA</span> 7.6) &#8211; When a container-managed entity manager is used, the lifecycle of the persistence context is always managed automatically, transparently to the application, and the persistence context is propagated with the <span class="caps">JTA</span> transaction.</li>
	</ul>

	<p>A container-managed persistence context may be defined to have either a lifetime that is scoped to a single transaction or an extended lifetime that spans multiple transactions, depending on the PersistenceContextType that is specified when its entity manager is created. This specification refers to such persistence contexts as transaction-scoped persistence contexts and extended persistence contexts respectively.</p>

	<h2>Entity Manager</h2>

	<p>There are, generally speaking, two main kinds of entity managers:</p>

	<ul>
		<li><strong>container-managed</strong>: Entity Manager may only be obtained from <span class="caps">JEE</span> container (application container or server that supports <span class="caps">JPA</span> <span class="caps">SPI</span>)
	<ul>
		<li><strong>transaction-scoped container-managed</strong></li>
		<li><strong>extended container-managed</strong></li>
	</ul></li>
		<li><strong>application-managed</strong> (or also non-managed): Second option for <span class="caps">JEE</span>, only option for <span class="caps">JSE</span> environment. Application must manually manage EntityManager instance lifecycle with close() method.</li>
	</ul>

	<p>EntityManager interface defines methods to interact with associated persistence context &#8211; to create and remove entitites, to find entitites, and to query over entitities.</p>

	<h3>Obtaining an EntityManager</h3>

	<p>Entity manager for a persistence context is always obtained from an entity manager factory. Altough in <span class="caps">JSE</span> environment, application has to obtain it directly from from <code>EntityManagerFactory</code> class (which is in turn obtained from <code>Persitence</code> root class).</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;">javax.persistence.*</span><span style="color: #339933;">;</span>
...
<span style="color: #006633;">EntityManagerFactory</span> emf <span style="color: #339933;">=</span> Persistence
	 .<span style="color: #006633;">createEntityManagerFactory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PetShop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
EntityManager em <span style="color: #339933;">=</span> emf.<span style="color: #006633;">createEntityManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #006633;">em</span>.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


	<p>If you don&#8217;t need EM anymore, it&#8217;s advisable to <code>close()</code> it. Closing should be performed before closing parent <span class="caps">EMF</span>.</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">em.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
emf.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


	<h3>Thread safety</h3>

	<p>Entity manager is not thread-safe and must be accessed in single-thread manner. [Z toho vyplývá] also persistence contexts are not required to be thread-safe.</p>

	<p>Unlike entity manager, entity manager factory is thread-safe.</p>

	<h3>Common entity manager methods</h3>

	<p>The persist, merge, remove, and refresh methods must be invoked within a transaction. If there is no transaction context, the <code>javax.persistence.TransactionRequiredException</code> is thrown.</p>

	<h4>persist()</h4>

	<p>Requirements:
	<ul>
		<li>Must be called in transaction, otherwise ??? is thrown.</li>
	</ul></p>

	<h4>merge()</h4>

	<p>Requirements:
	<ul>
		<li>Must be called in transaction, otherwise ??? is thrown.</li>
	</ul></p>

	<h4>remove()</h4>

	<p>Requirements:
	<ul>
		<li>Must be called in transaction, otherwise ??? is thrown.</li>
	</ul></p>

	<h4>lock()</h4>

	<p>Requirements:
	<ul>
		<li>Entity must be managed otherwise IllegalArgumentException is thrown.</li>
	</ul></p>

	<h4>find()</h4>

	<h4>contains()</h4>

	<h2>Locking</h2>

	<p>Locking is essential feature to avoid collisions resulting from simultaneous updates to the same data by concurrent users. <span class="caps">JPA</span> support two types of locking:</p>

	<ul>
		<li><strong>optimistic locking</strong> &#8211; The most common type of locking. Lock on object is placed on transaction commit. Every object that has to be updated or deleted is checked and exception is thrown when <span class="caps">JPA</span> detects that there is newer version of this object.</li>
		<li><strong>pesimistic locking</strong> &#8211; When need to know whether collision can occur earlier then on commit, use persimistic locking. This kind of locking locks object immediately when they are used in transaction.</li>
	</ul>

	<p>Optimitic locking should be prefered as it is easier to use and more efficient. The transaction will fail with <code>OptimisticLockException</code> on commit (or flush) operation if <span class="caps">JPA</span> detects that version field of being updated object is different from version is datastore (i.e. object has been already chaged by another user).</p>

	<p>In most <span class="caps">JPA</span> providers you will need to add field annotated with @Version to entity class. Although your <span class="caps">JPA</span> provider don&#8217;t force you to do this, it still make sence to expose version because your application can for example write version value to log on failure.</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyEntity <span style="color: #009900;">&#123;</span>
   ..
   @Version <span style="color: #000066; font-weight: bold;">long</span> version<span style="color: #339933;">;</span>
   ...
<span style="color: #009900;">&#125;</span></pre></div></div>


	<p>Also, if you do this, you should never allow modification of this field (never provide setter method).</p>

	<h3>Specifing locking mode</h3>

	<p>Enum <code>javax.persistence.LockModeType</code> is used to specify locking mode in methods that takes locks (lock, find, or refresh) or to the Query.setLockMode() or TypedQuery.setLockMode() methods.</p>

	<p><strong>Optimistic locking</strong>:
	<ul>
		<li><code>OPTIMISTIC</code> (formerly <code>READ</code> in <span class="caps">JPA</span> 1.0) &#8211; perform a version check on locked Entity before commit, throw an OptimisticLockException if Entity version mismatch.</li>
		<li><code>OPTIMISTIC_FORCE_INCREMENT</code> (formerly <code>WRITE</code> in <span class="caps">JPA</span> 1.0) &#8211; same but force an increment to the version at the end of the transaction, even if the entity is not modified.</li>
	</ul></p>

	<p><strong>Pesimistic locking</strong>:
	<ul>
		<li><code>LockModeType.PESIMISTIC</code> &#8211; lock the database row when reading</li>
		<li><code>LockModeType.PESIMISTIC_FOR_INCREMENT</code> &#8211; same but force an increment to the version at the end of the transaction, even if the entity is not modified.</li>
		<li>LockModeType.PESIMISTIC_READ</li>
		<li>LockModeType.PESIMISTIC_WRITE</li>
	</ul></p>

	<h2>Entity Manager Factory</h2>

	<p>Persistence unit have just one entity manager factory. Instance of <code>EntityManagerFactory</code> interface is used to create application-managed entity managers. Each <span class="caps">EMF</span> provides identically configured EM instances (connecting to the same database, same user and password etc.).</p>

	<h3>Obtaining an Entity Manager Factory</h3>

	<p><code>javax.persistence.Persistence</code> class is the bootstrap class that provides access to an entity manager factory.</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">EntityManagerFactory emf <span style="color: #339933;">=</span>
javax.<span style="color: #006633;">persistence</span>.<span style="color: #006633;">Persistence</span>.<span style="color: #006633;">createEntityManagerFactory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Order&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
EntityManager em <span style="color: #339933;">=</span> emf.<span style="color: #006633;">createEntityManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


	<p>At the end of lifetime of aplication, obtainted <span class="caps">EMF</span> should be closed with <code>close()</code> method. Closing <span class="caps">EMF</span> causes all its EM to move into the closed state also. This is not same as closing EM! There is still requirement to <code>EM.close()</code> before closing <span class="caps">EMF</span>.</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">em.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
emf.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


	<h2>Transactions</h2>

	<p><span class="caps">JPA</span> supports two different kinds of transactions.</p>

	<ul>
		<li><strong><span class="caps">JTA</span> transactions</strong> &#8211; typically used when runnin in <span class="caps">JEE</span> container. They are started and commited using usual container techniques (UserTransaction <span class="caps">API</span>, or transaction demarcation in <span class="caps">EJB</span> or Spring).</li>
		<li><strong>resource local transaction</strong> &#8211; in <span class="caps">JSE</span> or non-managed mode in <span class="caps">JEE</span>. You, as developer, must manage transaction manually by calling EntityTransaction instance methods begin(), commit() and rollback().</li>
	</ul>

	<h3>Transaction and Entity Manager</h3>

	<p>You can&#8217;t choose transaction type. <code>EntityTransaction</code> instance obtainted from EntityManager <code>getTransaction()</code> method has type defined according to underlying entity manager factory (i.e. specified in persistence.xml). See sections 8.2.1.2 and 9.1 in <span class="caps">JPA</span> specification.</p>

	<h3>EntityTransaction methods</h3>

	<h4>begin()</h4>

	<p>Start a resource transaction.</p>

	<p>Throws IllegalStateException if isActive() is true (i.e. there is already active transaction).</p>

	<h4>commit()</h4>

	<p>Commit the current resource transaction, writing any unflushed changes to the database.</p>

	<p>Throws &#8216;IllegalStateException&#8217; if isActive() is false.<br />
Throws &#8216;RollbackException&#8217; if the commit fails.</p>

	<p>If the EntityTransaction.commit operation fails, the persistence provider must roll back the transaction.</p>

	<p>Managed entities of transaction-scoped PC become detached when the trasaction commits; the managed entities of an extended PC remain managed.</p>

	<p>If the commit fails, then the managed objects are considered detached, and the EntityManager is cleared. This means that commit failures cannot be caught and retried, if a failure occurs, the entire transaction must be performed again.</p>

	<h4>rollback()</h4>

	<p>Roll back the current active resource transaction.</p>

	<p>Throws &#8216;IllegalStateException&#8217; if isActive() is false.<br />
Throws &#8216;PersistenceException&#8217; if an unexpected error condition is encountered.</p>

	<p>When a resource-local entity manager is used, and the persistence provider runtime throws an exception defined to cause transaction rollback, the persistence provider must mark the transaction for rollback.<br />
setRollbackOnly() and getRollbackOnly()</p>

	<p>Mark the current resource transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.</p>

	<p>Throws IllegalStateException if isActive() is false</p>

	<p>Important note: Transactions in <span class="caps">JPA</span> are always at the object level, this means that all changes made to all persistent objects in the persistence context are part of the transaction.</p>

	<p>There is 1:1 relationship between EntityManager and transaction so is common to see this code pattern</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">em.<span style="color: #006633;">getTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">// something</span>
em.<span style="color: #006633;">getTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>


	<p>instead of</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">EntityTransaction tx <span style="color: #339933;">=</span> em.<span style="color: #006633;">getTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tx.<span style="color: #006633;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// something</span>
tx.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>


	<p>because will always get same EntityTransaction instance. Also if you need more transactions, you have to get more entity managers.<br />
Declaring in persistence.xml</p>

	<p><code>transaction-type</code> attribute has value <code>RESOURCE_LOCAL</code>.</p>

	<h2>Resources</h2>

	<ul>
		<li><a href="http://jcp.org/aboutJava/communityprocess/final/jsr317/index.html"><span class="caps">JPA</span> 2.0 specification aka <span class="caps">JSR</span>-317</a></li>
		<li><a href="http://en.wikibooks.org/wiki/Java_Persistence">Java Persistence wikibook</a></li>
		<li><a href="http://weblogs.java.net/blog/caroljmcdonald/archive/2009/07/jpa_20_concurre.html"><span class="caps">JPA</span> 2.0 Concurrency and locking</a></li>
	</ul>]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/09/java-persistence-api-in-non-jee-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>en: How to redirect both stdin and stderr to text file in Windows?</title>
		<link>http://devblog.virtage.com/2011/07/en-how-to-redirect-both-stdin-and-stderr-to-text-file-in-windows/</link>
		<comments>http://devblog.virtage.com/2011/07/en-how-to-redirect-both-stdin-and-stderr-to-text-file-in-windows/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 13:56:08 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Etc.]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=288</guid>
		<description><![CDATA[Trick can be done using numbered redirections. You have to redirect and number stdout, redirect to a file, then redirect stderr to already redirected first redirection. Because an example is better then thousands of words: java -jar %HOMEDIR%\CleanForum.jar 1&#62; CleanForum.log 2&#62;&#38;1 or someapp 1&#62; CleanForum.log 2&#62;&#38;1 Here I am redirecting stdout 1&#62; to file CleanForum.log. [...]]]></description>
			<content:encoded><![CDATA[	<p>Trick can be done using numbered redirections. You have to redirect and number stdout, redirect to a file, then redirect stderr to already redirected first redirection. </p>

	<p><span id="more-288"></span></p>

	<p>Because an example is better then thousands of words:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-jar</span> <span style="color: #000000; font-weight: bold;">%</span>HOMEDIR<span style="color: #000000; font-weight: bold;">%</span>\CleanForum.jar <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;</span> CleanForum.log <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
   or
someapp <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;</span> CleanForum.log <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></pre></div></div>


	<p>Here I am redirecting stdout <code>1&gt;</code> to file <code>CleanForum.log</code>. Then stderr stream <code>2&gt;</code> is asked to output back to the first redirection using ampersand notation.</p>

	<p>That is it. If it is a little bit complicated, releax and just use it.</p>]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/07/en-how-to-redirect-both-stdin-and-stderr-to-text-file-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>en: Derby/Java DB like classic client-server DBMS</title>
		<link>http://devblog.virtage.com/2011/05/en-derbyjava-db-like-classic-client-server-dbms/</link>
		<comments>http://devblog.virtage.com/2011/05/en-derbyjava-db-like-classic-client-server-dbms/#comments</comments>
		<pubDate>Wed, 11 May 2011 06:52:50 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Etc.]]></category>
		<category><![CDATA[derby]]></category>
		<category><![CDATA[java db]]></category>

		<guid isPermaLink="false">http://devblog.virtage.com/?p=244</guid>
		<description><![CDATA[Please stop think about Derby/Java DB like simply only-suitable-for-embedding database. Derby can also run in Network Server mode and in this post I would like to show you that Derby DB can also &#8220;minics&#8221; or behave like classic more traditional client-server DBMS. Steps overview Install Derby (= just unpack .tar.gz) somewhere, e.g. /opt/derby. Create directory [...]]]></description>
			<content:encoded><![CDATA[	<p>Please stop think about Derby/Java DB like simply only-suitable-for-embedding database. Derby can also run in Network Server mode and in this post I would like to show you that Derby DB can also &#8220;minics&#8221; or behave like classic more traditional client-server <span class="caps">DBMS</span>.</p>

	<p><span id="more-244"></span></p>

	<h3>Steps overview</h3>

	<ol>
		<li>Install Derby (= just unpack .tar.gz) somewhere, e.g. <code>/opt/derby</code>.<br />
Create directory where files conprising database will reside, e.g. <code>/var/derby-dbs</code>.</li>
		<li>Create <code>derby.properties</code> configuration file here.</li>
		<li>Derby will create here also log file <code>derby.log</code></li>
		<li>Start Derby Network Server with</li>
	</ol>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> java -Dderby.system.home=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>derby-dbs <span style="color: #660033;">-jar</span> <span style="color: #007800;">$DERBY_HOME</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>derbyrun.jar server start</pre></div></div>


	<p>Please notice <code>derby.system.home</code> property cannot be placed in <code>derby.properties</code> file. It has to be known to Derby in start time, not later.</p>

	<h3>Example derby.properties file</h3>

	<p>If you are in hurry, here is example derby.properties file. For more details are tips continue bellow please.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Accept connections outside of localhost</span>
derby.drda.host=10.0.0.40
<span style="color: #666666; font-style: italic;"># Change default port 1527</span>
<span style="color: #666666; font-style: italic;">#derby.drda.portNumber=1527</span>
<span style="color: #666666; font-style: italic;"># Log connections</span>
derby.drda.logConnections=<span style="color: #c20cb9; font-weight: bold;">true</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Authentication and users</span>
derby.database.defaultConnectionMode=noAccess
derby.connection.requireAuthentication=<span style="color: #c20cb9; font-weight: bold;">true</span>
derby.authentication.provider=BUILTIN
derby.user.sa=veryStrongPassword
derby.user.readonly=<span style="color: #7a0874; font-weight: bold;">readonly</span>
derby.database.fullAccessUsers=sa
derby.database.readOnlyAccessUsers=<span style="color: #7a0874; font-weight: bold;">readonly</span></pre></div></div>


	<h3>Enable network connections from remote hosts</h3>

	<p>Default configuration disallow us to connect to Derby server outside of localhost. You have to specify network adapter on which Derby should listen using property <code>derby.drda.host</code>.</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Specify your server IP address
derby.drda.host<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">192.168.10.95</span>
# Or use special value 0.0.0.0 to listen on every NICs
derby.drda.host<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0.0.0.0</span></pre></div></div>


	<h3>Shutting down database or server</h3>

	<p>Because of nature of Derby shutting down is little complicated. You have a many ways to the the same thing &#8211; correctly shutdown database or server.</p>

	<h4>Using <span class="caps">JDBC</span> connection string</h4>

	<p>Shut down entire system:<br />
<code>jdbc:derby:;shutdown=true</code></p>

	<p>Shut down salesDB (authentication not enabled):<br />
<code>jdbc:derby:salesDB;shutdown=true</code></p>

	<p>Shut down using Network Server:<br />
<code>jdbc:<a href="">derby://localhost</a>:1527/mydb;shutdown=true</code></p>

	<h4>Using shell script</h4>

	<p><code>stopNetworkServer [-h hostname] [-p port] [-user user] [-password pwd]</code></p>

	<h4>Using derbyrun.jar</h4>

	<p><code>java -jar derbyrun.jar server shutdown [-h hostname] [-p port] [-user user] [-password pwd]</code></p>

	<h4>Using Java class</h4>

	<p><code>java org.apache.derby.drda.NetworkServerControl shutdown [-h hostname] [-p port] [-user user] [-password pwd]</code></p>

	<h3>Start, shutdown and restart helper scripts</h3>

	<p>You can save a lot of typing if you create three helper scripts to start, shutdown and to restart Derby server. I named it my<em>Command</em>.sh.</p>

	<p><strong>myStartServer.sh:</strong></p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
java -Dderby.system.home=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>derby-dbs <span style="color: #660033;">-jar</span> \
    <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>derby<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>derbyrun.jar server start</pre></div></div>


	<p><strong>myStopServer.sh:</strong></p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
java <span style="color: #660033;">-jar</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>derby<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>derbyrun.jar server \
   shutdown <span style="color: #660033;">-h</span> 10.120.34.25 <span style="color: #660033;">-p</span> <span style="color: #000000;">1527</span> <span style="color: #660033;">-user</span> sa <span style="color: #660033;">-password</span> <span style="color: #000000;">12356</span></pre></div></div>


	<p><strong>myRestartServer.sh:</strong></p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
.<span style="color: #000000; font-weight: bold;">/</span>myStopServer.sh
.<span style="color: #000000; font-weight: bold;">/</span>myStartServer.sh</pre></div></div>


	<p>And don&#8217;t forget make scripts executable:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x my<span style="color: #000000; font-weight: bold;">*</span>.sh</pre></div></div>


	<h3>How to shutdown broken zoombie Derby</h3>

	<p>Sometimes Derby cannot be stopped gracefully with shutdown method. In such case you have to kill it manually. I should be always used with care because you can lose data cached in memory or database can become unconsistent.</p>

	<p>Find process id (<span class="caps">PID</span>) of Derby</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> java</pre></div></div>


	<p>You you get output similar to this:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root     <span style="color: #000000;">27304</span>  <span style="color: #000000;">4.6</span>  <span style="color: #000000;">2.6</span> <span style="color: #000000;">411172</span> <span style="color: #000000;">27504</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>    Sl   09:<span style="color: #000000;">21</span>   <span style="color: #000000;">0</span>:01 java -Dderby.system.home=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>derby-dbs <span style="color: #660033;">-jar</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>derby<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>derbyrun.jar server start
<span style="color: #000000;">1000</span>     <span style="color: #000000;">27450</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.0</span>   <span style="color: #000000;">3324</span>   <span style="color: #000000;">804</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>    S+   09:<span style="color: #000000;">21</span>   <span style="color: #000000;">0</span>:00 <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">--color</span>=auto java</pre></div></div>


	<p>First line is your zoombie Derby. We can see that Derby has <span class="caps">PID</span> 27304. Second line is command used to identify <span class="caps">PID</span> itself. Kill <span class="caps">PID</span> 27304 with:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-kill</span> <span style="color: #000000;">27304</span></pre></div></div>


	<h3>Clients cannot connect with &#8220;Connection refused&#8221; error</h3>

	<p>For example if you try to shutdown Derby server with</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>stopNetworkServer <span style="color: #660033;">-user</span> sa <span style="color: #660033;">-password</span> <span style="color: #000000;">12356</span></pre></div></div>


	<p>or with</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>stopNetworkServer <span style="color: #660033;">-h</span> localhost <span style="color: #660033;">-p</span> <span style="color: #000000;">1527</span> <span style="color: #660033;">-user</span> sa <span style="color: #660033;">-password</span> <span style="color: #000000;">12356</span></pre></div></div>


	<p>Or you will try to connect using <code>ij</code> tool or any <span class="caps">JDBC</span> client you can encounter error<br />
<code>Fri May 06 10:02:19 CEST 2011 : Could not connect to Derby Network Server on host localhost, port 1527: Connection refused</code></p>

	<p>Suprisied by is connection refused? If you omit <code>-h</code> option, Derby will suppose that you mean <code>localhost</code>. But we previously instruct Derby to listen on <span class="caps">NIC</span> with some IP address, not on looback (i.e. localhost).</p>

	<h3>Auto start with computer</h3>

	<p>In Ubuntu and Debian place myStartServer.sh to <code>/etc/rc.local</code> file so it will looke like:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh -e</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># rc.local</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script is executed at the end of each multiuser runlevel.</span>
<span style="color: #666666; font-style: italic;"># Make sure that the script will &quot;exit 0&quot; on success or any other</span>
<span style="color: #666666; font-style: italic;"># value on error.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># In order to enable or disable this script just change the execution</span>
<span style="color: #666666; font-style: italic;"># bits.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># By default this script does nothing.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Start Derby Network Server</span>
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>derby<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>myStartServer.sh
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2011/05/en-derbyjava-db-like-classic-client-server-dbms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

