Whatterz


ColdFusion ORM Frameworks & Tools

by Simon. Average Reading Time: almost 3 minutes.

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.riaforge.org/

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/

This article has been tagged

, , , , , , , , , , , , , , , , , , , , , , , , ,

Other articles I recommend

The Law of Demeter

The Law of Demeter (LoD), or Principle of Least Knowledge, is a design guideline for developing software applications, particularly object-oriented programs. The guideline can be succinctly summarised as “Only talk to your immediate friends.” The fundamental notion is that a given object should assume as little as possible about the structure or properties of anything else, including its sub-components.

The Java Behind a ColdFusion Array and Structure

Following a conversation with a friend regarding how ColdFusion handles arrays and structures in ‘the background’, I was interested to find out what Java classes each were mapped to. This was a relatively simple case of using the functions getClass(), getSuperClass() and getName() to parse out the name of the Java classes.

Coldfusion AJAX Frameworks

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, CSS, DOM, XML, XSLT and XMLHttpRequest.

  • Chris S

    These would certainly improve code readability by getting ride of SQL, but how would it impact performance? What’s the overhead involved?

  • http://www.simonwhatley.co.uk Simon

    I personally don’t like to use ORM frameworks as I prefer to hand-code my objects and queries, the latter of which I prefer to remove from the ColdFusion layer and create as stored procedures. This technique greatly improves ColdFusion and the network’s performance.

    I can see the case for using ORM frameworks for rapid application development, but sometimes building an application too rapidly has detrimental impact upon the performance of that system, as little thought is put into design.

  • http://www.fusionteam.co.uk Neil S

    Simon,

    I quite agree with you. If you cna go down the stored procs route, then you will notice a great performance increase. I think using ORM is a nice concept, but does not give you that flexibility of your own CFC’s and business processes that can sometimes be imposed on a developer!

  • viewer

    http://cfcpowertools.com/ is not the exact link