Rob Gonda's Blog

Speaking at CFUnited Express - Atlanta

CFUnited express invited me to speak next month in Atlanta, next to Charlie Arehart, Ben Forta, Hal Helms, and Andrew Powell. It will be a one-day event that you can attend risk free if you're planning to attend the main CFUnited event, since the entire cover price will count towards your CFUnited ticket.

I will be speaking again on Ajax, Charlie on caching and performance, Ben on Apollo, and Hal on large-scale applications. I'm really exited about speaking and attending the other sessions. Hope to see a few familiar faces there.

AjaxCFC for jQuery Alpha3 Release

I just updated the SVN with the 3rd alpha release of AjaxCFC for jQuery. For those of you not familiarized with source control repositories, I included the code into the main AjaxCFC download (thank Rey Bango for reminding me four times a day), available at RIAForge and my blog. You can also just click here.

This release includes several small fixes in the JavaScript and upgrade to the latest CFJSON. Thanks to Larry Reinhard for pointing it out.

The code seems to be really stable; I haven't got many bug reports, au contraire, Jacob Munson, from CFQuickDocs, said he dropped it into his code w/o any complications, maintaining all existing functionality.

I shall wrap up some documentation and officially release it for production.

Leverage SQL Session at the South Florida CFUG

I will be speaking this coming February 22nd at the South Florida CFUG. For this month I chose a topic that will benefit you regardless of your programming language of preference, and should hopefully allow to you take back something that you can apply immediately.

Topic:      Leverage the power of SQL
Description:     Many developers don't realize the power of SQL to perform data related tasks and computations. Learn how to utilize triggers, stored procedures, constraints, and user-defined-functions to their full potential, and see the huge impact this could have in your organization or day-to-day coding.

Tell your friends.

ColdFusion Vs. SQL UUID

A few days ago I blogged about database level data integrity and promised a follow up concentrating in uuids.

A UUID stands for Universally Unique Identifier. The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. Thus, anyone can create a UUID and use it to identify something with reasonable confidence that the identifier will never be unintentionally used by anyone for anything else. Information labelled with UUIDs can therefore be later combined into a single database without needing to resolve name conflicts. The most widespread use of this standard is in Microsoft's Globally Unique Identifiers (GUIDs) which implement this standard (source: wikipedia).

A UUID is essentially a 16-byte (128-bit) number. In its canonical form a UUID may look like this:

    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12)

However, for some reason ColdFusion's UUID looks like

    xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16)

Microsoft SQL has a native datatype called uniqueidentifier, which represents the 36-characters GUID. Many ColdFusion developers choose not to use the GUID because it cannot be implicitly validated by ColdFusion and it cannot be seamlessly moved to a different database like mysql, postgre, oracle.

The most widely adopted solution is to use a 35-character primary key and insert a ColdFusion UUID, nonetheless, how do you validate a proper uuid at the database level? What if you want the database to generate the primary key? If the key gets altered, it will fail ColdFusions implicit UUID datatype validation.

The solution is to add some constraints in the database level.

Is it really simple to generate a UUID, since all it takes it just to remove the 4th hyphen.

CREATE FUNCTION dbo.newUUID(@GUID varchar(36))
RETURNS varchar(35)
AS
BEGIN
 RETURN left(@GUID, 23) + right(@GUID,12)
END


Note that due to limitations and not being able to invoke a newID() function inside a user defined function, we need to pass the GUID. Now, that said, we can add a default value to our primary keys and let SQL Server generate them for us:

Default Value: dbo.newUUID(newid())


To validate a proper UUID is a little more complicated, since SQL has no native isUUID or isGUID function. I chose to use a regular expression, but guess what? SQL Server 2000 has no regular expression capabilities.

So step one is to create a regular expression evaluator function

CREATE FUNCTION dbo.find_regular_expression
    (
        @source varchar(5000),
        @regexp varchar(1000),
        @ignorecase bit = 0
    )
RETURNS bit
AS
    BEGIN
        DECLARE @hr integer
        DECLARE @objRegExp integer
        DECLARE @objMatches integer
        DECLARE @objMatch integer
        DECLARE @count integer
        DECLARE @results bit
       
        EXEC @hr = sp_OACreate 'VBScript.RegExp', @objRegExp OUTPUT
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OASetProperty @objRegExp, 'Pattern', @regexp
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OASetProperty @objRegExp, 'Global', false
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OASetProperty @objRegExp, 'IgnoreCase', @ignorecase
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END   
        EXEC @hr = sp_OAMethod @objRegExp, 'Test', @results OUTPUT, @source
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OADestroy @objRegExp
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
    RETURN @results
    END


Now that we have this, all we need is the UUID regEx pattern and call this function.

CREATE FUNCTION dbo.isUUID (@uuid varchar(35)) 
RETURNS bit AS 
BEGIN

DECLARE @uuidRegex varchar(50)
SET @uuidRegex = '^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{16}$'

RETURN dbo.find_regular_expression(@uuid,@uuidRegex ,0)

END


Alright! now we have a isUUID function, which you can easily invoke from everywhere... open a sql script and execute

SELECT [dbo].[isUUID]('D929E4FB-537C-495F-BB3F31B8E42C0FBB')


Now that we tested it and know how it works, all we need is to add a constraint to your primary key:

Open your table in design mode, click constraints, new, and add this line:

([dbo].[isUUID]([ID]) = 1)


where ID is the name of the primary key.

So you learned how to generate a UUID, default your primary key to use one, validate a UUID regEx, and add a constraint to enforce db data integrity.

cf.Objective() posts speakers list

The speakers list is now up at the cf.Objective() site. I couldn't assist last year, but I heard nothing but great stories, so I'm really happy to make it this year. Sessions and topics will be posted shortly, but registration is already open. Trust me, no matter what are the final topics, just look at the speakers, you know it will be good. Hope to see you all there.

Framework Conference highlights

The frameworks conference was great... big applause to Liz and the Teratech team for putting it together. Like in most conferences, I only made it to a selected number of sessions, however, I learned a lot from the speakers at the bar.

The two sessions I enjoyed the most were Hal Helm's Interface Driven Architecture, and Chris Scott's Intro to Aspect Oriented Programming.

The food was great; we had food available from 8am till 6pm ... We had a foosball tournament and the prize was two Flex 2.0 licenses... too bad the tables were even worse than the beat-up one at my office :)

My session was on object factories, providing some history and evolution in CF programming, and examples taking apart Ray Camden's Galleon forums and showing alternative ways to wire dependencies together. Ray assisted my presso and it seems like I could have made a difference; that's great!.

I'll post my slides and code shortly, plus a bonus video or two, showing what speakers really do at these conferences.

cfcUnit 1.2 beta 1 now with Ant

After a long wait, Paul announced the beta release of cfcUnit 1.2, which now finally includes Ant support. cfcUnit allows you to perform tests on very specific functionality of your components (units), and now they can be funny automated with your builds by being invoked by Ant right from within Eclipse. I know Paul has been working on this for a long time under Sean's pressure, so you know this code must be good. You can get the latest release at sourceforge.

CFEclipse 1.3 Released

Good news: CFEclipse 1.3 is out; thanks Mark! It is one of the many Eclipse plugins I use daily, and by far the best tool to write ColdFusion code. 

AjaxCFC for jQuery Alpha2 Release

AjaxCFC for jQuery is almost ready and I just uploaded to RIAForge the new Alpha 2 release. You may sync up your SVN repository or if you don't use source control, use RIAForge's zip download utility to fetch the latest version. Once you download the zip file, the jQuery related code is located in the branches/jquery folder.

I am using the just released jQuery 1.1, so if you drop this code on an old site using jQuery, you probably want to download the back-compatibility plugin.

Like I mentioned in my alpha 1 post, I included a plugin to maintain DWR syntax compatibility, and to illustrate it, I updated a few examples to use this code instead of DWR. Thus far, the only significant different I found is when returning a query using JSON serialization method (default on this release). The syntax to access the query columns is a little different, as you will see in the examples and soon-to-come documentation.

Among some other changes, I updated logging, error trapping, security checks, constructor methods, serialization capabilities, and more.

Most of these changes affect the DWR and jQuery version since the Ajax.cfc core file is shared between them.

Constructor method: many of you tried to extend your existing domain model objects and provide remote methods inside them. Although I don't particularly agree with this practice, I don't want to restrict it. AjaxCFC used to rely on it's built-in init method constructor, which interfered with you own component once extended, so I renamed the AjaxCFC to allow your objects to contain an init() method.

Error trapping: AjaxCFC catches most errors in your components and by default, alert you with the error message. I added the file and line number since sometimes the message was not enough. I also added a method to optionally popup a window showing the error dump, which is extremely useful because you can see the full trace... to enable this just invoke the setPopupErrorDump(true) method inside your CFC.

Security Check (for jQuery version only): jQuery sends additional x-header data in the http request, so I added an option to check for it, to prevent access to the CFC if it's accessed by any method other than an XmlHttpRequest. To enable it just invoke the setCheckHttpRequestData(true) method inside your CFC. In fact, by default AjaxCFC ships with all the security methods turned off, for easier debugging. It is advisable to turn them on by calling: setAllowedVerbs('post'); setCheckHTTPReferer(true); setPopupErrorDump(false); setCheckHttpRequestData(true);

Serialization (for jQuery only): The new AjaxCFC is able to serialize using pure JS, JSON, or WDDX. I haven't fully benchmarked the performance differences, so for now just use the one you like the most.

Logging: I updated the log4javascript version, plus I added a little more information in the request logs.

Documentation will be included with the beta release.

Please note that despite some comments out there, this release does not mean that AjaxCFC switched to jQuery. This release is a branch using a different Ajax engine, and both versions will continue to be updated and supported.

That's it for now, please report any issues using RIAForge's bug tracker.

Enjoy.

CFMX7 + W2k3 r2 = Access is denied

Back in August I blogged about problems installing ColdFusion in a Windows 2003 box with sp1 pre-installed... the same applies for R2 version. My solution last time was to run the silent install, but there is a much easier one: turn off DEP (Data Execution Prevention), which should work for sp1 and r2.

To do this, right click my computer, goto properties, advanced, top tab: Data Execution Prevention, and switch to the first radio: for essential services only. After that, just reboot and install. It should work flawlessly.

More Entries

This blog is running version 5.9.003. Contact Blog Owner