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: Migrating from Flex 3 to Flex 4

These are notes from Adobe MAX 2009. This session will help us see what problems we may encounter moving to Flex 4, as well as what new features we can use.

Packages. The old mx packages are still there. But now everything new is in the spark packages. Why two different packages? At first, they had them all in the same package, but the component had a prefix for the new version. It wasn’t received well. So instead, Adobe just put the new components in new namespaces.

The MX namespace is also called “Halo”. Don’t consider it a “legacy” namespace. These are still fully supported. Spark is all of the new stuff. The general MXML has a new 2009 namespace, but the legacy namespace is still supported.

Graphics

You can add graphic primitives enabling you to draw lines, ellipses, and curves, directly within the MXML. With the new FXG file format, you can import a graphic in as a vector graphic that appears as code. Cool. Using a static FXG image is great for icons or other static simple images, because its rendering is faster than an MXML graphic container.

Flex States

Instead of using AddChild and RemoveChild for changing states, you have includeIn=”" and excludeIn=”" attributes that go directly on components. What’s more, you can set various attributes of a component for the different states by using a dot notation. For instance, title.mystate=”Title”. This seems like a pretty drastic change.

With states, you have to use the OLD way with the 2006 namespace, and you have to use the NEW way with the 2009 namespace.

Skinning

Components all have separate skin files. This will allow you to create a custom skin for any component easily.

Common migration issues

Type selectors need namespaces now in your Flex CSS. For instance, if you’re styling a button, Flex doesn’t know if it is a Spark button or a Halo button. So you need to define the namespace in your stylesheet and update your selectors accordingly.

You must compile against Flash Player 10. This won’t be an issue if you use Flash Builder 4 with Flex 4.

Application.application should now be renamed to FlexGlobals.topLevelApplication. Just a direct rename.

RSLs are on by default.

The “Declarations” tag is a problem child. In Flex 4, anything that is not a display object or default property must be within the fx:Declarations tag. Even tags like RadioButtonGroup. Formatters, Effects, RPC stuff, Validators, etc. need to go in the Declarations.

“If Looks Could Kill.” The default theme is now Spark, which looks different than the old Halo theme. You can switch back to the Halo theme. To do so, turn on “Use Flex 3 compatibility mode” in the project properties, or go into the “Flex Theme” panel and change the theme (this is the preferred way).

If moving to Flex 4, try to use as many Spark components as you can. They should play nicely with MX components. You can intermix them together. Caveats: (1) The graphic primitives cannot go in an MX component, just wrap them with a group; (2) you cannot put MX components in Spark containers; (3) MX effects do not work on Spark graphic primitives; (4) MX navigators (ViewStack, Accordion, etc) should use NavigatorContent component.

Other things to watch out for:

  • Spark components don’t support the Halo theme.
  • Cannot create spark component based itemRenderers for MX List based components
  • APIs between MX and Spark components are different (e.g. addChild vs. addElement)!
  • When using MX and Spark components together, you may see a text difference since they are themed differently. There is a TLFText theme that can help with this.

So, migrating an app from Flex 3 to Flex 4 is a bit of a slippery slope. And even just beginning to use Flex 4 with current Flex 3 knowledge will require a bit of a slowdown as you undo some of those brain synapses to do things the new Flex 4 way. But these changes going forward are good for the Flex framework.

  Theme Brought to you by Directory Journal and Elegant Directory.