<?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; programming</title>
	<atom:link href="http://blog.projectnibble.org/tag/programming/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>Excluding resources and test classes from war/ear in Eclipse</title>
		<link>http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/</link>
		<comments>http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 15:15:24 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=358</guid>
		<description><![CDATA[Today I was trying to figure out how to exclude certain resources/classes from the war that was being deployed to my embedded server in Eclipse. I couldn&#8217;t find out how to do this in the Eclipse settings file. Apparently, it has nothing to do with the source folder you see in the Project Explorer view, [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was trying to figure out how to exclude certain resources/classes from the war that was being deployed to my embedded server in Eclipse. I couldn&#8217;t find out how to do this in the Eclipse settings file. </p>
<p>Apparently, it has nothing to do with the source folder you see in the Project Explorer view, or the export settings in the Buildpath dialogs: instead you need to edit the Eclipse settings file “project-war\.settings\org.eclipse.wst.common.component” (viewable in the Navigator view) and modify the deployed source folders in there. Changes there do *not* reflect in the Project explorer (at least not with my version of Eclipse, Galileo). I’ve removed the test sourcefolder from there and everything was honky dory.</p>
<pre  name="code" class="xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project-modules id=&quot;moduleCoreId&quot; project-version=&quot;1.5.0&quot;&gt;
  &lt;wb-module deploy-name=&quot;foo-war&quot;&gt;
    &lt;wb-resource deploy-path=&quot;/&quot; source-path=&quot;/src/main/webapp&quot;/&gt;
    &lt;wb-resource deploy-path=&quot;/WEB-INF/classes&quot; source-path=&quot;/src/main/java&quot;/&gt;
    &lt;wb-resource deploy-path=&quot;/WEB-INF/classes&quot; source-path=&quot;/src/main/resources&quot;/&gt;
    &lt;property name=&quot;context-root&quot; value=&quot;foo&quot;/&gt;
    &lt;property name=&quot;java-output-path&quot;/&gt;
  &lt;/wb-module&gt;
&lt;/project-modules&gt;
</pre>
<p><a href="http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/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>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>
