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

<channel>
	<title>Lemming Technology Blog</title>
	<atom:link href="http://lemnik.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://lemnik.wordpress.com</link>
	<description>it's all rather confusing really...</description>
	<lastBuildDate>Tue, 03 Nov 2009 06:47:21 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='lemnik.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/dcc1047428fbb7966f06959965a50ee4?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Lemming Technology Blog</title>
		<link>http://lemnik.wordpress.com</link>
	</image>
			<item>
		<title>EoD SQL 2.1 &#8211; Now in First RC Release</title>
		<link>http://lemnik.wordpress.com/2009/11/03/eod-sql-2-1-now-in-first-rc-release/</link>
		<comments>http://lemnik.wordpress.com/2009/11/03/eod-sql-2-1-now-in-first-rc-release/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 06:47:21 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=300</guid>
		<description><![CDATA[EoD SQL just got a 2.1 Release Candidate kicked out the door. While there are (once again) many performance improvements and a few bug fixes, the big news of this release has got to be Batch Updates!
Some people (myself included) have been waiting a very long time to see this feature in EoD SQL, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=300&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="EoD SQL Home Page" href="https://eodsql.dev.java.net/" target="_blank">EoD SQL</a> just got a <a title="Download EoD SQL 2.1-RC" href="https://eodsql.dev.java.net/servlets/ProjectDocumentList?folderID=8364&amp;expandFolder=8364" target="_blank">2.1 Release Candidate</a> kicked out the door. While there are (once again) many performance improvements and a few bug fixes, the big news of this release has got to be <strong>Batch Updates</strong>!</p>
<p>Some people (myself included) have been waiting a very long time to see this feature in EoD SQL, and it&#8217;s taken a fair amount of discussion to decide how it would work. The final answer came from Bernd Rinn: allow parameters to be specified as various Collection types. So to add a list of User objects to your database:</p>
<pre class="brush: java;">
@Update(sql=&quot;INSERT INTO users (name, birth_date, password, email) VALUES (?{1.name}, ?{1.birth_date}, ?{1.password}, ?{1.email})&quot;,batchUpdate=true)
void insertUsers(List&lt;User&gt; users);
</pre>
<p>Batch updates will work with any class extending Collection, or an array type. It can also be used with simple parameters:</p>
<pre class="brush: java;">
@Update(sql=&quot;REPLACE INTO user_group_join (user_id, group_id) VALUES (?{1.id}, ?{2.id})&quot;,batchUpdate=true)
void ensureUserInGroups(User user, Collection&lt;Group&gt; groups);
</pre>
<p>A Batch Update is generally much faster than a series of normal update invocations, because EoD SQL will use PreparedStatement.addBatch() to build up all of the parameters on the client-side before sending all of the data to the database in one statement. It doesn&#8217;t mean it&#8217;s a single transaction, but it does mean that the database can execute all of the parameter variations before sending any data back.</p>
<p>So why not go <a title="Download EoD SQL 2.1-RC" href="https://eodsql.dev.java.net/servlets/ProjectDocumentList?folderID=8364&amp;expandFolder=8364" target="_blank">download</a> the new release and give it a try.</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;">
<pre>Bernd Rinn</pre>
</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=300&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/11/03/eod-sql-2-1-now-in-first-rc-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>EoD SQL 2.1-Beta Released</title>
		<link>http://lemnik.wordpress.com/2009/10/16/eod-sql-2-1-beta-released/</link>
		<comments>http://lemnik.wordpress.com/2009/10/16/eod-sql-2-1-beta-released/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 08:58:46 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=293</guid>
		<description><![CDATA[EoD SQL 2.1-Beta has been released, you can go download it from the Documents &#38; Files section of the homepage. The 2.1 release is about improving speed and usability over the 2.0 release. Some of the new features included are:

Specific Collection implementations (including those not in the standard Java API&#8217;s) can now be returned:
@Select(&#34;SELECT * [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=293&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>EoD SQL 2.1-Beta has been released, you can go download it from the <a title="Download EoD SQL 2.1-Beta" href="https://eodsql.dev.java.net/servlets/ProjectDocumentList?folderID=8364&amp;expandFolder=8364&amp;folderID=0" target="_blank">Documents &amp; Files</a> section of the <a title="EoD SQL Home Page" href="https://eodsql.dev.java.net/" target="_blank">homepage</a>. The 2.1 release is about improving speed and usability over the 2.0 release. Some of the new features included are:</p>
<ul>
<li>Specific Collection implementations (including those not in the standard Java API&#8217;s) can now be returned:
<pre class="brush: java;">@Select(&quot;SELECT * FROM users WHERE group = ?{1.id}&quot;)
 ArrayList&lt;User&gt; selectUserGroup(Group group);</pre>
</li>
<li>Select methods can now populate existing objects:
<pre class="brush: java;">@Select(sql=&quot;SELECT * FROM user_meta_info WHERE user_id = ?{1.id}&quot;,into=1)
void selectMetaInfo(User user);</pre>
</li>
<li>Faster construction of query implementations</li>
<li>Better error reporting</li>
<li>Several small bug fixes</li>
</ul>
<p>This is of course a beta release, so there may be bugs. That said the code is pretty well unit tested and should be relatively stable. One new feature not in the release (but on the way) is batch updates. Stay tuned for more information!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/293/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=293&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/10/16/eod-sql-2-1-beta-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>Using an Aladdin eToken with Java keytool</title>
		<link>http://lemnik.wordpress.com/2009/10/06/using-an-aladdin-etoken-with-java-keytool/</link>
		<comments>http://lemnik.wordpress.com/2009/10/06/using-an-aladdin-etoken-with-java-keytool/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 09:34:18 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=291</guid>
		<description><![CDATA[The Aladdin eToken is a great little security device when you have sensitive private key information. They are a great USB solution in that they support all major operating-systems with a PKCS#11 driver. This means they also integrate with Java on all major platforms (through the SunPKCS11 Security Provider).
The one problem we have come across  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=291&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The <a href="http://www.aladdin.com/etoken/security-applications.aspx" target="_blank">Aladdin eToken</a> is a great little security device when you have sensitive private key information. They are a great USB solution in that they support all major operating-systems with a PKCS#11 driver. This means they also integrate with Java on all major platforms (through the SunPKCS11 Security Provider).</p>
<p>The one problem we have come across  with the device is trying to create keys on it using the standard Java keytool application. There are two errors you&#8217;ll almost certainly face, both in the form of a <tt>sun.security.pkcs11.wrapper.PKCS11Exception.</tt></p>
<h2>Error 1: CKR_ATTRIBUTE_TYPE_INVALID</h2>
<p>This error (we found) pops up when you don&#8217;t specify the key algorithm on the command line. You need to specify &#8220;-keyalg RSA&#8221; to ensure that an RSA key (instead of the default DSA) is generated for the eToken.</p>
<h2>Error 2: CKR_TEMPLATE_INCONSISTENT</h2>
<p>This one is a little more nasty.  It&#8217;s not well documented, but effectively the keytool doesn&#8217;t generate signatures that the eToken&#8217;s PKCS#11 implementation likes (we couldn&#8217;t find any tool other than the eToken software that did). Under Windows you need a registry key:</p>
<p><tt>HKEY_LOCAL_MACHINE\SOFTWARE\Aladdin\eToken\MIDDLEWARE\GENERAL</tt></p>
<p>The key is a DWORD attribute: &#8220;TolerantX509Attributes&#8221; with a value of &#8220;1&#8243;. But what about Mac and Linux. You&#8217;ll need to look for the eToken config file: <tt>/etc/eToken.conf</tt>, then under the &#8220;[GENERAL]&#8221; section of the file add the line:</p>
<p><tt>TolerantX509Attributes=1</tt></p>
<p>This will allow keytool (and other PKCS#11 tools) to generate and store keypairs on your USB eToken.</p>
<h2>A Command Line Example</h2>
<p><tt> keytool -v -genkeypair </tt><tt>-keyalg RSA </tt><tt>-alias myKey -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /home/me/pkcs11.conf<br />
</tt></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/291/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=291&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/10/06/using-an-aladdin-etoken-with-java-keytool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>EoD SQL Applied – Part 5 / 5 (GWT Applications)</title>
		<link>http://lemnik.wordpress.com/2009/09/18/eod-sql-applied-%e2%80%93-part-5-5-gwt-applications/</link>
		<comments>http://lemnik.wordpress.com/2009/09/18/eod-sql-applied-%e2%80%93-part-5-5-gwt-applications/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 17:23:25 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=280</guid>
		<description><![CDATA[The Dreaded &#8220;Not Serializable&#8221; Problem
GWT turns all of your Java code into JavaScript, but it also obfuscates everything. With this in mind, it makes serialization a bit more complex than usual. GWT generates a serializer and deserializer for each class that could be transported across the wire to an RPC service. The difficulty comes in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=280&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>The Dreaded &#8220;Not Serializable&#8221; Problem</h2>
<p>GWT turns all of your Java code into JavaScript, but it also obfuscates everything. With this in mind, it makes serialization a bit more complex than usual. GWT generates a serializer and deserializer for each class that could be transported across the wire to an RPC service. The difficulty comes in knowing which types had code generated, and which didn&#8217;t. GWT solves this problem for itself with the Serialization Policy file, where the compiler lists all of the classes that the client code will know how to deserialize.</p>
<p>This however leads to another problem: what happens when something unexpected gets in the way. Hibernate is the most used, and thus most complained about when it comes to Serialization problems. Hibernate turns any Collection object into a special &#8220;lazy&#8221; implementation that will only load your data when you ask for it. All very fine and well for a server bound application, but a GWT application needs all that data up front for serialization. When GWT comes to sending that List&lt;Message&gt; to the client, it chokes. It knows how to serialize an ArrayList, and LinkedList (since you worked with them on the client side), but a Hibernate List or PersistentCollection is a totally unknown type, so it&#8217;s not in the Serialization Policy, so the server side throws an Exception at you.</p>
<p>So how does <a title="EoD SQL Home Page" href="https://eodsql.dev.java.net/" target="_blank">EoD SQL</a> help with these problems? Read on to find out! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <span id="more-280"></span></p>
<h3>Loosing the Lazy Loading</h3>
<p>EoD SQL  (unlike most OR mapping layers) makes no attempt to understand the internal relationships between you objects. The reason for this is that EoD SQL is technically dialect neutral, it doesn&#8217;t actually care what you put into you @Select annotation so long as it can create a PreparedStatement and populate it with parameters. This frees you to take maximum advantage of database extensions, or weird SQL dialects. It also means that EoD SQL will never generate any SQL code for you: what you type is what gets executed.</p>
<p>Within a GWT application, you don&#8217;t have a way to block until a method is complete, and thus lazy-loading data becomes a chore, since you need to work with a lot of callbacks (a nice way of abstracting lazy-like-loading <a title="Property Binding with Async Callbacks" href="http://lemnik.wordpress.com/2008/07/22/easy-property-binding-and-aync-callbacks-in-gwt/" target="_blank">is posted on my blog</a>). This means that most of the object model given to GWT needs to be (at least partly) eager-loaded.</p>
<p>So because EoD SQL doesn&#8217;t do any lazy-loading, it &#8220;forces&#8221; you into thinking about how much data and what data you will be sending to the client. It takes a little getting used to, but over time you will find your code much clearer to read and running much faster (since less data comes from the database, fewer queries are run and the JavaScript has less data to deal with).</p>
<h2>Arrays instead of Collections</h2>
<p>The first trick to working with GWT is: when you need more than one object fetched from the database (which is most of the time), return an array instead of a Collection:</p>
<pre class="brush: java;">
public interface MessageQuery extends BaseQuery {

/*
* This is not a great way to do things in EoD SQL 2.0 when dealing with GWT.
* This method will return an ArrayList of Message objects, however the List implementation could
* possibly be changed in the future (not likely). Further the ArrayList is populated using the basic
* List.add(Object) method. The ArrayList will re-copy it's internal array over-and-over again as
* the ResultSet is scanned.
*
* So while this method will work with GWT, it's really not recommended.
*/
@Select(&quot;SELECT * FROM messages WHERE parent_id = ?1 ORDER BY date DESC LIMIT ?3 OFFSET ?2&quot;)
List&amp;lt;Message&amp;gt; selectChildMessagesAsList(int parentId, int start, int count);

/*
* This won't work at all with GWT. The DataSet may offer lazy-loading
* and some other wonderful tricks, but since the client code has no idea
* how to deal with a DataSet it's useless here. I thought I'd put it in for completeness.
*/
@Select(&quot;SELECT * FROM messages WHERE parent_id = ?1 ORDER BY date DESC LIMIT ?3 OFFSET ?2&quot;)
DataSet&amp;lt;Message&amp;gt; selectChildMessagesAsDataSet(int parentId, int start, int count);

/*
* This is the way to do it! Using only arrays for Serialization has a side effect
* on the GWT side of things: less JavaScript code for your clients to download.
* GWT understands how to deserialize arrays, and doesn't need to include
* Serialization code for different List implementations.
*/
@Select(&quot;SELECT * FROM messages WHERE parent_id = ?1 ORDER BY date DESC LIMIT ?3 OFFSET ?2&quot;)
Message[] selectChildMessagesAsArray(int parentId, int start, int count);

}
</pre>
<p>Now for the big question: why are arrays &#8220;so much better&#8221; than a List of some sort? EoD SQL takes fairly extreme measures to keep the performance of an Array as fast as possible. For the most part (that is: on most JDBC drivers) the array will be pre-sized and fetched backwards. This sounds very strange, but it is generally a lot faster than trying to work forwards and re-growing the array whenever it runs out of space (and then down-sizing it at the end). EoD SQL will run forwards if the JDBC driver requires it, but for the most part it runs backwards.</p>
<p>This technique will not only improve performance, JavaScript size, and simplicity of the code (arrays are just easier in most cases); it&#8217;ll also reduce the amount of memory your server uses (since the array is pre-sized and never copied).</p>
<p>Finally: because the type is declared as an array, you know exactly what Serialization code GWT is going to generate.</p>
<h2>Looking to the Future (EoD SQL 2.1)</h2>
<p>In EoD SQL 2.0 you can declare Collection objects as return types, but only as their interfaces (as you saw in the above code example). EoD SQL 2.1 has a new feature which allows you to declare concrete implementations as return types. This is the preferred method of declaration for GWT (since again: it minimizes the amount of JavaScript generated). A few nice little examples:</p>
<pre class="brush: java;">
public interface MessageQuery extends BaseQuery {

@Select(&quot;SELECT * FROM messages WHERE parent_id = ?1 ORDER BY date DESC LIMIT ?3 OFFSET ?2&quot;)
ArrayList&amp;lt;Message&amp;gt; selectMessages(int parentId, int start, int count);

@Select(&quot;SELECT title, date, author FROM messages WHERE parent_id IS NULL ORDER BY date&quot;)
MyCollectionImplementation&amp;lt;Message&amp;gt; selectTopLevelMessages();

}
</pre>
<p>The big difference between 2.0s handling of Collection objects, and 2.1 is that 2.1 will allow the Collection implementation (including those declared as their interfaces) to optimize their fetching of the data internally (if they are able). Thus returning a List or ArrayList will no longer cause the resize-resize-resize effect (or shouldn&#8217;t anyways). Collections will be given the same treatment as arrays in 2.1.</p>
<h2>Conclusion</h2>
<p>So we&#8217;ve looked at four different situations where EoD SQL works really well.</p>
<p>The concept to take away from this (I feel) is that: <em>with EoD SQL you are in total control of how the code is going to behave</em>.</p>
<p>If you need lazy-loading and scrolling data (like in our Swing example), you can use a DataSet; to minimize memory a DataIterator; and when lazy-loading can&#8217;t be used because of other constraints Collections and Arrays are available. Whatever the situation: EoD SQL is going to make life that little bit easier for you, without you giving up control of what goes on behind the scene.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/280/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=280&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/09/18/eod-sql-applied-%e2%80%93-part-5-5-gwt-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>EoD SQL Applied &#8211; Part 4 / 5 (JavaScript)</title>
		<link>http://lemnik.wordpress.com/2009/09/17/eod-sql-applied-part-4-5-javascript/</link>
		<comments>http://lemnik.wordpress.com/2009/09/17/eod-sql-applied-part-4-5-javascript/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 17:36:05 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servlets]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=270</guid>
		<description><![CDATA[JavaScript vs. Web Applications
So far in this series we&#8217;ve discussed using DataSets for Swing applications and DataIterators for web-applications. Why would I now bring in JavaScript as something outside of &#8220;web-application&#8221;? JavaScript applications have very different requirements to a normal web-application. Where a normal web-application has little ability to do things like preload data (like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=270&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>JavaScript vs. Web Applications</h2>
<p>So far in this series we&#8217;ve discussed using DataSets for Swing applications and DataIterators for web-applications. Why would I now bring in JavaScript as something outside of &#8220;web-application&#8221;? JavaScript applications have very different requirements to a normal web-application. Where a normal web-application has little ability to do things like preload data (like the next page), a JavaScript application may (for example) download the entire data-set and then display it in pages. This next section is about binding to JSON for JavaScript applications.</p>
<p>First thing to remember here is that an <a title="EoD SQL Home Page" href="https://eodsql.dev.java.net/" target="_blank">EoD SQL</a> DataSet is a List and thus compatible with the Collections API. For this example we&#8217;re going to be working with the outstanding <a title="GSON Project Page" href="http://code.google.com/p/google-gson/" target="_blank">GSON API</a> from our friends at Google. Our objective here is to minimize the amount of time spent between the Database and pushing the data to the client. Because GSON doesn&#8217;t appear to support Iterable object out-of-the-box, we&#8217;re going to start off using a DataSet.<br />
<span id="more-270"></span></p>
<h3>Using a DataSet with GSON</h3>
<p>The advantage with this approach is that you don&#8217;t need any additional binding classes in GSON. The approach should work well with any JSON API. The DataSet class has the additional advantage of being able to perform &#8220;paged&#8221; requests on databases that don&#8217;t have a LIMIT statement (by using absolute get() invocations or DataSet.subList()).</p>
<pre class="brush: java;">
public class UserQuery extends BaseQuery {
@Select(sql=&quot;SELECT * FROM users ORDER BY name LIMIT ?2 OFFSET ?1&quot;,cache=NullDataSetCache.class)
DataSet&amp;lt;User&amp;gt; selectUserPage(int start, int count);

@Select(&quot;SELECT COUNT(*) FROM users&quot;)
int getUserCount();
}

public class PageOfUsersServlet extends HttpServlet {

private static final UserQuery USER_QUERY = QueryTool.getQuery(UserQuery.class);

protected void doGet(
final HttpServletRequest request,
final HttpServletResponse response)
throws ServletException,
IOException {

final int start = Integer.parseInt(request.getParameter(&quot;start&quot;));
final int count = Integer.parseInt(request.getParameter(&quot;count&quot;));

final DataSet&amp;lt;User&amp;gt; users = USER_QUERY.selectUserPage(start, count);

try {
response.setContentType(&quot;application/json&quot;);
final Gson gson = new Gson();
gson.toJSON(new PageResponse&amp;lt;User&amp;gt;(
start,
USER_QUERY.getUserCount(),
users),
response.getWriter());
} finally {
users.close();
}
}

private static class PageResponse&amp;lt;E&amp;gt; {

private final int startItem;

private final int totalItems;

private final Collection&amp;lt;E&amp;gt; items;

PageResponse(
final int start,
final int total,
final Collection&amp;lt;E&amp;gt; items) {

this.startItem = start;
this.totalItems = total;
this.items = items;
}

public int getStartItemIndex() {
return startItem;
}

public int getTotalItemCount() {
return totalItems;
}

public Collection&amp;lt;E&amp;gt; getItems() {
return items;
}
}
}
</pre>
<p>Some important things about the above code:</p>
<ol>
<li>We use the NullDataSetCache in the @Select annotation. This stops the returned DataSet caching the objects for identity equality, and since JSON has no back-referencing support, such caching would be a waste of time</li>
<li>We wrap the Users returned in a PageResponse object and serialize that to the client. This object allows for a single callback function to handle the responses from any request for a page of users (since the response contains the index to insert the first user in). So we avoid the need for a closure on the JavaScript side.</li>
<li>We send the total number of users in the database back to the client with each request, allowing us to determine the number of pages that can be fetched, even when the number of users is constantly changing.</li>
<li>Finally: we have GSON pipe the JSON directly to the responses Writer. If the response is small it&#8217;ll be buffered by the container and then sent, but if we overflow the buffer boundary, the response will be chunked into blocks allowing us to free up some server-side memory.</li>
</ol>
<h3>DataIterators and Rubberstamping</h3>
<p>Now for some black-magic. This part has only been tested with GSON, it may work with other JSON api&#8217;s but it strongly depends on how they treat Collection objects. The idea here is to avoid writing special binding objects and to leave the selection of data from the database until as late as possible. We rely on the fact the GSON never uses the size() or toArray() methods of a Collection object, only iterator(). This means that we can have a Collection implementation that doesn&#8217;t have a size() method, and returns a DataIterator for it&#8217;s iterator() method.</p>
<p>The example is virtually identical to the one above, except that it will run much faster, and use much less memory.</p>
<pre class="brush: java;">
public class UserQuery extends BaseQuery {
@Select(sql=&quot;SELECT * FROM users ORDER BY name LIMIT ?2 OFFSET ?1&quot;,rubberstamp=true)
DataIterator&amp;lt;User&amp;gt; selectUserPage(int start, int count);

@Select(&quot;SELECT COUNT(*) FROM users&quot;)
int getUserCount();
}

public class PageOfUsersServlet extends HttpServlet {

private static final UserQuery USER_QUERY = QueryTool.getQuery(UserQuery.class);

protected void doGet(
final HttpServletRequest request,
final HttpServletResponse response)
throws ServletException,
IOException {

final int start = Integer.parseInt(request.getParameter(&quot;start&quot;));
final int count = Integer.parseInt(request.getParameter(&quot;count&quot;));

final Collection&amp;lt;User&amp;gt; lazyUserCollection = new AbstractCollection&amp;lt;User&amp;gt;() {

public Iterator&amp;lt;User&amp;gt; iterator() {
// we perform the query as late as possible
return USER_QUERY.selectUserPage(start, count);
}

public int size() {
// we could return the &quot;count&quot; field here,
// however the &quot;count&quot; is simply the maximum number
// of rows that could be returned, not the actual number
throw new UnsupportedOperationException();
}

};

response.setContentType(&quot;application/json&quot;);
final Gson gson = new Gson();
gson.toJSON(new PageResponse&amp;lt;User&amp;gt;(
start,
USER_QUERY.getUserCount(),
lazyUserCollection),
response.getWriter());
}

private static class PageResponse&amp;lt;E&amp;gt; {

private final int startItem;

private final int totalItems;

private final Collection&amp;lt;E&amp;gt; items;

PageResponse(
final int start,
final int total,
final Collection&amp;lt;E&amp;gt; items) {

this.startItem = start;
this.totalItems = total;
this.items = items;
}

public int getStartItemIndex() {
return startItem;
}

public int getTotalItemCount() {
return totalItems;
}

public Collection&amp;lt;E&amp;gt; getItems() {
return items;
}
}
}
</pre>
<h3>Conclusion</h3>
<p>We&#8217;ve run through using both DataSets and DataIterators for turning your objects into JSON data for a client. Bare in mind that you should test the DataIterator technique well before using it with any other JSON API. In the final part of this series we will look at using EoD SQL with GWT, and take a sneak peak into future of EoD SQL and the upcoming 2.1 releases features.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=270&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/09/17/eod-sql-applied-part-4-5-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>EoD SQL Applied &#8211; Part 3 / 5 (JSP / Servlets)</title>
		<link>http://lemnik.wordpress.com/2009/08/27/eod-sql-applied-part-3-5-jsp-servlets/</link>
		<comments>http://lemnik.wordpress.com/2009/08/27/eod-sql-applied-part-3-5-jsp-servlets/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 06:54:45 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servlets]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=265</guid>
		<description><![CDATA[Static Data Display
In a Swing application with a direct connection to a database, it makes sense to leave the database to do much of the heavy lifting. The Swing client can keep a minimum amount of data in memory, while holding a scrollable Result Set open on the database (fetching more of the data as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=265&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>Static Data Display</h2>
<p>In a Swing application with a direct connection to a database, it makes sense to leave the database to do much of the heavy lifting. The Swing client can keep a minimum amount of data in memory, while holding a scrollable Result Set open on the database (fetching more of the data as required). In a web application on the other hand, things are a little more complex. For one thing, your database isn&#8217;t exposed to the any part of the network; for another: your clients have no ability to keep Result Sets open; and finally: you generally are working with much higher loads than a Swing application.</p>
<p><a title="EoD SQL Home Page" href="https://eodsql.dev.java.net/" target="_blank">EoD SQL</a> has many different approaches to loading data from the database. We&#8217;ve already looked at DataSet objects, which remain connected to the database and work well with scrollable, cursor backed, Result Sets. DataSets are (in a way) a leftover from the origional EoD API from Java6-beta (where they were the only way to fetch objects from the database). In this post we&#8217;ll take a look at an EoD SQL idea: DataIterators.</p>
<p><span id="more-265"></span></p>
<h2>Data Iterator Introduction</h2>
<p>A DataIterator as the name implies as an Iterator which is connected directly to the database (like a DataSet). Here are the most important features of a DataIterator:</p>
<ul>
<li>DataIterators are forward-only (no going backwards)</li>
<li>They are always connected to the database (no notion of a &#8220;disconnected&#8221; DataIterator)</li>
<li>They are not backed by any sort of cache (ie: DataSetCache)
<ul>
<li>There is no need for one, since you can&#8217;t go backwards</li>
</ul>
</li>
<li>They also implement Iterable (their &#8220;iterator()&#8221; method returns &#8220;this&#8221;) for convenience
<ul>
<li>So they work easily with the Java-5 enhanced for loop</li>
</ul>
</li>
<li>They close themselves when their last object has been read (ie: &#8220;hasNext()&#8221; returns false)
<ul>
<li>If you do not work through all of the DataIterator: you will need to invoke it&#8217;s &#8220;close&#8221; method by hand</li>
</ul>
</li>
<li>You cannot modify a DataIterator (remove() will throw an UnsupportedOperationException)
<ul>
<li>The following is an error (InvalidQueryException)<br />
<tt>@Select(sql="SELECT * FROM users",readonly=false)<br />
DataIterator&lt;User&gt; selectUsers();</tt></li>
</ul>
</li>
</ul>
<p>DataIterators are a great fit whenever you only need to work through the ResultSet once and in a single direction.  The database can stream the ResultSet to the JDBC driver, since there is no need for a scrollable cursor. This forward-only, streaming nature is a very good fit to web-applications. Web applications work with a user that is on the other side of an HTTP connection. So scrollable DataSets that hold onto their database Connections are of limited use, since a web application generally holds onto a database Connection for as short-a-time as possible (while DataSets are best used with long lived Connections).</p>
<h3>Rubberstamping</h3>
<p>Rubberstamping is the key feature we will be looking at in this post.  Rubberstamping is only available to a DataIterator, and is setup in the @Select annotation:</p>
<pre class="brush: java;">
@Select(sql=&quot;SELECT * FROM users&quot;,rubberstamp=true)
DataIterator&lt;User&gt; selectUsers();
</pre>
<p>So what is rubberstamping? Take a look at the following code and you&#8217;ll see.</p>
<pre class="brush: java;">
DataIterator&lt;User&gt; users = userQuery.selectUsers();
User user1 = users.next();
User user2 = users.next();

if(user1 == user2) {
  // this is the big deal, this will always be true
}
</pre>
<p>Rubberstamping only ever creates one &#8220;row&#8221; object, in this case a single User object is created. Each time you invoke next(), instead of creating a new User object (and so forcing the GC to clean the old one up): it pushes the new values into the exsting User object and returns it. This saves memory and time (both allocation time and GC time later on). You could argue that the eden-space GC will take care of these short lived objects, but in a web environment the rubber-stamped row object will also be handles by the eden-gc and so the eden GC will trigger less often (since there will be fewer objects).</p>
<h3>Rubberstamping and Web Applications</h3>
<p>So why is rubber-stamping so nice for web applications in particular. A web-application is connected (fairly directly) to a socket that the browser sits on the other end of. Objects being processed for display as HTML are almost never needed (within the same request) after the HTML has been written. In this case: rubber-stamping is a perfect fit, since the object is re-used instead of being discarded.</p>
<p>I find the best way to work with a DataIterator in a web-application is with the JSTL &#8220;forEach&#8221; tag which supports DataIterator as a Iterator instance. Generally you should try and avoid using the begin and end attributes of the tag, opting instead for a &#8220;LIMIT&#8221; (or similar) clause in your SQL statement. Because the for each tag uses the DataIterator as a plain Iterator object it fully supports the rubber-stamping ability, and because you are outputting directly to a JspWriter you almost certainly won&#8217;t need to keep references to objects already outputted.</p>
<h4>Comparison to the JSP SQL tags</h4>
<p>So why not just use the JSP SQL tags then? There are several reasons to rather make use of the DataIterator class.</p>
<ul>
<li> The JSP remains agnostic to the type being passed in, any object supported by the &#8220;forEach&#8221; tag can be used, if a DataIterator becomes unsuitable in the future you can swap it without modification to the JSP.</li>
<li>The SQL code remains in an EoD SQL BaseQuery interface which is (or should be) executed by normal Java code and passed into the JSP using a request attribute (or similar mechanism).</li>
<li>The SQL query (and thus the DataIterator) is centralized, and so usable by the Java code that supports the JSP. So you avoid code duplication (and wondering why the JSP is still showing the wrong data).</li>
<li>You&#8217;re working with your objects and not just raw SQL data.</li>
</ul>
<h2>Caching Data from the Database</h2>
<p>A major concern now is database performance. With a DataIterator you will be accessing the database every time you want to read some data. Many web-application make use of a caching system (such as memcache, terracotta, eh-cache or similar), how can you have a DataIterator interact with the cache? As I already said in the previous section: the &#8220;forEach&#8221; tag doesn&#8217;t care if the input type changes between 2 invocations.</p>
<p>I generally put my JSP pages &#8220;behind&#8221; a Servlet which invokes the JSP using a RequestDispatcher.forward call. Here&#8217;s a simple example of a Servlet that invokes a JSP, and plays nicely with an imaginary &#8220;cache&#8221; object.</p>
<pre class="brush: java;">
public class TopicListServlet extends HttpServlet {
  private final Cache&lt;Long, Collection&lt;Topic&gt;&gt; cache = ...;
  private final TopicQuery query = QueryTool.getQuery(TopicQuery.class);

  private Iterator&lt;Topic&gt; getTopicsFromCache(final Long id) {
    final Collection&lt;Topic&gt; topics = cache.get(id);
    return topics != null
      ? topics.iterator()
      : null;
  }

  protected void doGet(
      final HttpServletRequest request,
      final HttpServletResponse response)
      throws ServletException,
      IOException {

    final Long id = Long.parseLong(request.getParameter(&quot;id&quot;));
    Iterator&lt;Topic&gt; topics = getTopicsFromCache(id);

    if(topics == null) {
      topics = new CachingIterator&lt;Long, Topic&gt;(id, cache, query.selectTopics(id));
    }

    request.setAttribute(&quot;topics&quot;, topics);
    request.getRequestDispatcher(&quot;/topics.jsp&quot;).forward(request, response);
  }

  private static class CachingIterator&lt;K, V&gt; implements Iterator&lt;V&gt; {
    private final Iterator&lt;V&gt; delegate;
    private final Cache&lt;K, Collection&lt;V&gt;&gt; cache;
    private final K key;

    private final Collection&lt;V&gt; values = new ArrayList&lt;V&gt;();

    public CachingIterator(
        final K key,
        final Cache&lt;K, Collection&lt;V&gt;&gt; cache,
        final Iterator&lt;V&gt; iterator) {

      // ...
    }

    public boolean hasNext() {
      if(!delegate.hasNext()) {
        cache.add(key, values);
        return false;
      }

      return true;
    }

     public V next() {
       final V value = delegate.next();
       values.add(value);

       return value;
     }

     public void remove() {
       throw new UnsupportedOperationException();
     }
  }

  public static interface TopicQuery extends BaseQuery {
    @Select(&quot;SELECT * FROM topics WHERE parent_id = ?1 ORDER BY post_date DESC&quot;)
    DataIterator&lt;Topic&gt; selectTopics(long parentId);
  }
}
</pre>
<p>As you can see in the above code, the need for caching has a potential side-effect: you loose the ability to rubber-stamp the objects. However this is not the end of the world, since rubber-stamping is particularly useful with potentially very large data-sets (where caching is often a bad idea). Another, often easier option than was used here (although slower for your request) is to have EoD SQL return a Collection&lt;Topic&gt; or List&lt;Topic&gt; instead of a DataIterator. This mechanism however is much slower, since EoD SQL will read in the entire ResultSet  before returning from the select query. We&#8217;ll explore using Collections as return types in the next two posts.</p>
<h2>Conclusion</h2>
<p>We&#8217;ve played with rubber-stamping, perfect for those days when you need lots of data with minimal memory usage. We&#8217;ve also looked at how to get the objects from a DataIterator into a cache for later use. DataIterators are a generally good mix with web applications, since you have a socket open, so you really want to pre-buffer as little data as you possibly can. In the next post we&#8217;ll take a look at using EoD SQL with JavaScript applications. While they are web-applications as well, they have different communication requirements to a typical web-application. So we&#8217;ll look at applying much the same techniques to AJAX applications.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/265/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=265&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/08/27/eod-sql-applied-part-3-5-jsp-servlets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>EoD SQL Applied &#8211; Part 2 / 5 (Swing Applications)</title>
		<link>http://lemnik.wordpress.com/2009/08/20/eod-sql-applied-part-2-5-swing-applications/</link>
		<comments>http://lemnik.wordpress.com/2009/08/20/eod-sql-applied-part-2-5-swing-applications/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 06:47:57 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=247</guid>
		<description><![CDATA[Swing Applications
Introduction
We start off the series with Swing Applications. Why? Although probably the application type least likely to be using EoD SQL right now, they nevertheless make use of the most commonly demonstrated EoD SQL data-structure: the DataSet. Swing Applications often have direct access to their database. They can therefore make much better use of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=247&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>Swing Applications</h2>
<h3>Introduction</h3>
<p>We start off the series with Swing Applications. Why? Although probably the application type least likely to be using EoD SQL right now, they nevertheless make use of the most commonly demonstrated EoD SQL data-structure: the DataSet. Swing Applications often have direct access to their database. They can therefore make much better use of long-lived database connections and cursor based ResultSets than web-applications can. So we open with a more detailed than-usual discussion of the DataSet interface and it&#8217;s implementations.</p>
<p>The DataSet is the original return type of the EoD API from Java 6 &#8211; beta. It&#8217;s a relatively thin wrapper on top of a scrollable ResultSet, and it performs best when your database that supports cursors, and your client that will be looking at large volumes of data over a longer periods of time. You&#8217;ll notice that this fits well with an intranet Swing client that has a direct connection to it&#8217;s database.</p>
<p><span id="more-247"></span></p>
<h2>DataSet</h2>
<p>Despite there only being one DataSet interface and one @Select annotation in EoD SQL, there are three DataSet implementations:</p>
<ol>
<li>ConnectedDataSet</li>
<li>DisconnectedDataSet</li>
<li>UpdatableDataSet</li>
</ol>
<p>The two we will be working with in Swing will be the ConnectedDataSet and the WritableDataSet (the DisconnectedDataSet effectively acts like a normal List object, and so isn&#8217;t interesting in the context of a Swing application).</p>
<p>Now some important factors to remember about the default DataSet implementations in EoD SQL:</p>
<ul>
<li>DataSet extends the <a title="List JavaDocs" href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html" target="_blank">java.util.List</a> interface and thus can be treated as a normal Java Collection object</li>
<li>DataSet implementations are <strong>not</strong> Serializable</li>
<li>Like the basic Collection implementations in Java SE, DataSet is not thread-safe</li>
<li>The ConnectedDataSet and UpdatableDataSet hold a <a title="Connection JavaDocs" href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Connection.html" target="_blank">Connection</a> open when they are in use
<ul>
<li>These implementations need to be closed when they are no longer in use</li>
</ul>
</li>
<li>The ConnectedDataSet and UpdatableDataSet both use a DataSetCache to cache objects
<ul>
<li>Most commonly used to keep identity equality working as expected</li>
<li>Can also be extended (later in this post) to perform more complex caching of objects</li>
</ul>
</li>
</ul>
<h3>The Swing side of things</h3>
<p>Swing has the advantage of being backed by generic Model interfaces, allowing you to back many Swing objects directly against the database through a DataSet object. When backing your Swing application onto a cursor based database (such as Postgres or Oracle), the DataSet class allows you to very quickly fetch data from the database and display it to the user without fetching the entire ResultSet into memory up front. It also allows you to treat the data within the Swing object as it&#8217;s true Object type rather than a Database row (as Swing was intended to do). Considering that Swing widgets generally only display a snapshot of all the available data (JList, JTree, JTable are all scrollable) working with a DataSet means that only the displayed data needs to be in memory (and sometimes not even that data).</p>
<h3>Example: A ListModel</h3>
<pre>
<pre class="brush: java;">
public class Movie {
 @AutoGeneratedKeys
 public long id;

 public String title;
 public String director;

 // ...

 public String toString() {
  return title;
 }
}

public interface MovieQuery extends BaseQuery {
 public static final MovieQuery MOVIES = QueryTool.getQuery(MovieQuery.class);

 @Select(&quot;SELECT * FROM movies ORDER BY title&quot;)
 DataSet&amp;amp;lt;Movie&amp;amp;gt; selectMovies();

 // ...
}

public class MovieListModel extends AbstractListModel {
 private final DataSet&amp;amp;lt;Movie&amp;amp;gt; movies = MovieQuery.MOVIES.selectMovies();

 public MovieListModel() {
 }

 public int getSize() {
  return movies.size();
 }

 public Object getElementAt(final int index) {
  return movies.get(index);
 }

 /**
 * Unlike a normal ListModel this implementation will hold open a
 * database Connection until we release it. Thus when the window
 * our JList is added to gets closed, we should get closed as well,
 * unfortunately for this example: we have no knowledge of when the
 * window will be closed, and as such we rely on outside code to
 * invoke our close() method so that we can close our DataSet.
 */
 public void close() {
  movies.close();
 }
}
</pre>
</pre>
<h2>DataSetCache</h2>
<p>Every ConnectedDataSet and UpdatableDataSet makes use of a DataSetCache object (each DataSet instance has it&#8217;s own DataSetCache instance). The default DataSetCache returned by a methods annotated with @Select will use WeakReference objects to allow the Garbage Collector to destroy any objects no longer in use. The main purpose of this default implementation is to keep identity equality working. Since the objects are only fetched from the DataSet during painting and when the outside application asks for the selected objects, the Garbage Collector is free to throw away any objects that are not visible (or even those that are visible, but have already been painted). The following code illustrates the difference between the ArrayDataSetCache (default) and the NullDataSetCache (which does no caching):</p>
<pre>
<pre class="brush: java;">
public interface MovieQuery extends BaseQuery {
  @Select(sql=&quot;SELECT * FROM movies LIMIT 2&quot;,cache=ArrayDataSetCache.class)
  DataSet&amp;amp;lt;Movie&amp;amp;gt; selectMoviesWithCache();

  @Select(sql=&quot;SELECT * FROM movies LIMIT 2&quot;,cache=NullDataSetCache.class)
  DataSet&amp;amp;lt;Movie&amp;amp;gt; selectMoviesWithNullCache();
}

public class MovieQueryTest {

  @Test
  public void testCacheIdentity() {
    final MovieQuery query = QueryTool.getQuery(MovieQuery.class);
    final DataSet&amp;amp;lt;Movie&amp;amp;gt; ds = query.selectMoviesWithCache();

    final Movie m1 = ds.get(0);
    final Movie m2 = ds.get(1);

    assertNotNull(m1);
    assertNotNull(m2);

    assertNotSame(m1, m2); // m1 != m2

    assertSame(m1, ds.get(0)); // m1 == ds.get(0)
    assertSame(m2, ds.get(1)); // m2 == ds.get(1)
  }

  @Test
  public void testNonCacheIdentity() {
    final MovieQuery query = QueryTool.getQuery(MovieQuery.class);
    final DataSet&amp;amp;lt;Movie&amp;amp;gt; ds = query.selectMoviesWithNullCache();

    final Movie m1 = ds.get(0);
    final Movie m2 = ds.get(1);

    assertNotNull(m1);
    assertNotNull(m2);

    assertNotSame(m1, m2); // m1 != m2

    // now the interesting part
    assertNotSame(m1, ds.get(0));
    assertNotSame(m2, ds.get(1));

    // and finally, just to prove the point
    assertNotSame(ds.get(0), ds.get(0));
  }
}
</pre>
</pre>
<p>The problem is: this can create a lot of load on your database when you have tens-of-thousands of concurrent users (Swing applications seldom see the scale of concurrent users to the database that web applications do, which is why a ConnectedDataSet still makes sense). In this case it&#8217;s a good idea to change how the objects are cached by the DataSet by implementing your own custom DataSetCache (such as a <a title="SoftReference JavaDoc" href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ref/SoftReference.html" target="_blank">SoftReference</a> cache or a <a title="Access Order LinkedHashMap JavaDocs" href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedHashMap.html#LinkedHashMap%28int,%20float,%20boolean%29" target="_blank">Least Recently Used (LRU)</a> cache). This will allow you to make fewer round-trips to the database, while still taking advantage of a cursor based database. A very simple example of a Least Recently Used cache based on a LinkedHashMap might look as follows:</p>
<pre>
<pre class="brush: java;">
public class LRUDataSetCache&amp;amp;lt;T&amp;amp;gt; implements DataSetCache&amp;amp;lt;T&amp;amp;gt; {
 private final Map&amp;amp;lt;Integer, T&amp;amp;gt; map = new LinkedHashMap&amp;amp;lt;Integer, T&amp;amp;gt;(16, 0.75f, true) {
  protected boolean removeEldestEntry(final Map.Entry&amp;amp;lt;Integer, T&amp;amp;gt; entry) {
   return size() &amp;amp;gt; 64;
  }
 };

 public void init(final DataSet&amp;amp;lt;T&amp;amp;gt; dataSet) {}

 public boolean isCached(final int row) {
  return map.containsKey(Integer.valueOf(row));
 }

 public T getObject(final int row) {
  return map.get(Integer.valueOf(row));
 }

 public void setObject(final int row, final T object) {
  map.put(Integer.valueOf(row), object);
 }

 public void destroy() {
  map.clear();
 }
}
</pre>
</pre>
<p>This is not a very good or efficient way to cache rows in an LRU mechanism, but it&#8217;s a simple example. The only rule for a DataSetCache (besides implementing  the DataSetCache interface) is that it must have a default constructor (public with no parameters). The next question is, how do we integrate the new cache with our application? The same way as we did with our unit test above:</p>
<pre>
<pre class="brush: java;">
@Select(sql=&quot;SELECT * FROM movies ORDER BY title&quot;,cache=LRUDataSetCache.class)
DataSet&amp;amp;lt;Movie&amp;amp;gt; selectMovies();
</pre>
</pre>
<p>The result: our MovieListModel will now keep up to 64 of the most recently used Movie objects in memory for the DataSet, eliminating the need to re-fetch them from the database. Note: we haven&#8217;t dealt with time-to-live or any such common caching practices here, it&#8217;s way beyond the scope of this post (however, you may want to look into doing such things if you are implementing a more complex DataSetCache).</p>
<h3>UpdatableDataSet</h3>
<p>So we&#8217;ve covered the reading side of a DataSet: opening a DataSet; closing a DataSet; and caching the data within a DataSetCache. What about writing data back into a DataSet? The <a title="ResultSet JavaDocs" href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html" target="_blank">ResultSet</a> interface has several methods to add new rows and update or delete existing rows. This code is available to you through EoD SQL, but is subject to the same constraints as those placed on a ResultSet object by the JDBC spec and driver. Some databases do not support updatable ResultSets at all, in which case this functionality will not work for you (check the &#8220;database_notes.txt&#8221; file in the docs directory of your EoD SQL distribution).</p>
<p>The most common constraints placed on an updatable ResultSet are:</p>
<ul>
<li>You must only select from a single table</li>
<li>You must select the entire primary-key</li>
<li>You generally must select all of the columns that don&#8217;t have a default value (and populate them)</li>
</ul>
<p>There is also one very important note with an UpdatableDataSet: it will not pickup changes to your objects <em>unless</em> you explicitly invoke the <a title="List.set JavaDocs" href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#set%28int,%20E%29" target="_blank">set</a> method for that row and object. The main reason for this is that EoD SQL does no enhancement of your bytecode (in fact EoD SQL is quite capable of running in a very tight sandbox), and as such has no way of knowing when your objects change (and then no way of knowing when you want those changes pushed back into the database). Thus you need to tell it when you&#8217;ve updated the object by &#8220;putting it back&#8221; into the DataSet.</p>
<h3>UpdatableDataSet Mutation Methods</h3>
<p>UpdatableDataSet actually extends the default ConnectedDataSet class. ConnectedDataSet has no mutation methods available (add, remove, clear and co all throw UnsupportedOperationExceptions). UpdatableDataSet implements some, but not all of the mutation methods defined in the List class:</p>
<ul>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#add%28E%29" target="_blank">add(E)</a></li>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#addAll%28java.util.Collection%29" target="_blank">addAll(Collection&lt;? extends E&gt;)</a></li>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#remove%28int%29" target="_blank">remove(int)</a></li>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#set%28int,%20E%29" target="_blank">set(int, E)</a></li>
</ul>
<p>But what about all the other mutation methods like <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#add%28int,%20E%29" target="_blank">add(int, E)</a> or <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html#retainAll%28java.util.Collection%29" target="_blank">retainAll(Collection&lt;?&gt;)</a>? These methods has been deliberately excluded from the implementation for some important reasons:</p>
<ol>
<li>The ResultSet update methods don&#8217;t allow inserting rows at specific indicis. Thus add(int, E) and addAll(int, Collection&lt;? extends E&gt;) are impossible</li>
<li>Methods like remove(Object) and retainAll(Collection&lt;?&gt;) require a scan of the entire DataSet to find which Object or Objects to remove</li>
</ol>
<p>While the first problem is impossible to solve, the second one is fairly easy. So why leave those methods out? These methods are left out in order to make end-developers using EoD SQL think about what they are doing. ConnectedDataSet includes the indexOf and lastIndexOf methods, so if you really want to perform a remove(Object), you can use:</p>
<pre>
<pre class="brush: java;">
DataSet&amp;amp;lt;Movie&amp;amp;gt; movies = ...;
int index = movies.indexOf(movieToRemove);
if(index &amp;amp;gt;= 0) movies.remove(index);
</pre>
</pre>
<p>However I would strongly advise rather using an @Update method with a &#8220;DELETE&#8221; in it over this method (ie: get the database to do the work for you). You need to bare in mind that EoD SQL will <strong>never</strong> generate any SQL code for you, so it&#8217;ll never try creating a &#8220;DELETE&#8221; statement for you. The remove method is great for processing rows in an iterator, and then removing them (or some similar functionality), but be careful with it.</p>
<h2>Conclusion</h2>
<p>We&#8217;ve taken a deep, long look at the DataSet interface, and it&#8217;s implementation details. Swing applications that directly access a database almost always have the database locally, or within an intranet. This means that a ConnectedDataSet can be used to leverage the database resources, allowing the Swing application to seemingly deal with very large volumes of data very quickly. When dealing with smaller volumes of data in a Swing application, it may be an idea to use a normal Collection object; an array or a single object as a return type instead of a DataSet. In the next post we&#8217;ll take a look at another EoD SQL specific data-structure better suited to web-applications dealing with large volumes of data.</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:1332px;width:1px;height:1px;">
<pre><strong>LinkedHashMap</strong></pre>
</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/247/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=247&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/08/20/eod-sql-applied-part-2-5-swing-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>Eod SQL Applied &#8211; Part 1/5 (Introduction)</title>
		<link>http://lemnik.wordpress.com/2009/08/18/eod-sql-applied-part-15-introduction/</link>
		<comments>http://lemnik.wordpress.com/2009/08/18/eod-sql-applied-part-15-introduction/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 06:53:02 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=245</guid>
		<description><![CDATA[Introduction
This is the first part of a series of posts, dedicated to how best to apply EoD SQL in different types of applications. Each post in this series will cover a specific type of application, and the different parts of EoD SQL that generally work best within those applications. The articles may dive fairly deep [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=245&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>Introduction</h2>
<p>This is the first part of a series of posts, dedicated to how best to apply <a title="EoD SQL Home Page" href="https://eodsql.dev.java.net/" target="_blank">EoD SQL</a> in different types of applications. Each post in this series will cover a specific type of application, and the different parts of EoD SQL that generally work best within those applications. The articles may dive fairly deep into the workings of the API, but at the end you&#8217;ll have a much better idea of where things fit in, and how they fit together.</p>
<p>EoD SQL well understands that (a) people like to do things differently and (b) one solution is not right for everything. While under the hood: any one part of EoD SQL works much the same way as any other part, as you climb the structural ladder, things begin to behave very differently. These behaviors have a massive performance and memory impact on your application and how you will be treating the underlying database drivers.</p>
<h3>What we&#8217;ll be covering</h3>
<ol>
<li>Swing Applications</li>
<li>JSP / Servlets and &#8220;Related Technologies&#8221;</li>
<li>JavaScript / JSON Applications</li>
<li>GWT Applications</li>
</ol>
<p>Although you could go with the &#8220;one size fits all&#8221; route (and EoD SQL would still perform wonderfully), the objective of these posts is to expose you to the different flavors of EoD SQL data structures and get you thinking about how you can mix and match them in your application to produce different results.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=245&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/08/18/eod-sql-applied-part-15-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>Where C++ Templates Fall Down</title>
		<link>http://lemnik.wordpress.com/2009/07/07/where-c-templates-fall-down/</link>
		<comments>http://lemnik.wordpress.com/2009/07/07/where-c-templates-fall-down/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 13:40:21 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=240</guid>
		<description><![CDATA[There are many articals out there detailing comparisons between C++ Templates and Java Generics (Google around and you&#8217;ll quickly find loads of them). Almost universally they view the erasure of Java generics as a fail-point. Even the ones written by &#8220;Java Gurus&#8221; seem to favour C++ templates as being more flexable. I recently stumbled upon [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=240&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There are many articals out there detailing comparisons between C++ Templates and Java Generics (Google around and you&#8217;ll quickly find loads of them). Almost universally they view the erasure of Java generics as a fail-point. Even the ones written by &#8220;Java Gurus&#8221; seem to favour C++ templates as being more flexable. I recently stumbled upon a simple case that I&#8217;ve been doing in Java for ages, and while trying to implement the same concept in C++ discovered that it&#8217;s impossible.</p>
<p>The case is a generic Visitor model:</p>
<pre class="brush: java;">
public interface Visitor&lt;R, P&gt; {
    R visitFirstNodeType(FirstNodeType node, P parameter);
    R visitSecondNodeType(SecondNodeType node, P parameter);
}

public abstract class AbstractNodeType {
    public abstract &lt;R, P&gt; R accept(Visitor&lt;R, P&gt; visitor, P parameter);
}
</pre>
<p>Looks simple enough, but try and implement it in C++ and you discover that you cannot use templates on a virtual method. At first this doesn&#8217;t make sense (even to a friend of mine who lives in C++). The simple reason is the way templates are handled: they are code generation shortcuts. Therefore the compiler needs to know the exact method to run, but by declaring the method virtual you are telling the compiler to deferre that descision until runtime. In Java the generics are &#8220;erased&#8221; (although they are kept in the signature), resolving to a single method implementation. This means that there is no problem trying to decide which method to run.</p>
<p>C++ can create the same structure without templates, but then you loose the type-safety contract that you defined in Java. It&#8217;s not really a fail-point on C++ (rather just a product of the implementation), but it is something that seems to be overlooked on the Java side of the fence. Generic erasure buys you fairly cool compile-time contracts.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/240/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=240&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/07/07/where-c-templates-fall-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
		<item>
		<title>EoD SQL Version 2.1-Alpha</title>
		<link>http://lemnik.wordpress.com/2009/07/06/eod-sql-version-2-1-alpha/</link>
		<comments>http://lemnik.wordpress.com/2009/07/06/eod-sql-version-2-1-alpha/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 14:37:44 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[eodsql]]></category>

		<guid isPermaLink="false">http://lemnik.wordpress.com/?p=238</guid>
		<description><![CDATA[EoD SQL doesn&#8217;t see very much development these days (although it sees plenty of downloads and usage). Mainly it&#8217;s very stable and does what it&#8217;s supposed to, so theres very little need to change things.
That said, there are a few issues that needed some attention, so theres the start of a new release (2.1). The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=238&subd=lemnik&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="EoD SQL Home Page" href="https://eodsql.dev.java.net" target="_blank">EoD SQL</a> doesn&#8217;t see very much development these days (although it sees plenty of downloads and usage). Mainly it&#8217;s very stable and does what it&#8217;s supposed to, so theres very little need to change things.</p>
<p>That said, there are a few issues that needed some attention, so theres the <a title="Download EoD SQL" href="https://eodsql.dev.java.net/servlets/ProjectDocumentList?folderID=8364" target="_blank">start of a new release</a> (2.1). The new features and changes are as follows:</p>
<ul>
<li>The engine now caches some of the more expensive construction data with SoftReferences, dramatically reducing the cost of creating a Query implementation</li>
<li>@Call methods may now return updatable DataSet objects by using the new &#8220;readOnly&#8221; annotation attribute</li>
<li>@Select methods now have a useful &#8220;fetchSize&#8221; hint that will be passed down to the JDBC driver</li>
<li>Much better error messages for invalid / unknown types and query parse errors</li>
<li>Improvements and updates to all of the JavaDocs</li>
<li>Some bug fixes and corrections</li>
</ul>
<p>Like I said: theres not that much there, but the changes that do exist make life that little bit easier. If you have any ideas of features you&#8217;d like to see in this upcomming release, leave a comment or a feature request and we&#8217;ll have a chat about it (always on the lookout for good ideas)!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lemnik.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lemnik.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lemnik.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lemnik.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lemnik.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lemnik.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lemnik.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lemnik.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lemnik.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lemnik.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lemnik.wordpress.com&blog=291115&post=238&subd=lemnik&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://lemnik.wordpress.com/2009/07/06/eod-sql-version-2-1-alpha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c7af948b9fdf02628f82c3c11dd5b55?s=96&#38;d=wavatar" medium="image">
			<media:title type="html">lemnik</media:title>
		</media:content>
	</item>
	</channel>
</rss>