<?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>Saturnboy &#187; LCDS</title>
	<atom:link href="http://saturnboy.com/tag/lcds/feed/" rel="self" type="application/rss+xml" />
	<link>http://saturnboy.com</link>
	<description>Code, Work, and Life</description>
	<lastBuildDate>Mon, 19 Dec 2011 21:56:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Faking Transaction in LCDS 3</title>
		<link>http://saturnboy.com/2010/02/faking-transaction-in-lcds-3/</link>
		<comments>http://saturnboy.com/2010/02/faking-transaction-in-lcds-3/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 11:58:09 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[LCDS]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=1000</guid>
		<description><![CDATA[Alas, LCDS 3 doesn&#8217;t support the notion of transaction (in the sense of a Database Transaction). I assume that somewhere deep within the system transactions are used to ensure correctness of data in the db, but none of this is exposed to the user. Fortunately, it is possible to bundle up a bunch of updates [...]]]></description>
			<content:encoded><![CDATA[<p>Alas, <a href="http://www.adobe.com/products/livecycle/dataservices/">LCDS 3</a> doesn&#8217;t support the notion of transaction (in the sense of a <a href="http://en.wikipedia.org/wiki/Database_transaction">Database Transaction</a>). I assume that somewhere deep within the system transactions are used to ensure correctness of data in the db, but none of this is exposed to the user. Fortunately, it is possible to bundle up a bunch of updates on the client and push them all at once to the server. <i>Fake transactions</i>, as I like to call them, are quite useful.  But they can also be dangerous because they are not really transactions (hence the <i>fake</i> part), and don&#8217;t always work as you would hope.</p>
<h5>Fake It</h5>
<p>Faking a tranaction is done using the <code>autoCommit</code> property on a generated service.  According to the <a href="http://help.adobe.com/en_US/LiveCycleDataServicesES/3.0/Developing/index.html">docs</a>, setting <code>autoCommit</code> to <code>false</code> blocks Data Management from pushing any changes to the server until <code>commit()</code> is called manually.</p>
<p class="bottom">Here&#8217;s a <a href="http://help.adobe.com/en_US/LiveCycleDataServicesES/3.0/Developing/WSc3ff6d0ea77859461172e0811f00f7045b-7f83.html#WSc3ff6d0ea77859461172e0811f00f6f23a-7ff7">direct quote</a>:</p>
<blockquote><p>&#8220;&#8230;set a <code>DataService</code> component <code>autoCommit</code> property to false to allow only manual calls to the <code>commit()</code> method. It is important to set <code>autoCommit</code> to <code>false</code> when you are going to make more than one change&#8230;so that the <code>DataService</code> component can batch those changes and send them in one batch to the destination.&#8221;</p></blockquote>
<p class="bottom">So to make life easy, I made a simple static function that does the <code>autoCommit</code> gymnastics:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> fakeIt<span style="color: #66cc66;">&#40;</span>service:DataService, func:<span style="color: #000000; font-weight: bold;">Function</span><span style="color: #66cc66;">&#41;</span>:AsyncToken <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>service.<span style="color: #006600;">autoCommit</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ERROR: autoCommit is already off.&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>service.<span style="color: #006600;">commitRequired</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ERROR: another transaction is already open.&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    service.<span style="color: #006600;">autoCommit</span> = <span style="color: #000000; font-weight: bold;">false</span>;
    func<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> token:AsyncToken = service.<span style="color: #006600;">commit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    service.<span style="color: #006600;">autoCommit</span> = <span style="color: #000000; font-weight: bold;">true</span>;
    <span style="color: #b1b100;">return</span> token;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>After some error handling, we toggle <code>autoCommit</code> to false, call our function, then commit any updates, toggle <code>autoCommit</code> back on, and return the token.</p>
<h5>Usage</h5>
<p>Using our fake transaction function is straight forward, and typically involves passing in and inline anonymous function.</p>
<p class="bottom">Imagine our favorite example of teams and players, where each team has one-to-many players.  We might choose to perform a sequence of operations to add a new player to an existing team, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> token:AsyncToken = FakeTransaction.<span style="color: #006600;">fakeIt</span><span style="color: #66cc66;">&#40;</span>
    teamService.<span style="color: #006600;">serviceControl</span>,
    <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//rename the team</span>
        team.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">'Denver Nuggetz'</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">//create player</span>
        <span style="color: #000000; font-weight: bold;">var</span> p:Player = <span style="color: #000000; font-weight: bold;">new</span> Player<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        p.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">'Carmelo Anthony'</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">//wire both side of relationship</span>
        p.<span style="color: #006600;">team</span> = team;
        team.<span style="color: #006600;">players</span>.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        playerService.<span style="color: #006600;">createPlayer</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
token.<span style="color: #006600;">addResponder</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AsyncResponder<span style="color: #66cc66;">&#40;</span>successHandler, faultHandler<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>In this case, the fake transaction is used to ensure the team is renamed and the player is added.  Both operations occur together, so it should not be possible to have the new player on the old team, or have the renamed team without the new player.</p>
<h5>Warning! Danger!</h5>
<p>Experience has shown me that fake transactions don&#8217;t always work as one would expect if they were real transactions. Sometimes, particularly when you are manipulating entities already under Data Management, it seems like operations are not really batched but instead executed one at a time.  Thankfully, it appears that LCDS is order preserving, and by that I mean it doesn&#8217;t magically re-order things.  LCDS always executes operations in the order they come in.  I can only recommend you test your application vigorously to ensure what you expect to happen actually happens (<a href="http://flexunit.org/">FlexUnit4</a> is pretty awesome for <a href="http://saturnboy.com/2010/02/async-testing-with-flexunit4/">testing async backends</a>). </p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/wp-content/uploads/2010/01/FakeTransaction.as">FakeTransaction.as</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2010/02/faking-transaction-in-lcds-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Like Peas and Carrots: LCDS 3 and UTF-8</title>
		<link>http://saturnboy.com/2010/02/lcds-and-utf-8/</link>
		<comments>http://saturnboy.com/2010/02/lcds-and-utf-8/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 17:54:32 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[LCDS]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=958</guid>
		<description><![CDATA[I just wrote about how to handle special characters in Flex 4 when written as HTML entities in MXML. Now I&#8217;ve moved my data with the special characters out of MXML and down into a MySQL database. Data access is provided by a vanilla LCDS 3 backend. I now have a very different problem than [...]]]></description>
			<content:encoded><![CDATA[<p>I just wrote about how to handle <a href="http://saturnboy.com/2010/01/special-characters-flex-4/">special characters in Flex 4</a> when written as HTML entities in MXML. Now I&#8217;ve moved my data with the special characters out of MXML and down into a MySQL database.  Data access is provided by a vanilla <a href="http://www.adobe.com/products/livecycle/dataservices/">LCDS 3</a> backend. I now have a very different problem than what I had before: How do I get UTF-8 data out of the database with LCDS and onto the display?</p>
<h5>MySQL and UTF-8</h5>
<p>In theory, LCDS is perfectly happy with special characters and foreign languages (here&#8217;s a link to <a href="http://help.adobe.com/en_US/livecycle/9.0/programLC/langref/charset-codes.html">supported characters sets</a> in LiveCycle ES2). So this time around, our problem has nothing to do with Flex 4 or LCDS, instead it&#8217;s all about the database. For our example, we&#8217;ll skip the pure model driven development route and just start with a simple database with a single <code>players</code> table.</p>
<p class="bottom">Create the database:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> ballerz <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_general_ci;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #ff0000;">'baller'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'password'</span>;
<span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> ballerz<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">TO</span> baller@localhost;</pre></div></div>

<p>It is possible to configure MySQL to default to UTF-8 friendly behavior but the <code>CREATE DATABASE</code> command guarantees that the newly created db will be happy.</p>
<p class="bottom">Create the <code>players</code> table:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> players <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Nothing special here, just use <code>VARCHAR</code> for the text fields.  In this case, we only have the player&#8217;s name.</p>
<p class="bottom">Insert some sample data:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Carmelo Anthony&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Chaunçey Billups&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Nenê&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Këñÿõn Martin&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;LeBrøn James&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Mo Williams&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Shaquille O†Neal&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Ænderson Varejao&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> players <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Zýdrunãs Ílgauskãs&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>I put some extra special characters into the <code>INSERT</code> statements just for fun.</p>
<blockquote class="deeper"><p><b>Digging Deeper:</b> When connecting to MySQL from the commandline you can use the <code>--default-character-set=utf8</code> option to force your terminal to show UTF-8 characters correctly.</p></blockquote>
<h5>LCDS and UTF-8</h5>
<p>Now that the database is correctly setup to handle UTF-8, the rest of the LCDS setup is straight forward (see my getting started <a href="http://saturnboy.com/2009/07/get-started-lcds-mysql-1/">part 1</a> and <a href="http://saturnboy.com/2009/07/get-started-lcds-mysql-2/">part 2</a> posts). Create a new LCDS webapp via copy-and-paste from the template app, then fire up Flash Builder 4 and get to work.  In the Modeler plugin, configure a new RDS connection and just drag-and-drop the players table into the model.</p>
<p class="bottom">Here&#8217;s a screenshot of our LCDS model:</p>
<div class="span-14 last" style="min-height:274px;">
<img src="http://saturnboy.com/wp-content/uploads/2010/01/lcds_utf8_model.png" alt="model" width="391" height="264" />
</div>
<p class="bottom">And here&#8217;s a screenshot of the running app (remember this is backed by LCDS, so no running demo):</p>
<div class="span-14 last" style="min-height:180px;">
<img src="http://saturnboy.com/wp-content/uploads/2010/01/lcds_utf8_screenshot.png" alt="screenshot" width="390" height="170" />
</div>
<p class="bottom">Lastly, the frontend code showing just the highlights:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> ...</span>
<span style="color: #000000;">        creationComplete=<span style="color: #ff0000;">&quot;complete()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">           private function complete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">                getPlayers.token = playerService.getAll<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">            <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CallResponder</span> id=<span style="color: #ff0000;">&quot;getPlayers&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;Ballerz:PlayerService</span> id=<span style="color: #ff0000;">&quot;playerService&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> </span>
<span style="color: #000000;">            dataProvider=<span style="color: #ff0000;">&quot;{getPlayers.lastResult}&quot;</span></span>
<span style="color: #000000;">            labelField=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Again, no magic here, I use a simple <code>getAll()</code> query to retrieve the entire <code>players</code> table then feed it into a <code>List</code> via the <code>CallResponder</code>&#8216;s <code>lastResult</code> property.</p>
<h5>Conclusion</h5>
<p>So the moral of our story is: if you correctly configure your database to support UTF-8 and you correctly get UTF-8 data into your tables, then everything just works.  LCDS will transparently get data out of the db and Flex will transparently get it onto the screen.</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/lcds/ballerz/Ballerz.tgz">Ballerz.tgz</a></li>
<li><a href="http://saturnboy.com/proj/lcds/ballerz/create_db.sql">create_db.sql</a></li>
<li><a href="http://saturnboy.com/proj/lcds/ballerz/create_tables.sql">create_tables.sql</a></li>
<li><a href="http://saturnboy.com/proj/lcds/ballerz/data.sql">data.sql</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2010/02/lcds-and-utf-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LCDS and MySQL Views</title>
		<link>http://saturnboy.com/2009/12/lcds-and-mysql-views/</link>
		<comments>http://saturnboy.com/2009/12/lcds-and-mysql-views/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 19:31:56 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[LCDS]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=849</guid>
		<description><![CDATA[Once upon a time, in what now seems to be a prior life, I became a published author when my thesis hit the university press. That time has come again. After much effort, the second longest thing I have ever written has been published by InsideRIA. I wrote a two-part article titled Getting Real with [...]]]></description>
			<content:encoded><![CDATA[<p>Once upon a time, in what now seems to be a prior life, I became a published author when my thesis hit the university press.  That time has come again.  After much effort, the second longest thing I have ever written has been published by <a href="http://www.insideria.com/">InsideRIA</a>.  I wrote a two-part article titled <i>Getting Real with LCDS 3</i> (<a href="http://www.insideria.com/2009/12/getting-real-with-lcds-3-beta.html">Part 1</a> &#038; <a href="http://www.insideria.com/2009/12/getting-real-with-lcds-3-part.html">Part 2</a>) that covers the basics of model driven development with LCDS 3.  Yeah me.</p>
<h5>More Fun with LCDS</h5>
<p>Since I&#8217;m such a new-stuff-loving guy I can&#8217;t help but return to the backend after a few months on the frontend with various <a href="http://www.axiis.org/">Axiis</a> visualizations (<a href="http://saturnboy.com/2009/10/axiis-quest-for-cool/">here</a> &#038; <a href="http://saturnboy.com/2009/11/interactive-visualization-with-axiis/">here</a>) and a <a href="http://www.gskinner.com/libraries/gtween/">GTween</a> animation (<a href="http://saturnboy.com/2009/12/gtween-easing-flex-4/">here</a>).  So, it&#8217;s back to LCDS.  Of course, since I last wrote about LCDS, Adobe has shipped <a href="http://www.adobe.com/products/livecycle/dataservices/">LCDS 3</a>, but thankfully they still provide a free developer trial.  This time around, I&#8217;ll look at LCDS and <a href="http://dev.mysql.com/doc/refman/5.1/en/create-view.html">MySQL Views</a>.</p>
<h5>Create Database and Tables</h5>
<p class="bottom">First, let&#8217;s set the scene by constructing a new database and some tables. Here&#8217;s the database:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> football;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #ff0000;">'baller'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'password'</span>;
<span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> football<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">TO</span> baller@localhost;</pre></div></div>

<p class="bottom">And here are the tables:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> teams <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> players <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  salary <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  team_id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> games <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  team_id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  opp_id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  points <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  win tinyint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Lastly, we insert some <a href="http://saturnboy.com/proj/lcds/football/data.sql">sample data</a> into the database via a script.  The final result is our familiar teams-and-players database, but this time with an additional <code>games</code> table.</p>
<h5>MySQL Views</h5>
<p>A database <i>view</i> is one way to push logic and computations down from the application layer into the database.  A judicious use of views can really help keep the application layer nice and clean.  But much like database de-normalization, adding views to the database often feels like premature optimization, so be careful.  LCDS and the Modeler plugin treat database views just like tables, so everything just works (sort of).  </p>
<p><a href="http://www.mysql.com/">MySQL</a> is a full-featured database that provides a simple <code>CREATE VIEW</code> syntax.  For our purposes, a <i>view</i> can be thought of as nothing more than another table that is constructed from other tables via a <code>SELECT</code> statement.  Because of this, database views are sometimes called <i>virtual tables</i>.  The <code>SELECT</code> statement used to construct the view is often very complicated, involving multiple tables, joins, functions, expressions, and more.</p>
<p class="bottom">For our example, we will construct two views.  First, the <code>team_summary</code> view packages up information from the <code>teams</code> and <code>players</code> tables:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">VIEW</span> team_summary <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">SELECT</span>
  t<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">,</span>
  t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> num_players<span style="color: #66cc66;">,</span>
  ROUND<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">.</span>salary<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000000</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> payroll<span style="color: #66cc66;">,</span>
  ROUND<span style="color: #66cc66;">&#40;</span>AVG<span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">.</span>salary<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> avg_salary<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">MIN</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">.</span>salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> lowest_salary<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">.</span>salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> highest_salary
<span style="color: #993333; font-weight: bold;">FROM</span> teams <span style="color: #993333; font-weight: bold;">AS</span> t<span style="color: #66cc66;">,</span> players <span style="color: #993333; font-weight: bold;">AS</span> p <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>team_id <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> t<span style="color: #66cc66;">.</span>id;</pre></div></div>

<p class="bottom">The <code>CREATE VIEW</code> above joins the <code>teams</code> and <code>players</code> tables to create seven columns.  Here&#8217;s a brief description of the generated columns:</p>
<hr class="bottom" style="height: 3px;" />
<div class="span-3">&nbsp;<b>id</b></div>
<div class="span-10 last">team id directly from teams table</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>name</b></div>
<div class="span-10 last">team name directly from teams table</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>num_players</b></div>
<div class="span-10 last">count up all player ids</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>payroll</b></div>
<div class="span-10 last">sum all player salaries</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>avg_salary</b></div>
<div class="span-10 last">average all player salaries</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>highest_salary</b></div>
<div class="span-10 last">find the maximum player salary</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>lowest_salary</b></div>
<div class="span-10 last">find the minimum player salary</div>
<hr style="height: 3px;" />
<p class="bottom">Next, we create the <code>game_summary</code> view to collect data from the <code>teams</code> and <code>games</code> tables:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">VIEW</span> game_summary <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">SELECT</span>
  t<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">,</span>
  t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">.</span>win<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">.</span>win<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> record<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">.</span>points<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SIGNED<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> points_for
<span style="color: #993333; font-weight: bold;">FROM</span> teams <span style="color: #993333; font-weight: bold;">AS</span> t<span style="color: #66cc66;">,</span> games <span style="color: #993333; font-weight: bold;">AS</span> g <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> g<span style="color: #66cc66;">.</span>team_id <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> t<span style="color: #66cc66;">.</span>id;</pre></div></div>

<p class="bottom">And a brief description of the generated columns:</p>
<hr class="bottom" style="height: 3px;" />
<div class="span-3">&nbsp;<b>id</b></div>
<div class="span-10 last">team id directly from teams table</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>name</b></div>
<div class="span-10 last">team name directly from teams table</div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>record</b></div>
<div class="span-10 last">concatenate number of wins with number of losses (computed via total games minus wins) </div>
<hr class="bottom" style="background-color:#aaa; height:1px;" />
<div class="span-3">&nbsp;<b>points_for</b></div>
<div class="span-10 last">sum up all the team&#8217;s points for all games</div>
<hr style="height: 3px;" />
<blockquote class="deeper"><p><b>Digging Deeper:</b> The <code>CAST</code> statements are not necessary to construct the <code>game_summary</code> view as far as MySQL is concerned, but I need them to force the correct column types to make LCDS happy.</p></blockquote>
<h5>LCDS 3 and the Modeler Plugin</h5>
<p class="bottom">Now that our database is happily configured, fire up Flash Builder 4 and switch to the Modeler plugin.  Create and configure a new LCDS webapp, and then take a look at the RDS Dataview panel:</p>
<div class="span-14 last" style="min-height:275px;">
<img src="http://saturnboy.com/wp-content/uploads/2009/12/mysql-views-rds-dataview.png" alt="rds-dataview" width="329" height="265" />
</div>
<p class="bottom">You can see both views and tables.  Next, simply drag whatever tables or views you want over to the Modeler.  Here&#8217;s the final model for our sample application:</p>
<div class="span-14 last" style="min-height:283px;">
<img src="http://saturnboy.com/wp-content/uploads/2009/12/mysql-views-model.png" alt="model" width="495" height="263" />
</div>
<h5>LCDS Modeler Tricks &amp; Tips</h5>
<p class="bottom">There are a couple of tricks to getting views working correctly in LCDS:</p>
<ol>
<li>Mark each view entity as persistent in the Properties panel (in theory, views can support updates to only those columns that are one-to-one mapped to a table)</li>
<li>Set the <code>id</code> column as the <code>ID</code> property (this is required because views don&#8217;t have primary keys, so you have to tell LCDS what to do)</li>
<li>Verify that the database types have correctly come across to LCDS, if not add a <code>CAST</code> to the view column to force the correct type (see table below)</li>
</ol>
<p class="bottom">Here&#8217;s a simple table showing how the types move from the MySQL database to LCDS, and then from LCDS to PASOs (aka Plain old ActionScript Objects):</p>
<hr class="bottom" style="height: 3px; width:320px;" />
<div class="span-2">&nbsp;<b>MySQL</b></div>
<div class="span-1">&rarr;</div>
<div class="span-2"><b>LCDS</b></div>
<div class="span-1">&rarr;</div>
<div class="span-2 last"><b>PASOs</b></div>
<hr class="bottom" style="background-color:#aaa; width:320px; height: 2px;" />
<div class="span-3">&nbsp;int</div>
<div class="span-3">int</div>
<div class="span-2 last">int</div>
<hr class="bottom" style="background-color:#aaa; width:320px; height:1px;" />
<div class="span-3">&nbsp;bigint</div>
<div class="span-3">long</div>
<div class="span-2 last">int</div>
<hr class="bottom" style="background-color:#aaa; width:320px; height:1px;" />
<div class="span-3">&nbsp;decimal</div>
<div class="span-3">double</div>
<div class="span-2 last">Number</div>
<hr class="bottom" style="background-color:#aaa; width:320px; height:1px;" />
<div class="span-3">&nbsp;varchar</div>
<div class="span-3">string</div>
<div class="span-2 last">String</div>
<hr style="height: 3px; width:320px;" />
<h5>Data</h5>
<p class="bottom">We can view the data in the database by using the RDS Query Viewer.  Here is the <code>team_summary</code> data:</p>
<div class="span-14 last" style="min-height:229px;">
<img src="http://saturnboy.com/wp-content/uploads/2009/12/mysql-views-rds-query-team-summary.png" alt="team-summary" width="530" height="219" />
</div>
<p class="bottom">And here is the <code>game_summary</code> data:</p>
<div class="span-14 last" style="min-height:239px;">
<img src="http://saturnboy.com/wp-content/uploads/2009/12/mysql-views-rds-query-game-summary.png" alt="game-summary" width="530" height="219" />
</div>
<h5>The App</h5>
<p class="bottom">Alas, since this is an LCDS app, no running demo is possible.  Here&#8217;s a screenshot instead, showing a selected team and the associated team &amp; game summary data.</p>
<div class="span-14 last" style="min-height:214px;">
<img src="http://saturnboy.com/wp-content/uploads/2009/12/mysql-views-app-screenshot.png" alt="screenshot" width="505" height="194" style="border: 1px solid #ccc; padding: 10px;" />
</div>
<p>Our sample app closely follows the plan I set forward in <a href="http://www.insideria.com/2009/12/getting-real-with-lcds-3-part.html">Getting Real with LCDS, Part 2</a>.  We define our services and associated <code>CallResponder</code>&#8216;s in MXML, and event handlers in ActionScript.</p>
<p class="bottom">Here is the relevant section of code showing the various event handlers:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> teamChangeHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> teamId:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">list</span>.<span style="color: #006600;">selectedItem</span>.<span style="color: #006600;">id</span>
	getTeamSummary.<span style="color: #006600;">token</span> = teamSummaryService.<span style="color: #006600;">getById</span><span style="color: #66cc66;">&#40;</span>teamId<span style="color: #66cc66;">&#41;</span>;
	getGameSummary.<span style="color: #006600;">token</span> = gameSummaryService.<span style="color: #006600;">getById</span><span style="color: #66cc66;">&#40;</span>teamId<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getTeamSummaryResult<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> summary:TeamSummary = <span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">result</span> as IList<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getItemAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> as TeamSummary;
	numPlayers.<span style="color: #0066CC;">text</span> = summary.<span style="color: #006600;">numPlayers</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	payroll.<span style="color: #0066CC;">text</span> = cf2.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span>summary.<span style="color: #006600;">payroll</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">' million'</span>;
	avgSalary.<span style="color: #0066CC;">text</span> = cf.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span>summary.<span style="color: #006600;">avgSalary</span><span style="color: #66cc66;">&#41;</span>;
	lowestSalary.<span style="color: #0066CC;">text</span> = cf.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span>summary.<span style="color: #006600;">lowestSalary</span><span style="color: #66cc66;">&#41;</span>;
	highestSalary.<span style="color: #0066CC;">text</span> = cf.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span>summary.<span style="color: #006600;">highestSalary</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getGameSummaryResult<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> summary:GameSummary = <span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">result</span> as IList<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getItemAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> as GameSummary;
	record.<span style="color: #0066CC;">text</span> = summary.<span style="color: #006600;">record</span>;
	pointsFor.<span style="color: #0066CC;">text</span> = summary.<span style="color: #006600;">pointsFor</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p class="bottom">And here is the MXML <code>Declarations</code> block:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CallResponder</span> id=<span style="color: #ff0000;">&quot;getAllTeams&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CallResponder</span> id=<span style="color: #ff0000;">&quot;getTeamSummary&quot;</span> result=<span style="color: #ff0000;">&quot;getTeamSummaryResult(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CallResponder</span> id=<span style="color: #ff0000;">&quot;getGameSummary&quot;</span> result=<span style="color: #ff0000;">&quot;getGameSummaryResult(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;football:TeamService</span> id=<span style="color: #ff0000;">&quot;teamService&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;football:TeamSummaryService</span> id=<span style="color: #ff0000;">&quot;teamSummaryService&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;football:GameSummaryService</span> id=<span style="color: #ff0000;">&quot;gameSummaryService&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>The application is very simple.  When a user clicks on a team, the <code>teamChangeHandler()</code> is called.  The handler queries the LCDS backend and sets the <code>CallResponder</code>&#8216;s <code>token</code> property.  When the asynchronous backend eventually returns some data, the data is forwarded to the appropriate result handler.  In the result handler, the incoming PASO has it&#8217;s properties are formatted and then assigned to the matching form element for display.</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/lcds/football/Football.zip">Football.zip</a></li>
<li><a href="http://saturnboy.com/proj/lcds/football/create_db.sql">create_db.sql</a></li>
<li><a href="http://saturnboy.com/proj/lcds/football/create_tables.sql">create_tables.sql</a></li>
<li><a href="http://saturnboy.com/proj/lcds/football/create_views.sql">create_views.sql</a></li>
<li><a href="http://saturnboy.com/proj/lcds/football/data.sql">data.sql</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/12/lcds-and-mysql-views/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting started with LCDS 3 Beta and MySQL, Part 2</title>
		<link>http://saturnboy.com/2009/07/get-started-lcds-mysql-2/</link>
		<comments>http://saturnboy.com/2009/07/get-started-lcds-mysql-2/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 21:40:40 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[LCDS]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=645</guid>
		<description><![CDATA[In Part 1, I covered the basic setup of LiveCycle Data Services 3 Beta sitting on a MySQL database. Now, I&#8217;ll get into the Flash Builder side of things, and talk about the Modeler plugin and model driven development. Setup Modeler Plugin Get Flash Builder 4 Beta (download) Get the LCDS Modeler plugin (download) Install [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://saturnboy.com/2009/07/get-started-lcds-mysql-1/">Part 1</a>, I covered the basic setup of <a href="http://labs.adobe.com/technologies/livecycle_dataservices3/">LiveCycle Data Services 3 Beta</a> sitting on a <a href="http://www.mysql.com/">MySQL</a> database.  Now, I&#8217;ll get into the <a href="http://labs.adobe.com/technologies/flashbuilder4/">Flash Builder</a> side of things, and talk about the Modeler plugin and model driven development.</p>
<h5>Setup Modeler Plugin</h5>
<ol>
<li>Get Flash Builder 4 Beta (<a href="http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4">download</a>)</li>
<li>Get the LCDS Modeler plugin (<a href="http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_livecycle_dataservices3">download</a>)</li>
<li>Install the Modeler plugin:
<ul>
<li>Unzip to a temp folder, which will create a <code>plugins</code> folder</li>
<li>Copy the <code>plugins</code> folder&#8217;s contents directly into Flash Builder&#8217;s <code>plugins</code> folder (typically located in <code>/Applications/Adobe Flash Builder Beta/plugins</code> if you are on a Mac)</li>
<li>Restart Flash Builder</li>
</ul>
</li>
</ol>
<h5>Model Driven Development</h5>
<ol>
<li>Create a new Flex project
<ul>
<li>In Flash Builder, right-click and say <i>New &gt; Flex Project</i><br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_1_new_project_thumb.png" alt="new flex project" title="new flex project" width="500" height="250" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_1_new_project.png">enlarge</a></li>
<li>Choose <i>J2EE</i> for Application Server Type, and select LCDS</li>
<li>Click Next to configure your server<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_2_server_config_thumb.png" alt="j2ee server config" title="j2ee server config" width="500" height="250" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_2_server_config.png">enlarge</a></li>
<li>Uncheck <i>Use Default Location</i>, and fill in your root folder, url, and context (see <a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_2_server_config.png">screenshot</a>)</li>
<li>Click <i>Validate Configuration</i> (this will fail if LCDS is not running), and then Finish</li>
</ul>
</li>
<li>Create a new data model
<ul>
<li>Select the <i>Data/Services</i> tab in the bottom window</li>
<li>Click the <i>Edit Active Data Model</i> icon in the tab&#8217;s menubar (see <a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_3_new_model.png">screenshot</a>)<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_3_new_model_thumb.png" alt="new model" title="new model" width="500" height="250" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_3_new_model.png">enlarge</a></li>
<li>This will create a new data model for your project, and bring up <code>MyApp.fml</code> in the Modeler&#8217;s design view (see <a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_3_new_model.png">screenshot</a>)</li>
<li>To see the file in the Package Explorer, click the <i>Filters</i> icon (see <a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_3_new_model.png">screenshot</a>), then uncheck <code>.*</code> and <code>.model</code></li>
</ul>
</li>
<li>Connect to the server
<ul>
<li>Switch to the <i>Adobe Data Model</i> perspective</li>
<li>In the <i>RDS Dataview</i> window, click the <i>RDS Configuration</i> icon<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_4_rds_config_thumb.png" alt="rds config" title="rds config" width="500" height="250" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_4_rds_config.png">enlarge</a></li>
<li>Set the <i>Context Root</i> to <code>myapp</code> (because our server is running at <code>http://localhost:8080/myapp/</code>)</li>
<li>Click <i>Test Connection</i>, and then OK</li>
</ul>
</li>
<li>Verify the server&#8217;s connection to MySQL
<ul>
<li>In the <i>RDS Dataview</i> window, expand until we can see our tables<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_5_rds_dataview_thumb.png" alt="rds dataview" title="rds dataview" width="344" height="244" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_5_rds_dataview.png">enlarge</a></li>
<li>Right-click on a table, and select <i>Show Table Contents</i><br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_6_rds_show_table_thumb.png" alt="rds show table" title="rds show table" width="494" height="156" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_6_rds_show_table.png">enlarge</a></li>
</ul>
</li>
<li>Edit the model
<ul>
<li>Just drag tables from the <i>RDS Dataview</i> to add them to the model<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_7_edit_model_thumb.png" alt="edit model" title="edit model" width="364" height="187" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_7_edit_model.png">enlarge</a></li>
</ul>
</li>
<li>Browse the generated services and code
<ul>
<li>Once the model is updated, the builder automatically generates standard CRUD services.  Switch back to the <i>Flash Builder</i> perspective, and you can view them in the <i>Data/Services</i> tab<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_8_services_browser_thumb.png" alt="services browser" title="services browser" width="295" height="249" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_8_services_browser.png">enlarge</a></li>
<li>The generated code is available in the <i>Package Explorer</i>.  Files you don&#8217;t want to touch are prefixed with an underscore.  The other files, like <code>Player.as</code> and <code>PlayerService.as</code> are available for you to customize.<br />
<img src="http://saturnboy.com/wp-content/uploads/2009/07/lcds_9_generated_code_thumb.png" alt="generated code" title="generated code" width="301" height="292" /><br />
<a href="http://saturnboy.com/wp-content/uploads/2009/07/lcds_9_generated_code.png">enlarge</a></li>
</ul>
</li>
</ol>
<h5>More Docs</h5>
<ol>
<li>LCDS Modeler Guide (<a href="http://download.macromedia.com/pub/labs/livecycle_dataservices3/livecycle_dataservices3_modelerguide_061509.zip">zip</a>)</li>
</ol>
<h5>Conclusion</h5>
<p>Once again, that&#8217;s it.  I&#8217;ll have to learn something new about LCDS before I write more.</p>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/07/get-started-lcds-mysql-2/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Getting started with LCDS 3 Beta and MySQL, Part 1</title>
		<link>http://saturnboy.com/2009/07/get-started-lcds-mysql-1/</link>
		<comments>http://saturnboy.com/2009/07/get-started-lcds-mysql-1/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 20:19:17 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[LCDS]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=614</guid>
		<description><![CDATA[With the beta release of LiveCycle Data Services 3, Adobe has changed the game by bringing model driven development to the forefront. The geniuses from the entity formerly known as Macromedia have put together a compelling product if you are in the business of enterprise RIAs like us. Here are a few choice words from [...]]]></description>
			<content:encoded><![CDATA[<p>With the beta release of <a href="http://labs.adobe.com/technologies/livecycle_dataservices3/">LiveCycle Data Services 3</a>, Adobe has changed the game by bringing model driven development to the forefront.  The geniuses from the entity formerly known as Macromedia have put together a compelling product if you are in the business of enterprise RIAs like <a href="http://www.gorillalogic.com/">us</a>.  Here are a <a href="http://www.infoq.com/news/2009/06/model-driven-dev-with-flex">few choice words</a> from Adobe about the beta release.</p>
<p>Now on to the fun part: playing with our new toy.  Vroom, vroom!  In Part 1, I&#8217;ll walk through getting started with LCDS sitting on top of <a href="http://www.mysql.com/">MySQL</a>.  <a href="http://saturnboy.com/2009/07/get-started-lcds-mysql-2/">Part 2</a> covers using the Modeler plugin in Flash Builder 4 to bring the dream of model driven development to reality.</p>
<blockquote><p><b>NOTE:</b> This article was written for LCDS 3 Beta 1, but I assume it&#8217;s mostly relevant for Beta 3 (released at AdobeMAX) and all future versions of LCDS 3.</p></blockquote>
<blockquote><p><b>NOTE 2:</b> The Mac installer for Beta 3 (released at AdobeMAX) does <b>not</b> included the integrated Tomcat which is a huge pain in the ass for all Mac developers.  I recommend you grab the integrated Tomcat out of the Windows installer.</p></blockquote>
<h5>Setup MySQL</h5>
<ol>
<li>Install &amp; start MySQL (this is an exercise for the reader, I remember it being a little painful on my Mac)</li>
<li>Create a new db &amp; user:
<ul>
<li><code>mysql -uroot -p</code>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> mydb;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #ff0000;">'myusr'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'mypassword'</span>;
<span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> mydb<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">TO</span> myusr@localhost;</pre></div></div>

<p>NOTE: Don&#8217;t use <code>user</code> in any part of a username (ex: <code>myuser</code> doesn&#8217;t work) because it is a reserved word in MySQL.</li>
</ul>
</li>
<li>Create some sample tables:
<ul>
<li><code>mysql -umyusr -pmypassword mydb</code>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> team;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> team <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> player;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> player <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">NUMBER</span> <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  salary <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  team_id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

</li>
</ul>
</li>
<li>Insert data:
<ul>
<li>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Denver Broncos&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Oakland Raiders&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Jay Cutler&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6497500</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Champ Bailey&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">24</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">8003050</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Eddie Royal&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">19</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2539830</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Tony Scheffler&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">88</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">612480</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;JaMarcus Russell&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">16872400</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Darren McFadden&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4375000</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> player <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NUMBER</span><span style="color: #66cc66;">,</span>salary<span style="color: #66cc66;">,</span>team_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Sebastian Janikowski&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">11</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2625000</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>NOTE: Ignore the fact that Jay Cutler now plays for Da Bears.</li>
</ul>
</li>
</ol>
<blockquote class="deeper"><p><b>Digging Deeper:</b> Setting up a database is required, but setting up tables or inserting data is not.  You can use the model driven development features of LCDS (and the Modeler plugin) to create <b>all</b> of your tables and data.</p></blockquote>
<h5>Setup LCDS</h5>
<ol>
<li>Grab LCDS 3 Beta from Adobe Labs (<a href="http://labs.adobe.com/technologies/livecycle_dataservices3/">download</a>)</li>
<li>Run installer &amp; choose to install with bundled Tomcat (on Mac this installs to <code>/Applications/lcds</code> and the bundled Tomcat to <code>/Applications/lcds/tomcat</code>)</li>
<li>Create a new LCDS app, by copying the template app (in <code>lcds/tomcat/webapps/lcds</code>) to a new folder:
<ul>
<li><code>cd /Applications/lcds/tomcat/webapps</code></li>
<li><code>cp -R lcds myapp</code></li>
</ul>
</li>
<li>Enable RDS (Remove Dev Services) &#8211; This enables some dev only stuff like updating the database tables on the server directly from Flash Builder.  For obvious security reasons, RDS would never be running in a production environment.
<ul>
<li>Edit <code>/Applications/lcds/tomcat/webapps/myapp/WEB-INF/web.xml</code></li>
<li>Uncomment the entire RDS section</li>
<li>Set <code>userAppserverSecurity = false</code> (in the newly uncommented RDS section)</li>
</ul>
</li>
<li>Update <code>services-config.xml</code> to avoid collisions with template <code>lcds</code> app:
<ul>
<li><code>cd /Applications/lcds/tomcat/webapps/myapp/WEB-INF/flex</code></li>
<li>Edit <code>services-config.xml</code>:
<ul>
<li>In the <code>&lt;channel-definition id="my-rtmp"&gt;</code> section, change port 2038 to port 2039</li>
<li>In the <code>&lt;channel-definition id="my-nio-amf"&gt;</code> section, change port 2880 to port 2881</li>
<li>In the <code>&lt;channel-definition id="my-nio-amf-poll"&gt;</code> section, change port 2880 to port 2881</li>
<li>In the <code>&lt;channel-definition id="my-nio-http"&gt;</code> section, change port 2880 to port 2881</li>
</ul>
</li>
</ul>
<p>NOTE: As an alternative, you can just remove the template <code>lcds</code> app and skip the collision avoidance stuff above.</li>
</ol>
<h5>Setup LCDS to talk to MySQL</h5>
<ol>
<li>Get MySQL Connector/J, and be sure to match the version to your MySQL version (<a href="http://dev.mysql.com/downloads/connector/j/5.1.html">download</a>)</li>
<li>Put <code>mysql-connector-java-5.1.7-bin.jar</code> into Tomcat&#8217;s <code>lib</code> folder:
<ul>
<li><code>cp mysql-connector-java-5.1.7-bin.jar /Applications/lcds/tomcat/lib/</code></li>
</ul>
</li>
<li>Config Tomcat to recognize your MySQL db by creating a new Context for your app:
<ul>
<li><code>cd /Applications/lcds/tomcat/conf/Catalina/localhost</code></li>
<li><code>cp lcds.xml myapp.xml</code></li>
<li>Add a JDBC Resource block to <code>myapp.xml</code>, so it looks like this:

<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;Context</span> <span style="color: #000066;">privileged</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">antiResourceLocking</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">antiJARLocking</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- JOTM --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Transaction</span> <span style="color: #000066;">factory</span>=<span style="color: #ff0000;">&quot;org.objectweb.jotm.UserTransactionFactory&quot;</span> <span style="color: #000066;">jotm.timeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- MySQL --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/MyDB&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;myusr&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;mypassword&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost:3306/mydb?autoReconnect=true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
</ul>
</li>
</ol>
<h5>Start LCDS</h5>
<ol>
<li>Point Tomcat to the bundled Tomcat installed with LCDS:
<ul>
<li><code>export CATALINA_HOME=/Applications/lcds/tomcat</code></li>
<li>Windows: <code>set CATALINA_HOME=C:\lcds\tomcat</code></li>
</ul>
</li>
<li>Set Java to Java 6:
<ul>
<li><code>export JRE_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home</code></li>
<li>Windows: <code>set JRE_HOME=C:\Program Files\Java\jdk1.6.0_14\jre</code></li>
</ul>
</li>
<li>Run it:
<ul>
<li><code>/Applications/lcds/tomcat/bin/catalina.sh run</code></li>
<li>Windows: <code>C:\lcds\tomcat\bin\catalina.bat run</code></li>
</ul>
</li>
<li>Sometimes Tomcat does not get the value of <code>JRE_HOME</code> (usually on Windows).  The caused by a hard-coded value inside <code>catalina.sh</code>, you&#8217;ll need to edit this file and comment out that line.</li>
<li>Verify it all worked by browsing to:
<ul>
<li><code>http://localhost:8400/myapp/</code></li>
</ul>
</li>
<li>A helpful bash script that does #1 &#8211; #3 all in one shot:
<ul>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CATALINA_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>lcds<span style="color: #000000; font-weight: bold;">/</span>tomcat
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JRE_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>System<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>JavaVM.framework<span style="color: #000000; font-weight: bold;">/</span>Versions<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.6</span><span style="color: #000000; font-weight: bold;">/</span>Home
<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>lcds<span style="color: #000000; font-weight: bold;">/</span>tomcat<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>catalina.sh run</pre></div></div>

</li>
<li>Windows:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">CATALINA_HOME</span>=C:\lcds\tomcat
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">JRE_HOME</span>=C:\Program Files\Java\jdk1.6.0_14\jre
C:\lcds\tomcat\bin\catalina.bat run</pre></div></div>

</li>
</ul>
</li>
</ol>
<h5>More Docs</h5>
<ol>
<li><a href="http://www.adobe.com/devnet/livecycle/articles/lcdses3_whatsnew.html">What&#8217;s new in LCDS 3</a></li>
<li>LCDS Dev Guide (<a href="http://download.macromedia.com/pub/labs/livecycle_dataservices3/livecycle_dataservices3_devguide_061509.zip">zip</a>)</li>
<li><a href="http://labs.adobe.com/technologies/livecycle_dataservices3/videos/lcds3_demo/">Tutorial Video</a> &#8211; awesome, 20 min long, and <b>very</b> worthwhile</li>
</ol>
<h5>To Be Continued&#8230;</h5>
<p>That&#8217;s it for Part 1.  LCDS should be up and running on top of MySQL.  Next up, <a href="http://saturnboy.com/2009/07/get-started-lcds-mysql-2/">Part 2</a> covers the Modeler plugin and model driven development.</p>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/07/get-started-lcds-mysql-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

