I just got out of a session with Jason Delmore talking about some of the new features being looked at in ColdFusion 9. He mostly talked about the ORM features being baked into the next version of ColdFusion courtesy of Hibernate. We also squeezed a few other tidbits of information out of him too.Right off the bat, I should put out the disclaimer that everything here is subject to change as Centaur proceeds into public beta and Adobe continues to develop it. ORM stands for Object Relational Mapping and is a layer of your application which handles all database access for you in a DBMS-agnostic way that allows you to access your data directly as business objects without having to write any SQL. It is configured to specify what tables map to what objects and how each object relates to the other objects. Main benefits of ORM include:
  • DB Independence
  • No more CRUD or SQL
  • Automatic ORM session creation and management

ORM via Hibernate

Java Hibernate is being built into ColdFusion which isn't new news, but today we finally saw some sample code up close to see how it will work.

New Application.cfc gets some new properties

When you want to use the ORM functionality in your application there some new application settings like ormenabled and ormsetting.dataource. Here is a sample Jason put on the power point. Hopefully I copied it down correctly: Application.cfc
Now if you are still using Application.cfm I can only assume there will be some additional attributes (and perhaps a sub-tag) to the cfapplication tag to capture this data.

<cfproperty /> is getting more useful

The next thing Jason showed us was an example of an art object from the artgallery Derby database that comes in CF. Notice that this CFC has nothing more than a handful of cfproperty tags. Art.cfc
[code]<cfcomponentpersistent="true" schema="app"> 
<cfproperty name="artid">
<cfproperty name="artname">
<cfproperty name="Price">
<cfproperty name="largeimage">
<cfproperty name="mediaid">
<cfproperty name="issold">
<cfproperty name="artist" fieldtype="many-to-one" column="artistid" cfc="artists" missingrowignored="true">
Notice that one of the property tag creates composition by defining an artist property with a many-to-on relationship to our art object. Additional attributes in the cfproperty tag include fieldtype, column, cfc, and missingrowignored. These tags roughly equivocate to the Hibernate configuration XML. One of the main points Jason made over and over was that they were taking special care NOT to disable or hide any of Hibernate's built-in features. This is a pretty common approach by Adobe--try to make the most common use cases turn-key easy, but allow access to all the underlying goodies so you can always dive deeper.

New functions implemented

Here is a basic example Jason shows us to access an array of Art objects via our ORM layer:
[code]<cfset art.entityload("art")>

<cfloop from="1" to="#arraylen(Art)#" index="i">
Jason mentioned that the exact names of the functions Adobe implements may change over time. As you can see, the entityload() function created the array of art objects. With lazy loading enabled only the records used will be fetched from the database. Here are some additional functions I saw as Jason scrolled through the code:
Art = entityloadbypk("art",url.artid);
Ormexecutequery () // takes hql returns objects
Another thing worth mentioning is the automatic tracking of dirty data. This means that when you go to save data, only the data you changed gets saved the to the database. Also, there is the option of having Hibernate via CF9 automatically add and remove columns from your database when you add or remove properties in your objects. I don't know how I feel about that one. I like the idea of only making your changes in one place, but I'd rather have my database be the source of those changes as opposed to my ORM modifying my database. Thoughts? Another common thing you find yourself doing a lot with objects, is taking a collection of form or URL fields and calling a bunch of setters to get that data into an object. ColdFusion 9 will likely contain a way to simply pass a struct into an object and have everything populated for you. Obviously, this would rely on some consistency in your naming conventions.

Implicit getters and setters

If you were paying attention to the previous code, you would have noticed that we accessed a getartname() and getprice() method which were not actually defined in our art.cfc component. This is the implicit getters and setters that have been talked about. We asked Jason if they planned to also allow for the ActionScript/Ruby behavior of appearing to directly access a property, but actually calling a public getter/setter. Rupesh said they have thought about it but haven't decided. I think Sean Corfield is going to bug them about it.

New CF IDE: Bolt

Jason was using the new CF IDE, Bolt for his presentation which is built on Eclipse. They said that, like Flex Builder, it will be available as both a stand-alone install as well as an Eclipse plug-in. A couple of features he showed us are the auto-creation of CFCs for you similar to code generators like Illudium. He stressed that Bolt's code generation is template based so you can configure services or beans specific to your application's needs. You can right click on a database table (DB information is available within the Bolt IDE) and ask it to create the CFCs for you. You can also generate hibernate mapping files. Also along the lines of Hibernate is HQL syntax highlight. HQL is a Hibernate DSL that allows you to query your database with a query language which is not specific to any particular database. (MySQL, MSSQL, Access, etc.)

Object instantiation Penalty and cfscript

Another notable thing that came up during the demo was when I asked Jason if we needed to worry about the overhead of object creation in CF 9--especially since his ORM examples were returning arrays of objects. He basically said that they did in fact have performance enhancements planned for it. That's about as far as he went, but I am anxious to see what results we get. I also pressed him on the cfscript enhancements since they are adding support for ColdFusion components written entirely in cfscript, yet there is no way to duplicate the cfproperty tag in cfscript. Jason said that they will be adding some properties to cfscript that you can specify in the same way that Java works. This means all of the ORM configuration will also be able to be leveraged in pure cfscript components.

Baked-in Caching in CF9?

While we are on the topic of new features on CF 9, this is NOT something Jason talked about, but it is a juicy tidbit I came across in the possible feature category. ColdFusion 9 may have a built-in caching mechanism such as memcahed or Ehcache. Nothing is confirmed, but I'll point out that Ehcache is written in Java... And in closing, I give you Jason's final slide which clearly shows that Bentuar + Hibernate = Happy Developers: