Viewers: in countries Watching now:
In ColdFusion 9 New Features, author and developer Dan Short has gathered together the important updates and improvements in this dynamic web application. Dan showcases the new ColdFusion Builder application throughout the course, using it to work through the new language and CFScript enhancements in this release. He shows how to use the new Server Manager to compare servers and create server groups, as well as monitor server health through notifications. He also explains the new integration with Office applications, building Excel, Word, and even PowerPoint files on the fly from ColdFusion. Finally, he covers the important new Object Relational Mapping feature and how to use the built-in Flash Player. Exercise files accompany this course.
This next feature is to me one of the most exciting features in ColdFusion 9, but probably won't be talked about much. In this video, I am going to show you how a complex object can be serialized to a binary representation of that object and then save to disk or database, or any other persistent medium where it can then be picked up and used elsewhere. This has uses when you're dealing with objects that you only need to instantiate occasionally. You may have a long spin up time or when you need to save the state of something for use later on in an application. So, in the Chapter 4 folder, we'll open serialized.CFM.
Now the only thing I'm doing here is instantiating an instance of the person CFC and setting some data, the first name, last name, city and state. My person CFC here is the same one we worked with in another video, which just has a few getters and setters. We will go ahead at the accessors = "true" on here, so we have all of our getters and setters available to us. So, in the serialized.cfm, I am just going to preview this in the browser and you'll see we just have Dan Short, Austin, and The Great State of Texas.
But what if I need to save this object out to a database or disk? In ColdFusion 9, I can just do cfSet objectSave, I could tell the object that I want to save, and the file name that I want to save it to. So, in this case we are going to save it to danshort.cfo. CFO isn't an official filename. It doesn't mean anything. In this case, it's just simply a way for me to look on disc and see that this is an object that has been serialized by me.
So, I am going to save this file and then, load it up in Safari. You notice we didn't see anything else happen. I don't have any output or feedback that anything good happened. But if go over here to my navigator and refresh, you'll now see I have a danshort.cfo file. If I open that thing up, we can see that I have a whole bunch of stuff. I can see there is a ColdFusion Runtime, TemplateProxyWrapper. I have a HashMap in here.
I can see that the state is The Great State of Texas, the last name is Short. I can see a bunch of information here but it isn't readable by me necessarily. So, I am going to go ahead and close this file and back in serialize.cfm, I am going to get rid of everything up here. I want to get rid of my ObjectSave and let's go ahead and load this file again, just to make sure that I got rid of everything that I needed to get rid of. We don't have our error.
And I am going to do cfSet ObjectLoad and I am going to load DanShort.cfo. And I should probably assign this to a variable so I want to do Person = object load. Now, if I preview this in Safari, it looks exactly like it did when I made the actual New keyword and created that new object. It's rebuilt this entire CFC from that binary file, including all of my implicit getters and setters, and everything.
So, if I had a large object. Let's say I made half a dozen HTTP calls to different servers to get set up, and it took 10-15 seconds to set up, I don't want to have to do that necessarily every time my application starts. So, what if on application end, I had it write this object to disk? And then when my application started back up, on application start, if that CFO file exists, I can just read it from disk and rebuild it. Without having to go through all of the set up and the time it takes to instantiate that large object.
Now, one bonus to this is that the ObjectSave can actually serialize any object or variable. So let's run a query real quick. So, I am just going to do cfquery = artists, and I am going to use the cfartgallery data source and Select * FROM Artists. Now, if I dump that, just make sure I got my query right, and see all of the query information.
Let's save that out using the new ObjectSave function. We're going to save our artists to artists.cfo. I will run this file. Again we don't get any feedback at all but if I refresh the Navigator over here, I can see artists.CFO. I will load that file and as you can see, we have all of that query information in here. Even down to the SQL statement that was run, the execution time, everything is in here.
Then, I will go back to serialize.cfm. If I want to get this back out, I can say cfSet Artists = ObjectLoad, Artists.cfo. So, now I am loading the data back into the Artists variable and then I am going to dump it out. And it's as easy as that. If I had a large query or any large data structure that I wanted to serialize out to disk, it's that easy. I can then save that binary object to a database, ship it off and email to do error reporting.
For example, if I plan on using this whenever there is an error with an object in my application, I am actually going to serialize that object, save it to an email and email it to myself as an attachment. I can then take that binary file on my local machine, load it up and take a look at all of the data in there to figure out exactly what went wrong. So being able to save a full CFC query or some other complex object to disk is a big deal. It has huge implications for clustering, persisting complex data storage, and application ramp-up time for large cached objects.
There are currently no FAQs about ColdFusion 9 New Features.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.