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

<channel>
	<title>AMIS Technology Blog &#187; Lucas Jellema</title>
	<atom:link href="http://technology.amis.nl/blog/author/lucas/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 10:48:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>On the Integrity of Data</title>
		<link>http://technology.amis.nl/2013/04/24/on-the-integrity-of-data/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=on-the-integrity-of-data</link>
		<comments>http://technology.amis.nl/2013/04/24/on-the-integrity-of-data/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 07:17:56 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SOA & Oracle Fusion Middleware]]></category>
		<category><![CDATA[business rule]]></category>
		<category><![CDATA[constraint]]></category>
		<category><![CDATA[corruption]]></category>
		<category><![CDATA[data integrity]]></category>
		<category><![CDATA[data quality]]></category>
		<category><![CDATA[robustness]]></category>
		<category><![CDATA[transaction]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=23039</guid>
		<description><![CDATA[To be useful, data held and used in information systems has to live up to a number of expectations. The data should be an accurate representation of its source. It should be reliable. The data should have internal consistency. The data should adhere to rules based on the logic of the real world.  [...]]]></description>
				<content:encoded><![CDATA[<p>To be useful, data held and used in information systems has to live up to a number of expectations. The data should be an accurate representation of its source. It should be reliable. The data should have internal consistency. The data should adhere to rules based on the logic of the real world. This accuracy, internal quality, and reliability of data is frequently referred as <i>data integrity</i>.
<p>Safeguarding the integrity of data is a challenge, one that increases in complexity when multiple users access and manipulate the data simultaneously , obviously a common situation. And that challenge reaches new heights when the data is managed in multiple independent data stores rather than a single database.
<p><img alt="Figure 12" src="http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/1929193.png" width="417" height="296">
<p>Earlier this month, the Oracle Technology Network published an article that I recently wrote on this subject: <a title="http://www.oracle.com/technetwork/articles/soa/jellema-data-integrity-1932181.html" href="http://www.oracle.com/technetwork/articles/soa/jellema-data-integrity-1932181.html">http://www.oracle.com/technetwork/articles/soa/jellema-data-integrity-1932181.html</a>. I was triggered into writing it by two recent experiences.
<p>One was at a customer of mine where we are designing a service oriented architecture, based on a number of distinct and independent data domains. These domains are exposed through elementary (entity) services. A second tier of composite (or business) services exposes functionality that may involve multiple data domains. We have had and are still having discussion about how to implement data integrity constraints and how to manage transactions that span across data domains. In order to ensure we all had the same understanding of what exactly the challenges are, I decided to record my understanding of integrity, constraints and transactions.
<p>The second situation was at a different customer. There they stated that data quality and absolute robustness of the enterprise database was essential. And they went on to explain how they had implemented their integrity enforcement using Java based logic. Their implementation was elaborate and impressive &#8211; but not robust. They would enforce attribute and record level constraints just fine, but any constraint involving multiple records was not enforced with the rigor they needed and thought they had achieved. They had forgotten to properly take into account the multi-user/multi-session environment in which their logic would be used (as well as the other entry point into the database that completely by-passed their business logic). Here again I was compelled into writing down what enforcing integrity entails, specifically the need for locking in a multi-session environment.
<p>I hope the article that was triggered by these two cases &#8211; and many cases before that &#8211; will help other organizations and teams as well, in understanding what data integrity and enforcing constraints in a truly robust way entails. Frequently, they will find that the current implementation is not in fact robust. For example many organizations using PL/SQL and Trigger based &#8216;business rule enforcement&#8217; have not implemented a proper locking mechanism and are therefore not as well protected against data corruption as they typically think they are.</p>
<p><span id="more-23039"></span>
<p>The article introduces some of the basics of data integrity enforcement. It then discusses how, in a multi-user environment with a single [Oracle] database, that integrity is realized. The article then extends that discussion to an environment with multiple data stores that jointly present unified data services to consumers &#8211; and that are together responsible for data integrity. Not just for the internal, encapsulated integrity within each store, but also for integrity across those stores.
<p>Find the article at OTN: <a title="http://www.oracle.com/technetwork/articles/soa/jellema-data-integrity-1932181.html" href="http://www.oracle.com/technetwork/articles/soa/jellema-data-integrity-1932181.html">http://www.oracle.com/technetwork/articles/soa/jellema-data-integrity-1932181.html</a>.
<p>Other, related stories that may be worthwhile to take a look at:
<p>How Oracle Database uses internal locks to make statement level constraint validation robust at the transaction level&nbsp; <a title="http://technology.amis.nl/2013/02/28/how-oracle-database-uses-internal-locks-to-make-statement-level-constraint-validation-robust-at-the-transaction-level/" href="http://technology.amis.nl/2013/02/28/how-oracle-database-uses-internal-locks-to-make-statement-level-constraint-validation-robust-at-the-transaction-level/">http://technology.amis.nl/2013/02/28/how-oracle-database-uses-internal-locks-to-make-statement-level-constraint-validation-robust-at-the-transaction-level/</a>
<p>RuleGen 3.0 – the latest, leanest and most robust solution for complex data constraints in an Oracle DatabaseRuleGen 3.0 – the latest, leanest and most robust solution for complex data constraints in an Oracle Database <a title="http://technology.amis.nl/2011/07/06/rulegen-3-0-the-latest-leanest-and-most-robust-solution-for-complex-data-constraints-in-an-oracle-database/" href="http://technology.amis.nl/2011/07/06/rulegen-3-0-the-latest-leanest-and-most-robust-solution-for-complex-data-constraints-in-an-oracle-database/">http://technology.amis.nl/2011/07/06/rulegen-3-0-the-latest-leanest-and-most-robust-solution-for-complex-data-constraints-in-an-oracle-database/</a></p>
<p>The Hunt for the Oracle Database On Commit trigger &#8211; <a title="http://technology.amis.nl/2006/08/07/the-hunt-for-the-oracle-database-on-commit-trigger/" href="http://technology.amis.nl/2006/08/07/the-hunt-for-the-oracle-database-on-commit-trigger/">http://technology.amis.nl/2006/08/07/the-hunt-for-the-oracle-database-on-commit-trigger/</a></p>
<p>The future of CDM RuleFrame – the Oracle framework for server-side business rules &#8211; <a title="http://technology.amis.nl/2004/09/11/the-future-of-cdm-ruleframe-the-oracle-framework-for-server-side-business-rules/" href="http://technology.amis.nl/2004/09/11/the-future-of-cdm-ruleframe-the-oracle-framework-for-server-side-business-rules/">http://technology.amis.nl/2004/09/11/the-future-of-cdm-ruleframe-the-oracle-framework-for-server-side-business-rules/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/04/24/on-the-integrity-of-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADF DVT: Analyzing Financial Position of the European Football (Soccer) Leagues using Treemap</title>
		<link>http://technology.amis.nl/2013/04/07/adf-dvt-analyzing-financial-position-of-the-european-football-soccer-leagues-using-treemap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adf-dvt-analyzing-financial-position-of-the-european-football-soccer-leagues-using-treemap</link>
		<comments>http://technology.amis.nl/2013/04/07/adf-dvt-analyzing-financial-position-of-the-european-football-soccer-leagues-using-treemap/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 20:34:22 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[ADF & JHeadstart]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[adf]]></category>
		<category><![CDATA[adf dvt]]></category>
		<category><![CDATA[analysis]]></category>
		<category><![CDATA[football]]></category>
		<category><![CDATA[sports]]></category>
		<category><![CDATA[treemap]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=22788</guid>
		<description><![CDATA[We all know a lot of money is involved with professional sports. One of Europe&#8217;s major sports is football (or soccer as some like to call it). A lot of money changes in hand in football. And it seems that the results are determined primarily by the money. The major pan-European competition &#8211; the  [...]]]></description>
				<content:encoded><![CDATA[<p>We all know a lot of money is involved with professional sports. One of Europe&#8217;s major sports is football (or soccer as some like to call it). A lot of money changes in hand in football. And it seems that the results are determined primarily by the money. The major pan-European competition &#8211; the UEFA Champion&#8217;s League- is called out of reach for representatives from smaller countries &#8211; because of their lag in terms of yearly budget. And the national leagues are dominated by [clubs that have the] money.</p>
<p>Together with my son Tobias we decided to investigate. How much money is in the budgets for all clubs taken together in each of the major football leagues? And how is that money distributed over the clubs. Is it evenly allocated or are there wild variations? And is money a guarantee for success?</p>
<p>We decided to use the ADF DVT Treemap component to visualize our findings. From left to right, you see four treemaps, representing the football leagues of England, Spain, Germany and The Netherlands. The size of each treemap corresponds with the sum of all club budgets in that league. Inside the treemap, each area represents a club. The size of the area corresponds with the budget of the club. The color is an indication of the current ranking of the club in the league. Yellow (gold), Gray (Silver) and Olive (Bronze) represents the number 1, 2 and 3 position. The Legend explains about all colors.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image38.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb38.png" width="859" height="431" border="0" /></a></p>
<p>The German Bundesliga has a higher budget than the Primera Division &#8211; and both trail behind the Premier League. It is clear how the Dutch is the dwarf in this collection. Its overall (league) budget is less than the club budget for both Barcelona and Real Madrid. It is also clear how the Spanish competition has two main contenders that dwarf the others. Valencia&#8217;s budget &#8211; #3 in Spain &#8211; is smaller than PSV&#8217;s &#8211; #2 in The Netherlands. The budget size seems a good indication for who will come at the top of the list. Only Real Madrid is not at the very top despite having the largest budget in Spain &#8211; although it is the runner up.</p>
<p><span id="more-22788"></span></p>
<h3>Implementation</h3>
<p>The implementation of this treemap is done using a trio simple POJOs: FootballClub, FootballLeague and FootballInvestigator.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image39.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb39.png" width="731" height="258" border="0" /></a></p>
<p>In FootballInvestigator, the data is hard coded:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image40.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb40.png" width="244" height="203" border="0" /></a><br />
Next, this class is published as Data Control, resulting in the following Data Control Palette:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image41.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb41.png" width="208" height="232" border="0" /></a></p>
<p>A new JSF page is created. The the Club collection is dragged to this new page, and dropped as a Treemap:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image42.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb42.png" width="491" height="471" border="0" /></a></p>
<p>The Treemap is subsequently configured like this:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image43.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb43.png" width="631" height="506" border="0" /></a></p>
<p>Then the page source is extended a little, with a PanelGridLayout and stuff:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image44.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb44.png" width="547" height="448" border="0" /></a></p>
<p>Notice the af:iterator that iterates over the leaguesIterator (the master for the clubs) that was created in the PageDef when the treemap binding for the clubs was added. Also worth mentioning: references &#8211; in the inlineStyle attribute for the scaleFactor that is used to manipulate the height -  and in the outputText that renders the name of each competition and ensures that the master iterator moves from league to league in each iteration.</p>
<p>The iteratorBean is configured in request scope and contains the following code:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image45.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb45.png" width="628" height="407" border="0" /></a></p>
<p>&nbsp;</p>
<p>Credits: I would like to thank Tobias Jellema for doing the research and compiling the numbers for this article.</p>
<h2>Resources</h2>
<p>Download JDeveloper 11gR1 PS6 (11.1.1.7) application: <a href="http://technology.amis.nl/wp-content/uploads/2013/04/FootballFinanceTreemap.zip">FootballFinanceTreemap</a> .</p>
<p>The <a href="http://www.deloitte.com/assets/Dcom-UnitedKingdom/Local%20Assets/Documents/Industries/Sports%20Business%20Group/uk-sbg-football-money-league-2013.pdf" target="_blank">Deloitte Football Money Report 2013</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/04/07/adf-dvt-analyzing-financial-position-of-the-european-football-soccer-leagues-using-treemap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ADF DVT &#8211; Scaling TreeMap components for comparisons across masters and categories</title>
		<link>http://technology.amis.nl/2013/04/07/adf-dvt-scaling-treemap-components-for-comparisons-across-masters-and-categories/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adf-dvt-scaling-treemap-components-for-comparisons-across-masters-and-categories</link>
		<comments>http://technology.amis.nl/2013/04/07/adf-dvt-scaling-treemap-components-for-comparisons-across-masters-and-categories/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 09:56:51 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[ADF & JHeadstart]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[adf]]></category>
		<category><![CDATA[adf dvt]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[styling]]></category>
		<category><![CDATA[treemap]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=22748</guid>
		<description><![CDATA[In a recent article (http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/) I discussed the ADF DVT Treemap component. This component visualizes data in such a way that comparisons between data values for different  [...]]]></description>
				<content:encoded><![CDATA[<p>In a recent article (<a title="http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/" href="http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/">http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/</a>) I discussed the ADF DVT Treemap component. This component visualizes data in such a way that comparisons between data values for different records and categories can quickly be made. The size of areas is a measure for some numerical value. As an additional dimension, the color of the areas can be used to identify groups (all members of the group having the same color) or to visualize a second numerical value (color can range for example from dark red to rich green depending on the net revenue per record).</p>
<p>This article describes the situation where we want to use multiple Treemap instances lined up. Each Treemap instance represents a collection of records on one or possibly multiple levels. Each instance can be drilled down into independently. And each instance can represent a different data set, even though we want to compare these data sets. Using a PanelGridLayout, it is easy to position multiple instances in a row or a grid. Using the inline style to scale the width and height of the Treemap instances, we can set the relative size of the treemaps.</p>
<p>The example presented here is based on two ADF BC ViewObjects &#8211; one returning Departments with some department level aggregations and the other returning Employees with their name, job and salary. There is a ViewLink between the two ViewObjects, that makes it easy to access the Employees in a certain Department.</p>
<p>The resulting data visualization is shown here:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image28.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb28.png" width="873" height="247" border="0" /></a></p>
<p>The sizes of the areas depicting individual employees can be compared across the four Treemap instances: King earns most, Scotty, Jones and Blake come next. The sizes of the Treemap instances themselves are scaled according to the salary sum in these departments. Accounting ranks first, Research is the runner up with Operations and Sales closing the rankings. A quick SQL query confirms that this is the correct visualization and interpretation:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image29.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb29.png" width="320" height="306" border="0" /></a></p>
<p><span id="more-22748"></span></p>
<h3>Implementing the multi-treemap</h3>
<p>The implementation of this &#8216;set of treemaps&#8217; is fairly straightforward &#8211; with some small tricks applied.</p>
<p>The Model is the same as used in the earlier article <a title="http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/" href="http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/">http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/</a>. The ViewController project contains a page with Treemap based on the (detail) collection DepartmentDetails1.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image30.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb30.png" width="187" height="163" border="0" /></a></p>
<p>The tree binding:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image31.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb31.png" width="244" height="141" border="0" /></a></p>
<p>The page also has a binding for an iterator based on the DepartmentMasters1 collection:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image32.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb32.png" width="244" height="109" border="0" /></a></p>
<p>The page contains the treemap inside a panelGridCell that is inside a af:iterator that iterates over the rows in the DepartmentMasters1Iterator. For each department, a treemap is rendered:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image33.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb33.png" width="664" height="444" border="0" /></a></p>
<p>The interesting elements in this page are of course the inlineStyle defined on the treemap that specifies the relative height and width. These are both calculated using the scaleFactorCurrentDepartment property on the iteratorBean. This is a request scope bean that is also invoked from the outputText that is rendered underneath the treemap. This outputText indirectly plays to parts: it displays the name of the department &#8211; the value returned from the method getGoNext() on the iteratorBean. And by invoking that method &#8211; that moves the master iterator to the next record &#8211; the outputText as a result ensures that the next batch of details is returned to the treemap&#8217;s DepartmentDetails.treeModel. Note: I am sure there other, perhaps better ways of feeding multiple sets of detail records to the treemap, but this one at least does the job with fairly minimal coding effort.</p>
<p>The IteratorBean is not my finest work either, but again: it does the job I need it for. It calculates the scalingFactor, either for the squarified case (see discussion below) or the slicedAndDiced case, and it moves the master iterator to the next record meanwhile returning the Department&#8217;s name.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image34.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb34.png" width="672" height="477" border="0" /></a></p>
<p>&nbsp;</p>
<p>Note: when the layout of the treemap instances is not slicedAndDiced but squarified, then the scale factor needs to be calculated differently. Right now, both width and height are scaled which means that for squarified areas, the size is reduced by the square of the scalefactor. The result would lead to wrong interpretations as the next figure demonstrates. Without using the correct scalefactor (the square root of the one used for one dimensional layouts) the user may be led to believe that Blake earns less than Clark, which is not the case in reality (3420 vs. 2940).</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image35.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb35.png" width="874" height="313" border="0" /></a></p>
<p>Using the squareroot of the previously used scalefactor, the squarified visualization becomes:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image36.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb36.png" width="875" height="273" border="0" /></a></p>
<p>The underlying data:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image37.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb37.png" width="431" height="337" border="0" /></a></p>
<h2>Resources</h2>
<p>Download the JDeveloper 11gR1 PS6 (11.1.1.7)  application: <a href="http://technology.amis.nl/wp-content/uploads/2013/04/TreeMapDemo.zip">TreeMapDemo</a>.</p>
<p>Discussion thread on the OTN Forums about how to get access to multiple sets of detail records in a single page request &#8211; <a title="https://forums.oracle.com/forums/thread.jspa?messageID=10732526" href="https://forums.oracle.com/forums/thread.jspa?messageID=10732526">https://forums.oracle.com/forums/thread.jspa?messageID=10732526</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/04/07/adf-dvt-scaling-treemap-components-for-comparisons-across-masters-and-categories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADF DVT: Using the Tree Map visualization component &#8211; to compare relative sizes and distributions</title>
		<link>http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions</link>
		<comments>http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 20:15:55 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[ADF & JHeadstart]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[adf]]></category>
		<category><![CDATA[adf dvt]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[dvt]]></category>
		<category><![CDATA[hierarchy]]></category>
		<category><![CDATA[treemap]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=22644</guid>
		<description><![CDATA[The tree map component is one of those data visualization components that can tell an entire story through a simple picture. But of course that picture is anything but simple. And it is not even just a picture: it supports various forms of interaction such as drill down and popup. I had seen the  [...]]]></description>
				<content:encoded><![CDATA[<p>The tree map component is one of those data visualization components that can tell an entire story through a simple picture. But of course that picture is anything but simple. And it is not even just a picture: it supports various forms of interaction such as drill down and popup. I had seen the Tree Map for the first time in demonstrations by Oracle Product Management. It seemed okay, but nothing very spectacular. Now, after having tried out the component for myself as well as studying the documentation, I may have to revise my initial opinion: it is actually a pretty cool and powerful component.</p>
<p>The Tree Map is used to present data values in a way that makes comparison easy, using two dimensions: (relative) size and color. The TreeMap uses containers for nodes with sizes relative to the numerical value associated with the nodes. Each node can have details and the container is presented with enclosed areas for each of the details. The size of these areas is proportional again to the value associated with the child node. All areas can be colored automatically &#8211; to create a pretty picture &#8211; or can be colored according to rules we can specify in order to have the colors also convey some meaning.</p>
<p>The Tree Map supports drilling down as well as other interactions including popups, context menus and more.</p>
<p>In this article, I will demonstrate the simplest, frankly most boring and probably easiest tree map I can create: one that demonstrates the relative salaries in the well known departments in table EMP. A data bound tree map uses one or more ViewObject usages. When multiple usages are bound in the treemap, then these usages need to be nested.</p>
<h3>Model</h3>
<p>The Model project in my example is a plain old ADF BC project that uses a JDBC connection to the SCOTT schema. It contains two read only ViewObjects that have been linked using a ViewLink. The first ViewObject returns the identifier, name and average salary of the departments:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image18.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb18.png" width="331" height="271" border="0" /></a></p>
<p>The second ViewObject just returns names and salaries of the employees along with their deptno:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image19.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb19.png" width="336" height="275" border="0" /></a></p>
<p>The ViewLink that links these ViewObjects is based on the join on deptno.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image20.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb20.png" width="576" height="188" border="0" /></a></p>
<p>The Data Model in the Application Module is defined as follows:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image21.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb21.png" width="577" height="302" border="0" /></a></p>
<p>The Data Control has the same structure of course:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image22.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb22.png" width="200" height="212" border="0" /></a></p>
<h3>ViewController project</h3>
<p>With this Data Control available, it is dead easy to create the Tree Map that will provide all this insight in the relative salaries in our departments.</p>
<p>Create JSF page SalaryComparison.jspx.</p>
<p>Drag the DepartmentMasters1 collection from the Data Control palette to the new page. Drop it as Tree Map:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image23.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb23.png" width="436" height="491" border="0" /></a></p>
<p>The Treemap editor appears, with the collection preselected:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image24.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb24.png" width="786" height="408" border="0" /></a></p>
<p>Select the value: the attribute that determines the relative size of the top level containers in the treemap; this is the average salary in the department. The Label is the header shown for the top level containers; it is set to the name of the department.</p>
<p>Next, select the detail collection DepartmentDetails &#8211; to configure the second level of containers or areas. This level represents the individual employees and their salaries through squares within the department level container. Select the salary as the attribute providing the value to determine the area size and set the label to ename. Then define a grouping rule to specify that the employee level areas should be colored based Ename which amounts to coloring at random.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image25.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb25.png" width="790" height="419" border="0" /></a></p>
<p>Press OK to complete the treemap and run the page.</p>
<p>The treemap appears, and provides us with useful information:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image26.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb26.png" width="590" height="363" border="0" /></a></p>
<p>Department ACCOUNTING has by far the highest average salary. Within that Department,it is clear that KING has the by far highest salary. Department OPERATIONS seems very well balanced: all four salaries seem about equal.</p>
<p>After KING, who seems to have the highest overall salary, BLAKE seems a clear runner-up with CLARK the number three in the ranking. A simple SQL query helps to analyze that finding and correct my misinterpretation of the treemap.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image27.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb27.png" width="431" height="336" border="0" /></a></p>
<p>So be warned: the sizes of the Department level containers are relative to each other, based on the average salary within the department. The sizes of the employee areas should only be compared to sizes of other employee areas within the same container. Scotty and Jones make more than ADAMS and more still than SMITH. Comparing SCOTTY to Martin or Clark is quite hard.</p>
<p>Edit 04-04-2013: If I use the total sum of all salaries in the department as the value driving the size of the master-regions, the tree map comes out like this:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/treemap_corrected.png"><img class="alignnone size-full wp-image-22690" alt="treemap_corrected" src="http://technology.amis.nl/wp-content/uploads/2013/04/treemap_corrected.png" width="638" height="387" /></a></p>
<p>Now we can use the absolute size of the employee areas to compare their salaries.</p>
<p>In this rendition of the treemap, I have used the job of the employee to determine the color of the area. This means that all employee areas with the same color indicate someone in the same job. Clark and Blake for example must be in the same job (i.e. MANAGER).</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/04/02/adf-dvt-using-the-tree-map-visualization-component-to-compare-relative-sizes-and-distributions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADF DVT: Using the Timeline component to visualize the recent history of an RSS feed</title>
		<link>http://technology.amis.nl/2013/04/01/adf-dvt-using-the-timeline-component-to-visualize-the-recent-history-of-an-rss-feed/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adf-dvt-using-the-timeline-component-to-visualize-the-recent-history-of-an-rss-feed</link>
		<comments>http://technology.amis.nl/2013/04/01/adf-dvt-using-the-timeline-component-to-visualize-the-recent-history-of-an-rss-feed/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 07:13:42 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[ADF & JHeadstart]]></category>
		<category><![CDATA[J(2)EE/Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[adf]]></category>
		<category><![CDATA[adf dvt]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[dvt]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[timeline]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=22485</guid>
		<description><![CDATA[One recurring theme in my articles on ADF has been that end users usually do not care about data. They are interested in getting information that helps them answer questions, make decisions and take actions. Data may be the foundation, but information is to be derived from the data. One way  [...]]]></description>
				<content:encoded><![CDATA[<p>One recurring theme in my articles on ADF has been that end users usually do not care about data. They are interested in getting information that helps them answer questions, make decisions and take actions. Data may be the foundation, but information is to be derived from the data. One way therefore to create applications that are more valuable to our end users is by preprocessing data and turning the data into information &#8211; or even into answers, proposed decisions and actions. A powerful way of turning data into information is through data visualization. By presenting data in a format that converts it to readily interpretable information, we help our users a lot. Bar charts, line graphs and other traditional charting formats are one of way visualizing data. The DVT library in ADF Faces goes far beyond traditional charts. It provides components such as the Gantt Chart, the Hierarchy Viewer, the Tree Map, Gauge and the TimeLine that help visualize data in natural, informative and attractive ways. This articles discusses the TimeLine component &#8211; introduced in ADF 11gR1 PS6 (11.1.1.7) in the Spring of 2013.</p>
<p>The TimeLine visualizes events against a time axis. It is as simple as that. This component is used to visualize data that has a meaningful chronological order. The TimeLine component supports scrolling through time as well as zooming in (to finer grained time periods) and out (to longer periods at higher aggregation levels). Events can be marked on the timeline using various types of display items, graphics and highlighting as well as with support for various interactions &#8211; such as click to drill down , drag &amp; drop and popup.</p>
<p>The TimeLine Component is very straightforward to use. It takes as its input a Collection of rows or POJOs of which at least one attribute or property should be a Date value. This property is used to determine the position on the TimeLine of each entry. Other properties can use used to flesh out and decorate the timeline events. One of example of what this TimeLine component allows us to do is this representation of the events in an RSS feed. In this case, the RSS feed is the feed for the AMIS Technology Blog that returns the last 10 articles published on the blog (in the second half of February and March):</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb.png" width="790" height="479" border="0" /></a></p>
<p>This article describes how to use the TimeLine component to visualize the entries in an RSS feed.</p>
<h3>Model</h3>
<p>First we will create a simple model that captures the RSS feed into a POJO layer that we then expose as a Data Control. I have made grateful use of one of the many great articles by Lars Vogel on his blog <a href="http://www.vogella.com">www.vogella.com</a>, in this case the <a href="http://www.vogella.com/articles/RSSFeed/article.html" target="_blank">RSS Feeds with Java Tutorial</a>. In this article Lars Vogel describes how to use StAX (Streaming API for XML) to parse the XML captured from the URL on which the RSS feed is published.</p>
<p>First, a simple Class FeedMessage is created that will represent an entry in the RSS feed. This class is a POJO with properties for the title, author, link and pubDate of the entry. The pubDate is a string representation (e.g. Fri, 29 Mar 2013 23:04:10 +0000) of the time of publication, that needs to be converted to a java.util.Date that is required by the TimeLine component. A SimpleDataFormat with the format string &#8220;EEE, d MMM yyyy HH:mm:ss Z&#8221; is used to parse the pubDate string into the timestamp property in FeedMessage. Each FeedMessage will end up as an entry on the TimeLime</p>
<p>Class Feed is created as the container for all FeedMessages in an RSS channel. An RSS URL may publish a channel with multiple messages. The channel is instantiated as a Feed.</p>
<p>The class RSSFeedParser does the real work. The class is instantiated with the URL of an RSS and a property url is initialized.  Its method readFeed is invoked to produce the Feed object with its enclosed collection of FeedMessages. The method uses an XMLEventReader for the inputStream created for the url for the RSS feed. It processes the RSS XML document, producing startElement and endElement events that are handled in the loop. Whenever an item element is completed, a new FeedMessage object is created and added to the list. It is all quite straightforward.</p>
<p>Class TestFeedReader has a main method and can be used to quickly test the RSSFeedParser for any URL.</p>
<p>Finally class RssFeedProvider is created to act as the middle man of the business service. This class has a single property &#8211; feedURL &#8211; and a method getFeedItems() that returns a List of FeedMessages. This class is published as Data Control.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb1.png" width="192" height="256" border="0" /></a></p>
<p>&nbsp;</p>
<h3>View</h3>
<p>With the Data Control in place, we can turn to the View. The View will consist of a simple JSF page that contains a data bound TimeLine component. This component is bound to the feedItems collection on the RssFeedProvider Data Control. The component is configured to display the title and author of each blog article.</p>
<p>The required steps in the View project are these:</p>
<p>Create a new JSF page, for example called RssFeedTimelineViewer.jspx.</p>
<p>Drag the feedItems collection from the Data Controls palette to this page and drop it as Timeline:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image2.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb2.png" width="509" height="433" border="0" /></a></p>
<p>The editor for configuring the timeline series data appears. It already selected the one Date property (timestamp) in the collection&#8217;s element as the Item Data Value.</p>
<p>The Item Group is used to identify items that can be grouped together: Timeline items that share a common date can be configured to display as a group that can be expanded or collapsed at runtime. By default, a number counter displaying the number of items in a group is provided in the collapsed view. Clicking the counter opens all items in the collapsed view and clicking in the timeline collapses the expanded view. Figure 28-5 shows a timeline item with a counter opened into an expanded view. The Item Group property is set to a property in the timeline item &#8211; am not sure exactly what the meaning is of this selected property.</p>
<p>&nbsp;</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image3.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb3.png" width="626" height="471" border="0" /></a></p>
<p>The Attributes section of this page is used to configure the values that should be displayed in the timeline for each event. Here I have configured four attributes, all using af:outputText. I can easily edit the exact appearance of these values in the page itself.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image4.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb4.png" width="497" height="113" border="0" /></a></p>
<p>In the second page, we can customize the appearance &#8211; relative size, color, shape &#8211; of the markers of the timeline entries. For now I will simply accept the defaults.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image5.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb5.png" width="627" height="469" border="0" /></a></p>
<p>The third page is for configuring the start and end time and date for the timeline as well as both the time-axis for the timeline as well as the scale for the overview (bird&#8217;s eye view) shown underneath the timelime. I have set them as shown in the next figure.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image6.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb6.png" width="633" height="263" border="0" /></a></p>
<p>With these simple, declarative steps we can already run the page and our first timeline displayed:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image7.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb7.png" width="244" height="122" border="0" /></a></p>
<p>The page could do with a little refinements: the end date for example should not only take into account the latest timestamp for any of the events, but it should allow for the length of the most recent items &#8211; therefore stretching a little farther into the future. There is way to much text in the entries right now. Let&#8217;s use the description as the tooltip (shortDesc) for the title and let&#8217;s use the link to actually make the title clickable &#8211; acting as a hyperlink to the real blog entry:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image8.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb8.png" width="526" height="346" border="0" /></a></p>
<p>Rerunning the page &#8211; that is: refreshing the page from the browser, as we did not change a data binding or other initialized only once aspect of the application &#8211; gives us this result:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image9.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb9.png" width="940" height="441" border="0" /></a></p>
<p>Clicking on the title will take me to the AMIS Technology Blog and display the selected article. I wonder, looking at this timeline, why we seem to publish articles in bursts. several close together, then a gap and then another burst.</p>
<p>Zooming in sheds a little more light, showing the actual days of the week of publishing. I thought perhaps there is a link with the weekend or some other pattern. But if there is one, I do not yet detect it:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image10.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb10.png" width="665" height="289" border="0" /></a></p>
<p>It seems though that most articles are published around midnight.</p>
<h3>Adding a Feed Switcher</h3>
<p>This page could be turned into a reusable taskflow that accepts a feed url as an input parameter. Or we can allow the user to select her own RSS feed as input. Then of course we might also want to add date selectors and other filter capabilities.</p>
<p>Let&#8217;s start with the simple ability to specify one&#8217;s own RSS URL.</p>
<p>The RssFeedSelectorBean class is added to the View project. The bean is configured in adfc-config.xml as view scope managed bean:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image11.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb11.png" width="641" height="158" border="0" /></a></p>
<p>This bean has a property rssURL that backs a new inputText item into which the user can enter the URL of an RSS feed:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image12.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb12.png" width="644" height="36" border="0" /></a></p>
<p>Note how autoSubmit is set to true: whenever a new value has been entered, the setRssURL() method on the bean is invoked. This method calls the private method resfreshFeed(). This method gets hold of the current binding container. It finds the attribute binding for the feedURL attribute on the RssFeedProvider Data Control and sets its value to the value from the rssURL property. Then its refreshes the iterator binding feedItemsIterator by invoking its executeQuery() operation, which causes the getFeedItems() on the RssFeedProvider POJO in the Model project to be reinvoked. Note that without this explicit executeQuery() the ADF binding framework would continue to use its cached collection of feed items that it retrieved previously from the RssFeedProvider.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image13.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb13.png" width="657" height="371" border="0" /></a></p>
<p>The final linking pin is the partialTriggers attribute on the timeline component that has been set to be triggered by the inputText. Note that alternatively we could have set the ChangeEventPolicy on the iterator binding to ppr.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image14.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb14.png" width="473" height="68" border="0" /></a></p>
<p>&nbsp;</p>
<p>When we next run the page, we can enter our own RSS Feed URLs and then watch the Timeline component trying to visualize its contents:</p>
<p>Dutch News Site nu.nl:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image15.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb15.png" width="365" height="363" border="0" /></a></p>
<p>OTN Technical Article Feed:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image16.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb16.png" width="363" height="228" border="0" /></a></p>
<p>and BBC Top Stories:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/04/image17.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/04/image_thumb17.png" width="364" height="229" border="0" /></a></p>
<p>&nbsp;</p>
<p>Obviously, I should cater for the different time scales for each of these sites (hours to weeks/months) and the slightly different ways in which they use RSS. But the essence of turning a data stream into a meaningful visualization has been proven as far as I am concerned!</p>
<p>&nbsp;</p>
<h2>Resources</h2>
<p>Download the JDeveloper 11gR1 PS6 (11.1.1.7) application: <a href="http://technology.amis.nl/wp-content/uploads/2013/04/TimelineForRSS.zip">TimelineForRSS.zip</a>.</p>
<p>Parsing RSS Feeds in Java using StAX by Lars Vogel:  <a title="http://www.vogella.com/articles/RSSFeed/article.html#read_stax" href="http://www.vogella.com/articles/RSSFeed/article.html#read_stax">http://www.vogella.com/articles/RSSFeed/article.html#read_stax</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/04/01/adf-dvt-using-the-timeline-component-to-visualize-the-recent-history-of-an-rss-feed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADF: (re-)Introducing Contextual Events in several simple steps</title>
		<link>http://technology.amis.nl/2013/03/14/adf-re-introducing-contextual-events-in-several-simple-steps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adf-re-introducing-contextual-events-in-several-simple-steps</link>
		<comments>http://technology.amis.nl/2013/03/14/adf-re-introducing-contextual-events-in-several-simple-steps/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 22:15:15 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[ADF & JHeadstart]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[adf]]></category>
		<category><![CDATA[contextual events]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[portal]]></category>
		<category><![CDATA[portlet]]></category>
		<category><![CDATA[publish event]]></category>
		<category><![CDATA[publish/subscribe]]></category>
		<category><![CDATA[refresh]]></category>
		<category><![CDATA[taskflow]]></category>
		<category><![CDATA[WebCenter]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=22262</guid>
		<description><![CDATA[Communication between taskflows and pages, beans and other components in ADF Faces applications is in many cases ideally implemented using contextual events. These events are published from a producer component &#8211; a page, taskflow or associated bean &#8211; and made available to all interested parties.  [...]]]></description>
				<content:encoded><![CDATA[<p>Communication between taskflows and pages, beans and other components in ADF Faces applications is in many cases ideally implemented using contextual events. These events are published from a producer component &#8211; a page, taskflow or associated bean &#8211; and made available to all interested parties. Events are handed over by the ADF run time infrastructure to any registered consumer in the current scope. This includes any taskflow or enclosing page which has been configured as such. This publish/subscribe model helps achieve interaction and reuse in a decoupled way. I like the principle. I have applied it on several occasions. And today I needed it again in a WebCenter Portal application with custom ADF 11g components. And once again I could not remember exactly how to implement the contextual events, the publication and subscription. This article therefore is primarily for me &#8211; so I can quickly recall how to do this in similar subsequent situations. However, if it is useful to you too, that is even better!</p>
<p>The use case discussed in this article is as follows:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image11.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb11.png" width="450" height="199" border="0" /></a></p>
<p>The section in the red rectangle is a taskflow that has been embedded as a region in the page. This taskflow has indicated that it is capable of consuming contextual events of type SaveEvent. What exactly it will do with such events is not fully disclosed (this example is taken from a use case where the taskflow has functionality to perform special validation of the values entered in the taskflow&#8217;s form). The enclosing page has a button in it. When that button is pressed by the user, the associated code will publish a Contextual Event of the type SaveEvent. The ADF runtime infrastructure takes this event and invokes the event consumer in the taskflow. Without knowing more about the taskflow than the fact that it listens to SaveEvents, the developer of the page could hook up the button with whatever action the taskflow will perform based on the event.</p>
<p>This article describes the few quick steps required to accomplish this and also provides a simple ADF application to download.</p>
<p><span id="more-22262"></span></p>
<h3>Creating the Taskflow</h3>
<p>The taskflow consists of a single page fragment &#8211; detailsPage.jsff. It shows three values taken from the pageFlowScope bean detailsBean. It also shows the value of the input parameter that is passed into the taskflow.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image12.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb12.png" width="549" height="246" border="0" /></a></p>
<p>The taskflow itself is configured with a single input parameter</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image13.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb13.png" width="617" height="173" border="0" /></a></p>
<p>and a single bean &#8211; detailsBean:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image14.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb14.png" width="615" height="156" border="0" /></a></p>
<p>This bean is extremely simple. Three properties with getters and setters and a single method &#8211; process() &#8211; that could be quite spectacular but is in fact very straightforward:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image15.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb15.png" width="182" height="244" border="0" /></a></p>
<h3>Declaring the taskflow&#8217;s interest in the SaveEvent</h3>
<p>The interest in the SaveEvent in this taskflow &#8211; or more specifically, in the detailsPage.jsff &#8211; is declared in the Page Definition for this fragment.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image16.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb16.png" width="442" height="316" border="0" /></a></p>
<p>The eventMap element contains entries for each event that this fragment is capable of consuming. In this case, only events that have been published as &#8220;SaveEvent&#8221; are subscribed to. It does not matter who is the producer of the event &#8211; hence the region=&#8221;*&#8221; setting. When the SaveEvent has been published, it should be propagated to the handleEvent method binding &#8211; as is specified through the handler attribute on the consumer element.</p>
<p>The handleEvent method binding has been configured in the Page Definition file for the method handleEvent on the Data Control EventHandlerBean.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image17.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb17.png" width="244" height="101" border="0" /></a></p>
<p>This Data Control has been created for a POJO called EventHandlerBean, a simple class with a method handleEvent that sort of processes the event:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image18.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb18.png" width="539" height="205" border="0" /></a></p>
<p>when the event is detected, the ADF Framework will call the handleEvent method on an instance of the EventHandlerBean &#8211; passing the event&#8217;s payload to the payload input parameter of this method. The method gets hold of the pageFlowScope managed bean detailsBean and invokes its process() method &#8211; apparently the appropriate action in this taskflow in response to the SaveEvent.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image19.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb19.png" width="682" height="337" border="0" /></a></p>
<p>&nbsp;</p>
<h3>Publishing the SaveEvent</h3>
<p>The subscription and processing side of the Contextual Events story was described above. The question to be answered next is: how do we publish SaveEvent instances? There are several ways to publish events &#8211; some are entirely declarative. All use bindings in the Page Definition file of a taskflow or page in whose context the event should be published. The cleanest, purely programmaitc approach, is discussed here.</p>
<p>A POJO is created &#8211; a simple class with a simple method that returns an Object that will be the payload for the event.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image20.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb20.png" width="380" height="206" border="0" /></a></p>
<p>This class &#8211; EventPublisherBean &#8211; is exposed as a Data Control, through the same action as was applied to the EventHandlerBean.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image21.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb21.png" width="181" height="135" border="0" /></a></p>
<p>When we want to publish the contextual event SaveEvent, we can create a MethodBinding in the current PageDefinition for the publishEvent method on this Data Control. We can then invoke this method binding from a page component or from custom logic in some managed bean. In this example, the page that contains the taskflow discussed above also contains a button. When this button is pressed, we want the SaveEvent to be published. The button has an actionListener:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image22.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb22.png" width="519" height="199" border="0" /></a></p>
<p>The referenced bean &#8211; parentBean &#8211; is defined in the adfc-config.xml file in this application:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image23.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb23.png" width="244" height="52" border="0" /></a></p>
<p>The class ParentBean is a POJO. It has two properties and the method buttonPressedEvent that is the action listener for the button in the page.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image24.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb24.png" width="521" height="310" border="0" /></a></p>
<p>The buttonPressedEvent method locates the operation binding publishEvent in the current Binding Container. This will turn out to be based on the method binding of the publishEvent method on the EventPublisherBean Data Control that we have seen before. This method returns the payload object that is passed into it. At that point, the ADF framework kicks in to actually publish the SaveEvent. It is triggered to do so by the event element that is configured inside the method action in the PageDefinition file:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image25.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb25.png" width="722" height="489" border="0" /></a></p>
<p>this configuration of events and event inside the method action instruct ADF to publish a contextual event of type SaveEvent whenever the publishEvent method action is invoked. The result of the method action is to be used as the payload for the SaveEvent &#8211; and will therefore be passed to all subscribed event handlers.</p>
<p>The above structure is visualized in the next figure:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image26.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb26.png" width="553" height="325" border="0" /></a></p>
<p>&nbsp;</p>
<p>When the parentPage.jspx is run, the user can press the button and the taskflow is notified of the SaveEvent, allowing it to take appropriate action. All very loosely coupled. Note: if the taskflow would not be interested in the SaveEvent, the button press would still cause it to be published, but to no avail.</p>
<p>&nbsp;</p>
<h2>Resources</h2>
<p>Download the JDeveloper 11gR1 PS5 application with the code discussed in this article: <a href="http://technology.amis.nl/wp-content/uploads/2013/03/taskflowRefreshTest.zip">taskflowRefreshTest.zip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/03/14/adf-re-introducing-contextual-events-in-several-simple-steps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle SQL &#8211; Finding free adjacent seats in an airplane, using Subquery Factoring, Analytical Functions (LISTAGG and LEAD), Outer Join, PIVOT and good old INSTR</title>
		<link>http://technology.amis.nl/2013/03/04/oracle-sql-finding-free-adjacent-seats-in-an-airplane-using-subquery-factoring-analytical-functions-listagg-and-lead-outer-join-pivot-and-good-old-instr/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oracle-sql-finding-free-adjacent-seats-in-an-airplane-using-subquery-factoring-analytical-functions-listagg-and-lead-outer-join-pivot-and-good-old-instr</link>
		<comments>http://technology.amis.nl/2013/03/04/oracle-sql-finding-free-adjacent-seats-in-an-airplane-using-subquery-factoring-analytical-functions-listagg-and-lead-outer-join-pivot-and-good-old-instr/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 09:31:00 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[instr]]></category>
		<category><![CDATA[lead]]></category>
		<category><![CDATA[listagg]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[subquery factoring]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=21930</guid>
		<description><![CDATA[Using Oracle SQL to resolve meaningful and slightly less serious challenges is one of my favorite (semi-)professional pastimes. In the last two weeks, I have been presenting on various topics including Oracle SQL to audiences in six cities all across India as part of the OTN Yathra 2013. These  [...]]]></description>
				<content:encoded><![CDATA[<p>Using Oracle SQL to resolve meaningful and slightly less serious challenges is one of my favorite (semi-)professional pastimes. In the last two weeks, I have been presenting on various topics including Oracle SQL to audiences in six cities all across India as part of the OTN Yathra 2013. These presentations and the interaction with the attendees on the various capabilities of SQL have inspired me in several ways. One of the outcomes is this article &#8211; also inspired by the fairly long journey home and the many flights within India. In this article I will use several powerful options in Oracle SQL to resolve some simple to ask questions. The SQL functions I am using include:</p>
<ul>
<li>Insert with Multiple Subqueries</li>
<li>Insert generating some random data</li>
<li>LISTAGG for aggregating strings</li>
<li>LEAD to produce the result for one row using information from the next</li>
<li>PIVOT to present the data in a matrix format</li>
</ul>
<p>The statements are straightforward (relatively), the data model is simple. You will like it.</p>
<p><span id="more-21930"></span></p>
<p>The case is an airplane. It has 46 rows and 6 seats per row. These seats are recorded in table SEATS:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb.png" width="387" height="103" border="0" /></a></p>
<p>Boarding passes are handed out to passengers who check in. When the boarding pass is created, the seat is allocated. The table BOARDING_PASSES holds… guess what?</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb1.png" width="271" height="80" border="0" /></a></p>
<p>The initial data in the SEATS table is created using a single INSERT statement. Interesting about this statement is the way in which it uses the WITH clause for subquery factoring to prepare the data to be inserted:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb2.png" width="256" height="361" border="0" /></a></p>
<p>The statement contains the subquery positions that returns capitals A through F. Subqwuery rowws produces 46 rows. The corss join between the two subqueries produces the 276 seat records.</p>
<p>Next, in order to later on create meaningful queries for finding free adjacent seats, I will hand out boarding passes for approximately 35% of the seats, in a more or less random fashion, scattered across the plane. This is done with the next insert statement:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb3.png" width="475" height="224" border="0" /></a></p>
<p>This subquery seat_allocations produces 276 records that each have a random value between 1 and 100. The main query filters on records that have a value below 35. These records represent seats that have been taken. Records are created in table BOARDING_PASSES for these records.</p>
<p>To get an overview of which seats are taken and which are free &#8211; a bit like the seat map of the plane often shown when doing an electronic check in &#8211; we can use a PIVOT query to create a matrix that has the 6 positions (A through F) as the columns. For each row the six seats are represented with a 0 (free) or a 1 (taken).</p>
<p>The query that produces this matrix:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb4.png" width="728" height="299" border="0" /></a></p>
<p>Note how the result from the inner most query contains a single record for each seat with an indication of 0 or 1. The PIVOT operator pivots these results and turns six rows into one: all the records with the same roww value are condensed into one with the columns A through F introduced into the result, returning the flag indicator for the corresponding seat.</p>
<p>The result of the PIVOT is shown next:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image31.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image3_thumb.png" width="348" height="355" border="0" /></a></p>
<p>Every row is shown and for each row the 6 seats from left to right (A through F). A value of 1 indicates a taken seat and a 0 indicates a seat that is still free.</p>
<p>Next I want to select a bitmap per row &#8211; the bitmap is a string with six 0 and 1 values, representing the free an taken seats. Similar to the matrix result produced by the pivot, but this time as simple strings. The interesting part about this query is the LISTAGG operator. It can be used as an analytical function as well as an aggregator. The latter is the case here. This operator adds strings together by concatenating them. In this case, we group by roww and for each roww, the bitmap of the seats is produced by concatenating the seat free flag values (0 or 1) for the seats. The (order by position) ensures that the flags are included in the string in the correct order [A..F].</p>
<p>&nbsp;</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb5.png" width="543" height="296" border="0" /></a></p>
<p>The selected bitmaps per row are produced like this:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image6.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb6.png" width="126" height="244" border="0" /></a></p>
<p>We can use these bitmaps to easily find the rows that have adjacent seats available. However, we need to cater for the fact that positions C and D are not really adjacent because there is an aisle in between. The query to find such rows looks like this &#8211; catering for the aisle:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb7.png" width="804" height="380" border="0" /></a></p>
<p>When we query for only those rowws that have two adjacent free seats, here is the result:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image8.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb8.png" width="118" height="244" border="0" /></a></p>
<p>When the seats start filling up, we may not always be able to find adjacent seats. In addition to truly adjacent we have alternatives that are perhaps acceptable as well. For example: seats that are on both sides of the aisle (C and D on the same row). Or seats next to the aisle on two subsequent rows. Each of these could be awarded a certain score. For example:</p>
<ul>
<li>truly adjacent = 10 points</li>
<li>adjacent across the aisle = 8 points</li>
<li>aisle seats in subsequent rows = 4 points</li>
</ul>
<p>Using such a scoring scheme, we can create a query that returns multiple options, even if the ideal option is not available. A query that will award scores to the various rows could be created like this next one:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image9.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb9.png" width="859" height="613" border="0" /></a></p>
<p>The CASE expression calculates the scores, by trying out the various options and picking the first one that actually is the case for a row. It uses LEAD again to find two subsequent rows that have free seats on the same side of the aisle.</p>
<p>The scores for the first few rows:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/03/image10.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/03/image_thumb10.png" width="244" height="93" border="0" /></a></p>
<p>&nbsp;</p>
<h2>Resources</h2>
<p>Download the SQL scripts for this article: <a href="http://technology.amis.nl/wp-content/uploads/2013/03/seats_in_plane.txt">seats_in_plane.txt</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/03/04/oracle-sql-finding-free-adjacent-seats-in-an-airplane-using-subquery-factoring-analytical-functions-listagg-and-lead-outer-join-pivot-and-good-old-instr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Out of the box usage of ADF DVT Scheduling Gantt Chart to report Database Query Results using stacked bar charts per time period</title>
		<link>http://technology.amis.nl/2013/03/01/out-of-the-box-usage-of-adf-dvt-scheduling-gantt-chart-to-report-database-query-results-using-stacked-bar-charts-per-time-period/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=out-of-the-box-usage-of-adf-dvt-scheduling-gantt-chart-to-report-database-query-results-using-stacked-bar-charts-per-time-period</link>
		<comments>http://technology.amis.nl/2013/03/01/out-of-the-box-usage-of-adf-dvt-scheduling-gantt-chart-to-report-database-query-results-using-stacked-bar-charts-per-time-period/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 21:09:00 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[ADF & JHeadstart]]></category>
		<category><![CDATA[adf]]></category>
		<category><![CDATA[adf dvt]]></category>
		<category><![CDATA[analytical function]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[gantt chart]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[schedule gantt]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=21753</guid>
		<description><![CDATA[Gantt Charts in ADF are interesting components to visualize data that is organized according to time. The Gantt Charts have a horizontal time axis. In rows along the vertical axis, resources or tasks are displayed. The cells in this time/resource matrix represent information about the resource or  [...]]]></description>
				<content:encoded><![CDATA[<p>Gantt Charts in ADF are interesting components to visualize data that is organized according to time. The Gantt Charts have a horizontal time axis. In rows along the vertical axis, resources or tasks are displayed. The cells in this time/resource matrix represent information about the resource or the task at some point in time or more specifically: in some time period.</p>
<p>In this <a href="http://technology.amis.nl/2013/02/27/adf-dvt-thinking-out-of-the-box-with-the-scheduling-gantt-chart-reporting-by-period-for-example-football-results-over-the-years/" target="_blank">recent blog-article</a>, I explained how we can use the Schedule Gantt chart to present results per resource per period using something closely resembling horizontal bar charts. The key thought is that when we present data associated with a standard period, we can use the Gantt Chart&#8217;s capability to set the length of the bar to express the size of the value in a specific period. More specifically: we can use the end date property to manipulate the length of the bar. This article we will take this one step further and create a Stacked Bar Chart for each resource for each period. In this case, I will present the number of Employees hired per Department per Year and do so using Stacked Bar Charts with segments per Job. The result &#8211; driven directly from SQL query in a read only ViewObject &#8211; looks like this:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image83.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb83.png" width="865" height="191" border="0" /></a></p>
<p>We can rapidly interpret the data: hiring was most intensive in 1981. Department 20 was both the earliest and the last to hire employees. The red segment represents the Job SALESMAN. It is clear that only department 30 ever hired any salesmen. The yellow job was hired in every department &#8211; as is the dark blue job. These represent CLERK and MANAGER respectively.</p>
<p><span id="more-21753"></span></p>
<h3>Model &#8211; preparing the data for the Gantt Chart</h3>
<p>The data model for the Schedule Gantt consists of a collection of Resources. Using ADF BC, that would be a ViewObject &#8211; in this case returning all records from table DEPT. So the first step after creating the Database Connection is the wizard based creation of Entity Object Department, ViewObject DepartmentsView and ApplicationModule HrmService.</p>
<p>Next, the Schedule Gantt also expects in the data model that each resource contains an accessor to the tasks or more generally to the cells that will be represented as bars. Each element in this collection should specify a start date and end date, a unique identifier and typically a label. Additionally, it can expose a type &#8211; used to categorize and assign colors per category &#8211; and other properties for example to be used in the tooltips shown when hovering over the bars.</p>
<p>The accessor is most easily added using a ViewLink between the ViewObject returning the Resources and the ViewObject returning the Tasks or cells &#8211; and make sure that an accessor method for this ViewLink is exposed in the Resources ViewObject. Note that you do not need the second ViewObject at all in the Application Module&#8217;s Data Model.</p>
<p>I will approach the challenge in two steps. First I will create a Gantt Chart that presents bars with proportionate length for the number of employees hired per year and per department without looking at the jobs. In a second iteration I will add the Jobs and introduce the stacked-ness of the bars.</p>
<p>The SQL query I need to create for this first step should return a record for each cell &#8211; which means for each combination of Department and Year &#8211; that has a value associated with it. I want to have the number of employees hired and I would like to know how long the bar should be. By calculating the ratio between the value in the cell and the maximum value in all the cells, I know which percentage of the total length available &#8211; 365 days &#8211; this cell&#8217;s bar can take up. Finally, I want the query to produce the start date (first day of the year) and the end date (first day of the year plus the 365 days times the percentage) of the bar. With all this information, the Gantt Chart can easily be produced.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image84.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb84.png" width="585" height="295" border="0" /></a></p>
<p>This query first sets up a subquery emp_count_per_d_and_y. It returns the number of employees hired per department and per year. The main query uses this subquery to calculate the start date and end date for each cell. The start date is just the first day of the year. The end date is a little bit harder to derive: it is calculated by determining the ratio between the cell value (emp_count) and the highest cell value and multiplying it with 360 [days] then adding it to the start date. The highest cell value is found using a Scalar Subquery that queries from the emp_count_per_d_and_y subquery.Additionally the query should return the unique identifier of the cell which is the combination of deptno and hireyear.</p>
<p>The result of this query is shown next:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image85.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb85.png" width="643" height="188" border="0" /></a></p>
<p>Based on this query, I create a ViewObject:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image86.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb86.png" width="244" height="107" border="0" /></a></p>
<p>Next I create the ViewLink between the DepartmentsView and the EmpCountView.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image87.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb87.png" width="244" height="136" border="0" /></a></p>
<p>The Data Control at this point is exposed to the ADF Faces developer:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image88.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb88.png" width="184" height="161" border="0" /></a></p>
<h3>View &#8211; take the data and visualize it</h3>
<p>Implementing the Gantt Chart that will display the data in a pretty Gantt Chart has become simple now. Create a new JSF page. Drag the DepartmentsView1 collection to the page and drop it as Gantt | Schedule. Then configure the Gantt Chart:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image89.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb89.png" width="431" height="397" border="0" /></a></p>
<p>The label in the Appearance tab is set to EmpCount.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image90.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb90.png" width="430" height="206" border="0" /></a></p>
<p>Some configuration on the dvt:scheduleGantt component in the jspx file</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image91.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb91.png" width="532" height="180" border="0" /></a></p>
<p>Set the startTime and endTime. Set the labelPlacement. Set the major timeAxis scale to years and the minor timeAxis scale to quarters. Set rendered to false for the second timeAxis as we do not need it.</p>
<p>Now we can run our page. We get the overview of the number of employees hired per department per year. The length of the bar is proportional to the number of employees hired. The bars in 1981 for departments ACCOUNTING and RESEARCH should be about a third of the long bar in (SALES,1981). And so on.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image92.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb92.png" width="998" height="158" border="0" /></a></p>
<p>&nbsp;</p>
<h3>Model &#8211; preparing the data for the Gantt Chart with Stacked Bars</h3>
<p>Now we are ready for the second iteration. The query should be extended to count the number of hirees not just per year and department (the cell) but also per job (the segment within the stacked bar). And then we need to calculate the length of each bar relative to the maximum number of employees (over all jobs) in a single year in a single department. The real complexity comes when we calculate the start date and the end date. Because we want to stack the count per job, the start date is not going to be the first day of the year for all bars: it is the end date of the previous job&#8217;s bar except for the first job. And the end date is now not relative to the first day of the year, but to the end date of the previous job.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image93.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb93.png" width="727" height="540" border="0" /></a></p>
<p>&nbsp;</p>
<p>This query starts with the subquery emp_count_per_d_and_y that we saw before. It returns the number of employees hired per department and per year. I have introduced a second subquery called emp_count_and_percentage that calculates the cell_identifier, cell_label and the emp_count_percentage for the Job in the Department in the Year. This percentage is calculated as the ratio between the count for the job, department and year combination and the maximum value for the sum of all emp_counts in a single deptno and hireyear combination (the largest number of employees hired in any department in any year).</p>
<p>The main query uses this subquery emp_count_and_percentage to calculate the start date and end date for each cell. The start date now is the first day of the year plus 360 [days] times the sum of the percentages of the preceding jobs in this cell &#8211; for the current Department and Year. Note: the coalesce (similar to NVL) is used to cater for the first Job dealt with in a cell for which the sum of preceding job percentages is undefined.</p>
<p>The end date is derived in almost the same way as the start day: it will sum all percentages of the preceding rows including the current one and multiply with 360 [days] then adding it to the start date.</p>
<p>The result of this query is shown next:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image94.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb94.png" width="722" height="225" border="0" /></a></p>
<p>Based on this query, I create a ViewObject:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image95.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb95.png" width="244" height="108" border="0" /></a></p>
<p>Next I create the ViewLink between the DepartmentsView and the EmpPerJobYearCountView.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image96.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb96.png" width="244" height="129" border="0" /></a></p>
<p>The Data Control exposed to the ADF Faces developer is not changed:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image97.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb97.png" width="184" height="161" border="0" /></a></p>
<h3>View &#8211; take the data and visualize the Stacked Bars</h3>
<p>Implementing the Gantt Chart that will display the data in a pretty Gantt Chart is again quite simple now. Create a new JSF page. Drag the DepartmentsView1 collection to the page and drop it as Gantt | Schedule. Then configure the Gantt Chart:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image98.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb98.png" width="476" height="439" border="0" /></a></p>
<p>The Label for the bars is set using the CellLabel attribute:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image99.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb99.png" width="474" height="251" border="0" /></a></p>
<p>Configure the dvt:scheduleGantt in the jspx page. Just like before set the labelPlacement, startDate and endDate. Then also set the binding attribute, the tooltipKeys and tooltipKeyLabels attributes as shown in the next figure. The bean these attributes refer to is created a little bit further on.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image100.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb100.png" width="607" height="228" border="0" /></a></p>
<p>Create a class GanttChartColorManager. This class will set up the custom formats for the various jobs. It will also provide the tooltipKeys and tooltipKeyLabels that were already used in the dvt:scheduleGantt.</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image101.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb101.png" width="244" height="227" border="0" /></a></p>
<p>Configure the managed bean</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image102.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb102.png" width="244" height="51" border="0" /></a></p>
<p>&nbsp;</p>
<p>Run the page:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image103.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb103.png" width="841" height="185" border="0" /></a></p>
<p>Just to show off a little I will insert two records into table EMP then update the page to see the effect on the Gantt Chart:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image104.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb104.png" width="396" height="274" border="0" /></a></p>
<p>Refresh the page. It will show new bars in (ACCOUNTING,1982) and (RESEARCH,1980):</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image105.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb105.png" width="836" height="177" border="0" /></a></p>
<p>and perhaps do a little Update:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image106.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb106.png" width="289" height="154" border="0" /></a></p>
<p>resulting in:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image107.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb107.png" width="841" height="178" border="0" /></a></p>
<p>&nbsp;</p>
<h2>Resources</h2>
<p>Download the JDeveloper 11gR1 PS5 (11.1.1.6) Application with the code for the example introduced in this article: <a href="http://technology.amis.nl/wp-content/uploads/2013/03/GanttSchedulerHorizontalBars.zip">GanttSchedulerHorizontalBars.zip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/03/01/out-of-the-box-usage-of-adf-dvt-scheduling-gantt-chart-to-report-database-query-results-using-stacked-bar-charts-per-time-period/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle SQL &#8211; spotting combinations that occur and those that do not &#8211; demonstrating Analytical Functions, Outer Join and SubQuery Factoring</title>
		<link>http://technology.amis.nl/2013/02/28/oracle-sql-spotting-combinations-that-occur-and-those-that-do-not-demonstrating-analytical-functions-outer-join-and-subquery-factoring/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oracle-sql-spotting-combinations-that-occur-and-those-that-do-not-demonstrating-analytical-functions-outer-join-and-subquery-factoring</link>
		<comments>http://technology.amis.nl/2013/02/28/oracle-sql-spotting-combinations-that-occur-and-those-that-do-not-demonstrating-analytical-functions-outer-join-and-subquery-factoring/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 15:41:00 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[analytical function]]></category>
		<category><![CDATA[anti join]]></category>
		<category><![CDATA[lead]]></category>
		<category><![CDATA[outer join]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[subquery factoring]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=21790</guid>
		<description><![CDATA[The challenge in this article is a simple one. I have a table with records (duh!) and each record describes the occurrence of a certain payload. In this example the payload will be a color. Every record also has a sequence number to indicate well, when it appeared relative to the other  [...]]]></description>
				<content:encoded><![CDATA[<p>The challenge in this article is a simple one. I have a table with records (duh!) and each record describes the occurrence of a certain payload. In this example the payload will be a color. Every record also has a sequence number to indicate well, when it appeared relative to the other observations. A subset of the data would look like this:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image124.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb124.png" width="134" height="180" border="0" /></a></p>
<p>The challenges I will discuss in this article are simple:</p>
<ul>
<li>which sequences of three color observations occur in the data set</li>
<li>how often do these sequences of three occur (give me the top 3 sequences)</li>
<li>given the colors that have been observed, which combinations of three can be created</li>
<li>which possible combinations (or color sequences of three colors) have not been observed at all</li>
</ul>
<p>Using Oracle SQL features such as Analytical Functions, Outer Join and Subquery Factoring &#8211; these questions become very easy to answer.</p>
<p><span id="more-21790"></span></p>
<p>First, let&#8217;s look at the sequences of three colors that have been observed and recorded. In order to construct the sequences, we need to combine each record with the subsequent two records. And creating a row result using other rows in the result set is almost the definition of Analytical Functions. So that is what we will use. In fact, I will use the LEAD function to take for each record the next two records into account for deriving the sequence. Note that records that do not have at least two subsequent records will not produce useful sequence results so they will be excluded. The query becomes:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image125.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb125.png" width="438" height="165" border="0" /></a></p>
<p>The results start with:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image126.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb126.png" width="137" height="114" border="0" /></a></p>
<p>The next challenge is to find out how often each color_sequence occurs. We get the query for addressing this challenge easily by adding the count(seq) and the group by color_sequence:</p>
<p>&nbsp;</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image127.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb127.png" width="484" height="268" border="0" /></a></p>
<p>The results start with:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image118.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb118.png" width="244" height="120" border="0" /></a></p>
<p>To only get the top 3 we can use &#8211; until 12c is upon us &#8211; the inline view construction:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image128.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb128.png" width="473" height="305" border="0" /></a></p>
<p>All the possible combinations of three colors using the different colors that have been observed is an easy enough challenge using the cross join (to get the cartesian product):</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image129.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb129.png" width="339" height="170" border="0" /></a></p>
<p>This results in 125 records (apparently we have five different colors in our data); the first few are:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image130.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb130.png" width="380" height="145" border="0" /></a></p>
<p>&nbsp;</p>
<p>The final challenge is little bit harder. Here are looking for all the color combinations that could have been &#8211; as is demonstrated by the previous query producing 125 records &#8211; but were never actually witnessed. So any color combination that is possible but that was never recorded should be produced by this query. It is a query to look for the things that do not exist in our data. And that call for the anti-join pattern. It goes like this:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image131.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb131.png" width="505" height="447" border="0" /></a></p>
<p>The query reuses query from the previous step that produces all possible combinations. Next, the subquery sequences is the one used at the beginning of this article. Only when we look at the main query see we something new. The possible color combinations are left outer joined with the color sequences that were recorded. The left outer join means that we will at least keep all color combinations and try to join them with the recorded sequences whenever possible. Any combination that did not actually occur &#8211; or at least was not recorded &#8211; will not be joined with a real sequence record but will instead be outer joined. Well, these combinations are the ones we are looking for: the color combinations that could not be joined for real because they have not been recorded for real. All we need to do to complete the solution is filter away all the color combinations that were joined, leaving the ones that were outer joined.</p>
<p>Some of the 106 results produced:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image123.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb123.png" width="244" height="148" border="0" /></a></p>
<p>&nbsp;</p>
<h2>Resources</h2>
<p>Download the SQL scripts that go with this article: <a href="http://technology.amis.nl/wp-content/uploads/2013/02/color_sequence_investigation.txt">color_sequence_investigation.txt</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/02/28/oracle-sql-spotting-combinations-that-occur-and-those-that-do-not-demonstrating-analytical-functions-outer-join-and-subquery-factoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle SQL: Using subquery factoring in an INSERT statement</title>
		<link>http://technology.amis.nl/2013/02/28/oracle-sql-using-subquery-factoring-in-an-insert-statement/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oracle-sql-using-subquery-factoring-in-an-insert-statement</link>
		<comments>http://technology.amis.nl/2013/02/28/oracle-sql-using-subquery-factoring-in-an-insert-statement/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 14:42:53 +0000</pubDate>
		<dc:creator>Lucas Jellema</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Devel. + PL/SQL tools]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[subquery factoring]]></category>

		<guid isPermaLink="false">http://technology.amis.nl/?p=21818</guid>
		<description><![CDATA[I use subquery factoring a lot, to make my SQL queries easier to write. This basically means that most of my queries these days start with WITH rather than SELECT. (this feature was introduced in the 9i release of the Oracle Database).
Today I was wondering whether I can also use subquery factoring  [...]]]></description>
				<content:encoded><![CDATA[<p>I use subquery factoring a lot, to make my SQL queries easier to write. This basically means that most of my queries these days start with WITH rather than SELECT. (this feature was introduced in the 9i release of the Oracle Database).</p>
<p>Today I was wondering whether I can also use subquery factoring in INSERT statements. You probably are familiar with INSERT statements that go like:</p>
<blockquote><p>INSERT INTO &lt;tablename&gt;</p>
<p>(column1, columns2,….)</p>
<p>SELECT value1,value2,…</p>
<p>FROM … [rest of the query]</p>
</blockquote>
<p>Such statements allow us to quickly and in a focused way load a table with records read from other tables (or PL/SQL Table Functions).</p>
<p>The question I had was: can I use WITH &lt;subquery&gt; as &lt;alias&gt;[, &lt;subquery&gt; as &lt;alias&gt;] SELECT value1,value2 from subquery,…. [rest of the query] inside an INSERT statement.</p>
<p>Best way to find it out &#8211; try and do it. </p>
<p><span id="more-21818"></span>
<p>I have create a simple table (required for some other demo scenario) with seats in airplane:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image132.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb132.png" width="345" height="89"></a></p>
<p>I would like to create rows for this table. Let&#8217;s assume a plane with 46 rows and 6 seats in each row. Would it be possible to create these SEAT records using this statement:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image133.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb133.png" width="238" height="325"></a></p>
<p>Copy and paste the statement into SQL*Plus and execute. Low and behold:</p>
<p><a href="http://technology.amis.nl/wp-content/uploads/2013/02/image134.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://technology.amis.nl/wp-content/uploads/2013/02/image_thumb134.png" width="209" height="41"></a></p>
<p>The conclusion can be: WITH and subquery factoring can in fact be used in INSERT statement, allowing even greater control over which rows will be generated and/or selected to be inserted.</p>
]]></content:encoded>
			<wfw:commentRss>http://technology.amis.nl/2013/02/28/oracle-sql-using-subquery-factoring-in-an-insert-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
