<?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>techno.blog(&#34;Dion&#34;) &#187; aptana</title>
	<atom:link href="http://almaer.com/blog/tag/aptana/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Tue, 28 Aug 2012 14:41:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Gears API supported by Aptana Jaxer</title>
		<link>http://almaer.com/blog/google-gears-api-supported-by-aptana-jaxer</link>
		<comments>http://almaer.com/blog/google-gears-api-supported-by-aptana-jaxer#comments</comments>
		<pubDate>Thu, 21 Feb 2008 15:00:52 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Gears]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[aptana]]></category>
		<category><![CDATA[jaxer]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/google-gears-api-supported-by-aptana-jaxer</guid>
		<description><![CDATA[
Man I love it when I can delete code. Seeing the line count go away and leaving a small amount of text is a sight for sore eyes. I got to delete a lot of code today thanks to the kind folks at Aptana.
I recently wrote a shim that allows the Google Gears API to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ajaxian.com/wp-content/images/jaxer.png" border="0" style="float: right; padding: 8px;" /></p>
<p>Man I love it when I can delete code. Seeing the line count go away and leaving a small amount of text is a sight for sore eyes. I got to delete a lot of code today thanks to the kind folks at Aptana.</p>
<p>I recently wrote a shim that allows the <a href="http://almaer.com/blog/google-gears-database-api-on-the-server">Google Gears API</a> to run as is on the server side. It wraps the <a href="http://code.google.com/apis/gears/api_database.html">Gears Database API</a> with the Jaxer one.</p>
<p>What is particularly cool about this is that you can then write some code and:</p>
<ul>
<li>If the user has Gears installed, it runs client-side</li>
<li>If the user doesn&#8217;t have Gears installed <b>just run it on the server</b></li>
</ul>
<p>I want to setup a nice way to make this trivial to setup.</p>
<p>The majority of the code was a simple wrapper around the result set, so Aptana decided to <a href="http://aptana.com/node/264">directly support the Gears API itself</a> which allowed me to get rid of it all!</p>
<p>This makes the shim as simple as <a href="http://code.google.com/p/google-gears-library/source/browse/trunk/jaxer/gears_init.js">this</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// -- Wrap this code so it is available if using a proxy call</span>
<span style="color: #003366; font-weight: bold;">function</span> oncallback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Make up the namespaces to mimic Gears and a place for Jaxer holders</span>
  google <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> google.<span style="color: #660066;">gears</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">factory</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">jaxer</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Create sets up a database instance to be used</span>
  google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">factory</span>.<span style="color: #660066;">create</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>className<span style="color: #339933;">,</span> version<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>className.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'database'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'I can only do Database work right now'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">jaxer</span>.<span style="color: #660066;">Db</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// -- The Database Wrapper</span>
  google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">jaxer</span>.<span style="color: #660066;">Db</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">db</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">jaxer</span>.<span style="color: #660066;">Db</span>.<span style="color: #660066;">prototype</span>.<span style="color: #000066;">open</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">db</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Jaxer.<span style="color: #660066;">DB</span>.<span style="color: #660066;">SQLite</span>.<span style="color: #660066;">Connection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      PATH<span style="color: #339933;">:</span> <span style="color: #3366CC;">'resource:///../data/'</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.sqlite'</span><span style="color: #339933;">,</span>
      CLOSE_AFTER_EXECUTE<span style="color: #339933;">:</span> <span style="color: #3366CC;">'open'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">jaxer</span>.<span style="color: #660066;">Db</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">execute</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>sqlStatement<span style="color: #339933;">,</span> argArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> rs <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>argArray<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">db</span>.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span>sqlStatement<span style="color: #339933;">,</span> argArray<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">db</span>.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span>sqlStatement<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> rs<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Philip Maker has also taken GearsORM and <a href="http://forums.aptana.com/viewtopic.php?t=4785">made it work with Jaxer</a>. Very cool indeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/google-gears-api-supported-by-aptana-jaxer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Gears Database API on the Server</title>
		<link>http://almaer.com/blog/google-gears-database-api-on-the-server</link>
		<comments>http://almaer.com/blog/google-gears-database-api-on-the-server#comments</comments>
		<pubDate>Tue, 05 Feb 2008 15:23:33 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Gears]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[aptana]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[jaxer]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/google-gears-database-api-on-the-server</guid>
		<description><![CDATA[
As soon as I started to play with Aptana Jaxer, I saw an interesting opportunity to port the Google Gears Database API (note the Gears in the logo!)
If I could use the same API for both client and server side database access, then I can be enabled to do things like:

Use one API, and have [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ajaxian.com/wp-content/images/jaxer.png" border="0" style="float: right; padding: 8px;" /></p>
<p>As soon as I started to play with <a href="http://ajaxian.com/archives/aptana-releases-jaxer-ajax-server-built-on-mozilla">Aptana Jaxer</a>, I saw an interesting opportunity to port the Google Gears <a href="http://code.google.com/apis/gears/api_database.html">Database API</a> (note the Gears in the logo!)</p>
<p>If I could use the same API for both client and server side database access, then I can be enabled to do things like:</p>
<ul>
<li>Use one API, and have the system do a sync from local to remote databases</li>
<li>If the user has JavaScript, use a local database, else do the work remotely</li>
<li>Share higher level database libraries and ORMs such as <a href="http://code.google.com/p/gears-dblib/">Gears DBLib</a> for use on server side data too</li>
</ul>
<p>I quickly built a prototype to see if this would all work.</p>
<p>The <a href="http://code.google.com/p/google-gears-library/source/browse/trunk/jaxer">Jaxer shim of the Gears API was born</a>, and to test it out I took the <a href="http://code.google.com/apis/gears/samples/hello_world_database.html">database example from Gears itself</a> and made it work.</p>
<p>To do so, I only had to make a few changes:</p>
<p><b>Run code on the server</b></p>
<p>I changed the main library to run on the server via:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;gears_init.js&quot; runat=&quot;server&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>I wrapped database access in proxy objects, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addPhrase<span style="color: #009900;">&#40;</span>phrase<span style="color: #339933;">,</span> currTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  getDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'insert into Demo values (?, ?)'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>phrase<span style="color: #339933;">,</span> currTime<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
addPhrase.<span style="color: #660066;">proxy</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>This now allows me to run the addPhrase code from the browser, and it will be proxied up to the server to actually execute that INSERT statement.</p>
<p>This forced me to separate the server side code from the client side code, which is a better practice anyway, but it does make you think about what goes where. In a pure Gears solution I can put everything in one place since it all runs on the client. </p>
<p><b>Create the new gears_init.js</b></p>
<p>A new <a href="http://code.google.com/p/google-gears-library/source/browse/trunk/jaxer/gears_init.js">gears_init.js</a> acts as the shim itself. Instead of doing the typical Gears logic, it implements the Gears database contract. This wasn&#8217;t that tough, although there are differences between the Gears way, and the Jaxer.DB way. The main difference is to do with the ResultSet implementation, where Gears goes for a rs.next()/rs.field(1) type model versus the Jaxer.DB rs.rows[x] model.</p>
<p>I actually much prefer <a href="http://code.google.com/p/gears-dblib/">Gears DBLib</a> as it hides all of that, and just gives the programmer what he wants&#8230; the rows to work on.</p>
<p><b>oncallback magic</b></p>
<p>In the current Jaxer beta, I ran into an issue where I wanted the Gears library to just &#8220;be there&#8221; for any proxy requests.</p>
<p>You have to think about the lifecycle of a Jaxer application, and the <a href="http://www.aptana.com/node/202">documentation tells you what you need to know</a> to work around the issue.</p>
<p>In this case, I wrapped the code in:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> oncallback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// create the wrapper here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is less than idea, and Aptana is playing with nice scoping which would enable you to just say &#8220;hey, load this library once and keep it around for the lifetime of the server | application | session | page&#8221;. That will be very nice indeed.</p>
<p>You can do a little bit of this by opening up your jaxer_prefs file and adding the resource for your file:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// This option sets up an html document that will be loaded</span>
<span style="color: #006600; font-style: italic;">// everytime a callback is processed.  This has to be a local file.</span>
<span style="color: #006600; font-style: italic;">// If not specified, an empty document will be loaded.</span>
<span style="color: #006600; font-style: italic;">// pref(&quot;Jaxer.dev.LoadDocForCallback&quot;, &quot;resource:///framework/callback.html&quot;);</span></pre></div></div>

<p><b>Future&#8230;</b></p>
<p>This is just the beginning. As I mentioned at the beginning, I am interested to see where you can take this to handle clients who do not support JavaScript, and also to deal with synchronization with minimal code (sync from local to remote with exactly the same SQL API).</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/google-gears-database-api-on-the-server/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
