<?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>dev-eth0.de &#187; Java</title>
	<atom:link href="http://www.dev-eth0.de/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dev-eth0.de</link>
	<description>Zu viele Lösungen für zu wenig Probleme...</description>
	<lastBuildDate>Tue, 24 Jan 2012 11:20:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Least recently used Cache in Java</title>
		<link>http://www.dev-eth0.de/least-recently-used-cache-in-java/</link>
		<comments>http://www.dev-eth0.de/least-recently-used-cache-in-java/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 09:02:24 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=850</guid>
		<description><![CDATA[For a persistence service we needed a local cache. We decided to use a least recently used cache which allows to set a maximum size and automatically deletes the oldest elements.

A simple implementation based on the Java-Class LinkedHashMap can be found here:

LRUCache.java

Usage:



If you need to access the cache with multiple threads, you can use ...]]></description>
			<content:encoded><![CDATA[<p>For a persistence service we needed a local cache. We decided to use a least recently used cache which allows to set a maximum size and automatically deletes the oldest elements.</p>
<p>A simple implementation based on the Java-Class LinkedHashMap can be found here:</p>
<p><a title="LRU-Cache" href="http://data.dev-eth0.de/code/lru/LRUCache.java" target="_blank">LRUCache.java</a></p>
<p>Usage:</p>
<pre class="brush: java; title: ; notranslate">LRUCache&lt;String, String&gt; myCache = new LRUCache&lt;String, String&gt;(10);</pre>
<p>If you need to access the cache with multiple threads, you can use the static Collections.synchronizedMap method:</p>
<pre class="brush: java; title: ; notranslate">Collections.synchronizedMap(new LRUCache&lt;String, String&gt;(CACHE_SIZE));</pre>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=850&amp;md5=8c4ffbef8ffa4dbb09e20a1a51fc9c02" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/least-recently-used-cache-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging in a Tapestry-Service</title>
		<link>http://www.dev-eth0.de/logging-in-a-tapestry-service/</link>
		<comments>http://www.dev-eth0.de/logging-in-a-tapestry-service/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 15:48:12 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tapestry]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=842</guid>
		<description><![CDATA[The usage of a Logging-Service in Tapestry is quite easy. You just have to use the @Inject Annotation in your classes.



A little bit more complicated is the usage in a Tapestry-Service. Here an @Inject Annotation will fail, so you would have to get an instance for your logger from another source. One possibility would ...]]></description>
			<content:encoded><![CDATA[<p>The usage of a Logging-Service in Tapestry is quite easy. You just have to use the @Inject Annotation in your classes.</p>
<pre class="brush: java; title: ; notranslate">import org.slf4j.Logger;
@Inject
private Logger logger;</pre>
</p>
<p>A little bit more complicated is the usage in a Tapestry-Service. Here an @Inject Annotation will fail, so you would have to get an instance for your logger from another source. One possibility would be to use a <strong>build-method</strong> in your Module class. But then, you would have to distribute such method for each service which should use a logger.</p>
<p>Tapestry helps you here and can contribute the needed Logger instance if you insert a constructor method to your service:</p>
<pre class="brush: java; title: ; notranslate">import org.slf4j.Logger;

private final Logger logger;

public MyServiceImpl(final Logger _logger){
    this.logger = _logger;
    this.logger.debug(&quot;Successfully initialized MyServiceImpl);
}</pre>
</p>
<p>Your Service will now be initialized with a working instance of the Logger-class.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=842&amp;md5=6fa050988b1ea44df37df7e86bb6bf1a" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/logging-in-a-tapestry-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to encrypt and decrypt data with Java</title>
		<link>http://www.dev-eth0.de/how-to-encrypt-and-decrypt-data-with-java/</link>
		<comments>http://www.dev-eth0.de/how-to-encrypt-and-decrypt-data-with-java/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 12:26:21 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=819</guid>
		<description><![CDATA[A common problem when using confidential data is how to save it. Usually you would encrypt this data and save a encrypted version.

Java provides several build-in algorithms for symmetric-key cryptography (AES, DES ...). To use those algorithms, you have to generate a secret-key and initialize a cipher for decryption and one for encryption with ...]]></description>
			<content:encoded><![CDATA[<p>A common problem when using confidential data is how to save it. Usually you would encrypt this data and save a encrypted version.</p>
<p>Java provides several build-in algorithms for symmetric-key cryptography (AES, DES &#8230;). To use those algorithms, you have to generate a secret-key and initialize a cipher for decryption and one for encryption with it.Those ciphers can now be used to crypt your data.</p>
<p>To simplify this task, I created a small library which provides the needed methods to decrypt and encrypt a String. There are several static methods to automatically initialize a crypter for a certain algorithm such as AES.</p>
<p>How to encrypt and decrypt a String:</p>
<pre class="brush: java; title: ; notranslate">Crypter myCrypter = Crypter.getAES_Crypter();
String encrypted = myCrypter.encrypt(&quot;my secret text&quot;);
String decrypted = myCrypter.decrypt(encrypted);
</pre>
<p>Download:</p>
<p><a href="http://www.dev-eth0.de/data/code/crypter/Crypter.jar" target="_blank">Library</a></p>
<p><a href="http://www.dev-eth0.de/data/code/crypter/Crypter-src.zip" target="_blank">Source</a></p>
<p>A big thank you goes out to the author of the used Base64-Coder: <a href="http://www.source-code.biz/" target="_blank">http://www.source-code.biz/</a></p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=819&amp;md5=d32110d2e6add42c31ee75167b79273a" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/how-to-encrypt-and-decrypt-data-with-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Einführung in Maven</title>
		<link>http://www.dev-eth0.de/einfuhrung-in-maven/</link>
		<comments>http://www.dev-eth0.de/einfuhrung-in-maven/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 10:38:32 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=812</guid>
		<description><![CDATA[Innerhalb eines unserer Projekte lernen wir gerade die Vorteile von Maven kennen. Dies betrifft vor allem das dynamische Nachladen von benötigten Libraries und die Möglichkeiten, die man zum Deployen einer Anwendung hat.

Bei unserem Projekt handelt es sich einerseits um eine Tapestry 5 Anwendung. Diese lässt sich auf jedem beliebigen Server mit installiertem Maven über ...]]></description>
			<content:encoded><![CDATA[<p>Innerhalb eines unserer Projekte lernen wir gerade die Vorteile von Maven kennen. Dies betrifft vor allem das dynamische Nachladen von benötigten Libraries und die Möglichkeiten, die man zum Deployen einer Anwendung hat.</p>
<p>Bei unserem Projekt handelt es sich einerseits um eine Tapestry 5 Anwendung. Diese lässt sich auf jedem beliebigen Server mit installiertem Maven über den Befehl</p>
<pre class="brush:java">mvn jetty:run
</pre>
<p>starten.</p>
<p>Auf der anderen Seite haben wir dann noch eine einfache Java-Anwendung, die eine Verbindung über einen Socket aufbaut.</p>
<p>Als Einführung ins Thema Maven haben wir uns das folgende Buch gekauft:<br />
<a href="http://www.amazon.de/gp/product/0596007507?ie=UTF8&amp;tag=bidstatsde-21&amp;linkCode=as2&amp;camp=1638&amp;creative=19454&amp;creativeASIN=0596007507">Maven: A Developer&#8217;s Notebook (Developer&#8217;s Notebooks)</a></p>
<p>Zwar behandelt es eine etwas ältere Maven Version, es ist aber gut für die Grundlagen geeignet.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=812&amp;md5=a79937719e2f9b6bc2e2d9d60836497e" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/einfuhrung-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to receive the geo coordinates of a certain address?</title>
		<link>http://www.dev-eth0.de/how-to-receive-the-geo-coordinates-of-a-certain-address/</link>
		<comments>http://www.dev-eth0.de/how-to-receive-the-geo-coordinates-of-a-certain-address/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 07:40:56 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=789</guid>
		<description><![CDATA[I just created a small piece of java-code, which allows you to receive geo coordinates (longitude / latitude) for a certain address.

It's quite simple to use:
final CoordinateTool ct = new CoordinateTool();
final Coordinate coord = ct.getCoordinateForAddress(YOUR_ADDRESS);

Another feature is the possibility to load a route from A to B. You have the possibility to get this ...]]></description>
			<content:encoded><![CDATA[<p>I just created a small piece of java-code, which allows you to receive geo coordinates (longitude / latitude) for a certain address.</p>
<p>It&#8217;s quite simple to use:</p>
<pre class="brush:java">final CoordinateTool ct = new CoordinateTool();
final Coordinate coord = ct.getCoordinateForAddress(YOUR_ADDRESS);
</pre>
<p>Another feature is the possibility to load a route from A to B. You have the possibility to get this route as String or to save it to a File.</p>
<pre class="brush:java">final CoordinateTool ct = new CoordinateTool();
final String route = ct.getRouteForAddresses(YOUR_ADDRESS, YOUR_DESTINATION);
ct.saveRouteForAddresses(YOUR_ADDRESS, YOUR_DESTINATION, FILENAME);
</pre>
<p>If you need the distance between two addresses or coordinates, you can use this &#8220;getDistanceBetween&#8221; method.</p>
<p>Download: </p>
<p><a href="http://data.dev-eth0.de/code/coordinateTool/CoordinateTool.jar" target="_blank">Library</a></p>
<p><a href="http://data.dev-eth0.de/code/coordinateTool/CoordinateTool-src.zip" target="_blank">Source</a>.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=789&amp;md5=2c2cde223f8f6a1ad7ea7dd54d9b1790" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/how-to-receive-the-geo-coordinates-of-a-certain-address/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buchempfehlung: Google Web Toolkit</title>
		<link>http://www.dev-eth0.de/buchempfehlung-google-web-toolkit/</link>
		<comments>http://www.dev-eth0.de/buchempfehlung-google-web-toolkit/#comments</comments>
		<pubDate>Sun, 30 May 2010 13:06:45 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Bücher]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=784</guid>
		<description><![CDATA[Letzte Woche wurde entschieden, dass wir für ein neues Projekt wohl etwas mit dem Google Web Toolkit auf die Beine stellen wollen. Ich hatte zwar von der Technik schon ein bisschen was gehört, aber noch keine Zeit gehabt, mich einzuarbeiten.

Für den einfachen Einstieg habe ich dann mal nach einem Buch gesucht und folgendes gefunden:

Das ...]]></description>
			<content:encoded><![CDATA[<p>Letzte Woche wurde entschieden, dass wir für ein neues Projekt wohl etwas mit dem Google Web Toolkit auf die Beine stellen wollen. Ich hatte zwar von der Technik schon ein bisschen was gehört, aber noch keine Zeit gehabt, mich einzuarbeiten.</p>
<p>Für den einfachen Einstieg habe ich dann mal nach einem Buch gesucht und folgendes gefunden:</p>
<p><a href="http://www.amazon.de/gp/product/3939084212?ie=UTF8&amp;tag=bidstatsde-21&amp;linkCode=as2&amp;camp=1638&amp;creative=19454&amp;creativeASIN=3939084212" target="_blank">Das Google Web Toolkit: Ajax-Applikationen mit Java</a></p>
<p>Die Bewertungen bei Amazon waren schon mal soweit ok und haben sich nun auch bestätigt. Der Autor erklärt in einem recht kleinem Rahmen die Grundlagen des Toolkits und was man damit so erreichen kann. Einziger Nachteil: es wird die Version 1.X behandelt. In der aktuellen 2.X Version sind einige Änderungen hinzugekommen, für einen Einstieg ist das Buch aber trotzdem gut geeignet.</p>
<p>Ein weiterer Pluspunkt ist der für ein Fachbuch doch sehr faire Preis <img src='http://www.dev-eth0.de/wp-includes/images/smilies/icon_wink.gif' alt="icon wink Buchempfehlung: Google Web Toolkit" class='wp-smiley' title="icon wink" /> </p>
<p><a href=" http://www.amazon.de/gp/product/3939084212?ie=UTF8&amp;tag=bidstatsde-21&amp;linkCode=as2&amp;camp=1638&amp;creative=19454&amp;creativeASIN=3939084212" target="_blank">Amazon-Link</a></p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=784&amp;md5=700e364ce53e3a25517c1807a14bda84" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/buchempfehlung-google-web-toolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic object creation</title>
		<link>http://www.dev-eth0.de/automatic-object-creation/</link>
		<comments>http://www.dev-eth0.de/automatic-object-creation/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 13:17:30 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[DummyCreator]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=761</guid>
		<description><![CDATA[In the process of software development there is often the need for dummy object. One of the main reasons for their usage is the fact, that a database or another data-provider might not be ready or available in the current stage of development.

Normally a developer would implement some methods to create those dummy objects ...]]></description>
			<content:encoded><![CDATA[<p>In the process of software development there is often the need for dummy object. One of the main reasons for their usage is the fact, that a database or another data-provider might not be ready or available in the current stage of development.</p>
<p>Normally a developer would implement some methods to create those dummy objects with random data. If you have many classes, this might become a quick time-consuming task. A good solution would be a library, which creates those objects automatically.</p>
<p><span id="more-761"></span>For this sake, I started the DummyCreator project. It is planned to provide a static method which returns a random Object of whatever class is needed. In the process of object-creation, the DummyCreator will rely on the usual JavaBean specifications of  setter methods. Those methods are defined by their name (starts with &#8220;set&#8221;), their parameter (just one) and that they are always void methods.</p>
<p>Object-creation will start by finding a suitable constructor and then set all available attributes of the object automatically. This will done by using the reflection API with all of it&#8217;s magic.</p>
<p>A first version of the DummyCreator and the source can be found on the Google-Code homepage: <a href="http://code.google.com/p/dummycreator/" target="_blank">http://code.google.com/p/dummycreator/</a></p>
<p>There is also a short introduction available which describes the first steps to use DummyCreator in your project. You can integrate the jar-File in the development and later deploy without it.</p>
<p>It currently works quite well, there are only some issues with classes which have lists as attribute. Those will be created but empty.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=761&amp;md5=beacc5b2cb503f12857a40348edaeb96" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/automatic-object-creation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Development mit Netbeans</title>
		<link>http://www.dev-eth0.de/android-development-mit-netbeans/</link>
		<comments>http://www.dev-eth0.de/android-development-mit-netbeans/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 07:42:05 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=730</guid>
		<description><![CDATA[Ich hatte zwar mal einen älteren Beitrag dazu geschrieben, dieser bestand aber eigentlich nur aus einem Link. Deswegen hier mal eine kleine Anleitung, wie man auch mit Netbeans in die Entwicklung von Android-Anwendungen einsteigen kann.

SDK herunterladen und installieren
Zuerst benötigt man natürlich das Android SDK. Dieses findet man samt einiger Anleitungen dazu auf dieser Seite. ...]]></description>
			<content:encoded><![CDATA[<p>Ich hatte zwar mal einen älteren Beitrag dazu geschrieben, dieser bestand aber eigentlich nur aus einem Link. Deswegen hier mal eine kleine Anleitung, wie man auch mit Netbeans in die Entwicklung von Android-Anwendungen einsteigen kann.<br />
<span id="more-730"></span></p>
<h3>SDK herunterladen und installieren</h3>
<p>Zuerst benötigt man natürlich das <strong>Android SDK</strong>. Dieses findet man samt einiger Anleitungen dazu auf dieser <a href="http://developer.android.com/sdk/index.html" target="_blank">Seite</a>. Nach dem herunterladen entpackt man das gesamte SDK in einen beliebigen Ordner und führt die zugehörige Setup Datei aus.</p>
<p>Mittels dieses Setups werden alle benötigten Pakete zu beliebigen API-Versionen heruntergeladen und installiert. Normalerweise sollte die neueste Version reichen, aber natürlich kann jede gewählt werden.</p>
<p>Nachdem das Setup erfolgreich abgeschlossen wurde, muss man noch ein Gerät (<strong>Device</strong>) hinzufügen. Dies geschieht auch über das Setup im Punkt Virtual Devices. Die Einstellungen für das Gerät sind beliebig zu wählen und sollten dem Zielgerät entsprechen (Ausstattung, Auflösung etc).</p>
<h3>Netbeans Plugin installieren</h3>
<p>Nachdem der Rechner nun quasi bereit ist, eine Android Anwendung zu starten, wird noch ein Plugin für Netbeans benötigt: <strong>nbandroid</strong>. Die zur Zeit gültige Webseite des zugehörigen Projektes findet sich <a href="http://kenai.com/projects/nbandroid/" target="_blank">hier</a>. In den zugehörigen <a href="http://kenai.com/projects/nbandroid/pages/Install" target="_blank">Installationsanweisungen</a> findet sich auch der Link, welcher das Plugin in Netbeans Update-Center integriert. Dieses findet man unter Tools =&gt; Plugins. Zum hinzufügen klickt man nun auf Settings =&gt; Add und fügt folgenden Link als Quelle hinzu: http://kenai.com/downloads/nbandroid/updates.xml</p>
<p>Im Anschluss findet sich unter den verfügbaren Plugins das Android Plugin, welches auch installiert werden muss.</p>
<h3>Android Plattform einrichten</h3>
<p>Um nun noch die passende Plattform für Netbeans einzurichten, startet man den zugehörigen Manager über Tools =&gt; Java Platforms =&gt; Add. Hier wählt man nun die <strong>Google Android Open Handheld Platform</strong>. Als Ordner wird das vorher entpackte und installierte SDK, die Version der Plattform entsprechend den Anforderungen gewählt.</p>
<h3>Projekt erstellen</h3>
<p>Wenn nun alle Punkte erfolgreich abgearbeitet wurden, kann man über File =&gt; New Project =&gt; Android ein neues Android Projekt anlegen. Sobald man im Projekt dann auf Run klickt (oder F6 drückt) startet der Emulator mit dem gewünschten Projekt.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=730&amp;md5=0ec48014e26aac7da55f78d610791109" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/android-development-mit-netbeans/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Using the GAE datastore</title>
		<link>http://www.dev-eth0.de/using-the-gae-datastore/</link>
		<comments>http://www.dev-eth0.de/using-the-gae-datastore/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 12:09:10 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Google App-Engine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tapestry]]></category>
		<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=709</guid>
		<description><![CDATA[For nearly every web-application you need a database to store your information. Usually you'd use a relational database like Postgresql or MySQL and a mapper like Hibernate to access it in your code. And here comes the problem:

Googles doesn't offer you a relational database but their own database-system called BigTable which you can't access ...]]></description>
			<content:encoded><![CDATA[<p>For nearly every web-application you need a database to store your information. Usually you&#8217;d use a relational database like Postgresql or MySQL and a mapper like <a href="http://www.hibernate.org/" target="_blank">Hibernate</a> to access it in your code. And here comes the problem:</p>
<p>Googles doesn&#8217;t offer you a relational database but their own database-system called <a href="http://en.wikipedia.org/wiki/BigTable" target="_blank">BigTable</a> which you can&#8217;t access with the usual Hibernate-Mapping. And one more thing: Google doesn&#8217;t call it a database but a datastore <img src='http://www.dev-eth0.de/wp-includes/images/smilies/icon_wink.gif' alt="icon wink Using the GAE datastore" class='wp-smiley' title="icon wink" /> </p>
<p>In this example I&#8217;d like to show you, how to save, get, update and delete an object.</p>
<h3><span id="more-709"></span>How to access the datastore</h3>
<p>There are several possibilities to access the datastore from your code. You can read about it in the <a href="http://code.google.com/intl/de/appengine/docs/java/datastore/" target="_blank">API-Document</a>. I want to focus on using JDO to connect and save data in a datastore.We will use the <a href="http://www.datanucleus.org/" target="_blank">Datanucleus Access Platform</a> which offers us a framework for data management.</p>
<p>First of it all, we&#8217;ll need to import the required libraries in our maven project. Most of them are available in the official repositories or distributed with the GAE SDK:</p>
<ul>
<li>datanucleus-appengine 1.0.5</li>
<li>datanucleus-core 1.1.6</li>
<li>datanucleus-jpa 1.1.5</li>
<li>maven-datanucleus-plugin 1.1.4</li>
<li>jdo2-api 2.3-ec</li>
</ul>
<p>If we&#8217;d use Hibernate with Tapestry, we would just inject the Hibernate-Service/Session into your DAO. With JDO we need to define a Singleton which represents the PersistanceManager for ourdatastore.</p>
<p><a href="http://data.dev-eth0.de/code/gae/PersistanceManagerFactory.java" target="_blank">PersistanceManagerFactory.java</a></p>
<h3>Making a class persistence-ready</h3>
<p>We want to save and edit an USER in our datastore, therefore we&#8217;ll implement a class called User.java in our entities-package.</p>
<p><a href="http://data.dev-eth0.de/code/gae/User.java" target="_blank">User.java</a></p>
<p>As you can see, I added some annotations which tell Datanucleus, that we want to save our class persistent. By using annotation you spare defining your classes in XML-Files.</p>
<p>If you want to implement inheritance in your data, you need to define your base-class with the following annotation:</p>
<pre class="brush:java">@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class EntityWithLongID {</pre>
<h3>The DAO</h3>
<p>We want to follow the design pattern of DAOs which allows us, to inject a DAO in our page and then use the CRUD (Create, Receive, Update and Delete) methods (and more if we want).</p>
<p><a href="http://data.dev-eth0.de/code/gae/UserDAO.java" target="_blank">UserDAO.java</a></p>
<p>In our implementation of the interface, we make use of our PersistanceManagerFactory:</p>
<p><a href="http://data.dev-eth0.de/code/gae/UserDAOImpl.java" target="_blank">UserDAOImpl.java</a></p>
<p>As you can see, there&#8217;s a little problem with the update method.</p>
<p>The PersistenceManager doesn&#8217;t offer any possibility to just send a update of a User. You have to load the user, you want want to edit, then edit it and save it in the same transaction. Due to this fact, if we want to edit a user on our website, we would need to open the transaction if the page is requested. Then the transaction needs to be kept open till the submit button is pressed and the edited user can be saved.  To prevent this, we need to load the user we want to edit in our update method again. Afterwards we copy every field from the edited user to the newly loaded user and then commit the action.</p>
<p>We could do this with a simple use of the getter/setter methods but then we would need to edit our DAO if we add/remove a field to our User-Class. For that reason we  use our old friend: reflection <img src='http://www.dev-eth0.de/wp-includes/images/smilies/icon_wink.gif' alt="icon wink Using the GAE datastore" class='wp-smiley' title="icon wink" /> </p>
<p>The other methods should be rather clear&#8230;</p>
<p>To bind the DAO to the fitting Implementation, we add this line to our AppModule.java bind-Method:</p>
<pre class="brush:java">binder.bind(UserDAO.class, DummyUserDAOImpl.class);
</pre>
<h3>Configuring JDO and adding enhancement for our classes</h3>
<p>There are only to steps left to save data in our datastore:</p>
<p>We need to to configure Datanucleus/JDO, which happens through a little file, we put in the META-INF Folder (in Netbeans: Other Sources/META-INF):</p>
<p><a href="http://data.dev-eth0.de/code/gae/jdoconfig.xml" target="_blank">jdoconfig.xml</a></p>
<p>Now, we only have to tell Maven to enhance our class-Files in the build-process. To do so, we modify our pom.xml and add this code in the build / plugins section:</p>
<pre class="brush:xml">&lt;plugin&gt;
      &lt;groupId&gt;org.datanucleus&lt;/groupId&gt;
      &lt;artifactId&gt;maven-datanucleus-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.1.4&lt;/version&gt;
      &lt;configuration&gt;
            &lt;log4jConfiguration&gt;${basedir}/log4j.properties&lt;/log4jConfiguration&gt;
            &lt;mappingIncludes&gt;**/entities/*.class, **/entities/account/*.class&lt;/mappingIncludes&gt;
            &lt;verbose&gt;true&lt;/verbose&gt;
            &lt;enhancerName&gt;ASM&lt;/enhancerName&gt;
            &lt;api&gt;JDO&lt;/api&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
            &lt;execution&gt;
                 &lt;phase&gt;process-classes&lt;/phase&gt;
                 &lt;goals&gt;
                     &lt;goal&gt;enhance&lt;/goal&gt;
                     &lt;goal&gt;enhance-check&lt;/goal&gt;
                &lt;/goals&gt;
           &lt;/execution&gt;
      &lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>Now we just build our project and the everything should work&#8230;</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=709&amp;md5=2ad61a6480422184f187f84f700c4827" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/using-the-gae-datastore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tapestry on Google&#8217;s app-engine</title>
		<link>http://www.dev-eth0.de/tapestry-on-googles-app-engine/</link>
		<comments>http://www.dev-eth0.de/tapestry-on-googles-app-engine/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 13:05:28 +0000</pubDate>
		<dc:creator>dev-eth0</dc:creator>
				<category><![CDATA[Google App-Engine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tapestry]]></category>
		<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://www.dev-eth0.de/?p=682</guid>
		<description><![CDATA[After deploying the first web-app to GAE, we now want to try to run a tapestry based application.

One problem I faced, resulted from google's JRE Class whitelist, which lists all classes, you can use in your application. The current stable release of Tapestry uses a blacklisted XML Parser.

Therefore you have two possibilities:

	Replace the XML-Parser
	or ...]]></description>
			<content:encoded><![CDATA[<p>After deploying the first web-app to GAE, we now want to try to run a tapestry based application.</p>
<p>One problem I faced, resulted from google&#8217;s <a href="http://code.google.com/intl/de/appengine/docs/java/jrewhitelist.html" target="_blank">JRE Class whitelist</a>, which lists all classes, you can use in your application. The current stable release of Tapestry uses a blacklisted XML Parser.</p>
<p>Therefore you have two possibilities:</p>
<ul>
<li><a href="http://wiki.github.com/derkoe/tapestry-sax-parser/" target="_blank">Replace</a> the XML-Parser</li>
<li>or just use Tapestry 5.2</li>
</ul>
<p>I decided to update my downloaded Tapestry Libs to 5.2.</p>
<h3>Create a project</h3>
<p>First we have to create a new Tapestry-app with Maven. I used the integrated support of Netbeans to achieve this. In <a href="https://repository.apache.org/content/groups/snapshots-group/" target="_blank">apache&#8217;s maven repository</a> you can find a quickstart-app for Tapestry 5.2, which is ideal for testing purpose.</p>
<p>Now you only have to add a appengine-web.xml file and that&#8217;s it&#8230;</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.dev-eth0.de/?flattrss_redirect&amp;id=682&amp;md5=30e272874ab00aeeaee216d3e1b32ab9" title="Flattr" target="_blank"><img src="http://www.dev-eth0.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.dev-eth0.de/tapestry-on-googles-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

