<?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>Benny's Blog &#187; Uncategorized</title>
	<atom:link href="http://blog.projectnibble.org/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.projectnibble.org</link>
	<description>House Of Code</description>
	<lastBuildDate>Fri, 13 Aug 2010 15:06:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Want to play Mass Effect 2, but lost your Mass Effect 1 save games?</title>
		<link>http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/</link>
		<comments>http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 22:21:40 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mass Effect]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=413</guid>
		<description><![CDATA[Want to play Mass Effect 2, but lost your Mass Effect 1 save games? Get new save games at masseffectsaves.com!]]></description>
			<content:encoded><![CDATA[<p>Yes, I play video games too. I won&#8217;t miss out on <a href="http://masseffect.bioware.com/">Mass Effect</a>, which I think portraits a world almost as intricate as any good sci-fi novel (oh yeah I read those too, you should try <a href="http://www.amazon.com/Fire-Upon-Deep-Zones-Thought/dp/0812515285/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1264888373&#038;sr=1-1">A Fire Upon the Deep</a>, by Vernor Vinge). </p>
<p>Since Mass Effect is going to be a trilogy (<a href="http://www.shacknews.com/onearticle.x/62032">and more</a> apparently), Bioware included a system that will use old save games as input for continuity in upcoming games, including ME2. Note that you&#8217;ll still be able to pick a different face and class.</p>
<h2>Get your Mass Effect 1 save games at masseffectsaves.com</h2>
<p>I didn&#8217;t know there would be an option to use ME1 save games as input until recently and I&#8217;ve deleted my save games a long time ago. No undelete program would find them. <a href="http://www.annakie.com/">Annakie</a> recognized this would be a problem and started a <a href="http://www.masseffectsaves.com/">small site</a> that offers various save games each with a different set of key choices made over time in ME1.</p>
<p>How awesome is that!</p>
<p>Take your pick as the list is growing fast and the website is becoming a popular hub for Shepards.</p>
<p><a href="http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/trackback/">trackback</a></p>
<p><img src="http://projectnibble.org/dump/blog/images/tali.jpg" alt="Mass Effect 2" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java generic paged lazy List with JSF/JPA example implementation</title>
		<link>http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/</link>
		<comments>http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 12:58:53 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[JSF/Facelets]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[lazy loading]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=310</guid>
		<description><![CDATA[Here&#8217;s a list implementation I came up with to enable true paged data fetching completely transparent to any user. It works independent of persistence layers, such as JPA implementations etc. download PagedList Lazy loading with the PagedList Originally I made the PagedList because I needed paged data fetching using JMS queues for a JSF Rich [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a list implementation I came up with to enable true paged data fetching completely transparent to any user. It works independent of persistence layers, such as JPA implementations etc.</p>
<ul>
<li><a href="http://projectnibble.org/dump/blog/pagedlist/PagedList.rar">download PagedList</a></li>
</ul>
<p><span id="more-310"></span></p>
<h3>Lazy loading with the PagedList</h3>
<p>Originally I made the PagedList because I needed paged data fetching using JMS queues for a JSF Rich datatable and datascroller; a common problem in JSF but less commonly solved, even less documented and less still solved in an elegant way. Most people are able to solve this problem by using an <a href="https://www.hibernate.org/43.html">OpenSessionInView</a> antipattern (keeping Hibernate-oid session open until the view requests the lazy loaded data) but since I&#8217;m using JMS queue, this was not an option. I decided to circumvent the entire JSF to JMS queue integration by providing my data in a paging lazy list. It works beautifully.</p>
<pre  name="code" class="java">
public class PagedList&lt;Dto, QueryParameters&gt; extends AbstractList&lt;Dto&gt; {

    private final QueryParameters queryParameters;

    private final PagedDataProvider&lt;Dto, QueryParameters&gt; pagedDataProvider;

    private final Map&lt;Integer, List&lt;Dto&gt;&gt; fetchedPages;

    private final int dataSize;

    private final int pageSize;

    public PagedList(PagedDataProvider&lt;Dto, QueryParameters&gt; pagedDataProvider, QueryParameters queryParameters) {
        this.pagedDataProvider = pagedDataProvider;
        this.queryParameters = queryParameters;
        fetchedPages = new HashMap&lt;Integer, List&lt;Dto&gt;&gt;();
        dataSize = pagedDataProvider.getDataSize();
        pageSize = pagedDataProvider.getPageSize();
    }

    public Dto get(int index) {
        int pageNr = (int) Math.floor(index / pageSize);
        if (fetchedPages.get(pageNr) == null) {
            fetchedPages.put(pageNr, pagedDataProvider.provide(pageNr, queryParameters));
        }
        return fetchedPages.get(pageNr).get(index % pageSize);
    }

    public int size() {
        return dataSize;
    }
}
</pre>
<p>It is different from <a href="http://commons.apache.org/collections/apidocs/org/apache/commons/collections/list/LazyList.html">Apache&#8217;s LazyList</a> (and many other implementations) in that it relies on an external dataprovider to provide the dataset&#8217;s total size, pagesize and data provision itself. For example, using my lazy list version the <i>size()</i> method actually returns the total size of data potentially available, not just physically available in the list at the present. This way the list works completely transparent to its users. Also, there is no simple factory being passed in that creates dummy objects or something: actual remote data is being fecthed in pages by a data provider. Pages being fetched are independent of each other; when requesting page 5, page 1 through 4 are not need or fetched.</p>
<p>The PagedList works in combo with a <em>PagedDataProvider</em> interface that external dataproviders (some dao for example) could implement. So it has no dependencies whatsoever on some specific implementation. The paged data provider provides the total size of the dataset, the page size and pages of the dataset itself when needed.</p>
<h3>Example implementation for JSF and JPA dao</h3>
<p>Here&#8217;s an example implementation which ties a JSF Richfaces datatable to a JPA dao using a PagedList. I cut out the service layer, view handlers/controllers and whatnot for sake of simplicity.</p>
<pre  name="code" class="xhtml">
&lt;rich:dataTable id="searchResults" value="#{appleService.apples}" var="apple"&gt;
...
&lt;/rich:dataTable&gt;
</pre>
<pre  name="code" class="java">
/**
 * JPA dao which acts as paged data provider for the paged list.
 *
 * Relies on two JPA named queries specified on the Entity being fetched.
 *
 * @author Benny Bottema
 * @see PagedDataProvider
 */
public class AppleJPADao implements AppleDao, PagedDataProvider&lt;AppleDto, AppleQueryParameters&gt; {

    // entitymanager stuff omitted for example (real world: injected by Spring)

    private static final int PAGESIZE = 50;

    /**
     * @see AppleDao#getAllApples(String, String)
     */
    public List&lt;AppleDto&gt; getAllApples(String type, String quality) {
        // optional query parameters: can be null
        AppleQueryParameters params = new AppleQueryParameters();
        params.setAppleType(type);
        params.setAppleQuality(quality);
        return new PagedList&lt;AppleDto, AppleQueryParameters&gt;(this, params);
    }

    /**
     * @see PagedDataProvider#provide(int, Object)
     */
    public List&lt;AppleDto&gt; provide(int page, AppleQueryParameters queryCriteria) {
        Query query = entityManager.createNamedQuery("Apple.findAll");
        query.setParameter("appleType", queryCriteria.getAppleType());
        query.setParameter("appleQuality", queryCriteria.getAppleQuality());
        // JPA's paging mechanism
        query.setFirstResult(PAGESIZE * page);
        query.setMaxResults(PAGESIZE);
        return (List&lt;AppleDto>) query.getResultList();
    }

    /**
     * @see PagedDataProvider#getDataSize()
     */
    public int getDataSize() {
        Query countQuery = entityManager.createNamedQuery("Apple.count");
        return ((Long) countQuery.getSingleResult()).intValue();
    }

    /**
     * @see PagedDataProvider#provide()
     */
    public int getPageSize() {
        return PAGESIZE;
    }
}
</pre>
<h3>Known issues</h3>
<p>So far there is only one known issue, which is more of a problem with lazy loading in general: synchronizing the lazy loading list with the remote dataset to avoid becoming stale when changes happen to the dataset. Example: when the dataset changes, the size of the list is not being updated and the <i>get()</i> method may try to fetch wrong or even unavailable data throwing an exception. Since I&#8217;m using the paged list in a limited way, I&#8217;ve not yet encountered this problem. </p>
<p>One way would be to solve this problem for the Rich datable and datascroller specifically is to have a a4j poll component that listens for dataset changes on the server and refreshes the entire datatable as necessary. Just thinking out loud here&#8230;</p>
<p><a href="http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More logging in Tomcat 5.5+</title>
		<link>http://blog.projectnibble.org/2009/02/27/more-logging-in-tomcat-55/</link>
		<comments>http://blog.projectnibble.org/2009/02/27/more-logging-in-tomcat-55/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 19:25:39 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://blogs.quintor.nl/bbottema/?p=12</guid>
		<description><![CDATA[If you&#8217;re trying to deploy a war under Tomcat and it isn&#8217;t going like it should be, the first thing you do is look in the console if you ran it from a console, or the log files in Tomcat&#8217;s homefolder otherwise. Now this provides you with some details as to why something went wrong, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re trying to deploy a war under Tomcat and it isn&#8217;t going like it should be, the first thing you do is look in the console if you ran it from a console, or the log files in Tomcat&#8217;s homefolder otherwise. Now this provides you with some details as to why something went wrong, but there is the chance that de application itself is throwing exceptions unlogged which are caught by Tomcat. Those are not logged by default by Tomcat! To log these as well, you&#8217;ll need to utilize log4j.</p>
<p><span id="more-12"></span></p>
<p>There are two steps to get logs through log4j in Tomcat. One, add the following log4j.properties to {tomcat.home}\common\classes\. Two, add the log4j and commons-logging jars to {tomcat.home}\common\lib\.</p>
<p>Here&#8217;s the content for log4j.properties.</p>
<pre>log4j.rootLogger=DEBUG, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/tomcat_log4j.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n</pre>
<p>Here are the jars that worked for me in Tomcat 5.5.27:</p>
<ul>
<li><a title="commons logging" href="http://commons.apache.org/downloads/download_logging.cgi" target="_blank">commons logging</a> 1.0.3</li>
<li><a title="log4j" href="http://logging.apache.org/log4j/1.2/download.html" target="_blank">log4j</a> 1.2.15</li>
</ul>
<p>There is one drawback to logging to a specific file though. I recon this is because Tomcat is trailing its own logfile into the console, which we have exempted by using our own logfile. The trouble is that Tomcat creates dynamic log files with a date, so we can&#8217;t easily just use that logfle for Tomcat to pickup on. Then again, maybe Tomcat is logging to a dynamic logfile as well as the console&#8230; I haven&#8217;t explored these possibilities.</p>
<p>For some more indepth information I found this article on <a title="Tomcat 5.5 logging" href="http://minaret.biz/tips/tomcatLogging.html#tomcat_5_5_logging" target="_blank">Tomcat 5.5 logging</a>, and here some of Apache&#8217;s own view on <a title="Tomcat logging" href="http://tomcat.apache.org/tomcat-5.5-doc/logging.html" target="_blank">Tomcat logging</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/02/27/more-logging-in-tomcat-55/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Science of Packages</title>
		<link>http://blog.projectnibble.org/2008/03/21/the-science-of-packages/</link>
		<comments>http://blog.projectnibble.org/2008/03/21/the-science-of-packages/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 20:25:00 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[common closure principle]]></category>
		<category><![CDATA[common reuse principle]]></category>
		<category><![CDATA[dependency inversion principle]]></category>
		<category><![CDATA[open closure principle]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[packages]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blogs.quintor.nl/bbottema/2008/03/21/the-science-of-packages/</guid>
		<description><![CDATA[Some time ago I came across a very interesting article by Robert C. Martin (1996 column in pdf) about how packages are supposed to be made up and how it helps building a release, debug and shared-workload strategy. I don&#8217;t think it all applies to modern package management, especially for web applications, but it is [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I came across a very interesting article by <a href="http://www.objectmentor.com/omTeam/martin_r.html">Robert C. Martin</a> (1996 column in pdf) about how packages are supposed to be made up and how it helps building a release, debug and shared-workload strategy. I don&#8217;t think it all applies to modern package management, especially for web applications, but it is an interesting perspective that deserves some attention.</p>
<p><a href="http://www.objectmentor.com/resources/articles/granularity.pdf">www.objectmentor.com/publications/granularity.pdf</a></p>
<p>My summary of his article (as I understood all of it):</p>
<p><span id="more-7"></span></p>
<p><strong>&lt;summary&gt;</strong></p>
<ul>
<li>Packages should have a one-way dependency graph. A cyclic dependency leads to having to import code from other packages you don&#8217;t always have to use. If an error is made in one of those packages, your code breaks. This can be avoided by removing all cyclic references; in the article he states two interesting solutions (of which one is applying the <a href="http://en.wikipedia.org/wiki/Dependency_inversion_principle">dependency inversion principle</a>, which is commonly used with classes regardless of any package).</li>
<li>Packages are release-units. With version control, you can work on a package level that way. Developers or teams are distributed to work on the packages rather than distributed classes. This is also an important reason why not to have cyclic dependencies in packages.According to The <a href="http://ifacethoughts.net/2006/04/05/common-reuse-principle/">Reuse/Release Equivalence Principle</a> Packages are only allowed to (re)use released packages. This is again conform version control principle. This way developers/teams can decide for themselves when they are ready to use a new release knowing it won&#8217;t change after they started using it.</li>
<li>The <a href="http://iface.wordpress.com/2006/04/05/common-reuse-principle/">Common Reuse Principle</a> states that classes that are likely to be used together should be packaged together. An example Robert mentions is a &#8220;container and its iterators&#8221;. These classes are reused together because they are so tightly coupled and therefore should be packaged together. Again, this seem to be in favor of the version control principle of to affect other packages as least as possible.</li>
<li>Classes should be packed together according to the <a href="http://ifacethoughts.net/2006/04/08/common-closure-principle/">The Common Closure Principle</a>. Which states that classes that are likely to change at the same time because of their high dependency-rate should be packaged together.<em><br />
<strong>Note:</strong><br />
In OOP there is a class-level principle called the <a href="http://doodleproject.sourceforge.net/articles/2000/openClosedPrinciple.html">The Open Closed Principle</a>, which states that classes should be closed to change but open to extension. This advocates that you should design a class in such a way that you can change its behavior by extending it rather than editing the source itself. The <em>Common Closure Principle</em> makes sure that when you ever do need to edit a class, any other class that is likely to be changed according to that should be packaged together. Again, this is to improve on package-level version control where you want to minimize the effect on other packages when changing a class in a package.</em></li>
</ul>
<p>Also, Robert mentions packages are designed bottom up, meaning you can&#8217;t know or approximate packages forehand; packages are *not* indicative of responsibilities or relationships within an application, which is why you can&#8217;t design them forehand. They are a building &#8216;map&#8217; as he calls it to map out how classes should be grouped together in such a way that changes within packages have minimum impact on other packages. Indeed the UML modeling language gives no more information about packages than that (as of UML 0.9, but I don&#8217;t think this changed since). This also means packages grow as classes are added. &#8216;If you do try to design a package diagram forehand without knowledge about the classes, you will likely fail&#8217; as Robert states and end up in badly maintainable classes, lots of &#8220;morning after syndromes&#8221; and cyclic dependencies.</p>
<p><strong>&lt;/summary&gt;</strong></p>
<h2>General impression</h2>
<p>I had never thought of packages in such a &#8216;considerate&#8217; way, but it mostly makes sense to me. I guess that&#8217;s because some of these things go natural and you do them without rationalizing everything. People generally seem to design packages pretty neatly (in small applications at least) and I think that&#8217;s because there&#8217;s an intuitive side to it; You just smack together the classes that you somehow feel belong together. That&#8217;s why the <em>Common Reuse Principle</em> is probably the most widely used principle, because people subconsciously realize that classes that seem to &#8216;belong together in a class&#8217; often are classes that adhere to this principle: they are likely to affect each other when changing them.</p>
<p>All in all I think this view rings true, which is confirmed by the fact that you can &#8216;design&#8217; a <a href="http://www.agilemodeling.com/artifacts/packageDiagram.htm">package layout in UML</a>. Robert says if you try to design a package without knowledge about the classes, you&#8217;ll fail. Obviously if you design an application you get some understanding of its structure and therefor knowledge of the classes. In UML I imagine you do the package diagram just after you did the class diagram, without having to do a bit of coding at all.</p>
<p>There are many guidelines and motivations ofcourse as to how and why package things a certain way, but Robert seems to be on the right track when considering large scale applications, and then desktop applications more so. If you take his advice as a guideline, you could do worse so to speak.</p>
<p><img border="0" width="16" src="http://images.slashdot.org/favicon.ico" alt="Slashdot" height="16" /> <a href="http://slashdot.org/slashdot-it.pl?op=basic&amp;url=http://blogs.quintor.nl/bbottema/2008/03/21/the-science-of-packages/">Slashdot It!</a>   /   <a href="http://blogs.quintor.nl/bbottema/2008/03/21/the-science-of-packages//trackback/">trackback</a><br />
<a href="http://technorati.com/faves?sub=addfavbtn&amp;add=http://blogs.quintor.nl/bbottema"><img src="http://static.technorati.com/pix/fave/btn-fave2.png" alt="Add to Technorati Favorites" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2008/03/21/the-science-of-packages/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
