<?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:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Narcanti</title>
	<atom:link href="http://narcanti.keyboardsamurais.de/feed" rel="self" type="application/rss+xml" />
	<link>http://narcanti.keyboardsamurais.de</link>
	<description>deep geeks click here</description>
	<lastBuildDate>Tue, 30 Mar 2010 10:16:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Fastfood f&#252;r&#8217;s Volk</title>
		<link>http://narcanti.keyboardsamurais.de/fastfood-fuers-volk.html</link>
		<comments>http://narcanti.keyboardsamurais.de/fastfood-fuers-volk.html#comments</comments>
		<pubDate>Mon, 29 Mar 2010 18:40:14 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Not lost but found]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=437</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/notlostbutfound.png" width="24" height="24" alt="" title="Not lost but found" /><br/>Zuf&#228;llig entdeckt: Ein Spiegel Artikel mit dem Namen &#8220;Fast Food kann s&#252;chtig machen&#8221;. Darin wird erkl&#228;rt, dass in Experimenten nachgewiesen werden konnte, wie dauerhaft erh&#246;hter Kalorienkonsum &#228;hnlich Abh&#228;ngig machen kann wie Drogen. Damit wirkt der Plan in den USA, aus gesundheitlichen Gr&#252;nden in Restaurants das Essen ohne Salz zu zubereiten, total sinnlos. Eher m&#252;ssten die [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/notlostbutfound.png" width="24" height="24" alt="" title="Not lost but found" /><br/><p>Zuf&#228;llig entdeckt: Ein Spiegel Artikel mit dem Namen <a href="http://www.spiegel.de/wissenschaft/medizin/0,1518,686101,00.html">&#8220;Fast Food kann s&#252;chtig machen&#8221;</a>. Darin wird erkl&#228;rt, dass in Experimenten nachgewiesen werden konnte, wie dauerhaft erh&#246;hter Kalorienkonsum &#228;hnlich Abh&#228;ngig machen kann wie Drogen. Damit wirkt der Plan in den USA, <a href="http://www.shortnews.de/id/821594/USA-Nach-Rauchverbot-Bald-auch-Salzverbot-in-Restaurants">aus gesundheitlichen Gr&#252;nden in Restaurants das Essen ohne Salz zu zubereiten</a>, total sinnlos. Eher m&#252;ssten die Kalorien verboten werden. Dann m&#252;sste man seine Pommes, Burger, Chips und den Kuchen von seinem lokalen Dealer beziehen. &#8220;Suchs&#8217;u? Brauchs&#8217;u? Hab korrekte Pommes Rot-Weiss !&#8221;&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/fastfood-fuers-volk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate Data View Objects Annotations</title>
		<link>http://narcanti.keyboardsamurais.de/hibernate-data-view-objects-annotations.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hibernate-data-view-objects-annotations.html#comments</comments>
		<pubDate>Sun, 28 Mar 2010 18:45:50 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=435</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>In my last article Hibernate Data View Objects I showed some basic ideas, of how filling up view objects can be done with the help of hibernate in a more or less automatic way. Meanwhile I created some little API classes, that can be used to annotate view objects. The basic of this partly worked [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>In my last article <a href="http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html">Hibernate Data View Objects</a> I showed some basic ideas, of how filling up view objects can be done with the help of hibernate in a more or less automatic way.<br />
Meanwhile I created some little API classes, that can be used to annotate view objects.<br />
<span id="more-435"></span></p>
<p>The basic of this partly worked out API is a simple DAO used to load and fill the view objects. (Please forgive me the german comments and todos)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> DtoDao <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> loadDtos<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> dtoClass, Criterion criterion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// TODO: query by exmaple</span>
	<span style="color: #666666; font-style: italic;">// aber hierzu müssen die dto-properties auf entity-properties zurück gemappt werden</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Also there is need of an implementation (of course). (You may recognize some spring-bean interface methods as well as the Hql/Criteria to SQL translator class from one of my previous posts for logging purposes of the generated SQL code.)<br />
This class does the part of the work, where a &#8220;query-path&#8221; is translated to a hibernate criteria.<br />
Also the dao implementation checks and registers the given class into a custom entity manager, the dvo entity manager, which analyses the annotations and creates the neccessary meta data for the dvo class.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DvoDaoImpl <span style="color: #000000; font-weight: bold;">implements</span> DvoDao, InitializingBean<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Log LOG <span style="color: #339933;">=</span> LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>DvoDaoImpl.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> HqlToSqlTranslator translator<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> DvoEntityManager entityManager <span style="color: #339933;">=</span> DvoEntityManager.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	@Transactional<span style="color: #009900;">&#40;</span>isolation<span style="color: #339933;">=</span>Isolation.<span style="color: #006633;">READ_COMMITTED</span>, propagation<span style="color: #339933;">=</span>Propagation.<span style="color: #006633;">REQUIRED</span>, readOnly<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span>, rollbackFor<span style="color: #339933;">=</span><span style="color: #003399;">Exception</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> loadDvos<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> dvoClass, Criterion criterion<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> loadDvos<span style="color: #009900;">&#40;</span>entityManager.<span style="color: #006633;">getMetaByDvo</span><span style="color: #009900;">&#40;</span>dvoClass<span style="color: #009900;">&#41;</span>, criterion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> loadDvos<span style="color: #009900;">&#40;</span>DvoEntityMeta meta, Criterion criterion<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/**/</span>
		<span style="color: #666666; font-style: italic;">// TODO: optimieren: wenn mehrere attribute einer aggregation (z.b. x.y.id und x.y.name) benutzt werden,</span>
		<span style="color: #666666; font-style: italic;">// dann sollen nicht zwei joins erzeugt werden</span>
		<span style="color: #000000; font-weight: bold;">final</span> Criteria criteria <span style="color: #339933;">=</span> sessionFactory.<span style="color: #006633;">getCurrentSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createCriteria</span><span style="color: #009900;">&#40;</span>meta.<span style="color: #006633;">getEntityClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// es werden zwei informationen von der meta benötigt:</span>
		<span style="color: #666666; font-style: italic;">// 1. welche felder sollen in der query geladen werden</span>
		<span style="color: #666666; font-style: italic;">// 2. in welche properties sollen die daten gespeichert werden</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// beispiel:</span>
		<span style="color: #666666; font-style: italic;">// dlrListDvoPropertiesByAlias.put(&quot;customerName&quot;, &quot;referencedMTMessage.customer.name&quot;);</span>
		<span style="color: #666666; font-style: italic;">// bedeutet, dass die dvo-property &quot;customerName&quot; mit den daten aus &quot;referencedMTMessage.customer.name&quot;</span>
		<span style="color: #666666; font-style: italic;">// befüllt werden soll.</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// der query-teil (&quot;referencedMTMessage.customer.name&quot;) muss gesplittet und mit joins in die abfrage integriert werden.</span>
		<span style="color: #666666; font-style: italic;">// auch muss der index jedes feldes nachgehalten werden, da das resultset nur über indizes einzelne kolumnen liefert</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> propertyToQueryMappings <span style="color: #339933;">=</span> meta.<span style="color: #006633;">getDvoPropertiesToQueryPaths</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;propertyToQueryMappings=&quot;</span><span style="color: #339933;">+</span>propertyToQueryMappings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// property -&gt; index in resultset</span>
		<span style="color: #000000; font-weight: bold;">final</span> HashMap<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> columnMappingsByIndex <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// key -&gt; ag_referencedMTMessage.country, value -&gt; ag_referencedMTMessage_country</span>
		<span style="color: #666666; font-style: italic;">// LEFT JOIN ag_referencedMTMessage.country AS ag_referencedMTMessage_country</span>
		<span style="color: #000000; font-weight: bold;">final</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> aggregations <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">final</span> ProjectionList projections <span style="color: #339933;">=</span> Projections.<span style="color: #006633;">projectionList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> maxAggregationDeepth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// maximale anzahl aggregationen bei allen querypaths</span>
		<span style="color: #000066; font-weight: bold;">int</span> propertyColumnIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// index der property in resultset</span>
&nbsp;
		<span style="color: #003399;">String</span> queryPath<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// querypath der aktuellen property</span>
		<span style="color: #000066; font-weight: bold;">int</span> aggregationDeepth<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// anzahl aggregationen im querypath der aktuellen property</span>
		<span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> aggregationParts <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// querypath der aktuellen property zerstueckelt</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>propertyToQueryMappings.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			queryPath <span style="color: #339933;">=</span> propertyToQueryMappings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// zur ermittlung der aggregationen</span>
			aggregationDeepth <span style="color: #339933;">=</span> StringUtil.<span style="color: #006633;">occurences</span><span style="color: #009900;">&#40;</span>queryPath, <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;property=&quot;</span><span style="color: #339933;">+</span>property<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, queryPath=&quot;</span><span style="color: #339933;">+</span>queryPath<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, aggregationDeepth=&quot;</span><span style="color: #339933;">+</span>aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationDeepth<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// keine aggregation</span>
				<span style="color: #666666; font-style: italic;">// state -&gt; d.state</span>
				projections.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>queryPath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;  adding direct property projection d.&quot;</span><span style="color: #339933;">+</span>queryPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				maxAggregationDeepth <span style="color: #339933;">=</span> <span style="color: #003399;">Math</span>.<span style="color: #006633;">max</span><span style="color: #009900;">&#40;</span>maxAggregationDeepth, aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// aggregationen vorhanden</span>
				<span style="color: #666666; font-style: italic;">// alle abarbeiten</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// erst alle teile ermitteln</span>
				aggregationParts.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				CollectionSplitter.<span style="color: #006633;">toList</span><span style="color: #009900;">&#40;</span>aggregationParts, queryPath, <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;  aggregationParts=&quot;</span><span style="color: #339933;">+</span>aggregationParts<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// beispiele für aggregationen:</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// customer.id -&gt; ag_customer.id + LEFT JOIN d.customer AS ag_customer</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// referencedMTMessage.country.iso3166</span>
				<span style="color: #666666; font-style: italic;">// -&gt; ag_referencedMTMessage_country.iso3166</span>
				<span style="color: #666666; font-style: italic;">// + LEFT JOIN d.referencedMTMessage AS ag_referencedMTMessage</span>
				<span style="color: #666666; font-style: italic;">// + LEFT JOIN ag_referencedMTMessage.country AS ag_referencedMTMessage_country</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Es gibt also 3 verschiedene Positionen, an denen ein queryPath-Teil stehen kann:</span>
				<span style="color: #666666; font-style: italic;">// 1. am anfang. Dann handelt es sich um ein attribut der domain</span>
				<span style="color: #666666; font-style: italic;">//	hier muss ein join erzeugt werden, weil weitere attribute folgen (mindestens ein weiteres, dass das projection attribut des joins darstellt) </span>
				<span style="color: #666666; font-style: italic;">// 2. am ende. dann handelt es sich um ein attribut der zuletzt erzeugten aggregation (z.b. ag_referencedMTMessage_country.iso3166)</span>
				<span style="color: #666666; font-style: italic;">//	hier braucht nichts mehr gejoint zu werden, sondern das attribut muss als projektion hinzugefügt werden</span>
				<span style="color: #666666; font-style: italic;">// 3. in der mitte. dann handelt es sich um ein attribut der zuletzt erzeugten aggregation, die aber</span>
				<span style="color: #666666; font-style: italic;">// 	gejoint werden muss, weil weitere attribute folgen</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// letzte aggregation</span>
				<span style="color: #003399;">String</span> lastAggregationName <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">String</span> currentAggregationPart, currentAggregationName<span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// es gibt hier mindestens zwei aggregationParts</span>
				<span style="color: #666666; font-style: italic;">// erster teil beschreibt attribut von domain, also z.b. d.customer</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> aggregationIndex<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> aggregationIndex<span style="color: #339933;">&lt;=</span>aggregationDeepth<span style="color: #339933;">;</span> aggregationIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					currentAggregationPart <span style="color: #339933;">=</span> aggregationParts.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;    checking aggregationIndex=&quot;</span><span style="color: #339933;">+</span>aggregationIndex<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, part=&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// entspricht &quot;LEFT JOIN d.referencedMTMessage AS ag_referencedMTMessage&quot;</span>
						lastAggregationName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ag_&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">;</span>
						aggregations.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart, lastAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #339933;">==</span>aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// letzter teil beschreibt das endliche attribut, dass zur projektion hinzukommt</span>
						projections.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span>lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;    last aggregation part found: adding projection &quot;</span><span style="color: #339933;">+</span>lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// mitten drin</span>
						<span style="color: #666666; font-style: italic;">// entspricht &quot;LEFT JOIN ag_referencedMTMessage.country AS ag_referencedMTMessage_country&quot;</span>
						currentAggregationName <span style="color: #339933;">=</span> lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">;</span>
						aggregations.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart, currentAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;    middle aggregation part found: adding aggregation &quot;</span><span style="color: #339933;">+</span>lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; -&gt; &quot;</span><span style="color: #339933;">+</span>currentAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						lastAggregationName <span style="color: #339933;">=</span> currentAggregationName<span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			columnMappingsByIndex.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>property, propertyColumnIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// wenn aggregationen vorhanden sind, dann einfügen</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>maxAggregationDeepth<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// aggregationen (joins)</span>
			<span style="color: #666666; font-style: italic;">// nach länge sortieren</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;building aggregations&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> aggregationsSizeSorted <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>aggregations.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Collections</span>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>aggregationsSizeSorted, <span style="color: #000000; font-weight: bold;">new</span> StringLengthComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;aggregations (sorted): &quot;</span><span style="color: #339933;">+</span>aggregationsSizeSorted<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> fromAggregation<span style="color: #339933;">:</span>aggregationsSizeSorted<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				criteria.<span style="color: #006633;">createAlias</span><span style="color: #009900;">&#40;</span>fromAggregation, aggregations.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>fromAggregation<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// projektionen</span>
		criteria.<span style="color: #006633;">setProjection</span><span style="color: #009900;">&#40;</span>projections<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>criterion<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			criteria.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>criterion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>translator<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;created query: &quot;</span><span style="color: #339933;">+</span>translator.<span style="color: #006633;">toSql</span><span style="color: #009900;">&#40;</span>criteria<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;columnmappings: &quot;</span><span style="color: #339933;">+</span>columnMappingsByIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// nun abfrage ausführen und dvofactory zum erzeugen der dvos benutzen</span>
		<span style="color: #000000; font-weight: bold;">final</span> HibernateBuildByRowScrollAction scrollAction <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DvoBuildByRowScrollActionImpl<span style="color: #009900;">&#40;</span>meta, columnMappingsByIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> loadByScroll<span style="color: #009900;">&#40;</span>scrollAction, criteria<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">List</span> loadByScroll<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> HibernateBuildByRowScrollAction scrollAction, <span style="color: #000000; font-weight: bold;">final</span> Criteria criteria<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">ArrayList</span> data <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ScrollableResults result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>scrollAction.<span style="color: #006633;">getCacheMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				criteria.<span style="color: #006633;">setCacheMode</span><span style="color: #009900;">&#40;</span>scrollAction.<span style="color: #006633;">getCacheMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>scrollAction.<span style="color: #006633;">getLockMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				criteria.<span style="color: #006633;">setLockMode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span>, scrollAction.<span style="color: #006633;">getLockMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>scrollAction.<span style="color: #006633;">getScrollMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				result <span style="color: #339933;">=</span> criteria.<span style="color: #006633;">scroll</span><span style="color: #009900;">&#40;</span>scrollAction.<span style="color: #006633;">getScrollMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				result <span style="color: #339933;">=</span> criteria.<span style="color: #006633;">scroll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> rowdata<span style="color: #339933;">;</span>
			<span style="color: #003399;">Object</span> resultObject<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				rowdata <span style="color: #339933;">=</span> result.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				resultObject <span style="color: #339933;">=</span> scrollAction.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span>rowdata<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resultObject<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					data.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>resultObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">finally</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				result.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> data<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHqlToSqlTranslator<span style="color: #009900;">&#40;</span>HqlToSqlTranslator translator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">translator</span> <span style="color: #339933;">=</span> translator<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSessionFactory<span style="color: #009900;">&#40;</span>SessionFactory sessionFactory<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sessionFactory</span> <span style="color: #339933;">=</span> sessionFactory<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterPropertiesSet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sessionFactory<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">NullPointerException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sessionFactory not set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The dao implementation uses some few helper classes, which interact with the annotations as well as with the beans itself.<br />
At first place there is a class holding the meta data for a view object:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DvoEntityMeta <span style="color: #009900;">&#123;</span>
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unused&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Log LOG <span style="color: #339933;">=</span> LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>DvoEntityMeta.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> dvoPropertiesToQueryPaths <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">Class</span> entityClass<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">Class</span> dvoClass<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DvoEntityMeta<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> entityClass, <span style="color: #000000; font-weight: bold;">Class</span> dvoClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#40;</span>entityClass, dvoClass, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DvoEntityMeta<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> entityClass, <span style="color: #000000; font-weight: bold;">Class</span> dvoClass, <span style="color: #000066; font-weight: bold;">boolean</span> useSimplePropertyMapping<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">entityClass</span> <span style="color: #339933;">=</span> entityClass<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dvoClass</span> <span style="color: #339933;">=</span> dvoClass<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>useSimplePropertyMapping<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// My custom BeanUtil class extracts all bean-method names from the given class,</span>
				<span style="color: #666666; font-style: italic;">// excluding methods like &quot;getClass()&quot;.</span>
				<span style="color: #000000; font-weight: bold;">final</span> Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> properties <span style="color: #339933;">=</span> BeanUtil.<span style="color: #006633;">getPropertyNamesFilteredFromClass</span><span style="color: #009900;">&#40;</span>dvoClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>properties<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					dvoPropertiesToQueryPaths.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>property, property<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span> e<span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">RuntimeException</span> r <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					r.<span style="color: #006633;">setStackTrace</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> r<span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">Class</span> getDvoClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> dvoClass<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">Class</span> getEntityClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> entityClass<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> getDvoPropertiesToQueryPaths<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> dvoPropertiesToQueryPaths<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getQueryPathForDvoProperty<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> dvoProperty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> dvoPropertiesToQueryPaths.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>dvoProperty<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addDvoPropertiesToQueryPaths<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> dvoProperty, <span style="color: #003399;">String</span> queryPath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		dvoPropertiesToQueryPaths.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>dvoProperty, queryPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;dvoClass=&quot;</span><span style="color: #339933;">+</span>dvoClass.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, domainClass=&quot;</span><span style="color: #339933;">+</span>entityClass.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, properties=&quot;</span><span style="color: #339933;">+</span>dvoPropertiesToQueryPaths<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then there is the dvo entity manager, which is used to analyse and organize all annotated dvo classes in a singleton.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DvoEntityManager <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Log LOG <span style="color: #339933;">=</span> LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>DvoEntityManager.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> DvoEntityManager INSTANCE <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DvoEntityManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> HashMap<span style="color: #339933;">&lt;</span>Class, DvoEntityMeta<span style="color: #339933;">&gt;</span> entityMetaByDvoClass <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>Class, DvoEntityMeta<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> DvoEntityManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;creating dvo entity manager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> DvoEntityManager getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> INSTANCE<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isDvo<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> isDvo<span style="color: #009900;">&#40;</span>o.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isDvo<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> cls<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cls<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> cls.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span>DvoAnnotation.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> registerDvo<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> dvo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;registering &quot;</span><span style="color: #339933;">+</span>dvo.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isDvo<span style="color: #009900;">&#40;</span>dvo<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>entityMetaByDvoClass.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>dvo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			DvoAnnotation dvoAnnotation <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DvoAnnotation<span style="color: #009900;">&#41;</span> dvo.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span>DvoAnnotation.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">final</span> DvoEntityMeta meta <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DvoEntityMeta<span style="color: #009900;">&#40;</span>dvoAnnotation.<span style="color: #006633;">rootDomainClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, dvo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// erzeugen einer entsprechenden meta-data</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Method</span> methods <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> dvo.<span style="color: #006633;">getDeclaredMethods</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">boolean</span> defaultPropertyMapping <span style="color: #339933;">=</span> dvoAnnotation.<span style="color: #006633;">defaultPropertyMapping</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			DvoPropertyAnnotation dvoPropertyAnnotation<span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> propertyName<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Method</span> method<span style="color: #339933;">:</span>methods<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				propertyName <span style="color: #339933;">=</span> BeanUtil.<span style="color: #006633;">getPropertyName</span><span style="color: #009900;">&#40;</span>method<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				dvoPropertyAnnotation <span style="color: #339933;">=</span> method.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span>DvoPropertyAnnotation.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dvoPropertyAnnotation<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					meta.<span style="color: #006633;">addDvoPropertiesToQueryPaths</span><span style="color: #009900;">&#40;</span>propertyName, dvoPropertyAnnotation.<span style="color: #006633;">attributePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>defaultPropertyMapping <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #0000ff;">&quot;class&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>propertyName<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> method.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Transient</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>propertyName.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;get&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> propertyName.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;set&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> propertyName.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;is&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					meta.<span style="color: #006633;">addDvoPropertiesToQueryPaths</span><span style="color: #009900;">&#40;</span>propertyName, propertyName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			entityMetaByDvoClass.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>dvo, meta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Created entity meta: &quot;</span><span style="color: #339933;">+</span>meta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> registerDvo<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> dvo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		registerDvo<span style="color: #009900;">&#40;</span>dvo.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DvoEntityMeta getMetaByDvo<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> dvoClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isDvo<span style="color: #009900;">&#40;</span>dvoClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			registerDvo<span style="color: #009900;">&#40;</span>dvoClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> entityMetaByDvoClass.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>dvoClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DvoEntityMeta getMetaByDvo<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> dvo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isDvo<span style="color: #009900;">&#40;</span>dvo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			registerDvo<span style="color: #009900;">&#40;</span>dvo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> entityMetaByDvoClass.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>dvo.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There are two annotations used for the dvos,<br />
one to annotate a class as a dvo called &#8220;DvoAnnotation&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Retention<span style="color: #009900;">&#40;</span>RetentionPolicy.<span style="color: #006633;">RUNTIME</span><span style="color: #009900;">&#41;</span>
@Target<span style="color: #009900;">&#40;</span>ElementType.<span style="color: #006633;">TYPE</span><span style="color: #009900;">&#41;</span>
@Inherited
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> DvoAnnotation <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">Class</span> rootDomainClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">boolean</span> defaultPropertyMapping<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It is used like this (on the classes from last article):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@DvoAnnotation<span style="color: #009900;">&#40;</span>rootDomainClass<span style="color: #339933;">=</span>Person.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonLastNameCountryViewObject<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> countryName<span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// more to come</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And one annotation called &#8220;DvoPropertyAnnotation&#8221; for the mapping of the query-path to the properties (only for getters):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Retention<span style="color: #009900;">&#40;</span>RetentionPolicy.<span style="color: #006633;">RUNTIME</span><span style="color: #009900;">&#41;</span>
@Target<span style="color: #009900;">&#40;</span>ElementType.<span style="color: #006633;">METHOD</span><span style="color: #009900;">&#41;</span>
@Inherited
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> DvoPropertyAnnotation <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> attributePath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Which is used as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@DvoAnnotation<span style="color: #009900;">&#40;</span>rootDomainClass<span style="color: #339933;">=</span>Person.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonLastNameCountryViewObject<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> countryName<span style="color: #339933;">;</span>
&nbsp;
	@DvoPropertyAnnotation<span style="color: #009900;">&#40;</span>attributePath<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;lastName&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLastName<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@DvoPropertyAnnotation<span style="color: #009900;">&#40;</span>attributePath<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;address.country.name&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCountryName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> name<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCountryName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> countryName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">countryName</span> <span style="color: #339933;">=</span> countryName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally there are further few classes to handle executing and mapping the resultsets to the dvos, which are used in the dvo dao implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DvoBuildByRowScrollActionImpl<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> CacheMode cacheMode<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> LockMode lockMode<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> DvoEntityMeta meta<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Map<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> propertyColumnMapping<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DvoBuildByRowScrollActionImpl<span style="color: #009900;">&#40;</span>DvoEntityMeta meta, Map<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> propertyColumnMapping<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">meta</span> <span style="color: #339933;">=</span> meta<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">propertyColumnMapping</span> <span style="color: #339933;">=</span> propertyColumnMapping<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> build<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resultSetRow<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Object</span> dvo<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			dvo <span style="color: #339933;">=</span> meta.<span style="color: #006633;">getDvoClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> err <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;While creating instance of dvo &quot;</span><span style="color: #339933;">+</span>meta.<span style="color: #006633;">getDvoClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; with default constructor&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isErrorEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				LOG.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>err, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span> e<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">RuntimeException</span> rt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>err, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				rt.<span style="color: #006633;">setStackTrace</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">throw</span> rt<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>propertyColumnMapping.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				PropertyUtils.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span>dvo, property, resultSetRow<span style="color: #009900;">&#91;</span>propertyColumnMapping.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> err <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;While setting property <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>property<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> from column <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>propertyColumnMapping.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> on dvo &quot;</span><span style="color: #339933;">+</span>dvo.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isErrorEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					LOG.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>err, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span> e<span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">RuntimeException</span> rt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>err, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					rt.<span style="color: #006633;">setStackTrace</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> rt<span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> dvo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> CacheMode getCacheMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> cacheMode<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> LockMode getLockMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> lockMode<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> ScrollMode getScrollMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> ScrollMode.<span style="color: #006633;">FORWARD_ONLY</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Still the API is not complete and not optimal. It is now easier to write dvo classes, but the limitations, that the datatype of the setter in the view object has to be the same as in the corresponding domain property as well as the limitation that restricting the query is quite difficult, as you don’t know the aliases of the generated aggregations a priori, still exists. Also there is some potential on optimizations on the generated queries.<br />
But this all is not too complicated to do, as now there is a better basis for continuing.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hibernate-data-view-objects-annotations.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tauwetter</title>
		<link>http://narcanti.keyboardsamurais.de/tauwetter.html</link>
		<comments>http://narcanti.keyboardsamurais.de/tauwetter.html#comments</comments>
		<pubDate>Sun, 28 Mar 2010 12:22:35 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Persönliche Erlebnisse]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=436</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/personal.png" width="26" height="26" alt="" title="Persönliche Erlebnisse" /><br/>Heute schreibe ich nicht, wie der Titel vielleicht suggeriert, vom Fr&#252;hlingswetter, sondern von einem Film, den ein Freund gedreht hat. Irgendwann gegen 1995/96. Philipp, ist ein Freund und Film-Geek. Er schaut sich Filme anders an als die meisten von uns, die sich einfach nur Unterhalten und vom Film mitnehmen lassen. Philipp analysiert regelrecht jedes Detail, [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/personal.png" width="26" height="26" alt="" title="Persönliche Erlebnisse" /><br/><p>Heute schreibe ich nicht, wie der Titel vielleicht suggeriert, vom Fr&#252;hlingswetter, sondern von einem Film, den ein Freund gedreht hat.<br />
<span id="more-436"></span></p>
<p>Irgendwann gegen 1995/96. Philipp, ist ein Freund und Film-Geek. Er schaut sich Filme anders an als die meisten von uns, die sich einfach nur Unterhalten und vom Film mitnehmen lassen. Philipp analysiert regelrecht jedes Detail, den Ausschnitt, die Perspektive, die Kamera, den Schnitt. Wie wird der Film erz&#228;hlt? Wie spielen die Schauspieler ihre Rolle? Er ist gro&#223;er Fan von Martin Scorsese und Robert DeNiro. Er liest viel zum Thema Film. Also nicht &#252;ber die Filme, wie in einer Wochenzeitschrift, sondern wie ein Film entsteht. Er erkl&#228;rt mir, was <a href="http://de.wikipedia.org/wiki/Mise-en-sc%C3%A8ne">&#8220;Mise-en-scène&#8221;</a> hei&#223;t und zeigt mir viele Beispiele in Filmen.</p>
<p>Wir sind jung und und Tr&#228;umen davon, einen eigenen Film zu machen. Wir beginnen mit einer einfachen Handkamera Szenen zu spielen, aus Jux. Ein paar weitere Freunde, wie Christoph und Thorsten, haben auch Spa&#223; an der Sache und machen mit. Philipp geht auf eine Waldorfschule und macht bald seinen Abschlu&#223;. Auf seiner Waldorfschule ist es &#252;blich, eine praktische Abschlu&#223;arbeit zu erstellen und zu pr&#228;sentieren. Philipps Idee: Er schreibt sein eigenes Drehbuch. Ich habe vor einiger Zeit mein Abitur hinter mich gebracht und bin noch etwas unentschlossen, ob und was ich studieren soll, da es mit einem Ausbildungsplatz nicht auf anhieb geklappt hat, und habe entsprechend einiges an freier Zeit. Wir setzen uns regelm&#228;&#223;ig zusammen, Philipp gibt mir Literatur zum Thema &#8220;Wie schreibt man ein Drehbuch?&#8221;.<br />
Einige Monate sp&#228;ter haben wir eine Grundstory, und die erste H&#228;lfte des Drehbuchs ist fertig. Arbeitstitel &#8220;Fische&#8221;. Es geht um zwei Protagonisten, die in rivalisierenden Gangsterorganisation sind. Eine Gangstergeschichte also, nicht verwunderlich, denn Philipp und ich sind nun mal gro&#223;e Scorsese und DeNiro Fans. Dennoch ist es keine klassische Gangstergeschichte, denn die Protagonisten m&#246;chten aussteigen.</p>
<p>Einige Zeit sp&#228;ter fange ich mit meinem Studium an, danach Arbeiten als Consultant, habe also nicht mehr die freie Zeit wie fr&#252;her. Philipp und ich verlieren uns aus den Augen.</p>
<p>6-7 Jahre sp&#228;ter l&#228;dt mich Philipp dazu ein, bei der Umsetzung des Films mitzuwirken, welchen er nun drehen m&#246;chte. Ein &#8220;Zero&#8221;-Budget Film. Denn keiner hat wirklich Geld, und schenken will es niemand. Ich bin von meiner Arbeit so in Beschlag genommen, dass ich leider nicht an der Umsetzung mitwirken kann.</p>
<p>Weitere 4 Jahre sp&#228;ter, vor einer Woche, l&#228;dt mich Philipp erneut ein, diesmal zur Crew-Pr&#228;miere des Films <a href="http://www.tauwetter-film.de/">&#8220;Tauwetter&#8221;</a>, der endg&#252;ltige Titel des Films. Ich bin begeistert und auch gespannt, was aus der Geschichte, die wir gemeinsam vor so vielen Jahren angefangen hatten, geworden ist.<br />
Vor dem Film sagt er mir noch, dass er den Film gerne aus meinen Augen sehen w&#252;rde.</p>
<p>Der Film geht los und ich bin begeistert dar&#252;ber, dass die Protagonisten noch ihre Namen von vor &#252;ber einer Dekade beibehalten haben, wie Tom, Samuel, Hoffmann, Fischer. Die Kamera und die Schnitte sind sehr gut, professionell. Nichts hat den Flair einer billigen Produktion, und auch nicht den eines Films, den sich Jugendliche erdacht haben. Die Darsteller sind fast alle echte Profis. Das K&#246;lner Philarmonieorchester hat die Musik zu dem Film gespielt, die unter anderem von Mirko, einem damaligen Schulkameraden komponiert wurde.<br />
Der Film beginnt mit einigen Sequenzen, die ich nicht kenne, da wir damals den Anfang anders hatten. Aber nach und nach sehe ich Sachen aus dem ersten Drehbuch wieder. Die Geschichte ist noch dieselbe, nat&#252;rlich erweitert, an einigen Stellen erg&#228;nzt um die Charaktere und die Story st&#228;rker zu tragen und mehr Dramaturgie ins Geschehen zu bringen. Dennoch enth&#228;lt der Film so gut wie alles aus der original Story, sogar an einige Dialoge erinnere ich mich. Es ist unglaublich zu sehen, wie die Charaktere, die wir uns damals ausgedacht hatten, nun auf der Leinwand zum Leben erwachen und der Film die Geschichte erz&#228;hlt.</p>
<p>87 Minuten sp&#228;ter beginnt der Abspann. Ich bin baff und stolz auf Philipp, dass er nicht nur sich und den Mitwirkenden einen Traum erf&#252;llt hat, sondern auch mir. Und obwohl es so lange her ist, dass ich &#252;berhaupt etwas f&#252;r den Film gemacht habe, kriege ich einen Adrenalinschub, als im Nachspann mein Name auftaucht: &#8220;Nach einer Idee von Phillipp M. H&#246;nig, Serhat Cinar und Christoph Pohlens&#8221;. Und mir wird klar, dass manche Tr&#228;ume doch in Erf&#252;llung gehen, vor allem dann, wenn man diese mit anderen teilt.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/tauwetter.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Marie: Geburtstag und Liebe</title>
		<link>http://narcanti.keyboardsamurais.de/marie-geburtstag-und-liebe.html</link>
		<comments>http://narcanti.keyboardsamurais.de/marie-geburtstag-und-liebe.html#comments</comments>
		<pubDate>Sun, 21 Mar 2010 16:48:22 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Marie]]></category>
		<category><![CDATA[cat]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=433</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/marie-icon.jpg" width="27" height="25" alt="" title="Marie" /><br/>Lange her, dass ich etwas neues &#252;ber Marie geschrieben habe, auch wenn es viel zu erz&#228;hlen gibt. Vor einem Monat hatte Marie &#8220;Geburtstag&#8221;. Da wir nicht genau wissen, wann Marie wirklich geboren wurde, haben wir den Tag, am dem wir sie bekommen haben, zu ihrem neuen Geburtstag erkl&#228;rt. Schlie&#223;lich hat sie bei uns auch ein [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/marie-icon.jpg" width="27" height="25" alt="" title="Marie" /><br/><p>Lange her, dass ich etwas neues &#252;ber Marie geschrieben habe, auch wenn es viel zu erz&#228;hlen gibt.<br />
Vor einem Monat hatte Marie &#8220;Geburtstag&#8221;. Da wir nicht genau wissen, wann Marie wirklich geboren wurde, haben wir den Tag, am dem wir sie bekommen haben, zu ihrem neuen Geburtstag erkl&#228;rt. Schlie&#223;lich hat sie bei uns auch ein neues Leben begonnen.<br />
<span id="more-433"></span></p>
<table>
<tr>
<td class="l t"><img src="http://farm4.static.flickr.com/3414/3590036672_acfe118a28_m.jpg"/></td>
<td>&nbsp;</td>
<td class="l t">
Aufmerksamen Lesern mag aufgefallen sein, dass mein erster Text &#252;ber Marie auf den 15.02.2009 datiert ist. Bekommen haben wir Marie am <i>14.02.2009</i>. Ja, das war der Valentinstag. Erst einige Zeit sp&#228;ter ist mir und Sarah auch aufgefallen, dass Marie einen schwarzen Fleck in Form eines Herzens auf der Brust hat (auf dem Foto links erkennbar). Wenn das mal nicht Kismet ist. Darum ist Maries neuer Geburtstag der Valentinstag.</td>
</tr>
</table>
<p>Dieses Jahr haben wir ihr Einj&#228;hriges gefeiert, indem wir Marie zum Mittag eine Dose Thunfisch serviert haben. Sie schien sehr begeistert von unserer Idee.</p>
<p>Etwas, &#252;ber das ich noch nicht berichtet hatte, ist Maries <i>Geschw&#228;tzigkeit</i>. Ich habe einige Katzen kennen gelernt, alle Mauzen ab und an, aber Marie ist auch hier etwas anders. Sie spricht recht h&#228;ufig und kann sowohl mit ihrem Tonfall als auch mit Worten erkl&#228;ren, was ihr anliegen ist, nat&#252;rlich in Katzensprache. Ja, klingt komisch, aber es ist wirklich so. Wenn Marie z. B. Hunger hat und uns erkl&#228;ren will, dass sie jetzt Essen erwartet, dann mauzt sie <i>&#8220;m-kau&#8221;</i>. Das hei&#223;t soviel wie &#8220;bitte f&#252;ttern&#8221;. Sie benutzt dieses Wort sonst nicht. Um genau zu sein, hei&#223;t es sogar Na&#223;futter, denn bei &#8220;m-kau&#8221; will sie nichts von Trockenfutter wissen.<br />
Wenn sie mich in meinem Bett oder im Wohnzimmer besucht und rumdruckst, dann Frage ich sie &#8220;m-kau?&#8221; und wenn sie tats&#228;chlich Hunger hat, antwortet sie mit &#8220;m-kau&#8221; und rennt Richtung K&#252;che.<br />
Auch an sonsten ist sie eine Labertasche. Wenn ich abends nach Hause komme, werde ich von ihr empfangen, und sie erz&#228;hlt mit scheinbar, was sie so &#252;ber den Tag gemacht und erlebt hat. Das meiste verstehe ich aber leider nicht.</p>
<p>Und Marie hat auch Fans. Ein Freund, der die Marie-Artikel immer gerne liest, war letztes Wochenende zu Besuch da und durfte Marie live kennenlernen. Leider ist Marie, wenn viel Besuch im Haus ist, eher weniger begeistert und legt sich lieber im Schlafzimmer auf die Fensterbank, um der sp&#228;twinterlichen K&#228;lte der letzten Tage durch die Heizung unter der Fensterbank zu entkommen und ihre Ruhe zu haben. Vielleicht wird Marie ja mal so ber&#252;hmt, dass ich Merchandise Artikel mit ihrem Bild verteilen kann.</p>
<p>Apropos Wetter: Einer meiner Lieblingsbesch&#228;ftigungen am Wochenende ist es, wenn denn mal wieder die Sonne scheint, mich im Schlafzimmer (S&#252;dseite) auf den Teppich zu legen und die Sonne durch das Fenster auf meine Plauze scheinen zu lassen. Und nat&#252;rlich geh&#246;rt das auch zu den Lieblingsbesch&#228;ftigungen von Marie. Sie legt sich dann meistens neben mich in die Sonne und l&#228;&#223;t sich auch gerne mal das Fell verwuscheln.</p>
<p>Zum Schluss noch ein <a href="http://www.youtube.com/user/simonscat">Video-Link zu &#8220;Simon&#8217;s Cat&#8221; auf Youtube</a>. Simon&#8217;s Cat gibt es &#252;brigens inzwischen auch als Comicbuch auf deutsch.<br />
<img src="http://narcanti.keyboardsamurais.de/images/posts/personal/simonscat.jpg"/></p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/marie-geburtstag-und-liebe.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Marie]]></series:name>
	</item>
		<item>
		<title>Etikettenschwindel bei Lebensmitteln</title>
		<link>http://narcanti.keyboardsamurais.de/etikettenschwindel-bei-lebensmitteln.html</link>
		<comments>http://narcanti.keyboardsamurais.de/etikettenschwindel-bei-lebensmitteln.html#comments</comments>
		<pubDate>Thu, 11 Mar 2010 19:50:02 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Not lost but found]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=432</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/notlostbutfound.png" width="24" height="24" alt="" title="Not lost but found" /><br/>Zuf&#228;llig dar&#252;ber gestolpert: Auf www.abgespeist.de werden Werbekampagnen und Produkte von Lebensmittelherstellern unter die Lupe genommen. Interessant: Der &#8220;Rosa-Joghurt-Riegel&#8221; hat mehr Fett und Kallorien als Vollmilchschokolade und die N&#228;hrwertangaben fehlen nat&#252;rlich auf der Packung. Aber auch der neue Werbeslogan f&#252;r die Schokoriegel f&#252;r Kinder ist nicht schlecht: &#8220;Die Extra Portion Zucker und Fett!&#8221;.]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/notlostbutfound.png" width="24" height="24" alt="" title="Not lost but found" /><br/><p>Zuf&#228;llig dar&#252;ber gestolpert: Auf <a href="http://www.abgespeist.de/alle_produkte/index_ger.html">www.abgespeist.de</a> werden Werbekampagnen und Produkte von Lebensmittelherstellern unter die Lupe genommen. Interessant: Der &#8220;Rosa-Joghurt-Riegel&#8221; hat mehr Fett und Kallorien als Vollmilchschokolade und die N&#228;hrwertangaben fehlen nat&#252;rlich auf der Packung. Aber auch der neue Werbeslogan f&#252;r die Schokoriegel f&#252;r Kinder ist nicht schlecht: &#8220;Die Extra Portion Zucker und Fett!&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/etikettenschwindel-bei-lebensmitteln.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardening WordPress: Basic generator obfuscation</title>
		<link>http://narcanti.keyboardsamurais.de/hardening-wordpress-basic-generator-obfuscation.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hardening-wordpress-basic-generator-obfuscation.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 20:56:38 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=429</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/>As previously noted, here another part of my Hardening WordPress series. This time I&#8217;ll show you the really basic technique of how you can obfuscate at least the generator-tag for your blog. The generator tag is the one in the sourcecode with &#60;meta name=&#8221;generator&#8221; content=&#8221;Wordpress version&#8221;/&#62;. Ususally it should provide visitors or search engines some [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/><p>As previously noted, here another part of my Hardening WordPress series. This time I&#8217;ll show you the really basic technique of how you can obfuscate at least the generator-tag for your blog.<br />
<span id="more-429"></span><br />
The generator tag is the one in the sourcecode with &lt;meta name=&#8221;generator&#8221; content=&#8221;Wordpress version&#8221;/&gt;. Ususally it should provide visitors or search engines some meta information on which software you use in which version. But it is also helpful to attackers. When they know which software in which version you use, they can reduce the attacks to known issues of this version. So it&#8217;s not a good idea to have this information in your blog. Also this information can help attackers to write scripts that will attack your blog on their own.</p>
<p>So the most basic step is to tell WordPress to remove this information, which is done by adding few methods into the functions.php within the theme folder (the plugin <a href="http://blogsecurity.net/wordpress/bs-wp-noversion">bs-wp-noversion</a> will do the same thing without modifying any theme files):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rsd_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// remove Really Simple Discovery entry</span>
remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wlwmanifest_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// remove Windows Live Writer Link  </span>
remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_generator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// remove Version output</span></pre></div></div>

<p>The most important thing here is that you removes the WordPress version from the header AND the feeds.<br />
And finally: Don&#8217;t forget to remove the files readme.html and license.txt from the root folder as an intruder may look at them to determine the version. Be aware: The removal of this files is needed everytime you update your WordPress core.</p>
<p>Additionally you can include some fake generator-tags within the header of your theme, like:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;generator&quot; content=&quot;Movable Type v3.2&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;Joomla! 1.5 - Open Source Content Management&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;TYPO3 4.1 CMS&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;Yahoo! SiteBuilder/2.4/1.5.0_02&quot; /&gt;
&lt;!-- 
	This website is powered by TYPO3 - inspiring people to share!
	TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
	TYPO3 is copyright 1998-2006 of Kasper Skaarhoj. Extensions are copyright of their respective owners.
	Information and contribution at http://typo3.com/ and http://typo3.org/
--&gt;</pre></div></div>

<p>Unfortunately an intruder can detect the lots of &#8220;wp-includes&#8221; and &#8220;wp-content&#8221; etc. on your page to at least determine that you&#8217;re using WordPress. There are several other strategies to obfuscate your wordpress up to a point, where it is really difficult for some intruder to tell what blogging-software you use at all.<br />
But this extends, for now, the scope of this post (as it requires lots of changes on your theme and a lot of rewrite rules in your htaccess files to hide eveything).</p>
<p>Perhaps later on I&#8217;ll tie together some of my personal functions together to a plugin to do this automatically.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hardening-wordpress-basic-generator-obfuscation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardening WordPress the geek way</title>
		<link>http://narcanti.keyboardsamurais.de/hardening-wordpress-the-geek-way.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hardening-wordpress-the-geek-way.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 20:30:16 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[mysql trigger]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=428</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/>My WordPress installation was hacked several times, and all because I was too lazy to use basic protection and hardening mechanisms. After some time I decided to investigate more on the security of my blog and applied some well known protection techniques as well as some really geeky dirty hacks right in the database. For [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/><p>My WordPress installation was hacked several times, and all because I was too lazy to use basic protection and hardening mechanisms. After some time I decided to investigate more on the security of my blog and applied some well known protection techniques as well as some really geeky dirty hacks right in the database.<br />
<span id="more-428"></span><br />
For the first part of this series, I just want to show my really geeky dirty hackish database-level protection.<br />
Other not so geeky and more proper protection techniques can be found at:<br />
<dir></p>
<li><a href="http://blogsecurity.net/wordpress/wordpress-security-whitepaper">Security whitepaper for wordpress incl. several very usefull plugins</a></li>
<li><a href="http://www.erich-kachel.de/?p=763">interesting article</a></li>
<li><a href="http://wpantivirus.com/">first wordpress antivirus plugin</a></li>
<li><a href="http://php-ids.org/">PHPIDS &#8211; PHP based intrusion detection and prevention system</a></li>
<p></dir><br />
Perhaps I&#8217;ll cover few of them in later articles.</p>
<h1><a name="0">The dirty hack</a></h1>
<p>Ususally the blogs on my dedicated system are owned and used by only one person as they are personal blogs. So there is only need for two user accounts on a WordPress install: One for the person owning the blog and one for the admin for maintainance purposes (like updating plugins and the WP core).<br />
When a blog is set up, changes on the wp_users are redundant for my blogs. Most hackers will try to create (by SQL-Injection) a new user with extended rights or modify the authentication data of existing users (like the one for admin). So I had the idea of preventing modifications on the wp_users. This only can be achieved within the database itself.<br />
After experimenting with the user rights in mysql (GRANT, REVOKE) I found out that restricting the access to only the wp_users table would need to set access rights to all other tables. No option for me.<br />
I investigated a little bit and found, that there is another possibility: TRIGGERS, which need at least mysql 5+ Version.<br />
In my database I have some administrator user who may do everything in the database, I&#8217;ll call this one &#8220;dba&#8221;. For the wordpress I create another user as described in the security whitepaper with less rights. Then I place a trigger on the wp_users table which avoids DELETE and INSERT except by the dba:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">delimiter <span style="color: #66cc66;">//</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`root_insert_only`</span> 
  BEFORE <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`wp_users`</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW BEGIN
    DECLARE dummy INT;
    <span style="color: #993333; font-weight: bold;">IF</span> STRCMP<span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SESSION_USER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'dba@'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;&gt;</span><span style="color: #cc66cc;">0</span> THEN
      <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'no'</span> <span style="color: #993333; font-weight: bold;">INTO</span> dummy <span style="color: #993333; font-weight: bold;">FROM</span> dual<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">WHERE</span> dual<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">=</span>NEW<span style="color: #66cc66;">.</span>id;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
  END
<span style="color: #66cc66;">//</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`root_delete_only`</span> 
  BEFORE <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`wp_users`</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW BEGIN
    DECLARE dummy INT;
    <span style="color: #993333; font-weight: bold;">IF</span> STRCMP<span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SESSION_USER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'dba@'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;&gt;</span><span style="color: #cc66cc;">0</span> THEN
      <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'no'</span> <span style="color: #993333; font-weight: bold;">INTO</span> dummy <span style="color: #993333; font-weight: bold;">FROM</span> dual<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">WHERE</span> dual<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">12</span>;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
  END
<span style="color: #66cc66;">//</span>
&nbsp;
delimiter ;</pre></div></div>

<p>This both triggers only allow inserts and deletes by the dba user (who has to login into mysql by a shell account). All other users get some sql-error on trying it.<br />
As there was the admin-account reset bug in WP, and a SQL-injection could update an existing login account, I also added a trigger to updates. Since a blog-user may want to change his email or other account data (except password and login name), the trigger for updates restricts changes to that fields:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">delimiter <span style="color: #66cc66;">//</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`restricted_update_only`</span> 
  BEFORE <span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`wp_users`</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW BEGIN
    DECLARE dummy INT;
    <span style="color: #993333; font-weight: bold;">IF</span> STRCMP<span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SESSION_USER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'dba@'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;&gt;</span><span style="color: #cc66cc;">0</span> THEN
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>ID;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_login<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_login;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_pass<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_pass;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_registered<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_registered;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_activation_key<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_activation_key;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_status<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_status;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
  END
<span style="color: #66cc66;">//</span>
&nbsp;
delimiter ;</pre></div></div>

<p>The update trigger restricts changes to all fields but the ones set in the trigger itself. This hack prevents changing of login-accounts but to the cost of some comfort loss. If a user wants to change his password we now have to log into the database as user dba and execute some query. But at least, this gives some more security to our blog.</p>
<p>By the way: Since newer versions of WordPress use some different encryption for the passwords, you should use <a href="http://scriptserver.mainframe8.com/wordpress_password_hasher.php">a wordpress password hasher</a> instead of MD5 when updating user passwords manually.</p>
<p>Of course, this makes no sense if you use weak passwords and the intruder can apply some brute force or hash-lookup to find it, or if you have multiple users using one blog and you have to recently update login data or are no geek.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hardening-wordpress-the-geek-way.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate DataViewObjects</title>
		<link>http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 20:03:54 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=427</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>When working with Hibernate and nested domain object models, it can be a performance problem when trying to display several (including nested) properties in a view. Usually for such cases the use of view objects is practical. This is the first scetch of my idea to automate population of view objects with hibernate. Meanwhile I [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>When working with Hibernate and nested domain object models, it can be a performance problem when trying to display several (including nested) properties in a view. Usually for such cases the use of view objects is practical.<br />
This is the first scetch of my idea to automate population of view objects with hibernate.<br />
<span id="more-427"></span><br />
Meanwhile I worked out some extended example with the use of Annotations. However, the current form is not usefull enough, as using criterions for restrictions is quite difficult. But more details on the next part of this. Here the first one:</p>
<p>Assume we have some nested domain model consisting of a person, an address and a country as following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> firstname<span style="color: #339933;">:</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> birthdate<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> comment<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Address address<span style="color: #339933;">;</span>
&nbsp;
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter for id,</span>
	<span style="color: #666666; font-style: italic;">// firstname, lastname, birthdate and comment</span>
&nbsp;
	@ManyToOne
	<span style="color: #000000; font-weight: bold;">public</span> Address getAddress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> address<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Address<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> street<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Country country<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter for </span>
	<span style="color: #666666; font-style: italic;">// id, street and country</span>
&nbsp;
	@ManyToOne
	<span style="color: #000000; font-weight: bold;">public</span> Country getCountry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> country<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Country<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> iso3166<span style="color: #339933;">;</span> 
	<span style="color: #666666; font-style: italic;">// iso 3166 2 letter code </span>
	<span style="color: #666666; font-style: italic;">// (uppercase), like DE for Germany</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
	@Id
	@Column<span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getIso3166<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> iso3166<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter for name and iso3166</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now let&#8217;s assume we want to build a list displaying only the lastname and the countryname of a person. In such a case it&#8217;s unneccessary to do a query like &#8220;SELECT p FROM Person p&#8221;, since even if lazy loading is enabled, hibernate will load all properties leading to lot&#8217;s of unneeded data transported from database to application.<br />
In such a case we would prefer to build a view object, that only will hold the information we need to display:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonLastNameCountryViewObject<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> countryName<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So we now have a lightweight view object, but how do we get the data into it?<br />
One possibility would be to build a custom query for this, like:</p>
<pre>
SELECT p.lastName, c.name FROM Person p LEFT JOIN p.address AS a LEFT JOIN a.country AS c
</pre>
<p>This would give us the needed data and we only would have to map the results to our view object.<br />
Having several views may lead to lots of custom queries and code doing the retrieval and mapping stuff. So why not automating it?</p>
<p>I created some classes to handle this work, but there are few informations that have to be given to it, especially about which view object properties to map to which domain model properties.<br />
In the above view object example, I decided to use a map of view object properties and define a domain model path for each, just like in commons-beanutils.<br />
The mapping for the above example would be:</p>
<pre>
lastName -> lastName
countryName -> address.country.name
</pre>
<p>The path here starts with the initial domain class, in this case the Person class. Since Hibernate does not support nested object paths like in</p>
<pre>
SELECT p.name, p.address.country.name FROM Person p
</pre>
<p>I built some code to split the path and join the appropriate domain models into the query just to have the working query denoted previously.<br />
So my view object mapping helpers contain of following classes:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Just an interface that will create a </span>
<span style="color: #666666; font-style: italic;">// view object for us for each resultset row</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ViewObjectFactory<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> createNewViewObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// a cimple class to hold all ,eta data needed for building our view objects</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ViewObjectMetaData<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// This will hold the mappings like</span>
  <span style="color: #666666; font-style: italic;">// lastName -&gt; lastName</span>
  <span style="color: #666666; font-style: italic;">// countryName -&gt; address.country.name</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> 
    propertiesToObjectPaths <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// this will hold our initial domain class, like Person.class.</span>
  <span style="color: #666666; font-style: italic;">// we need this to create a criteria in hibernate later on</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">Class</span> domainClass<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// the factory we will use to create the view objects</span>
  <span style="color: #000000; font-weight: bold;">private</span> ViewObjectFactory voFactory<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// as default, if no object paths are given, we assume that each view object property</span>
  <span style="color: #666666; font-style: italic;">// will be mapped non-nestingly to the domain class propertys with the same name.</span>
  <span style="color: #666666; font-style: italic;">// so the mapping will be something like:</span>
  <span style="color: #666666; font-style: italic;">// propertyA -&gt; propertyA</span>
  <span style="color: #666666; font-style: italic;">// propertyB -&gt; propertyB</span>
  <span style="color: #666666; font-style: italic;">// will need BeanUtils to work, or make some own code with reflection</span>
  <span style="color: #000000; font-weight: bold;">public</span> ViewObjectMetaData<span style="color: #009900;">&#40;</span>ViewObjectFactory voFactory, 
    <span style="color: #000000; font-weight: bold;">Class</span> domainClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">voFactory</span> <span style="color: #339933;">=</span> voFactory<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">domainClass</span> <span style="color: #339933;">=</span> domainClass<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">Map</span> desc <span style="color: #339933;">=</span> BeanUtils.<span style="color: #006633;">describe</span><span style="color: #009900;">&#40;</span>dtoFactory.<span style="color: #006633;">createDto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      desc.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;class&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">final</span> Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> properties <span style="color: #339933;">=</span> 
        <span style="color: #009900;">&#40;</span>Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> desc.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>properties<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        propertiesToObjectPaths.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>property, property<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// just make a runtime exception from it...</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span> e<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">RuntimeException</span> r <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        r.<span style="color: #006633;">setStackTrace</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> r<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ViewObjectMetaData<span style="color: #009900;">&#40;</span>ViewObjectFactory voFactory, 
    <span style="color: #000000; font-weight: bold;">Class</span> domainClass, 
    Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> propertiesToObjectPaths<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">voFactory</span> <span style="color: #339933;">=</span> voFactory<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">domainClass</span> <span style="color: #339933;">=</span> domainClass<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">propertiesToObjectPaths</span>.<span style="color: #006633;">putAll</span><span style="color: #009900;">&#40;</span>propertiesToObjectPaths<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// appropriate getters</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we have all information needed to build up queries and populate the view objects. The main work will consist of building up the query from the object path and mapping the resultset to the view objects.<br />
For building the query, I used the criteria API of hibernate, which allows to add further restrictions on the query later on. The algorithm for transforming the object path to a criteria is not that complicated. We have to think about two different cases in the object path:</p>
<p>1. object path consists of one part, like &#8220;lastName&#8221;. This has to be mapped to a projection, like:</p>
<pre>
SELECT p.lastName FROM Person p
</pre>
<p>2. the object consists of multiple parts, like &#8220;address.street&#8221; or &#8220;address.country.name&#8221;. In this case we have to create a hibernate alias (which internally maps to a join) for each part except the first (which is the root domain class) and the last, which has to be added as a projection as it is the property we want to have. So we have for the two part object path example:</p>
<pre>
SELECT a.street FROM Person p LEFT JOIN p.address AS a
</pre>
<p>and the three part object path example:</p>
<pre>
SELECT c.name FROM Person p LEFT JOIN p.address AS a LEFT JOIN a.country AS c
</pre>
<p>Also we&#8217;ll keep track of the indices of the projected properties in the resultset for the mapping between resultset and viewobject</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ViewObjectCriteriaBuilder<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// just a helper class to transport </span>
  <span style="color: #666666; font-style: italic;">// criteria and columnmappings</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> ViewObjectCriteria<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Criteria criteria<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> HashMap<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> propertyToColumnMappings <span style="color: #339933;">=</span> 
      <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// apropriate getters/setters</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// appropriate setter for the sessionFactory </span>
  <span style="color: #666666; font-style: italic;">// or just pass a current session to the next method</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ViewObjectCriteria buildCriteria<span style="color: #009900;">&#40;</span>ViewObjectMetaData voMetaData<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> ViewObjectCriteria voCriteria <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ViewObjectCriteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">final</span> Criteria criteria <span style="color: #339933;">=</span> sessionFactory.
      <span style="color: #006633;">getCurrentSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
      <span style="color: #006633;">createCriteria</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span>, voMetaData.<span style="color: #006633;">getDomainClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    voCriteria.<span style="color: #006633;">setCriteria</span><span style="color: #009900;">&#40;</span>criteria<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> propertiesToObjectPaths <span style="color: #339933;">=</span> 
      voMetaData.<span style="color: #006633;">getPropertiesToObjectPaths</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// our projections</span>
    <span style="color: #000000; font-weight: bold;">final</span> ProjectionList projections <span style="color: #339933;">=</span> Projections.<span style="color: #006633;">projectionList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// max. amount of aggregations in object path</span>
    <span style="color: #000066; font-weight: bold;">int</span> maxAggregationDeepth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// index of property in resultset</span>
    <span style="color: #000066; font-weight: bold;">int</span> propertyColumnIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">String</span> objectPath<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// objectpath of current vo property</span>
    <span style="color: #666666; font-style: italic;">// amount of aggregations in current object path</span>
    <span style="color: #000066; font-weight: bold;">int</span> aggregationDeepth<span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> aggregationParts <span style="color: #339933;">=</span> 
      <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// parts of the object path, splitted</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">// in the first step we only collect information </span>
    <span style="color: #666666; font-style: italic;">// about the needed aggregations,</span>
    <span style="color: #666666; font-style: italic;">// the joins will be build later on</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>propertiesToObjectPaths.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      objectPath <span style="color: #339933;">=</span> propertiesToObjectPaths.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// this helper just counts the </span>
      <span style="color: #666666; font-style: italic;">// occurences of '.' in the objectPath</span>
      aggregationDeepth <span style="color: #339933;">=</span> StringUtil.<span style="color: #006633;">occurences</span><span style="color: #009900;">&#40;</span>objectPath, <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationDeepth<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// no aggregation, like</span>
        <span style="color: #666666; font-style: italic;">// lastName -&gt; d.lastName</span>
        projections.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>objectPath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
        maxAggregationDeepth <span style="color: #339933;">=</span> 
          <span style="color: #003399;">Math</span>.<span style="color: #006633;">max</span><span style="color: #009900;">&#40;</span>maxAggregationDeepth, aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// aggregations exist</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// first split the object path</span>
        aggregationParts.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// this helper splits the objectPath </span>
        <span style="color: #666666; font-style: italic;">// on &quot;\\.&quot; and adds all parts to the </span>
        <span style="color: #666666; font-style: italic;">// aggregationParts-list. Works the same </span>
        <span style="color: #666666; font-style: italic;">// way as String.split</span>
        CollectionSplitter.<span style="color: #006633;">toList</span><span style="color: #009900;">&#40;</span>aggregationParts, objectPath, <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// last aggregations alias</span>
        <span style="color: #003399;">String</span> lastAggregationName <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> currentAggregationPart, currentAggregationName<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// when we're here, there are at least two parts in the object path</span>
        <span style="color: #666666; font-style: italic;">// first part is an property of the </span>
        <span style="color: #666666; font-style: italic;">// root domain class, e. g. address -&gt; d.address</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> aggregationIndex<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> 
          aggregationIndex<span style="color: #339933;">&lt;=</span>aggregationDeepth<span style="color: #339933;">;</span> aggregationIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
          currentAggregationPart <span style="color: #339933;">=</span> aggregationParts.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// equals to &quot;LEFT JOIN d.address AS ag_address&quot;</span>
            lastAggregationName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ag_&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">;</span>
            aggregations.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>
              <span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart, 
              lastAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #339933;">==</span>aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// last part in object path, which </span>
            <span style="color: #666666; font-style: italic;">// denotes a property we want to have projected</span>
            <span style="color: #666666; font-style: italic;">// equals to &quot;SELECT ... ag_address_country.name FROM ...&quot;</span>
            projections.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>
              Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span>
                lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// somewhere in the middle</span>
            <span style="color: #666666; font-style: italic;">// equals to </span>
            <span style="color: #666666; font-style: italic;">// &quot;LEFT JOIN ag_address.country AS ag_address_country&quot;</span>
            currentAggregationName <span style="color: #339933;">=</span> 
              lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">;</span>
            aggregations.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>
              lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart, 
              currentAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            lastAggregationName <span style="color: #339933;">=</span> currentAggregationName<span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// update index of property in resultset</span>
      voCriteria.<span style="color: #006633;">getPropertyToColumnMappings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
        <span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>property, propertyColumnIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// if there are any aggregations, we have</span>
    <span style="color: #666666; font-style: italic;">// to add an alias for each to the criteria</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>maxAggregationDeepth<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// sort aggregatios (joins) by their alias length</span>
      <span style="color: #666666; font-style: italic;">// this is to enshure that ag_address is </span>
      <span style="color: #666666; font-style: italic;">// added before ag_address_country</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> aggregationsSizeSorted <span style="color: #339933;">=</span> 
        <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>aggregations.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003399;">Collections</span>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>aggregationsSizeSorted, 
        <span style="color: #666666; font-style: italic;">// the string length comparator just compares</span>
        <span style="color: #666666; font-style: italic;">// the length of two strings</span>
        <span style="color: #000000; font-weight: bold;">new</span> StringLengthComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> fromAggregation<span style="color: #339933;">:</span>aggregationsSizeSorted<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// here we also may use LEFT JOIN or some other join type</span>
        criteria.<span style="color: #006633;">createAlias</span><span style="color: #009900;">&#40;</span>
          fromAggregation, 
          aggregations.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>fromAggregation<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add projections to criteria</span>
    criteria.<span style="color: #006633;">setProjection</span><span style="color: #009900;">&#40;</span>projections<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> voCriteria<span style="color: #339933;">;</span>    
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we have build a criteria which will load all neccessary data from the database. Meanwhile we could add some restrictions or limitations to the query to only retrieve a portion of all rows. Somewhere all along the code we will need to have a valid session/transaction, but I&#8217;ll skip that, as this is just an example.</p>
<p>Next we build a class that will execute the criteria and map the columns from the resultset to the viewobjects. Here are several possibilites. For example using a special hibernate rowsetmapper, but the way I did it below also works fine.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> buildViewObjects<span style="color: #009900;">&#40;</span>ViewObjectCriteria voCriteria, 
  ViewObjectMetaData voMetaData<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  ScrollableResults result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
    Criteria criteria <span style="color: #339933;">=</span> voCriteria.<span style="color: #006633;">getCriteria</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Map<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> propertyColumnMappings <span style="color: #339933;">=</span> 
      voCriteria.<span style="color: #006633;">getPropertyColumnMappings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// some cache method or scroll lock method here, if needed</span>
    result <span style="color: #339933;">=</span> criteria.<span style="color: #006633;">scroll</span><span style="color: #009900;">&#40;</span>ScrollMode.<span style="color: #006633;">FORWARD_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> rowdata<span style="color: #339933;">;</span>
    <span style="color: #003399;">Object</span> resultObject<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">ArrayList</span> viewObjects <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      rowdata <span style="color: #339933;">=</span> result.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      resultObject <span style="color: #339933;">=</span> voMetaData.<span style="color: #006633;">getViewObjectFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
        <span style="color: #006633;">createNewViewObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>
        propertyColumnMapping.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// also possible via reflection</span>
          PropertyUtils.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span>resultObject, 
            property, rowdata<span style="color: #009900;">&#91;</span>propertyColumnMappings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isErrorEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            LOG.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;While setting property <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>
              property<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> from column <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>
              propertyColumnMapping.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          resultObject <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resultObject<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        viewObjects.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>resultObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> viewObjects<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">finally</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      result.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it (for now).</p>
<p>Limitations:<br />
<dir></p>
<li>the datatype of the setter in the view object has to be the same as in the corresponding domain property</li>
<li>restricting the query is quite difficult, as you don&#8217;t know the aliases of the generated aggregations a priori</li>
<p></dir></p>
<p>Further improvements could be:<br />
<dir></p>
<li>some annotations so that we just annotate our view object and rest is done in background</li>
<li>make a full working open-source API out of it</li>
<li>optimizations on the queries. if we only would like to select the id of a nested domain class, like &#8220;address.id&#8221;, which already is known to the Person table (since this is the referencing foreign key), it would be great not to have to join the addresses</li>
<li>automatic mapping between differring property types of view object and domain object (eg. long to string convertions)</li>
<li>improve the possibility to restrict the generated query</li>
<p></dir></p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript Dateformatting</title>
		<link>http://narcanti.keyboardsamurais.de/javascript-dateformatting.html</link>
		<comments>http://narcanti.keyboardsamurais.de/javascript-dateformatting.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 19:56:40 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Computer]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=426</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/binary.gif" width="22" height="22" alt="" title="Computer" /><br/>I just recognized that there is no convenient method in Javascript to format a date-object to a string with the help of a dateformat-pattern, like in java.text.SimpleDateFormat. So I have writen a simple method, which just does this, including most important patterns. /* Usage: formatDate(new Date(), 'yyyy/MM/dd HH:mm:ss.SSS'); will return current date as something like [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/binary.gif" width="22" height="22" alt="" title="Computer" /><br/><p>I just recognized that there is no convenient method in Javascript to format a date-object to a string with the help of a dateformat-pattern, like in java.text.SimpleDateFormat. So I have writen a simple method, which just does this, including most important patterns.<br />
<span id="more-426"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
Usage:
formatDate(new Date(), 'yyyy/MM/dd HH:mm:ss.SSS');
will return current date as something like '2010/01/01 14:41:52.957'.
&nbsp;
Implemented:
y  	Year 	Year  	1996 (by using yyyy); 96 (by using yy)
M 	Month in year 	Month 	7 or 10 (by using M); 07 or 10 (by using MM)
d 	Day in month 	Number 	7 or 10 (by using d); 07 or 10 (by using dd)
H 	Hour in day (0-23) 	Number 	7 or 10 (by using H); 07 or 10 (by using HH)
k 	Hour in day (1-24) 	Number 	7 or 10 (by using k); 07 or 10 (by using kk)
m 	Minute in hour 	Number 	7 or 10 (by using m); 07 or 10 (by using mm)
s 	Second in minute 	Number 	7 or 10 (by using s); 07 or 10 (by using ss)
S 	Millisecond 	Number 	 7 or 10 or 100 (by using S); 07 or 10 or 100 (by using SS); 007 or 010 or 100 (by using SSS);
&nbsp;
Not implemented:
M 	Month in year 	Month 	July; Jul; textual values (by using MMM or MMMM)
G  	Era designator 	Text  	AD
w 	Week in year 	Number 	27
W 	Week in month 	Number 	2
D 	Day in year 	Number 	189
F 	Day of week in month 	Number 	2
E 	Day in week 	Text 	Tuesday; Tue
a 	Am/pm marker 	Text 	PM
K 	Hour in am/pm (0-11) 	Number 	0
h 	Hour in am/pm (1-12) 	Number 	12
 * */</span>
<span style="color: #003366; font-weight: bold;">function</span> formatDate<span style="color: #009900;">&#40;</span>date<span style="color: #339933;">,</span> format<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dayInMonth <span style="color: #339933;">=</span> date.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullDayInMonth <span style="color: #339933;">=</span> dayInMonth<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullDayInMonth.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullDayInMonth <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullDayInMonth<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> month <span style="color: #339933;">=</span> date.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMonth <span style="color: #339933;">=</span> month<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMonth.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMonth <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullMonth<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullYear <span style="color: #339933;">=</span> date.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> year <span style="color: #339933;">=</span> fullYear.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> hour <span style="color: #339933;">=</span> date.<span style="color: #660066;">getHours</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullHour <span style="color: #339933;">=</span> hour<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullHour.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullHour <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullHour<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> khour <span style="color: #339933;">=</span> hour<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullKhour <span style="color: #339933;">=</span> khour<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullKhour.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullKhour <span style="color: #339933;">=</span> fullKhour<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> minutes <span style="color: #339933;">=</span> date.<span style="color: #660066;">getMinutes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMinutes <span style="color: #339933;">=</span> minutes<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMinutes.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMinutes <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullMinutes<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> seconds <span style="color: #339933;">=</span> date.<span style="color: #660066;">getSeconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullSeconds <span style="color: #339933;">=</span> seconds<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullSeconds.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullSeconds <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>seconds<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> millis <span style="color: #339933;">=</span> date.<span style="color: #660066;">getMilliseconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMillis1 <span style="color: #339933;">=</span> millis<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMillis1.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMillis1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0'</span><span style="color: #339933;">+</span>fullMillis1<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMillis2 <span style="color: #339933;">=</span> fullMillis1<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMillis2.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMillis2 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0'</span><span style="color: #339933;">+</span>fullMillis2<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> format<span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/MM/g</span><span style="color: #339933;">,</span> fullMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/M/g</span><span style="color: #339933;">,</span> month<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/yyyy/g</span><span style="color: #339933;">,</span> fullYear<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/yy/g</span><span style="color: #339933;">,</span> year<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/dd/g</span><span style="color: #339933;">,</span> fullDayInMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/d/g</span><span style="color: #339933;">,</span> dayInMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/HH/g</span><span style="color: #339933;">,</span> fullHour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/H/g</span><span style="color: #339933;">,</span> hour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/kk/g</span><span style="color: #339933;">,</span> fullKhour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/k/g</span><span style="color: #339933;">,</span> khour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/mm/g</span><span style="color: #339933;">,</span> fullMinutes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/m/g</span><span style="color: #339933;">,</span> minutes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ss/g</span><span style="color: #339933;">,</span> fullSeconds<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/s/g</span><span style="color: #339933;">,</span> seconds<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/SSS/g</span><span style="color: #339933;">,</span> fullMillis2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/SS/g</span><span style="color: #339933;">,</span> fullMillis1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/S/g</span><span style="color: #339933;">,</span> millis<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/javascript-dateformatting.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Acegi/Security auto-login</title>
		<link>http://narcanti.keyboardsamurais.de/spring-acegisecurity-auto-login.html</link>
		<comments>http://narcanti.keyboardsamurais.de/spring-acegisecurity-auto-login.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 17:40:18 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=425</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>Usefull and thus noted: In one of my current workprojects I had a registrationform the user filled. After formvalidation, I wanted to login the user automatically. This can be achieved in Spring / Acegi quite easy: User user = createUser&#40;&#41;; final RememberMeAuthenticationToken auth = new RememberMeAuthenticationToken&#40;webKey, userAccount.getUser&#40;&#41;, userAccount.getUser&#40;&#41;.getAuthorities&#40;&#41;&#41;; auth.setAuthenticated&#40;true&#41;; SecurityContextHolder.getContext&#40;&#41;.setAuthentication&#40;auth&#41;; Also logging user out (after [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>Usefull and thus noted:<br />
In one of my current workprojects I had a registrationform the user filled. After formvalidation, I wanted to login the user automatically. This can be achieved in Spring / Acegi quite easy:<br />
<span id="more-425"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">User user <span style="color: #339933;">=</span> createUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> RememberMeAuthenticationToken auth <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RememberMeAuthenticationToken<span style="color: #009900;">&#40;</span>webKey, userAccount.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, userAccount.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAuthorities</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
auth.<span style="color: #006633;">setAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAuthentication</span><span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also logging user out (after database new creattion or session invalidation):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/spring-acegisecurity-auto-login.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
