Notes: Improved Flash Remoting and Adobe AIR Integration in ColdFusion 9

These notes are taken at Adobe MAX 2009.

You can use HTTPService, WebService, RemoteObject components in Flex to pull data in different ways. Now what about ColdFusion 9?

ColdFusion’s Flash Remoting has been improved. So Flash applications that have ColdFusion 9 as a backend will interact much faster, and it can handle circular references.

There is now direct data translation between ActionScript and CF types, instead of previously having an intermediate Java layer that handled this. This involves changes in services-config.xml, but no code changes are required in your apps. Support for the old style remoting is still present for backward compatibility.

So how much faster is it? Drastically faster. Easily x9 faster, and that increases as the number of transactions occurs, according to the whitepaper Adobe has released about it.

BlazeDS. ColdFusion 9 is now integrated with BlazeDS as the default installation.

Configuration File. Services-Config.xml is now split into 4 files. There are a handful of ColdFusion-specific properties under the channel definition now. An “enable-small-messages” property is there and should be set to “false”. This is important for the new Flash Remoting in CF9, because BlazeDS’s default is “true”.

There is an AMFChannel component in Flex for the new Flash Remoting (Note: You can alternatively tell the AMFChannel component to have enableSmallMessages=”false”). Finally, the endpoint class is changed for the new CF9 one.

Offline AIR apps with ColdFusion 9

Now the fun stuff. ColdFusion 9 has an ORM for AIR! Build offline AIR apps without the SQL mess and conflict handling. There is a CF-AIR persistent framework for SQLite on the client side. CF keeps track of all updates to local database and synchronizes with the server, including conflict resolution.

By having ORM on the client- and server-side, these two are integrated through the CF-AIR persistent framework.

In the application code for the demo, there were customer.cfc and address.cfc persistent objects. Then a sync CFC is used for providing the fetch and sync functions for communication with the AIR client.

Step #1: Create the persistent CFCs.

Step #2: Create the sync CFC. He called it custmgr.cfc. The CFC has implements=”ISyncManager” as an attribute. Then you have fetch() and sync() methods that handle the transactions. Here you can provide your logic for handling certain scenarios, such as conflicts.

Step #3: On client side, create equivalent AS classes that map to the CFC via the [RemoteClass(alias=”")] metadata tag.

Step #4: Use the CF-built AIR libraries provided to fetch data from server, with the SyncManager component. It’s very simple, practically just point it to the sync CFC and do a fetch() method. To work with the database, you then openSession() and can create new AS objects and call save() on the session to insert/update/etc. Finally, using commit() will commit the results and invoke the sync() process.

On the client side, it can receive conflict notification and receive both versions of the data so that you can decide what to do with the conflict.

It is very exciting to have some help implementing synchronization without having to purchase LCDS. Using the CF9/AIR integration libraries will be very nice.

Notes: Advanced ORM in ColdFusion 9

These are notes from Adobe MAX 2009 about advanced ORM in ColdFusion 9.

Join Mapping. You can have a CFC whose primary table is “Person”, but it has properties that fetch values from a joined table, such as the “City” property from an “Address” table. Interesting.

ORM Initialization. When application first starts, it looks to see if ORM is enabled. If so, it creates/loads the Hibernate configuration, the loads Hibernate mapping files, searches for persistent CFCs (you can point it at only a particular directory to speed things up), generate Hibernate mapping for persistent CFCs, then even generate the schema on the database if it doesn’t exist, and then finally build the Hibernate Session Factory. Once this is done, it will not occur again unless you tell it to, because this initial setup is an expensive operation. You can use ormReload() to force it.

ORM Session. All ORM operations happen in the session. It provides some simple caching. The session tracks changes made to the objects. So it doesn’t actually execute SQL until a session is flushed, which happens when the request completes or when you force it with ormFlush().

When using CFTRANSACTION, the Hibernate session will be flushed and closed at the end of your CFTRANSACTION.

Object States. When you create an object with EntityNew(), CreateObject(), etc, the object is transient and is not known by Hibernate yet. Once an object is saved or loaded, it is in a persistent state. The kicker is “detached” objects. If the Hibernate session ends, and object that you have will become “detached” since the session ended. So if you have lazy loading for your object, for instance, it will throw an error because Hibernate has nowhere to lazy load the object’s data. However, you can use EntityMerge() or redo an EntityLoad() to bring it back into a persistent state.

Concurrency Control. You can use the “optimisticlock” attribute of a CFC to “All”, “Dirty”, “Version”, or “None” to control how record updates occur. “Version” is the default which uses a timestamp to check the version of the record vs. the object. “All” does a where statement of all record fields, and “Dirty” only handles the changed fields.

Fetching strategy. How will you fetch relationships of tables? “Immediate”, “Lazy”, “Eager”, or “Batch” fetching. “Immediate” fetches everything immediately. The default “Lazy” fetches things on demand. “Eager” fetching fetches everything in a single SQL statement, good for frequently used one-to-one relationships. There was a bit of confusion in regard to “Batch” fetching.

Caching. Session-level cache fetches data the first time and will not reload subsequent requests. EntityReload() will force a reload. Secondary-level cache can cache data across Hibernate sessions. It can be in-memory, disk, clustered. They have the default caching engine as EHCache.

How to use secondary cache? Enable it first. In application.cfc, use ormsettings.secondarycacheenabled=”true”. Then in your ORM CFC, the cacheuse=”" attribute defines the caching strategy (such as “read-only”, the most performant), and cachename=”" defines the name of this specific cache.

Secondary cache can also be used on relationships. And when using ormExecuteQuery() functions to use HQL to query the database, you can cache as well with cacheable=”true” as one of the options. This can be used in EntityLoad() too.

When cleaning up caches, there are ormEvictXXX() functions to remove entities, collections, and queries.

Event Handling. Hibernate lets you set ormsettings.eventhandling=”true” to have many CFC level events, like preLoad(), postLoad(), preInsert(), postInsert(), preLoad(), postLoad(), etc. This can be used for logging or other nifty features. Wow! That’s awesome. Nice hooks.

Interesting user questions. One gentleman asked about using an XML file as a datasource through Hibernate. That would be interesting to try/use.

This session could have been 90 minutes. There are a lot of advanced things that can be done with the ColdFusion integration with Hibernate from the ColdFusion API.

Notes: Managing, Monitoring, and Upgrading Your ColdFusion Servers

These are notes from Adobe MAX 2009. This is what is new in ColdFusion Administrator for ColdFusion 9.

Mail. You can sign mail with a keystore. You can view undeliverable email by clicking a button instead of browsing to the directory on the server.

Document. You can configure ColdFusion to point to an OpenOffice installation on the server. This is necessary for a lot of the document integration features in ColdFusion.

Data Collections. You can now have Verity or Solr collections. You can configure Solr in the Administrator. So ColdFusion 9 includes both Verity and Solr.

Security. Since there are ColdFusion services (CFaaS) now, you can configure which IP addresses may use your server for these services.

Server Monitor. The server monitor allows you to see how the server is using memory, which templates are running slow, the database pooling, how are template and database queries running, etc.

Server Manager. A basic AIR app that provides a way to perform administrative functions on ColdFusion server(s). It provides a nice way to manage multiple servers at once. At the CF Unconference, this became a topic of light debate on Wednesday at lunch, because there are typical 1.0 weaknesses in the interface of the server manager that make it a little bit of a pain to use. But it is a great start, and hopefully the next iteration will be a little more fine-tuned.

Migrating to CF9. Beware using these keywords: interface, pageencoding, finally, import, local. These are new CF9 keywords that will cause a conflict if your code was using them. BlazeDS now ships out of the box with CF9, which is great. LCDS Express Edition is no longer supported. It is recommended to upgrade from Verity to Solr. To do this, you’ll need to add engine=”solr” in your CFCOLLECTION tags. What’s more, the CFSEARCH tag will need some slight syntax changes when migrating to Solr! Ugh.

Notes: What’s New in ColdFusion 9

These are notes from Adobe MAX 2009. The talk was given by Adam Lehman.

First, ColdFusion 9 also introduces the new ColdFusion Builder product, an Eclipse-based IDE “to rule them all”. Because it is based on Eclipse, you can also combine other products, like Flash Builder, so that one IDE gets the job done for everything, whether it is HTML, CFML, JS, Flex, ActionScript, CSS, etc.

ColdFusion Builder also supports some interesting server integration features. You can access ColdFusion Administrator and other functionality right from ColdFusion Builder; you can see and browse all of the databases that ColdFusion has datasources for. With such functionality, you can do cool stuff like auto-generate ORM-based CFCs by pointing it to an existing database table! Now, it doesn’t generate just the bean CFC. It generates the entire service layer: DAO and Gateway beans as well!! Now, this obviously is just a starter step. It’s expected that you’d tweak it from that point. With the Flash Builder integration, you can take this to the next step by also generating ActionScript objects to help with Flex integration as well.

CFML Enhancements

Well, in CF7, they introduced Application.cfc that supported hooks for application events. But now in CF9, there is a Server.cfc with an onServerStart() method for handling that event.

Various other holes have been filled. You can now have nested CFTRANSACTION tags. Error catching now supports “finally”. And looping now supports CFCONTINUE.

Variable level enhancements: You can now pass implicit structures/arrays to tags and functions. Before you had to assign it to a var and then pass it. There is assignment chaining (a=b=c). Direct access to elements of returned arrays (i.e. myFunction()[x] couldn’t be done previously). And, finally, ternary operators! For instance, you can do something like: a = (b<c)?b:c

CFSCRIPT enhancements. Starting in CF9, you can now write 100% script-based code, including classes/components.

CFC enhancements. There is now an explicit LOCAL scope. Instead of doing var myvar=1, you can do LOCAL.myvar=1. What’s more, you can declare a variable with var anywhere in the code, not just at the top. CFCs also support implicit getters/setters by using the CFPROPERTY tag. These are worth using if there is no special handling going on, because they’re 7x faster than your own getters/setters.

Here’s an awesome feature. You no longer have to use CreateObject() to create a CFC. You can use the IMPORT keyword to point to a directory of CFCs and have them be first-class citizens in your code. And you can use the NEW keyword to create CFCs, like user = new User(). Looking more Java-like all the time.

How to convince your boss to upgrade

First, with CFIMAP, you can now access email with IMAP support, such as GMail.

There are many PDF support enhancements. Create PDF packages, add/remove headers and footers, optimize PDFs (down-sample images, for instance), extract text/images, high-quality thumbnails, convert Word documents to PDF.

There are presentation options. The CFPRESENTATION tag will generate PPT files from CFML/HTML content. And you can go the other way: Convert PPT to HTML or Flash. Supports Microsoft PowerPoint ‘97 to ‘08 and Open Office Presentations.

Spreadsheet support. The CFSPREADSHEET helps you create, read, and merge native Excel spreadsheets. This isn’t just a CSV file. This is a real Excel spreadsheet with formulas and formatting support.

SharePoint integration. Native access to SharePoint data and services (Sites, templates, sub-sites, web parts, and workspaces). You can get lists including data, views, and alerts and querying against lists. Users, permissions, site groups, cross-site groups, security groups, and distribution groups. Build web parts with CFML. Integrate with SharePoint Single sign-on. You may wonder, “Why is this necessary since SharePoint has web services and exposes information as XML?” Because it’s painful. ColdFusion makes it significantly easier and faster.

ColdFusion Server Manager. A Flex-based AIR application that helps you manage multiple ColdFusion servers. And it receives system notifications and alerts. Helps apply settings for multiple servers.

The next generation of applications

Coldfusion 9 ORM functionality. Powered by the Java Hibernate framework, so it is industry standard. Various ormXXX() and entityXXX() functions provide this functionality for you. With this feature, no more SQL is necessary, so apps can be developed faster (and potentially with fewer errors). CFCs will just be automagically saved. But it’s not just a matter of saving time on development; it also makes it so that your app is no longer database-dependent. It can point to any database server and it should just work.

Enhanced caching. ColdFusion is already pretty optimized for speed (esp. between CF7 to CF8). So to get more speed, developers need to use these new caching features. Using cacheGet(), cachePut(), and cacheGetMetaData(), you can save/retrieve objects from a built-in cache. Page fragment caching allows you to have a combination of static and dynamic content on a page. This provides a HUGE performance boost, depending on what you’re doing. For instance, you only want to generate a menu dynamically the first time, but then another area of the page is dynamic every time.

Performance gains. Okay, Adam lied. ColdFusion 9 is actually 40% faster than ColdFusion 8, with no changes to code, just upgrading ColdFusion. CFC creation is 8x faster, method invocation is 3x faster. And UUID creation is 100x faster. These are some huge bottlenecks that have been blown away. There is a performance brief that Adobe will be releasing on ColdFusion 9 in the near future.

Search engine. ColdFusion 9 now includes Apache Solr. Verity is still included, but so is Solr, which is actually even faster than Verity. So you may choose to upgrade to Solr! They even provide a Verity-to-Solr migration utility.

ColdFusion Server API. You can have direct access to ColdFusion services for CFCHART, CFDOCUMENT, CFPDF, CFIMAGE, and more. This makes it even easier to access ColdFusion mail/pdf/images services directly within Flex without having to custom code some ColdFusion code.

What’s more, Flash Remoting is 9x faster. It may arguably be the fastest flash remoting server-side technology around.

There are various JavaScript/Ajax tags, like CFMAP for Google Maps, CFMESSAGEBOX, CFSLIDER, and more. Ajax functionality in CF is powered by ExtJS 3.0 (which is nice, because ExtJS isn’t free anymore, so getting CF9 gets you a copy of ExtJS basically), and JQuery is also supported.

This presentation was very rapid fire, which is testimony to how feature-rich of an upgrade ColdFusion 9 is.

  Theme Brought to you by Directory Journal and Elegant Directory.