Object-Relational Mapping (or ORM), is a programming technique that links databases to object-oriented language concepts, creating (in effect) a “virtual object database.” There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to code their own object-relational mapping for their systems.

In object-oriented programming, programming objects represent real-world objects. To illustrate, consider the example of an address book, which contains listings of people along with zero or more phone numbers and zero or more addresses. In object-oriented terms this would be represented by a “person object” with “slots” (fields, members, instance variables etc.) to hold the data that make up this listing: the person’s name, a list (or array) of phone numbers, and a list of addresses.

The crux of the problem is in translating those objects to forms which can be stored in files or databases, and which can later be retrieved easily while preserving the properties of the objects and their relationships; these objects can then be said to be persistent.

Object-Relational systems attempt to solve this problem by providing libraries of classes which are able to do this mapping automatically. Given a list of tables in the database, and objects in the program, they will automatically map requests from one to the other. Asking a person object for its phone numbers will result in the proper query being created and sent, and the results being “magically” translated directly into phone number objects inside the program.

From a programmer’s perspective, the system looks like a persistent object store. One can create objects and work with them as one would normally, and they automatically end up in the relational database.

A number of ORM frameworks have been created for ColdFusion:

Reactor

Reactor, created by Doug Hughes of Alagad fame, is a very simple API for ColdFusion which generates and instantiates database abstraction CFCs on the fly as needed.

http://www.doughughes.net/

Arf!

Active Record Factory (Arf!) is a Rails-style ActiveRecord implementation in ColdFusion.

Below is a list of the basics that Arf! provides:

  • JDBC metadata based reflection: not database specific
  • Creates ActiveRecord API‘d instances out of CFCs that extend a base ActiveRecord component
  • Implements hasMany() and belongsTo() methods for establishing Record properties that point to other tables
  • Allows for overloading any of the automagically generated methods to add custom business logic
  • Automagic methods on Records include GetInstance(), Create(), Read(), Update(), Delete(), Save() [smart create/update], List(orderBy, whereClause), Validate() [does type and length checking], and SetNNN()/GetNNN() methods for each DB column

http://www.clearsoftware.net/

objectBreeze

Developed by Nicholas Tunney, objectBreeze is an ORM tool that allows you to interact with your data persistence layer and easily model objects within your ColdFusion applications. With no setup, objectBreeze will instantly create objects directly from your database schema. objectBreeze requires that your table has -a- primary key defined. Currently, objectBreeze works with Microsoft SQL, Oracle, MySQL and PostgreSQL, but other versions are on the way.

http://www.objectbreeze.com/ob/

cfcPowerTools

Batch generation of your data layer objects in minutes.

http://cfcpowertools.com/

Transfer

Transfer was built out of a need to speed up the development process that is normally slowed down by the development of Business Objects and Data Access Objects.

Transfer does this through a series of methods, including SQL generation and CFML code generation, that all occur during the run-time process.

All this is configured through a XML file, that maps your object generation back to the tables and columns in your database.

http://www.compoundtheory.com/

What is AJAX?

Asynchronous JavaScript and XML. It’s a whole new way of looking at the web where HTML page makes asynchronous calls to the server using JavaScript and loads the data in bits and pieces as needed. Ajax is not a new technology. It’s a new developing approach, based on the following existing technologies:

  • XHTML and CSS for standard presentation,
  • DOM (Document Object Model) for dynamic and interactive presentation,
  • XML and XSLT for data exchange and manipulation, and
  • XMLHttpRequest for asynchronous data retrieval

The term “AJAX” was first muted by Jesse James Garrett of AdaptivePath and has become synonymous with the ideas and concepts of Web 2.0. Ajax has been popularised by the likes of Google in their Gmail and Google Suggest applications, Flickr and del.icio.us, now both owned by Yahoo!.

Below I have listed a few of the frameworks available to the ColdFusion community. I will leave it up to you to decide which one is the best and easiest to implement. Please tell me your experiences.

AjaxCFC

AjaxCFC, created by Rob Gonda, is a ColdFusion framework meant to speed up Ajax application development and deployment by providing developers seamless integration between JavaScript and ColdFusion, and providing built-in functions, such as security and debugging, to quickly adapt to any type of environment and helping to overcome cross-browser compatibility problems.

  • ColdFusion components following the best practices of object oriented programming and design patterns. Programming with ajaxCFC involves extending components and creating your own ajax façades.
  • Intergration with Model-Glue, one of the most popular MVC frameworks widely used by the ColdFusion community.
  • Works with ColdFusion MX 6.0, 6,1, 7.0 and Blue Dragon.
  • Automatically handles complex object transmitted from the client to the server and vice versa.
  • Server returns pure JavaScript code to the callback handler (instead of XML or JSON) to vastly improve performance.
  • On-the-works: Built-in base64 and/or blowfish encryption.
  • Licensed under the Apache License Version 2.0, by Rob Gonda.

The project can be downloaded from Rob Gonda’s website at the following address: http://www.robgonda.com/blog/projects/ajaxcfc/

JSMX

JSMX is a simple API available for connecting your Web Applications to an AJAX front end. The main difference between JSMX and other AJAX implementations is that JSMX allows you to pass either XML or JavaScript to the API. JSMX was originally created to be used with ColdFusion applications because of how easy it is to create JavaScript Strings natively within ColdFusion (using either the CFWDDX tag or the ToScript() function). However, because there is no server-side component to be installed, JSMX can really be used with any programming language.

  • Using the CFWDDX tag, or the toScript() function, within ColdFusion makes converting your ColdFusion Objects to JavaScript a SNAP!
  • Smaller Packet Sizes over the wire (JavaScript Vs. XML).
  • Reduced latency due to less parsing of the responses.
  • Parameters can be sent to the server in multiple formats including, strings, objects, and entire forms without having to build extra logic to handle each type.
  • API has no Server Side components which makes it more portable.
  • Extremely simple syntax shortens the learning curve and speeds up development.
  • Open-source (Creative Commons Attribution-ShareAlike License).

JSMX is the creation of Todd Kingham at LaLaBird.com and can be downloaded from the following link: http://www.lalabird.com/?fa=JSMX.downloads

CFAjax

CFAjax is the AJAX implementation for coldfusion. It makes ColdFusion method calls on server directly from HTML page using JavaScript and return backs the result to the calling HTML page. CFAjax comes with simple to use JavaScript API and simple ColdFusion implementation that marshal’s the response between your ColdFusion methods and HTML page. Using CFAjax you can create highly interactive websites with greater performance and usability.

CFAjax can be downloaded at the following link: http://www.indiankey.com/cfajax/project.asp

SAJAX for ColdFusion

Sajax is an open source tool to make programming websites using the Ajax framework — also known as XMLHTTPRequest or remote scripting — as easy as possible. Sajax makes it easy to call PHP, Perl or Python functions from your webpages via JavaScript without performing a browser refresh. The toolkit does 99% of the work for you so you have no excuse to not use it.

Sajax for ColdFusion is the creation of Steve Smith at Ordered List and can be downloaded from the following link: http://www.orderedlist.com/downloads/SAJAX_ColdFusion.zip

With the introduction of ColdFusion MX, the ColdFusion community is maturing. Most CF developers have moved beyond spaghetti code and the mixing of business logic with presentation code. But it can be difficult and wasteful to “re-invent the wheel” for every application you write.

Frameworks can help promote good development practices, standards, and a sound foundation for creating an application.

In this article I list a number of these frameworks, but I will leave you to compare them, and decide which you may want to adopt.

Fusebox

An Historically Strong Framework

Fusebox is a popular framework for building ColdFusion and PHP web applications. “Fuseboxers” find that the framework releases them from much of the drudgery of writing applications and enables them to focus their efforts on creating great, customer-focused software.

Fusebox provides a small set of ‘core’ files and large amount of structure which is helpful to developers. It emphasizes separation of presentation from logic and uses a readily understandable vocabulary for modeling websites, namely circuits, fuses and switches.

http://www.fusebox.org

Mach-II

Mach II is a web-application framework developed by Hal Helms and Ben Edwards that evolved out of a desire to create a framework that specifically addressed maintenance issues using an OO style. Mach II is based on an Implicit Invocation Architecture and directly supports the MVC design pattern.

http://www.mach-ii.com

Model-Glue

Model-Glue helps you build Object-Oriented ColdFusion applications based on the Model View Controller pattern. It’s designed to be easy to use and play well with others, like Tartan.

http://www.model-glue.com

onTap

The onTap framework is an Open Source Framework for quickly developing powerful web applications using Adobe’s ColdFusion application server. The framework itself bears a marked resemblance to the recently buzzy Ruby on Rails.

http://www.fusiontap.com

TheHUB

TheHUB, like other application development frameworks, utilizes the notion of a central hub template that all requests for the application pass through. That cental hub is the point or place within the application that the processing of all code hinges upon. The code simply checks for a query string and then reads the parameters passed to handle template loading and screen rendering.

http://www.codesweeper.com

Tartan

Tartan is a command-driven service framework for ColdFusion. It was built to help produce the service layer within a larger application architecture which relies on strict separation or layering of functionality.

All access to the underlying business logic is controlled by public services which are available locally as CFCs and remotly via Flash Remoting and SOAP web services. A service can be composed of any number of commands, each of which implements a discreet operation within the application. These contain the core logic for the application. Commands can communicate with databases via DAOs, manipulate values received from the client, execute other commands and even communicate with services available on other remote servers.

At the center of Tartan are 6 Core classes : LocalServiceProxy, LocalService, Command, DAO, ValueObject and ExceptionHandler. They provide most of the functionality of the framework, and must be extended by the application developer.

http://www.tartanframework.org

ColdSpring

ColdSpring is a framework for CFCs (ColdFusion Components).

ColdSpring’s core focus is to make the configuration and dependencies of your CFCs easier to manage. ColdSpring uses the “inversion-of-control” pattern to “wire” your CFCs together. Inversion-of-control provides many advantages over traditional approaches to assembling your application’s model. Also part of ColdSpring is the first Aspect-Oriented-Programming (AOP) framework for CFCs.

http://www.coldspringframework.org

UPDATE: Since creating this blog post many years ago, two more frameworks have been released that require an honourable mention.

ColdBox

My New Framework of Choice

ColdBox is an event-driven conventions based ColdFusion Framework. It provides you with a set of reusable code and tools that you can use to increase your productivity, and it provides you with a development standard when working in a team environment. It makes use of an MVC (Model View Controller) design pattern and an extensive array of patterns for its operations such as Factories, Helpers, Workers, etc. And since it is based on CFCs it does not rely on an XML dialect.

NB. ColdBox also takes advantage of ColdSpring or Lightwire.

http://www.coldboxframework.com

Lightwire

Lightwire is a very lightweight Direct Injection (DI)/Inversion of Control (IoC) engine for directly injecting dependencies into singletons and transient business object. The framework is optimised to create transient objects as well as singletons and allows for programmatic as well as XML configuration. It is the lightweight framework for people who’d like to put more logic in their beans and less in their service layer.

http://lightwire.riaforge.org

The onTap framework is an Open Source Framework for quickly developing powerful web applications using Macromedia’s ColdFusion application server. The framework itself bears a marked resemblance to the recently buzzy Ruby on Rails.

The onTap Framework can be downloaded at the following url:

http://www.fergusonhouse.com/?netaction=download

Application developers face a daunting task: they must translate the often fuzzily-defined requirements for a new application into the rigid language of computers. While the Fusebox Lifecycle Process (FLiP) offers help in managing the project management aspects of creating a new application, what help is there available to developers approaching the technical challenges of creating and maintaining applications?

Application frameworks answer this question, offering pre-built (and pre-tested) code — a collection of services that can provide the architectural underpinnings for a particular type of application. Web-based applications are increasingly the choice for new application development in which the browser becomes the “universal client”. As web development matures, web-based application frameworks allow the developer to concentrate more on meeting the business needs of the application and less on the “plumbing” needed to make that application work.

Fusebox is, by far, the most popular and mature web framework available for ColdFusion and PHP developers. The architecture of a Fusebox application is divided into various sections (”circuits” in Fusebox parlance), each of which has a particular focus. For example, the responsiblity for ensuring that only authorized users have access to all or part of the application might fall under a Security circuit.

The Fusebox application architect defines these circuits, as well as the individual actions (”fuseactions”) that may be requested of it. When a fuseaction request is made of the application, the Fusebox machinery (the “Fusebox”) routes the request to the appropriate circuit, where the fuseaction is processed. This idea of encapsulation of responsibilities makes it easy for different functional circuits to be “plugged” into an application, making it possible to reuse code.

Within the individual circuit responsible for carrying out the requested fuseaction, the Fusebox architect specifies the individual files (”fuses”) needed to fulfill the fuseaction request. Thus, the Fusebox acts like a good manager, delegating tasks to appropriate departments where it is decomposed into individual tasks, each of which can be assigned to individuals to carry out.

Mach-II is a web-application framework focused on easing software development and maintenance developed by Hal Helms and Ben Edwards.

http://www.mach-ii.com

Model-Glue is:

  • An Implicit Invocation framework simplifying use of the Model View Controller design pattern in ColdFusion applications. It’s designed to be easy to use and play well with others, like Tartan.
  • Released under the Lesser GPL, meaning that it’s free to download, use, and alter.
  • A framework encouraging clear seperation of Model, View, and Controller
  • Lightweight enough to play well with others: it comes with out-of-the-box connectors to Paul Kenney’s Tartan Framework.
  • Akin to Mach-II, another II, MVC framework, but with slightly simpler functionality, and more clearly defined boundaries between Model and Controller.
  • Written by Joe Rinehart, a quasi-popular ColdFusion blogger with an interest in developing better OO applications in ColdFusion, with constant feedback provided by Doug Hughes of Alagad, Inc.

TheHUB, like other application development frameworks, utilizes the notion of a central hub template that all requests for the application pass through. That cental hub is the point or place within the application that the processing of all code hinges upon. The code simply checks for a query string and then reads the parameters passed to handle template loading and screen rendering.

The concept is that each request passes a unique set of keys that relate one-to-one with a site or application directory and template within the named directory. In applications and websites that utilize TheHUB, the query string looks like “?dsp=the_hub…”. This indicates to the “framework hub” template… the “index.cfm” that it should include the “the_hub.cfm” template from the “dsp” directory.

Download the code at this url http://www.codesweeper.com/index.cfm?code=main

Tartan is a command-driven service framework for ColdFusion. It was built to help produce the service layer within a larger application architecture which relies on strict separation or layering of functionality.

All access to the underlying business logic is controlled by public services which are available locally as CFCs and remotely via Flash Remoting and SOAP web services. A service can be composed of any number of commands, each of which implements a discreet operation within the application. These contain the core logic for the application. Commands can communicate with databases via DAOs, manipulate values received from the client, execute other commands and even communicate with services available on other remote servers.

At the center of Tartan are 6 Core classes : LocalServiceProxy, LocalService, Command, DAO, ValueObject and ExceptionHandler. They provide most of the functionality of the framework, and must be extended by the application developer.

Overview and Explanation

The driving need behind Tartan was a production application that needed to transfer data between 5 different databases and 3 different applications. There was a complex set of DAO classes and a faade class that provided access. Each fa ade class had a single public method called “execute” that would simply take arguments and return a result.

This concept worked well, but obviously had its limitations. So Tartan was created to be able to quickly and easily add new commands to services, and new services to the system.

Tartan is described as a “command-driven service framework.” What does that mean? In this context a “service” is a set of commands that have commonality, and a “command” is a method that executes any number of other methods and returns a result. It’s that simple. A service such as “televisionViewer” could include a command such as “getListings” which would, based on locality data provided either by a config file or a method argument, check local listings and return a collection of data regarding current television listings.

To further explain the concept of “commands,” we could offer that method a second argument such as “returnType” and return the listings as an array of structures, a CF query object, or an XML file. By adding commands from granular to broad, we can incorporate them into sequences. For instance, if we wanted to offer the findMyShow command, we could have it first execute getListings, then parse the resulting data and determine if our show is on soon or not.

By doing this carefully and with some planning, we develop a very simple interface between our application and any persistant storage mechanism and/or business objects, with the ability to filter, alter, or convert our results before they’re returned to the caller. If we start with granular and move to broad commands, we maintain the flexibility and encapsulation of an OO design, but gain the convenience and natural-thinking appeal of procedural programming.