<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  			<channel>
    			<title>singularityconcepts.com</title>
    			<link>http://www.singularityconcepts.com/</link>
    			<description>The design portfolio of Joel Watson - Web Designer and Web Application Developer</description>
    			<language>en-us</language>
    			<pubDate>
					
                	<![CDATA[Sat, 29 May 2010 09:42:53	]]> GMT
					
                </pubDate>
    			<lastBuildDate>Wed, 04 Apr 2007 09:41:01 GMT</lastBuildDate>
    			<webMaster>existdissolve@gmail.com</webMaster>

			
    			<item>
				
      				<title><![CDATA[Add an MP3 Player to EasyBe]]></title>
	  				<pubDate>Sat, 29 May 2010 09:42:53 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[88]]></link>
	  				<description><![CDATA[I recently worked on a project which, among other things, involved implementing the &quot;<a href="http://easybe.com/">easybe 1-2-3</a>&quot; music store software (basically, it&#39;s a pretty simple-to-use platform for managing for-sale music downloads).<br /><br />One of the major drawbacks of this software is that it doesn&#39;t come pre-built with a music player.&nbsp; While it does provide links to file samples that users can download and listen to (way too many steps for 30 seconds...), there&#39;s no one-step player for checking out clips from all the songs on an album. &nbsp;<br /><br />No fear!&nbsp; There are ways around this, and in the following I&#39;ll walk you through the simple steps to deploy a free, light-weight mp3 player that can play the music you want your visitors to hear.<br /><br />First, let&#39;s get the mp3 player.&nbsp; While you could use many of the freely-available mp3 players out there, I like the one from <a href="http://premiumbeat.com">premiumbeat.com</a>.&nbsp; It&#39;s super-stipped down and simple to use.&nbsp; Plus, it accepts an XML file, which will work perfectly for our needs.<br /><br />Once you have the mp3 player of your choice, go ahead and deploy it on your server.&nbsp; Don&#39;t worry, I&#39;ll wait until you&#39;re done.<br /><br />All set?&nbsp; Excellent.&nbsp; The next step is to open up the Album Details template file in easybe.&nbsp; It&#39;s in the 123-music-shop/templates/shop/ directory, named something like &quot;albumdetails.tpl&quot;.&nbsp; Why this page?&nbsp; Well, when this page is active, certain data is exposed via PHP that we can access and pass on to other pages that we&#39;ll need to modify.&nbsp; So for example, on the album details page, an object named &quot;Album&quot; is available, and from this we can access the &quot;id&quot; value, which identifies our album in the database.&nbsp; (NOTE: I&#39;m not sure this is documented.&nbsp; I found it out simply by playing around and making good guesses!)<br /><br />So here&#39;s what we&#39;ll add to the &quot;albumdetails.tpl&quot; page:<br /><br />&lt;script type=&quot;text/javascript&quot; src=&quot;swfobject.js&quot;&gt;&lt;/script&gt;<br />&lt;div id=&quot;flashPlayer&quot;&gt;<br />&nbsp; This text will be replaced by the flash music player.<br />&lt;/div&gt;<br />&lt;script type=&quot;text/javascript&quot;&gt;<br />&nbsp;&nbsp; var so = new SWFObject(&quot;playerMultipleList.swf&quot;, &quot;mymovie&quot;, &quot;295&quot;, &quot;160&quot;, &quot;7&quot;, &quot;#FFFFFF&quot;); &nbsp;<br />&nbsp;&nbsp; so.addVariable(&quot;autoPlay&quot;,&quot;no&quot;)<br />&nbsp;&nbsp; so.addVariable(&quot;playlistPath&quot;,&quot;playlist.php?albumid={$Album.id}&quot;)<br />&nbsp;&nbsp; so.addVariable(&quot;playerSkin&quot;,&quot;2&quot;)<br />&nbsp;&nbsp; so.write(&quot;flashPlayer&quot;);<br />&lt;/script&gt;<br /><br />Pretty simple.&nbsp; Basically, we simply initialize the mp3 player (the one from premiumbeats.com, in this instance), passing a dynamic path in our playlistPath variable.&nbsp; Notice that I&#39;m passing {$Album.id} -- this is id of the album I mentioned before that is exposed.<br /><br />Ok, so we&#39;re almost there!&nbsp; All that&#39;s left now is to generate the XML that will build our playlist and feed the mp3 player.<br /><br />Now go ahead an open up a new file.&nbsp; I creatively named mine &quot;playlist.php&quot;, but feel free to be more generic if it suits you :)<br /><br />In this file, we need to do a couple things.&nbsp; First, we need to evaluate the &quot;albumid&quot; that we pass through the URL query string.&nbsp; Next, we need to query the database to get all the songs for the albumid that we&#39;ve passed.&nbsp; And finally, we need to generate some XML that the mp3 can understand.<br /><br />(I&#39;m going to assume you know how to set up your database connection in PHP, and hopefully you also know how to parse out the query string.&nbsp; WIth that assumption, let&#39;s move on to the database query.)<br /><br />So one of the odd things about easybe is their db structure.&nbsp; Rather than storing info about albums, songs, etc. in a flat, relational way, they store the data in an almost key-value pair (or trio or quad...) manner.&nbsp; While not impossible to work with, it can make getting at the data a little less that straightforward if you&#39;re not used to seeing this kind of thing. <br /><br />For example, 1 song in the &quot;productav&quot; table spans at least 7 rows, producing a structure like this:<br /><br /><strong>ID&nbsp;&nbsp; &nbsp;Name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ord&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Value</strong><br />1 &nbsp;&nbsp;&nbsp; artist &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL &nbsp;&nbsp;&nbsp; Seth Condrey<br />1 &nbsp;&nbsp; &nbsp;title &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; NULL &nbsp;&nbsp; &nbsp;Jesus Paid It All<br />1 &nbsp;&nbsp; &nbsp;running_time &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NULL &nbsp;&nbsp; &nbsp;5:17<br />1 &nbsp;&nbsp; &nbsp;free_download &nbsp;&nbsp; &nbsp; NULL &nbsp;&nbsp; &nbsp;true<br />1 &nbsp;&nbsp; &nbsp;song_file_name &nbsp;&nbsp; NULL &nbsp;&nbsp; &nbsp;Jesus Paid It All_1.mp3<br />1 &nbsp;&nbsp; &nbsp;demo_file_name &nbsp; NULL &nbsp;&nbsp; &nbsp;Jesus Paid It All 30sec_1.mp3<br />1 &nbsp;&nbsp; &nbsp;single &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL &nbsp;&nbsp; &nbsp;yes<br /><br />Obviously, a regular relational approach will not serve your queries very well!&nbsp; Of course, there are several ways to accomplish the desired result, but here&#39;s the final query that I arrived at:<br /><br />select &nbsp;&nbsp; &nbsp;p.id,<br />&nbsp;&nbsp; &nbsp;(select value from productav pv where name = &#39;artist&#39; and pv.productid = p.id limit 1) as artist,<br />&nbsp;&nbsp; &nbsp;(select value from productav pv where name = &#39;title&#39; and pv.productid = p.id&nbsp; limit 1) as title,<br />&nbsp;&nbsp; &nbsp;(select value from productav pv where name = &#39;demo_file_name&#39; and pv.productid = p.id&nbsp; limit 1) as path<br />from product p<br />join bundleproductasm b on p.id = b.productid<br />where bundleid = $albumid<br />order by childorder<br />&nbsp;<br />The most interesting thing to note here is the use of the subqueries in the select statement.&nbsp; If you&#39;re not familiar with this approach, what I&#39;m doing is to basically create a faux column of data, based on the results of another query within the scope of the currently executed statement. In other words, I can take the 7 or so rows from the productav table and flip them into a structure that I can actually use.<br /><br />Ok, so much for mySQL.&nbsp; Now our last step is to write the PHP code that will produce the XML.&nbsp; What follows is a very limited approach: you may want to try something a little more robust if you have more extensive needs:<br /><br />&lt;?php<br />&nbsp;&nbsp; &nbsp;// Send the headers<br />&nbsp;&nbsp; &nbsp;header(&#39;Content-type: text/xml&#39;);<br />&nbsp;&nbsp; &nbsp;header(&#39;Pragma: public&#39;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;header(&#39;Cache-control: private&#39;);<br />&nbsp;&nbsp; &nbsp;header(&#39;Expires: -1&#39;);<br />?&gt;<br />&lt;?php echo(&#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&#39;); ?&gt;<br />&lt;xml&gt;<br />&lt;?php if ($count &gt; 0): ?&gt;<br />&nbsp;&nbsp; &nbsp;&lt;?php while($row=mysql_fetch_array($rsongs)): ?&gt;<br />&nbsp;&nbsp; &nbsp;&lt;track&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;path&gt;public/demos/&lt;?php echo $row[&#39;path&#39;]?&gt;&lt;/path&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;title&gt;&lt;?php echo $row[&#39;title&#39;]?&gt; - &lt;?php echo $row[&#39;artist&#39;]?&gt;&lt;/title&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/track&gt;<br />&nbsp;&nbsp; &nbsp;&lt;?php endwhile; ?&gt;<br />&lt;?php endif; ?&gt;<br />&lt;/xml&gt;<br /><br />Nothing even worth pointing out here.&nbsp; A simple loop of the data, and we have some nice XML to spit back at our mp3 player.<br /><br />And that&#39;s about it.&nbsp; Even though easybe is pretty limited OOTB, it is easily hackable, so adding on some nice little touches here and there are relatively easy and make for a much better product when it&#39;s all said and done.]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[88]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[Font Problem...Resolved!]]></title>
	  				<pubDate>Wed, 19 May 2010 09:22:03 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[87]]></link>
	  				<description><![CDATA[<p>Recently, one of my clients sent me a purchased font in the dreaded .dfont format (.dfont is how Macs save fonts...it stands for &quot;Data Fork Font&quot;...dumb!).&nbsp; While this is nice on Macs [several fonts can be bundled in one .dfont file], it&#39;s not great for a PC because, well, Windows has no idea what to do with it.</p><p>Fortunately, Google provided an answer pretty quickly.&nbsp; Apparently, there&#39;s a nifty little bit of freeware out there called <a href="http://peter.upfold.org.uk/projects/dfontsplitter">DfontSplitter</a>.&nbsp; If the name isn&#39;t obvious, <a href="http://peter.upfold.org.uk/projects/dfontsplitter">DfontSplitter</a> basically breaks up the .dfont file from the Mac and converts it into individual True Type Font files...these Windows understands :) </p><p>So for those of you out there who have a Mac and are making fun of me for my lack thereof, bite me! For those that are in the same boat as me, check out <a href="http://peter.upfold.org.uk/projects/dfontsplitter">DfontSplitter</a>--it pretty much rocks! </p>]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[87]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[Quick connectionString Epiphany]]></title>
	  				<pubDate>Fri, 14 May 2010 08:47:29 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[86]]></link>
	  				<description><![CDATA[Ok, if you&#39;re like me and aren&#39;t the smartest cookie in the jar, something like specifying a connectionString in a web.config file can be maddening.&nbsp; Of course, it doesn&#39;t help that there are literally 123 billion possible ways to do a connection string...but I digress.<br /><br />While searching for an answer, I ran across a pretty neat little technique that will make the development of your connection string quite painless.<br /><br />First, open Explorer, and create a new file. Now, rename the file to <strong>X.UDL</strong>. Double-clicking this file will open up a <strong>Data Link Properties</strong> dialog window.<br /><br />The super nifty thing about the DLP is that you can actually create a full-on connection to a datasource, and test out various settings.&nbsp; Nice.<br /><br />But the really beneficial part (well, besides verifying that, yes, this particular service account does, in fact, have access to SQL Server...) is the &quot;All&quot; tab.&nbsp; Here, you&#39;ll see all of the properties of your connection.&nbsp; While nice information, this is super sweet because these properties are precisely the parameters that you need to enter into your web.config connection string in order to make SQL Server happy.&nbsp; That&#39;s awesome, and a huge time saver if building connection strings isn&#39;t something that you do on a routine basis :) ]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[86]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[SharePoint 2010 is Official]]></title>
	  				<pubDate>Wed, 12 May 2010 07:14:10 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[85]]></link>
	  				<description><![CDATA[<p>Readers of this blog no that I am no fan of Microsoft.&nbsp; However, I am actually kind of excited about the <a href="http://sharepoint.microsoft.com/en-us/Pages/default.aspx">official launch of SharePoint 2010 today</a>. </p><p>Previous versions of SharePoint were okay...actually, they were pretty limited, extremely clunky, and revealed Microsoft&#39;s blatant desire to give the finger to everyone not on &quot;approved&quot; (read Microsoft-developed) platforms.</p><p>Well, 2010 reverses alot of this.&nbsp; The architecture has been reworked, so sites in SharePoint actually bear some resemblence to web standards.&nbsp; User interfaces have been SERIOUSLY upgraded so that managing content is more enjoyable and less like oral surgery.</p><p>But perhaps the coolest part of 2010 is that there is truly deep interaction with the full suite of Office products.&nbsp; From Word, to SQL Server, to Visual Studio, it seems that every single Office app has really meaningful hooks into the core of what SharePoint does.&nbsp; What does this mean?&nbsp; Well, Office is now no longer something you have on your crappy work PC...with SharePoint 2010, it&#39;s the power of the Office Suite available anywhere you might be. </p>]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[85]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[New Spry Enhancements]]></title>
	  				<pubDate>Sat, 01 May 2010 06:28:28 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[84]]></link>
	  				<description><![CDATA[<p>Even though I&#39;ve pretty much given up on Adobe&#39;s Spry Framework, I noticed yesterday that some major updates have been added in, primary among them the introduction of <a href="http://labs.adobe.com/technologies/spry/ui/">Spry UI</a>.&nbsp; According to the Spry Team&#39;s <a href="http://blogs.adobe.com/spryteam/">blog post</a>, Spry UI is a new way of approaching Spry widgets that moves away from the previous (and kind of annoying) necessity of following a prescribed markup model and now attempts to work with user-defined patterns.&nbsp; This *should* allow for much more flexibility and customizability, and allow for much more robust opportunities for skinning that were previously possible.&nbsp; Moreover, because all the widgets will now inherit from the same shared base classes, the door is widened for Spry to become a much more robust framework in the future. </p><p>Does the introduction of Spry UI mean that Spry development is alive and well, and that Adobe is committed to making something of it long term?&nbsp; Only time will tell.&nbsp; </p><p>The problem for me, of course, is that <em><strong>time</strong></em> is precisely the problem.&nbsp; Development of the framework has been seemingly eternal, and significant updates (whether features or simply information about ongoing development) are VERY infrequent.&nbsp; While I see a lot of promise in what Spry can do (and can become), &quot;facts on the ground&quot; force me to use other, more mature frameworks for serious development. &nbsp;</p><p>I don&#39;t mean this as a slight to Spry, nor to the talented Spry team (or even the thousands of developers who make really good use of it).&nbsp; The bottom line for me is that I need a framework <em><strong>today</strong></em> that has the fully formed features of a jQuery or Ext.&nbsp; If Spry Framework is in that position <em><strong>tomorrow</strong></em>, I&#39;ll more than happily give it a another chance. </p>]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[84]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[Quick JavaScript Goodness]]></title>
	  				<pubDate>Sat, 10 Apr 2010 10:48:12 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[83]]></link>
	  				<description><![CDATA[Ok, so this is nothing new nor is it something that hasn&#39;t been blogged about before.&nbsp; However, I thought I&#39;d share in case it helps some other googler that can&#39;t find what they&#39;re looking for :)<br /><br />So in JavaScript, most functions have a pretty standard form: you name the function and then define which arguments you wish to pass to the function.&nbsp; Depending on how you work out the logic in the remainder of the function, the arguments can all be required, all be optional, or whatever.<br /><br />The one major drawback, however, is that the arguments must be passed <strong>in the proper order.</strong>&nbsp; For example, if I have a describeMovie() function that takes an actor, title, and year argument, the order I define these arguments in will be the order in which I have to pass them in my function call.<br /><br /><strong>function describeMovie(actor,title,year) {<br />&nbsp;&nbsp;&nbsp; // alert the movie&rsquo;s lead actor<br />&nbsp;&nbsp;&nbsp; alert(actor);<br />&nbsp;&nbsp;&nbsp; &hellip;&hellip;&hellip;&hellip;<br />}</strong><br /><br />would require<br /><br /><strong>onclick=&quot;describeMovie(&#39;Bruce Willis&#39;,&#39;Surrogates&#39;,&#39;2009&#39;)&quot;</strong><br /><br />in order to work properly.&nbsp; <br /><br />(This won&rsquo;t work:)<br /><br /><strong>onclick=&quot;describeMovie(&#39;Bruce Willis&#39;,&#39;2009&#39;,&#39;Surrogates&#39;)&quot; </strong><br /><br />Also, while I can easily pass the actor and title parameters without the year parameter (describeMovie(&#39;Bruce Willis&#39;,&#39;Surrogates&#39;)), I&rsquo;ll run into issues if I try to pass just the actor and year parameters (describeMovie(&#39;Bruce Willis&#39;,&#39;2009&#39;)), for the order in which they are passed will make my function think that what I want to be the &quot;year&quot; parameter is actually the &quot;title&quot;. Lame.<br /><br />Usually, the answer is just to pass an empty placeholder parameter in order to &quot;skip&quot; an unneeded parameter.&nbsp; While this works, it can be a bit unreadable if you have a butt-load of empty parameters&hellip;wait, is the eighth set of &#39;&#39; for this or is the thirteenth&hellip;? <br /><br />But honestly, the biggest problem is that the correlation of &quot;Bruce Willis&quot; to the parameter &quot;actor&quot; is only defined by order.&nbsp; There&rsquo;s nothing beyond this that binds the two together.&nbsp; <br /><br />Is there a way around this unsavory state of affairs?&nbsp; Of course!<br /><br />Instead of passing x number of arbitrary, unnamed arguments to the function, you can actually pass an object literal as the only argument.&nbsp; <br /><br />Now of course, an object literal is nothing special.&nbsp; It&rsquo;s just a simple collection of name-value pairs.&nbsp; But here&rsquo;s where the coolness of this approach is realized.&nbsp; Because we&rsquo;re using name-value pairs, not only are the values we&rsquo;re passing &ldquo;named&rdquo;, but we can also use them in any arbitrary order that we want to, precisely because they&rsquo;re named!<br /><br />So in our example, instead of having to invoke our function like this:<br /><br /><strong>describeMovie(&#39;Bruce Willis&#39;,&#39;&#39;,2009)</strong>&nbsp; [remember, the empty title?]<br /><br />With an object literal we can do this:<br /><strong><br />describeMovie({actor:&#39;Bruce Willis&#39;,year:2009})</strong><br /><br />To me, the second is much cleaner and more intuitive. We&#39;re only passing what we want to, and not forcing the issue with empty, placeholder arguments.&nbsp; Moreover, I feel like I have more confidence in how arguments are passed, since they are now &quot;named&quot; in the object literal.<br /><br />On our actual function, then, it&rsquo;s equally easy to deal with using the object literal, especially now that everything is wrapped in name-value pairs:<br /><br /><strong>function describeMovie(obj) {<br />&nbsp;&nbsp;&nbsp; // alert the movie&rsquo;s lead actor<br />&nbsp;&nbsp;&nbsp; alert(obj.actor);<br />}</strong><br /><br />Super nice!]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[83]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[Update Miscellany]]></title>
	  				<pubDate>Mon, 29 Mar 2010 07:20:06 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[82]]></link>
	  				<description><![CDATA[<p>Wow, it&#39;s been far too long since I&#39;ve posted.&nbsp; I&#39;ve been quite busy as of late, and have been putting the finishing touches on a couple of pretty decent sized projects.</p><p>But perhaps most interesting to followers of this site is the fact that I&#39;ll be working with a friend of mine over the next couple of months to completely revamp a site that we think will be pretty sweet in a couple of months.&nbsp; But the coolest part is that we&#39;re going to be creating this site--as much as possible--using exclusively ColdFusion ORM. As we make progress, I&#39;m going to do my best to regularly blog about our experiences as we tap into this extremely cool technology that is available in CF9.</p><p>So anyway, stay tuned...I hope to have some killer posts up very soon :) </p>]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[82]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[Ext JS Screenshot Fun]]></title>
	  				<pubDate>Tue, 02 Mar 2010 22:51:34 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[81]]></link>
	  				<description><![CDATA[<p>Quick (ok, not really) video about some screenshot croppin&#39; goodness with Ext.</p><p>Check it out, and become my Facebook friend while you&#39;re at it!</p><p><a href="http://www.facebook.com/video/video.php?v=10150094359185371"><strong>Here&#39;s the super-fly video </strong></a></p>]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[81]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[ColdFusion and ORM...Yummy!]]></title>
	  				<pubDate>Tue, 02 Mar 2010 05:33:43 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[80]]></link>
	  				<description><![CDATA[The other day, I was flipping through the ColdFusion docs (yeah, super exciting!) and came across <strong><a href="http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSA59BCAA1-7773-49a9-977C-F8755BC2E0B8.html">the section about ColdFusion&#39;s support of ORM</a></strong>.&nbsp; If you&#39;re not familiar with it (I wasn&#39;t really until a few days ago), ORM stands for &quot;object-relational mapping.&quot; While it sounds a bit overly technical, ORM is basically a way to interface objects in code to relational databases that levels the playing field, allowing your code to be more or less agnostic about what kind (or kinds) of databases that it&#39;s connecting to.<br /><br />At first, I was unimpressed, but then I took a few moments to think about it.&nbsp; How often have I had to switch between database systems?&nbsp; Plenty.&nbsp; And how fun was it to have to go back and rework my code to account for the differences in typing and syntax?&nbsp; It wasn&#39;t.&nbsp; With ORM, however, alot of these headaches are removed because you can create an abstraction layer in your application using ORM to not really have to worry about what datasource you might be connecting to.<br /><br />Now obviously, the subject of ORM is much more complex than my admittedly weak description.&nbsp; However, after a lot of reading I feel like I have a decent idea on what the approach is, at least, so I decided to try my hand at a little ORM development.<br /><br />As with most things, ColdFusion 9 makes ORM development stupidly simple.&nbsp; Utilizing skills that you already have, you can make a few tweaks here and there and have some seriously cool ORM action up and running in a matter of minutes.<br /><br />So let&#39;s look at some of the peices.<br /><br />First, in Application.cfc, you have to turn ORM &quot;on&quot; and tell CF which datasource you want to use for this ORM voodoo.&nbsp; This is accomplished pretty easily:<br /><br /><strong>this.ormenabled = &quot;true&quot;;<br />this.datasource = &quot;my_test_orm_db&quot;;</strong><br /><br />Next, you&#39;ll want to start creating some CFC&#39;s--something tells me you&#39;ve done this before :)<br /><br />But before we do that, the CFC is going to be a bit different than it might otherwise be.&nbsp; Rather than creating a collection of functions and properties that are just kind of grouped together, this CFC is going to be created for the express purpose of describing a data object.&nbsp; It&#39;s going to be the interface for how our ORM app colludes with the database.<br /><br /><pre>component persistent=&quot;true&quot; {<br />&nbsp;&nbsp; &nbsp;property name=&quot;jobid&quot; generator=&quot;increment&quot; fieldtype=&quot;id&quot; ormtype=&quot;integer&quot;;<br />&nbsp;&nbsp; &nbsp;property name=&quot;title&quot; ormtype=&quot;string&quot;;<br />&nbsp;&nbsp; &nbsp;property name=&quot;description&quot; ormtype=&quot;string&quot;;<br />&nbsp;&nbsp; &nbsp;property name=&quot;startdate&quot; ormtype=&quot;date&quot;;<br />&nbsp;&nbsp; &nbsp;property name=&quot;enddate&quot; ormtype=&quot;date&quot;;<br />&nbsp;&nbsp; &nbsp;property name=&quot;datecreated&quot; ormtype=&quot;timestamp&quot;;<br />&nbsp;&nbsp; &nbsp;property name=&quot;lastupdated&quot; ormtype=&quot;timestamp&quot;;<br />}</pre><br /><br />In this example (done completely in cfscript, btw--thank you CF9!!), I create a component like normal, but add the attribute &quot;persistent&quot; to it.&nbsp; This attribute will tell ColdFusion to persist this object (which is really like a dataconnection to a particular table in your db) in the application so that you can interface with this object to perform your run-o-the-mill CRUD ops.<br /><br />After creating the component, I simply add a property for each column in my table that will be the &quot;maps&quot; that ColdFusion uses to interact with the database.<br /><br />Ok, so once this object gets persisted in the application, ColdFusion is going to do something terrifically cool.&nbsp; For this object, it&#39;s going to create a bunch of standard methods that can be used for retreiving information about the object, updating it, creating new objects, and even deleting it.&nbsp; Additionally, it&#39;s going to create getters and setters for each property for super-easy retrieval later on.<br /><br />So let&#39;s see how this plays out.&nbsp; Let&#39;s say that I want to create a new &quot;Job&quot; record in my &quot;jobs&quot; table in the db.&nbsp; Before, I probably would have created a component for &quot;jobs&quot; and added a method to it called &quot;createJob.&quot;&nbsp; CreateJob() would have taken some arguments, and then performed a query to the db...pretty <br /><br />standard stuff.&nbsp; With ORM, however, this is more or less ALREADY READY TO GO now that I&#39;ve finished defining my data object. &nbsp;<br /><br />Now, I can simply do the following (this is on a non-cfc page where I have a form action or something):<br /><br /><pre>&lt;cfset job = EntityNew(&quot;jobs&quot;)&gt;<br />&lt;cfset job.setTitle(&quot;Web Designer&quot;)&gt;<br />&lt;cfset job.setDescription(&quot;A full-time position for the best damn web designer out there&quot;)&gt;<br />&lt;cfset job.setStartDate(&quot;2010-03-10&quot;)&gt;<br />&lt;cfset job.setEndDate(&quot;2010-03-21&quot;)&gt;<br />&lt;cfset EntitySave(job)&gt;</pre><br /><br />Here, I create a new instance of my &quot;jobs&quot; object with EntityNew().&nbsp; Again, EntityNew() was auto generated by CF--I didn&#39;t have to worry about it.&nbsp; Next, I simply set the value of each property of my object that I want to create using set&lt;property&gt;().&nbsp; And again, the method is auto-created by CF.&nbsp; Once I&#39;ve set all the properties that I want for my new object, I can simply commit it and save my object using EntitySave(), yet another auto-generated method.<br /><br />And...that&#39;s it.&nbsp; If I check my database table, I&#39;ll see that a new record has been added with all the values that I applied to the object that was created and saved.<br /><br />Now if you&#39;re like me, and are still kind of mired in older-school ways of thinking about data connections, this can be a trip.&nbsp; After all, where the heck is the query?!?!&nbsp; But that&#39;s the beauty of ORM.&nbsp; After defining the properties of my data object, I don&#39;t have to worry necessarily about SQL syntax to get data into and out of my database.&nbsp; Rather, I can use the definition I&#39;ve created about my data to interface with the database and be happy and healthier for it.<br /><br />So over the next several weeks, I&#39;m going to be experimenting alot more with ORM, and hopefully will post some more thoughts.&nbsp; But before I go, let me share my initial impressions.<br /><br />One of the big reasons I like this approach is that it really forces you to start thinking in a more object-oriented manner. Of course, ORM is no magic bullet for developing an OO app, but I think the way in which it makes you think about your data is a very strong step in that direction.&nbsp; Secondly, and related, I like that it turns data into objects.&nbsp; In other modes of programming, it&#39;s very easy to get very lost in patching together code here and there to get something functional.&nbsp; However, this approach really makes you think about the connections that your data have with one another, and I think helps to guide the way in which you approach developing an application in order to support these relationships.<br /><br />Of course, I have very limited knowledge of OO, so I might be way off.&nbsp; However, I feel like this is a move in the right direction, so let&#39;s see where it leads :)]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[80]]></guid>
				
            	</item>
			
    			<item>
				
      				<title><![CDATA[Ext to ColdFusion...Nice!]]></title>
	  				<pubDate>Sun, 21 Feb 2010 09:38:53 GMT</pubDate>
      				<link>http://singularityconcepts.com/blog.cfm?postid=<![CDATA[79]]></link>
	  				<description><![CDATA[So I know a lot of the posts I&#39;ve been writing recently have been about stuff that&#39;s been around a while--Ext helper functions, CFScript, etc. Nonetheless, I post them because some of the answers to questions I&#39;ve found in developing solutions have been less-than-easy to find, so perhaps repeating some of the same things again will help Google find it a bit easier for someone else someday.<br /><br />On with redundancy!<br /><br />Obviously, JSON-related technologies have been around for a while, and with ColdFusion 8, a lot of native JSON handling was added for the creation of some sweet AJAX-y goodness.&nbsp; While I&#39;ve dabbled with these, I&#39;ve never really had a need for them...until now.<br /><br />I recently developed a remote CFC function that required about 12 different arguments.&nbsp; On the client side, I also developed a quick EXT Ajax.request() method to pass these arguments into the CFC function. &nbsp;<br /><br />Now with Ext, it&#39;s incredibly simple to pass arguments to server-side functions, as this example illustrates:<br /><br /><pre>Ext.Ajax.request({<br />&nbsp;&nbsp; &nbsp;url: &#39;com/functions.cfc&#39;,<br />&nbsp;&nbsp; &nbsp;success: successMethod,<br />&nbsp;&nbsp; &nbsp;failure: errorMethod,<br />&nbsp;&nbsp; &nbsp;headers: {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded; charset=UTF-8&quot;<br />&nbsp;&nbsp; &nbsp;},<br />&nbsp;&nbsp; &nbsp;params: {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;method: &nbsp;&nbsp; &nbsp;&#39;setupLife&#39;,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;argument1: &nbsp;&nbsp; &nbsp;arg1,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;argument2:&nbsp;&nbsp; &nbsp;arg2,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;...<br />&nbsp;&nbsp; &nbsp;}<br />});</pre><br /><br />I like this alot, because it allows me to treat each argument as its own &quot;thing,&quot; rather than stringing together a bunch of &quot;&amp;argument1=arg1&quot; in the query string. &nbsp;<br /><br />But what if want to treat several arguments as a group?&nbsp; For example, there are several times where I create arrays or objects in JavaScript, and then want to use the values in these arrays or objects as arguments for my remote function.&nbsp; Like this:<br /><br /><pre>var person = new Object();<br />person.name = &#39;Joel&#39;;<br />person.hobby = &#39;Philosophy&#39;;<br />person.favband = &#39;Emery&#39;;</pre><br /><br /><br />If I were to pass individual arguments, I&#39;d have to break out each of these properties and assign them to arguments--lots of duplicated work, and it sorta breaks the natural relationship these arguments had to each other natively as a JS object.<br /><br />Fortunately, EXT and CF together make this super easy.<br /><br />First, the EXT side. Instead of breaking out my &quot;person&quot; properties into indivdual arguments, I can use the handy JSON-encoding capabilities of EXT to treat this object as what it is--a collection of related properities:<br /><br /><pre>Ext.Ajax.request({<br />&nbsp;&nbsp; &nbsp;url: &#39;com/functions.cfc&#39;,<br />&nbsp;&nbsp; &nbsp;params: {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;method: &nbsp;&nbsp; &nbsp;&#39;setupLife&#39;,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;argument1: &nbsp;&nbsp; &nbsp;arg1,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;argument2:&nbsp;&nbsp; &nbsp;arg2,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;...<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;person:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Ext.encode(person);<br />&nbsp;&nbsp; &nbsp;}<br />});</pre><br /><br />As you can see, by JSON-encoding the object I already created in JS, I can treat the full object as an object, and pass it as a single argument to my remote function.<br /><br />What is super cool about this, however, is what happens on the CF side.&nbsp; Because I&#39;m passing my person object as an object, I can now retrieve the object with CF and treat it as an object within CF.<br /><br />Here&#39;s my function:<br /><br /><pre>&lt;cffunction name=&quot;setupLife&quot; access=&quot;remote&quot;&gt;<br />&nbsp;&nbsp; &nbsp;...<br />&nbsp;&nbsp; &nbsp;&lt;cfargument name=&quot;person&quot; required=&quot;yes&quot; /&gt;<br />&nbsp;&nbsp; &nbsp;&lt;cfset PlayerArray = deserializeJSON(arguments.players) /&gt;<br />&nbsp;&nbsp; &nbsp;...<br />&lt;/cffunction&gt;&nbsp;&nbsp; &nbsp;</pre><br /><br />This function requires the &quot;person&quot; argument, which you&#39;ll remember is what we JSON-encoded on the JS side of things.&nbsp; Now that we&#39;ve retrieved the argument, we can use CF&#39;s deserializeJSON() function to transform the JSON object which is passed as an argument and convert it to a CF structure. &nbsp;<br /><br />The super-sweet part about this is that once we run this function, the JSON object will become a ColdFusion structure, and we can do whatever super-bad juju we want to do with it, not having to worry about what format it came to our function in.&nbsp; Awesome.<br /><br />So that&#39;s it.&nbsp; With Ext and CF, you can do some really nice things very easily, and don&#39;t really have to worry a whole lot about messing around with data conversion between the client and server. ]]></description>
      				<guid>http://singularityconcepts.com/index.cfm?postid=<![CDATA[79]]></guid>
				
            	</item>
			
            </channel>
		</rss>
