My Projects
Search Blog

Categories
Archives
Photo Albums
RSS

Powered by
BlogCFM v1.15

07 March 2008
Value Object Generator

I wrote a little CFM file to generate actionscript classes for value objects from coldfusion queries.  It uses getMetaData() on the query to determine data types for the VO.  I've only coded in some simple datatypes in the getColType() method to handle the conversion from the dbtype to actionscript data type - you can add whatever you need.

<cfsetting enablecfoutputonly="yes">
<cfset voName = "EntityLogVO">
<cfset voPackage = "model.vo">
<cfset remoteClass = "cfcs.enquire.vo.#voName#">

<cfquery name="qry" datasource="ENQUIRE" maxrows="1">
 select
  A.QUERYID, A.USERID, A.QUERYDATE, A.INSTANCE,
  A.TITLE, A.SAVED, A.LASTRUNDATE,
  A.CRITERIA
 from dbo.DROP_QUERIES A
 where
  A.USERID=<cfqueryparam cfsqltype="cf_sql_char" value="ADSRJR">
  AND A.SAVED=<cfqueryparam cfsqltype="cf_sql_smallint" value="1">
 order by
  A.QUERYDATE desc
</cfquery>

 

<cffunction name="getColType" output="false" returnType="string">
 <cfargument type="string" name="coltypename" required="yes">
 
 <cfset coltypename = listfirst(coltypename, " ")>
 <cfif coltypename contains "char">
  <cfreturn "String">
 <cfelseif coltypename contains "int">
  <cfreturn "int">
 <cfelseif coltypename contains "date">
  <cfreturn "Date">
 <cfelseif coltypename contains "text">
  <cfreturn "String">
 <cfelseif coltypename contains "float">
  <cfreturn "Number">
 <cfelseif coltypename contains "double">
  <cfreturn "Number">
 <cfelse>
  <cfthrow message="Unhandled Database Type" detail="the database type #coltypename# is not handled.">
 </cfif>
</cffunction>

<cfoutput><pre>
/////////////////////////////////////////////////////
// #voName#.as
//
// generated by voGenerator.cfm (Rick Root)
// generated on #dateFormat(Now(),'yyyy-mm-dd')# at #TimeFormat(Now(),'h:mm tt')#
//
//
/////////////////////////////////////////////////////

package #voPackage#
{
 [RemoteClass(alias="#remoteClass#")]
 public class #voName#
 {
</cfoutput>
<cfset metadata = getMetaData(qry)>
<cfloop from="1" to="#ArrayLen(metadata)#" step="1" index="x">
 <cfoutput>  private var _#metadata[x].Name#: #getColType(metadata[x].TypeName)#;#chr(10)#</cfoutput>
</cfloop>

<cfloop from="1" to="#ArrayLen(metadata)#" step="1" index="x">
 <cfoutput>
  public function get #metadata[x].Name#(): #getColType(metadata[x].TypeName)#
  {
   return _#metadata[x].Name#;
  }

  public function set #metadata[x].Name#(value:#getColType(metadata[x].TypeName)#): void
  {
   _#metadata[x].Name# = value;
  }

 </cfoutput>
</cfloop>
<cfoutput>
  public function #voName#()
  {

  }
 }
}
</pre>
</cfoutput>

 

Here is an example of the value object generated from the code above:

/////////////////////////////////////////////////////
// EntityLogVO.as
//
// generated by voGenerator.cfm (Rick Root)
// generated on 2008-03-07 at 12:40 PM
//
//
/////////////////////////////////////////////////////

package model.vo
{
 [RemoteClass(alias="cfcs.enquire.vo.EntityLogVO")]
 public class EntityLogVO
 {
  private var _QUERYID: int;
  private var _USERID: String;
  private var _QUERYDATE: Date;
  private var _INSTANCE: String;
  private var _TITLE: String;
  private var _SAVED: int;
  private var _LASTRUNDATE: Date;
  private var _CRITERIA: String;

  public function get QUERYID(): int
  {
   return _QUERYID;
  }

  public function set QUERYID(value:int): void
  {
   _QUERYID = value;
  }

 
  public function get USERID(): String
  {
   return _USERID;
  }

  public function set USERID(value:String): void
  {
   _USERID = value;
  }

 
  public function get QUERYDATE(): Date
  {
   return _QUERYDATE;
  }

  public function set QUERYDATE(value:Date): void
  {
   _QUERYDATE = value;
  }

 
  public function get INSTANCE(): String
  {
   return _INSTANCE;
  }

  public function set INSTANCE(value:String): void
  {
   _INSTANCE = value;
  }

 
  public function get TITLE(): String
  {
   return _TITLE;
  }

  public function set TITLE(value:String): void
  {
   _TITLE = value;
  }

 
  public function get SAVED(): int
  {
   return _SAVED;
  }

  public function set SAVED(value:int): void
  {
   _SAVED = value;
  }

 
  public function get LASTRUNDATE(): Date
  {
   return _LASTRUNDATE;
  }

  public function set LASTRUNDATE(value:Date): void
  {
   _LASTRUNDATE = value;
  }

 
  public function get CRITERIA(): String
  {
   return _CRITERIA;
  }

  public function set CRITERIA(value:String): void
  {
   _CRITERIA = value;
  }

 
  public function EntityLogVO()
  {

  }
 }
}

 

 

Posted by rickroot at 10:11 AM | Link | 0 comments
15 August 2007
AIR Url - Adobe AIR Project

The Adobe on AIR bus tour is stopping by the Raleigh area on Saturday, courtesy of TACFUG and RDAUG, and they're having a contest.  Best AIR app wins a prize!

Well, my url shortener app may not be the best, but if I'm lucky, it'll be the only app submitted.

I've recompiled the URL shortener app as an AIR app (I built it when it was still called Apollo), and you can get it here:

Here's the source code:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
 xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute"
 width="400" height="68"
 creationComplete="init()">
<mx:Script>
 <![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.Fault;
import mx.controls.Alert;

import mx.utils.StringUtil;

private function init():void {
 txtLongUrl.setFocus();
}
private function genericFault(e:FaultEvent):void
{
 txtShortUrl.text = e.fault.faultString;
 btnTryIt.enabled = false;
}
private function tryUrl(url:String):void {
 navigateToURL(new URLRequest(url), '_blank');
}
private function addUrlResult(e:ResultEvent):void {
 txtLongUrl.text = '';
 txtShortUrl.text = e.result.toString();
 if (e.result.toString() != 'Invalid Source URL!') {
  btnTryIt.enabled = true;
 }
}
 ]]>
</mx:Script>
 <mx:WebService id="ro" wsdl="http://url.rickroot.com/url.cfc?wsdl" showBusyCursor="true">
  <mx:operation name="addUrl" fault="genericFault(event)" result="addUrlResult(event)"/>
 </mx:WebService>
 <mx:VBox x="10" y="10">
  <mx:HBox>
   <mx:Label text="Url to Shorten:" width="100" fontWeight="bold"/>
   <mx:TextInput id="txtLongUrl" width="200"/>
   <mx:Button id="btnDoIt" label="Do It!" click="txtShortUrl.text = ''; ro.addUrl(txtLongUrl.text);"/>
  </mx:HBox>
  <mx:HBox>
   <mx:Label text="Results:" width="100" fontWeight="bold"/>
   <mx:TextInput id="txtShortUrl" width="200"/>
   <mx:Button id="btnTryIt" label="Try It!" click="tryUrl(txtShortUrl.text);" enabled="false"/>
  </mx:HBox>
 </mx:VBox> 
</mx:WindowedApplication>

 

 

Posted by rickroot at 9:06 AM | Link | 0 comments
31 May 2007
ImageCFC 2.16 Now Available

ImageCFC Project Page:  http://www.opensourcecf.com/imagecfc/

I released ImageCFC 2.15 yesterday without testing it.

Today, I released ImageCFC 2.16 *AFTER* testing it.  Not heavily, but I did run at least one test of every method.  I also included my simple test file, "test-cases.cfm"

If you haven't gotten ImageCFC lately, you should definately update!  If you're using a recent version of ImageCFC, you should be able to just drop the code in place without changing YOUR code.  ImageCFC 2.15 and 2.16 only included changes to the main "image.cfc" file.

See the CHANGELOG for details.

Posted by rickroot at 8:48 AM | Link | 1 comment
11 May 2007
My First Apollo Application

okay, it's really my second apollo application.  But it seemed silly for my first apollo blog entry here to say "My second apollo application" when I never mentioned the first one.  Plus, the first one is really an internal app for my job that serves no purpose outside my department.

Anyway, if you participate in a lot of mailing lists, then you probably use tinyurl a lot.  Need a shorten a URL, load up www.tinyurl.com, paste in your url, and submit.  It returns a nice "tiny url" for you.

Well now you can have a little flex app running all the time called "My Url Shortener" that does the same thing, without having to launch a browser.  Just keep it running.. put it in your startup or something like that. 

To run this application, you'll first need to install the Apollo Runtime from Adobe, then get the MyUrlShortener installer and run it.

If you'd like the source, which includes the mxml, cfc, and cfm files, along with a README.TXT, the LICENCE.TXT, the air file, and a sample virtual host entry from httpd.conf using mod_rewrite, you should download MyUrlShortner.zip.

Posted by rickroot at 2:37 PM | Link | 0 comments
08 May 2007
Smith Project - Open Source Coldfusion Server

The Smith Project, another alternative CFML server, announced yesterday that they've gone to an open source license.

From their web site:

07-May-2007

Smith goes open-source.

After the very positive feedback from the ColdFusion® Developer Community, youngculture decided to open source its ColdFusion® Server "Smith". Till the end of April Smith Application Server has been downloaded more than 6'000 times.

Developers are welcome to join the project. The project is published under the GPL Licence and will be run and maintained by the newly founded Smith Open Source Software Association (SOSSA).

I haven't tried Smith yet, but it looks promising.

Posted by rickroot at 6:14 AM | Link | 6 comments