<?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>Ardekantur &#187; Experiments</title>
	<atom:link href="http://blog.ardekantur.com/category/experiments/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ardekantur.com</link>
	<description>Computer Science, Ruby, and Software Engineering.</description>
	<lastBuildDate>Wed, 15 Apr 2009 20:14:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>From Code to Design Document: A Play in Four Acts</title>
		<link>http://blog.ardekantur.com/2009/04/from-code-to-design-document-a-play-in-four-acts/</link>
		<comments>http://blog.ardekantur.com/2009/04/from-code-to-design-document-a-play-in-four-acts/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 20:09:49 +0000</pubDate>
		<dc:creator>Ardekantur</dc:creator>
				<category><![CDATA[Code Projects]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Projects I Support]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[amorfus]]></category>
		<category><![CDATA[asciidoc]]></category>
		<category><![CDATA[autodia]]></category>
		<category><![CDATA[dia]]></category>
		<category><![CDATA[nokogiri]]></category>
		<category><![CDATA[uml]]></category>

		<guid isPermaLink="false">http://blog.ardekantur.com/?p=219</guid>
		<description><![CDATA[Act One: The Code and The Motivation

Here&#8217;s the first player, our code.

    % ls Repository/trunk/clementine/interfaces/gesture
    CLGestureCue.cxx           CLGestureCueAppearance.h   CLGestureListener.cxx      CLGestureParser.h
    CLGestureCue.h          [...]]]></description>
			<content:encoded><![CDATA[<h2>Act One: The Code and The Motivation</h2>

<p>Here&#8217;s the first player, our code.</p>

<pre><code>    % ls Repository/trunk/clementine/interfaces/gesture
    CLGestureCue.cxx           CLGestureCueAppearance.h   CLGestureListener.cxx      CLGestureParser.h
    CLGestureCue.h             CLGestureInterface.cxx     CLGestureListener.h        CLGestureTrainer.cxx
    CLGestureCueAppearance.cxx CLGestureInterface.h       CLGestureParser.cxx        CLGestureTrainer.h

    % cat CLGestureListener.h
    #ifndef __CLEMENTINE_INTERFACES_GESTURE_CLGESTURELISTENER_H__
    #define __CLEMENTINE_INTERFACES_GESTURE_CLGESTURELISTENER_H__

    #include "CLGestureParser.h"
    #include &lt;string&gt;

    /**
     * CLGestureListener is responsible for listening on the CLGestureInterface
     * for a single gesture type.
     */
    class CLGestureListener
    {
            public:
                    /**
                     * Instantiate the listener.
                     * @param gestureName the name of the gesture
                     * (and consequently, the filename to parse) that this object is created to listen for.
                     */
                    CLGestureListener(std::string gestureName);
    ... etc
</code></pre>

<p>It&#8217;s a whole bunch of header and implementation files for a C++ project I&#8217;m involved with. This project requires the use of thorough documentation, but our design documents are hundreds of revisions behind our code. While it&#8217;s important to have gone through initial designs, our code at this point is miles removed from those designs. It would be nice to be able to automagically update our design document to be kept current on what is occurring in the code. <strong>This will not make up our entire design document</strong>. It is meant to be used in conjunction with manual, hand-written and hand-proofed analysis of the larger architecture.</p>

<p>The second player is <a href="http://www.methods.co.nz/asciidoc/">AsciiDoc</a>, a wonderful formatting and markup system. You may know it from the <a href="http://www.kernel.org/pub/software/scm/git/docs/user-manual.html">Git User&#8217;s Manual</a>. AsciiDoc affords us several advantages.</p>

<ul>
<li>It is in plain text, which means it can sit in source control, right alongside our code, and diffs are easily viewable.</li>
<li>It is a templating language, which allows output into HTML, PDF, you name it. With enough hacking, you can produce really distinct output for webpages and PDF readers.</li>
<li>It allows division of sections into different files, so authors can focus on the sections that concern them without being overwhelmed by the text they&#8217;re editing.</li>
</ul>

<h2>Act Two: The Tools</h2>

<p>We want the comments in our code to be part of the documentation, but that&#8217;s not all. Since UML is the standard when it comes to software engineering description, it would be nice to have UML diagrams in our output as well. The ubiquitous free diagramming tool <a href="http://live.gnome.org/Dia">Dia</a> provides, with its invocation, command line arguments to convert Dia diagrams into images. It goes like this, where you wish the output to be <code>image_name.png</code>:</p>

<pre><code>    dia -t png -e image_name.png diagram_name.dia
</code></pre>

<p>So this part will be simple. Generating the Dia diagrams from code is already taken care of for us. Aaron Trevena has written an excellent script called <a href="http://www.aarontrevena.co.uk/opensource/autodia/">AutoDia</a> which provides this functionality. All we need to do is put these pieces together, along with writing the functionality to extract the comments we want to become documentation.</p>

<h2>Act Three: The Program</h2>

<p>I am calling it <a href="http://gist.github.com/95979">Amorfus</a>, because I think client-side applications should start getting into the Web 2.0 naming crazes.</p>

<p>How do you use it?</p>

<ol>
<li>Create a new <code>CommentDocParser</code>, with these parameters: a string pointing to the subdirectory of your trunk that you wish to document, a string containing the conceptual name of the code in that directory, and a string containing your trunk directory. You can leave this last one out, and it will default to <code>'.'</code>.</li>
<li>Run <code>#parse</code> on that parser.</li>
<li>Create a file handle, and output the return value of <code>#to_asciidoc</code> to that file.</li>
<li>That&#8217;s it!</li>
</ol>

<p>Here&#8217;s an example:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">	<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'amorfus'</span>
	DIRECTORY_HEADER_LEVEL = <span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;"># This will become the section depth, in AsciiDoc, for each individual class we find</span>
	r = CommentDocParser.<span style="color:#9900CC;">new</span> <span style="color:#996600;">'interfaces/gesture'</span>, <span style="color:#996600;">'Gesture Interface'</span>, <span style="color:#996600;">'Repository/trunk'</span>
	r.<span style="color:#9900CC;">parse</span>
	t = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'output.txt'</span>, <span style="color:#996600;">'w'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	t.<span style="color:#9900CC;">write</span> r.<span style="color:#9900CC;">to_asciidoc</span>
	t.<span style="color:#9900CC;">close</span></pre></div></div>


<p>What does it do in the background?</p>

<ol>
<li>It uses a dumb regex based heurestic to determine if a comment has value.</li>
<li>It classifies methods by what it can find of their name.</li>
<li>It generates Dia diagrams whenever it can find an object.</li>
<li>When generating images, it parses Dia diagrams using Nokogiri and removes irrelevant objects from that diagram,
so that only the featured object shows up in the image.</li>
</ol>

<p>Finally, we&#8217;ll need to make a small patch to AutoDia to make it recognize structs as equally valid objects. This is extremely hackish (see the Epilogue), but it manages to work for now.</p>


<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">--- Autodia-<span style="">2.03</span>/lib/Autodia/Handler/Cpp.pm     <span style="">2009</span>-04-<span style="">15</span> 01:<span style="">10</span>:<span style="">46.000000000</span> -0400
<span style="color: #888822;">+++ Autodia-2.03.orig/lib/Autodia/Handler/Cpp.pm        <span style="">2005</span>-04-<span style="">15</span> 08:02:<span style="">49.000000000</span> -0400</span>
<span style="color: #440088;">@@ -<span style="">72</span>,<span style="">7</span> +<span style="">72</span>,<span style="">7</span> @@</span>
          $i++;
&nbsp;
          # check for class declaration
<span style="color: #991111;">-         if <span style="">&#40;</span>$line =~ m/^\s*<span style="">&#40;</span>?:class|struct<span style="">&#41;</span>\s+<span style="">&#40;</span>\w+<span style="">&#41;</span>/<span style="">&#41;</span></span>
<span style="color: #00b000;">+         if <span style="">&#40;</span>$line =~ m/^\s*class\s+<span style="">&#40;</span>\w+<span style="">&#41;</span>/<span style="">&#41;</span></span>
            <span style="">&#123;</span>
&nbsp;
 #            print &quot;found class : $line \n&quot;;</pre></div></div>


<h2>Act Four: The Results</h2>

<p>The resultant HTML looks like this:</p>

<p><img src="http://blog.ardekantur.com/wp-content/uploads/2009/04/amorfusexamplehtml.png" alt="Example of Amorfus-generated documentation" /></p>

<p>From our previous example, this can be generated on the command line like so:</p>

<pre><code>    % asciidoc --unsafe -e data-uri output.txt
</code></pre>

<p>The <code>--unsafe</code> and <code>-e data-uri</code> allows AsciiDoc to embed the images you&#8217;ve created directly into the HTML, instead of referencing them externally. This makes the document self-contained, in a sense. You can ignore these flags if you wish. In that case, standard <code>&lt;img&gt;</code> tags will be generated.</p>

<h2>Epilogue: Warnings</h2>

<p>This functionality was hacked together in about two hours. It does horrible things to Dia&#8217;s XML documents, it guesses at what the current spec for AsciiDoc is, and requires a hastily applied patch to a third party tool, AutoDia, in order to accomplish its goals. Because of it&#8217;s nature, I can&#8217;t make any guarantees as to how effectively it will work, what circumstances it will work under, and the like. If you have any suggestions or improvements, I implore you to fork the code (currently hosted at <a href="http://gist.github.com/95979">this Gist</a>) and see what you can come up with. For example:</p>

<ul>
<li>I don&#8217;t even think it recognizes variables correctly. You might want to fix this. </li>
<li>It ignores <code>public:</code>, <code>private:</code>, and <code>protected:</code>. You might want to fix this, but it is meant for design documents, so all methods should be documented.</li>
<li>If a class has more than one constructor, only one will be displayed in the documentation. You might want to fix this.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.ardekantur.com/2009/04/from-code-to-design-document-a-play-in-four-acts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My Adventures with Entity Framework and Oracle</title>
		<link>http://blog.ardekantur.com/2008/08/my-adventures-with-entity-framework-and-oracle/</link>
		<comments>http://blog.ardekantur.com/2008/08/my-adventures-with-entity-framework-and-oracle/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 17:07:59 +0000</pubDate>
		<dc:creator>Ardekantur</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[Configuration Files]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[eforacleprovider]]></category>
		<category><![CDATA[entity framework]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://blog.ardekantur.com/?p=110</guid>
		<description><![CDATA[I struggle to understand the Entity Framework, and struggle even more to force it to make sense with Oracle.]]></description>
			<content:encoded><![CDATA[<h3>Brief Overview</h3>

<p>Okay, so here we go. This is going to be a bit of a rambling adventure, because that&#8217;s the only way it can follow what I actually managed to accomplish.</p>

<p>I&#8217;ve been obsessed with learning <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx">LINQ to SQL</a> since I first heard of it, but never really had the time. Besides time constraints, I was also put off by the fact that there seemed to be nothing coming <a href="http://oakleafblog.blogspot.com/2007/04/future-linq-to-sql-support-for-multiple.html">from the Oracle camp</a> regarding the exciting new technology I saw unfolding. After a while I began hearing whispers of the <a href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx">Entity Framework</a>, a complete object-relational mapping solution coming from the Microsoft camp, and was immediately interested. I had never really taken a look at the other available ORM solutions for .NET, NHibernate and the like, simply because I thought there would be a slim chance I would be able to use both Oracle and LINQ with them without too much trouble. As it stands, I had exactly that trouble with Entity Framework, but it feels justified in a weird way. I&#8217;m sure after this I&#8217;ll try taking a look around for other available solutions, but so far this looks extremely promising, if a little unpolished.</p>

<p>This all starts off with <a href="http://code.msdn.microsoft.com/EFOracleProvider">EFOracleProvider</a>, an Entity Framework-friendly provider used to generate the necessary classes and mapping files for database access. Compiling <code>EFOracleProvider</code> gave me a DLL and some configuration settings I could toss at the already existing data model generator, <a href="http://msdn.microsoft.com/en-us/library/bb387165.aspx">EdmGen.exe</a>, to generate the classes that map to the database tables and fields I specified.</p>

<p>I&#8217;m going to show you the files I worked with in all of this, but I&#8217;m not going to obfuscate them, or simplify them. I&#8217;m going to give you an idea of the exact situation I was in, in order to show you the problems I encountered, and how easy it is to encounter them. I&#8217;d also like to remind you that use of <code>EFOracleProvider</code> is not recommended in production environments, as it is extremely rough quality code. This was more of an adventure than a focused goal, but it raises a lot of questions.</p>

<h3>Observing the Database</h3>

<p>My first step, after compiling <code>EFOracleProvider</code>, was to create a storage model for the part of the database I wanted to present to .NET. I decided to go straight to our live database and take my queues from it. I took a small cross-section of our available schema &#8212; just a single table, with two columns, both <code>VARCHAR2</code>s.</p>

<pre><code>    +--------------------------+
    | tblAsset                 |
    +--------------------------+
    | Asset_Number             |
    | Asset_Type               |
    +--------------------------+
</code></pre>

<p>Yes, <code>Asset_Number</code> is a string. It refers to alphanumeric serial numbers. But it&#8217;s also our primary key, so it&#8217;ll make do. In any event.</p>

<p>The storage model file is XML, and fairly easy to create, but has a lot of hidden gotchas that we&#8217;ll cover.</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>    
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Schema</span> <span style="color: #000066;">Namespace</span>=<span style="color: #ff0000;">&quot;TestAppEFModel.Administration&quot;</span> <span style="color: #000066;">Alias</span>=<span style="color: #ff0000;">&quot;Self&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/ado/2006/04/edm/ssdl&quot;</span> <span style="color: #000066;">Provider</span>=<span style="color: #ff0000;">&quot;EFOracleProvider&quot;</span> <span style="color: #000066;">ProviderManifestToken</span>=<span style="color: #ff0000;">&quot;10g&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EntityContainer</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;dbo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EntitySet</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Assets&quot;</span> <span style="color: #000066;">EntityType</span>=<span style="color: #ff0000;">&quot;TestAppEFModel.Administration.Assets&quot;</span> <span style="color: #000066;">Table</span>=<span style="color: #ff0000;">&quot;tblAsset&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EntityContainer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	  
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EntityType</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Assets&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyRef</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Asset_Number&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Property</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Asset_Number&quot;</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;varchar2&quot;</span> <span style="color: #000066;">Nullable</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">StoreGeneratedPattern</span>=<span style="color: #ff0000;">&quot;Identity&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Property</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Asset_Type&quot;</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;varchar2&quot;</span> <span style="color: #000066;">MaxLength</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EntityType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Schema<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<p>Fairly straightforward. We&#8217;re reminded in the <code>EFOracleProvider</code> documentation to set the <code>ProvierManifestToken</code> to the relevant version number of our database. You&#8217;ll note that your namespace seems to require a secondary class. You cannot place your entities in <code>TestAppEFModel</code>, you need to create something like <code>TestAppEFModel.Administration</code>. Also note that I&#8217;ve manually specified the table name in the <code>EntitySet</code> tag, since it does not map cleanly to what .NET expects.</p>

<p>Fire up <code>EdmGen.exe</code>:
<pre>
    C:\OracleEFTests>edmgen.exe /mode:FromSSDLGeneration \
        /c:"Data Source=TNSNAME;User ID=user_id;Password=password..." \
        /project:TestApp /prov:EFOracleProvider \
        /inssdl:TestAppEFModel.Oracle.ssdl /project:TestAppEFModel
    Microsoft (R) EdmGen version 3.5.0.0
    Copyright (C) Microsoft Corporation 2007. All rights reserved.</pre></p>

<pre><code>Creating conceptual layer from storage layer...
Writing msl file...
Writing csdl file...
Writing object layer file...
Writing views file...

Generation Complete -- 0 errors, 0 warnings
</code></pre>

<p></p>

<h3>Preparing the Application</h3>

<p>There are two basic steps to preparing your application: Providing a DLL of the object model, and configuring your application for use with <code>EFOracleProvider</code> and your database. Providing the DLL is easy enough &#8212; take the two <code>.cs</code> files created by <code>EdmGen.exe</code> and throw them into a project, and reference that project in your app.</p>

<p>I had initially put all of the test and generation files in one root directory on my disk, just to keep track of them. This turned out to be a good idea for a secondary reason. In your application configuration, you must provide access to the metadata files you&#8217;ve just created. The example code in the <code>EFOracleProvider</code> project used the following syntax in its <code>App.config</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NorthwindEntities&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">connectionString</span>=<span style="color: #ff0000;">&quot;provider=EFOracleProvider;metadata=res://NorthwindEFModel/NorthwindEFModel.NorthwindEFModel.csdl|res://NorthwindEFModel/NorthwindEFModel.NorthwindEFModel.msl|res://NorthwindEFModel/NorthwindEFModel.NorthwindEFModel.ssdl;Provider Connection String='data source=XE;user id=edmuser;password=123456'&quot;</span> <span style="color: #000066;">providerName</span>=<span style="color: #ff0000;">&quot;System.Data.EntityClient&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<p>Note those <code>res://</code> addresses. I imagine those are used to refer to resource files, but I didn&#8217;t see any of the projects involved actually containing one. On top of that, there&#8217;s that double-namespace thing, i.e. <code>NorthwindEFModel.NorthwindEFModel.csdl</code>. I couldn&#8217;t get this syntax to even work a little bit with my configuration, so I just pointed my application at the root directory I created, that contained all of the necessary files. I imagine on a test or application server, leaving these files in a common place may be the most useful option.</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;TestServer&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">connectionString</span>=<span style="color: #ff0000;">&quot;provider=EFOracleProvider;metadata=C:\OracleEFTests\TestAppEFModel.csdl|C:\OracleEFTests\TestAppEFModel.msl|C:\OracleEFTests\TestAppEFModel.Oracle.ssdl;Provider Connection String='Data Source=TNSNAME;User ID=user_id;Password=password...'&quot;</span>  <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<p>Don&#8217;t forget to add <code>EFOracleProvider</code> to the <code>&lt;DbProviderFactories&gt;</code> section of your configuration, as well. Also note that I didn&#8217;t use the <code>providerName</code> attribute, which in the test code was listed as <code>System.Data.EntityClient</code>, even though the provider in the connection string is our good old <code>EFOracleProvider</code>.</p>

<p>Finally, write a small piece of code to test the functionality.</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Data.EntityClient</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Configuration</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">TestAppEFModel</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> TestAppEFOracleTests
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            TestAppEFModelContext context <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TestAppEFModelContext<span style="color: #000000;">&#40;</span> ConfigurationManager.<span style="color: #0000FF;">ConnectionStrings</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;TestServer&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ConnectionString</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var query <span style="color: #008000;">=</span> from asset <span style="color: #0600FF;">in</span> context.<span style="color: #0000FF;">Assets</span>
                        where asset.<span style="color: #0000FF;">Asset_Type</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;TEST ASSET TYPE&quot;</span>
                        select asset<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span>var asset <span style="color: #0600FF;">in</span> query<span style="color: #000000;">&#41;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}, {1}&quot;</span>, 
                    asset.<span style="color: #0000FF;">Asset_Number</span>, 
                    asset.<span style="color: #0000FF;">Asset_Type</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<h3>The Troubles</h3>

<p>And we&#8217;re good to go, right? Not quite.</p>

<pre><code>ORA-00942: table or view does not exist
</code></pre>

<p>Whoops. What did we do wrong? Well, let&#8217;s look at the SQL that was generated.</p>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
    <span style="color: #ff0000;">&quot;Extent1&quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;Asset_Number&quot;</span><span style="color: #66cc66;">,</span>
    <span style="color: #ff0000;">&quot;Extent1&quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;Asset_Type&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
    <span style="color: #ff0000;">&quot;tblAsset&quot;</span> <span style="color: #ff0000;">&quot;Extent1&quot;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span>
    <span style="color: #66cc66;">&#40;</span>N<span style="color: #ff0000;">'TEST ASSET TYPE'</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;Extent1&quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;Asset_Type&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>


<p>What&#8217;s wrong with that? Actually, something very subtle and dangerous that I&#8217;m sure is causing Oracle a lot of pain in trying to get a provider out for the Entity Framework. Observer the following session in SQL*Plus:</p>

<pre><code>SQL&gt; DESC tblAsset;

Name           Null?    Type          
-------------- -------- --------------

ASSET_NUMBER   NOT NULL VARCHAR2(50)  
ASSET_TYPE              VARCHAR2(50)  

SQL&gt; DESC "tblAsset";
ERROR:
ORA-04043: object "tblAsset" does not exist

SQL&gt; DESC "TBLASSET";
Name           Null?    Type          
-------------- -------- --------------

ASSET_NUMBER   NOT NULL VARCHAR2(50)  
ASSET_TYPE              VARCHAR2(50)  
</code></pre>

<p>This hearkens back to a long-standing conflict in dealing with Oracle and mixed-case or reserved identifier names, to wit: In order to ensure that table names that happen to be reserved keywords can be used, we need to enclose them in double-quotes. But we can create tables with or without quotes, with differing cases, and create two different tables. We may not be able to rely on the user telling us the exactly correct name of a table in our storage model file, but we can&#8217;t convert it to all caps without the risk of accidentally referring to a different table!</p>

<p>My solution at this point was to cave and refer to the table name in all caps in my storage model file. But now the problem is the column names! And we can&#8217;t refer to a column name in the storage model, but we can in the mapping file, the <code>.msl</code>, but we can&#8217;t simply generate the mapping file, change the column names to all caps, and have it compile. What I ended up doing was simply referring to all of the fields in all caps in the storage model, which of course breaks our code, making us refer to <code>asset.ASSET_TYPE</code>, as well as uglifying the constructor code for creating new objects:</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Create a new Assets object.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;aSSET_NUMBER&quot;&gt;Initial value of ASSET_NUMBER.&lt;/param&gt;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> Assets CreateAssets<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> aSSET_NUMBER<span style="color: #000000;">&#41;</span></pre></div></div>


<h3>One More Thing</h3>

<p>So, those are the big things, the deal-breakers. The largest problem to me is the idea that we can specify a table name in our storage model file, but not column names. This seems entirely too half-baked to me, but maybe I just don&#8217;t understand the conceptual tactics behind a move like that.</p>

<p>And I just noticed this as I was signing off, a quick bizarre thing I wanted to try:</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var query <span style="color: #008000;">=</span> context.<span style="color: #0000FF;">Assets</span>.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span> a <span style="color: #008000;">=&gt;</span> a.<span style="color: #0000FF;">ASSET_TYPE</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;A&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>


<p>Take the top ten items that have an uppercase A in them. Simple enough, right? Nope. A rewriting of the generated SQL:</p>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> 
    asset_number<span style="color: #66cc66;">,</span> 
    asset_type 
<span style="color: #993333; font-weight: bold;">FROM</span> 
    tblAsset 
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>INSTR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'A'</span><span style="color: #66cc66;">,</span> asset_type<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">AND</span>   <span style="color: #66cc66;">&#40;</span> ROWNUM <span style="color: #66cc66;">&lt;=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>


<p>This is a mess. First off, that <code>ROWNUM</code> clause is not going to do what we expect, no matter what the rest of the query is. Secondly, <code>INSTR</code> takes its parameters in the <strong>reverse order</strong>. Little things like this are going to be the hell Oracle would have to go through to get a decent provider out there for Entity Framework, and I don&#8217;t even envy them a little bit.</p>

<p>One more thing I want to say about all of this. The work I did above took seven hours, a lot of Googling, a lot of searching through documentation, and a lot of guessing. The following is how everything above would be handled in <a href="http://datamapper.org">my current favorite Ruby ORM</a>.</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Asset
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">DataMapper::Resource</span>
  property <span style="color:#ff3333; font-weight:bold;">:asset_type</span>, <span style="color:#CC0066; font-weight:bold;">String</span>
  property <span style="color:#ff3333; font-weight:bold;">:asset_number</span>, <span style="color:#CC0066; font-weight:bold;">String</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
query = Asset.<span style="color:#9900CC;">get</span> <span style="color:#ff3333; font-weight:bold;">:asset_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'TEST ASSET TYPE'</span></pre></div></div>


<p>This is not to compare languages or ideologies, but methodologies. Simplicity always trumps complexity in the software engineering world. Always always always. Make Entity Framework easier for people to use, and it could be a godsend for shops that want a Microsoft-written ORM solution.</p>

<p>I&#8217;ll try and answer any questions anyone has, but this is literally the maximum scope of what I was able to accomplish. I&#8217;ll probably throw myself back at it later this weekend.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ardekantur.com/2008/08/my-adventures-with-entity-framework-and-oracle/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Apple Excursion &#8211; Complete Newbie Development Musings</title>
		<link>http://blog.ardekantur.com/2008/03/apple-excursion-complete-newbie-development-musings/</link>
		<comments>http://blog.ardekantur.com/2008/03/apple-excursion-complete-newbie-development-musings/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 23:44:14 +0000</pubDate>
		<dc:creator>Ardekantur</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Linux Philosophy]]></category>
		<category><![CDATA[Observations]]></category>
		<category><![CDATA[apple.developer.com]]></category>
		<category><![CDATA[geekbind]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://blog.ardekantur.com/archives/45</guid>
		<description><![CDATA[The other day I was mildly bothered that Mac OS X doesn&#8217;t implement some built-in way of moving and resizing windows like most Linux WMs do &#8211; by allowing shortcut keys and mouse presses in combination to move and resize from and point on the window, instead of the title bar and resize handles. My [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was mildly bothered that Mac OS X doesn&#8217;t implement some built-in way of moving and resizing windows like most Linux WMs do &#8211; by allowing shortcut keys and mouse presses in combination to move and resize from and point on the window, instead of the title bar and resize handles. My first stop was iusethis, where I found remnants of a pre-Intel program called <a href="http://osx.iusethis.com/app/geekbind">GeekBind</a>. Curious, I hit up its SourceForge page and downloaded the code. It was in an Xcode project, so I loaded up Xcode and tried a compile. Unsurprisingly, it failed, due to some errors in a set of files I later learned was part of the <a href="http://rentzsch.com/mach_inject/">mach_inject</a>  project. The code in question involved calls to initialize a &#8216;ppc&#95;thread&#95;state_t&#8217; &#8211; clearly a reference to PowerPC, which explained the failed build on my Intel iMac.</p>

<p><em>To the Apple-mobile,</em> I cried, slamming developer.apple.com into my browser. A search for &#8216;ppc&#95;thread&#95;state&#95;t&#8217; was &#8211; less than helpful. A few references to it, but no actual useful documentation. Google was the next stop, where someone trying to get another older program working on Intel <a href="http://blog.medallia.com/2006/05/smacbook_pro.html#comment-126">received a comment</a> about the new &#8216;i386&#95;thread&#95;state&#95;t&#8217; &#8212; something I could have guessed but was useless without the new register names provided by the comment. Plugged that in, and the program built without error &#8211; but would not run.</p>

<p>Confused, I hit up developer.apple.com and searched for &#8216;i386&#95;thread&#95;state&#95;t&#8217; &#8211; and Apple returned no results. I googled around some more for &#8216;mach&#95;inject intel&#8217;, finding that <a href="http://guiheneuf.org/mach%20inject%20for%20intel.html">one of the developers of iCal</a> had produced a port of mach_inject. Replacing this with my hacking around produced another clean build, and a failure with an explicit error &#8211; what GeekBind was trying to do involved being part of the procmon group.</p>

<p>It was at this point I figured I could do one of three things:</p>

<ol>
<li>Do one of the arbitrary and unsafe methods recommended to make the running user part of procmon</li>
<li>Learn about the complexities of user elevation in Mac OS and see if that was applicable to GeekBind</li>
<li>Find another program that did what I wanted GeekBind to do.</li>
</ol>

<p>So I did step 3. <a href="http://homepage.mac.com/tconkling/windowdragon/">Window Dragon</a> does what I want, for the most part, and only required the install of some hefty Application Extension Management System that deposited itself in my System Preferences and god knows where else on my system. It doesn&#8217;t work with applications started through X11, which is nearly a dealbreaker. But it&#8217;s what works for now.</p>

<p>Why do I write about this? Several things.</p>

<ol>
<li>There&#8217;s always an alternate program. Someone on iusethis recommended paying 8 dolllars for a <a href="http://osx.iusethis.com/app/zooom">program with similar functionality</a> &#8211; and the idea made me balk. Eight dollars for something that should be built-in? I&#8217;m not horrifically poor but I know when to shop around.</li>
<li>developer.apple.com&#8217;s search sucks something horrible. Maybe I don&#8217;t understand what it does, but looking up two object names returned absolutely nothing for me. I may be too used to MSDN, I guess, and should be checking the documentation that came installed with Xcode.</li>
<li>even knowing nothing about Xcode, Objective-C, Cocoa, or any part of the Mac development process, I was nearly able to port a PPC source code project to an Intel Mac binary. A little more work and I&#8217;d have what I want working on my system, and the source code to give to other people under GPL. This is a powerful incentive.</li>
</ol>

<p>And that was my Apple Excursion.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ardekantur.com/2008/03/apple-excursion-complete-newbie-development-musings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Errors I Got In Merb Within 10 Minutes Of Starting To Use It</title>
		<link>http://blog.ardekantur.com/2008/01/errors-i-got-in-merb-within-10-minutes-of-starting-to-use-it/</link>
		<comments>http://blog.ardekantur.com/2008/01/errors-i-got-in-merb-within-10-minutes-of-starting-to-use-it/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 05:45:27 +0000</pubDate>
		<dc:creator>Ardekantur</dc:creator>
				<category><![CDATA[Code Projects]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Merb]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[errors]]></category>

		<guid isPermaLink="false">http://blog.ardekantur.com/archives/18</guid>
		<description><![CDATA[$ rake
(in /home/.../Documents/Projects/Merb/Blog)
Connecting to database...
Fri, 04 Jan 2008 05:43:52 GMT: loading gem 'merb_datamapper' from config/dependencies.rb:13 ...
rake aborted!
Don't know how to build task 'default'


And&#8230;

$ rake dm:db:automigrate
(in /home/.../Documents/Projects/Merb/Blog)
Connecting to database...
Fri, 04 Jan 2008 05:44:33 GMT: loading gem 'merb_datamapper' from config/dependencies.rb:13 ...
Started merb_init.rb ...
Loading Application...
Compiling routes..
Loaded DEVELOPMENT Environment...
rake aborted!
Your query failed.
Incorrect table name 'data_mapper/bases'
CREATE TABLE `data_mapper/bases` (`id` int(11) [...]]]></description>
			<content:encoded><![CDATA[<pre><code>$ rake
(in /home/.../Documents/Projects/Merb/Blog)
Connecting to database...
Fri, 04 Jan 2008 05:43:52 GMT: loading gem 'merb_datamapper' from config/dependencies.rb:13 ...
rake aborted!
Don't know how to build task 'default'
</code></pre>

<p>And&#8230;</p>

<pre><code>$ rake dm:db:automigrate
(in /home/.../Documents/Projects/Merb/Blog)
Connecting to database...
Fri, 04 Jan 2008 05:44:33 GMT: loading gem 'merb_datamapper' from config/dependencies.rb:13 ...
Started merb_init.rb ...
Loading Application...
Compiling routes..
Loaded DEVELOPMENT Environment...
rake aborted!
Your query failed.
Incorrect table name 'data_mapper/bases'
CREATE TABLE `data_mapper/bases` (`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT)
</code></pre>

<p>And based on the almost no documentation and out of date tutorials I&#8217;ve found, there&#8217;s nothing that could even remotely explain what is going on here.</p>

<p>EDIT: The second problem appears to be noticed <a href="http://merb.devjavu.com/ticket/377">here</a>. Don&#8217;t know if the recommended course of action actually works yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ardekantur.com/2008/01/errors-i-got-in-merb-within-10-minutes-of-starting-to-use-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Switching To Opera: Initial Thoughts</title>
		<link>http://blog.ardekantur.com/2007/11/switching-to-opera-initial-thoughts/</link>
		<comments>http://blog.ardekantur.com/2007/11/switching-to-opera-initial-thoughts/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 04:33:58 +0000</pubDate>
		<dc:creator>Ardekantur</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Web Browsers]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://blog.ardekantur.com/archives/5</guid>
		<description><![CDATA[
    I should have my tab bar on the side for all my browsers, it makes so much more sense.
    I like having my mail client in the browser, but it&#8217;s easy to forget it&#8217;s there.
    Mail looks very powerful, now I just have to wait for it [...]]]></description>
			<content:encoded><![CDATA[<ul>
    <li>I should have my tab bar on the side for all my browsers, it makes so much more sense.</li>
    <li>I like having my mail client in the browser, but it&#8217;s easy to forget it&#8217;s there.</li>
    <li>Mail looks very powerful, now I just have to wait for it to download all my Gmail headers.</li>
    <li>Why the hell can&#8217;t IMAP subfolders collapse?</li>
    <li>Speed Dial is very awesome, but needs to allow me to add more dials for it.</li>
    <li>There aren&#8217;t any good looking, tiny themes for Opera.</li>
    <li>Where do I tell all folders to display in a threaded view?</li>
    <li>No good del.icio.us integration.</li>
    <li>Fonts on linux are ugly as sin, surprise surprise.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.ardekantur.com/2007/11/switching-to-opera-initial-thoughts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.593 seconds -->
