Entries Tagged as 'ColdFusion'

Announcing tableSnapshots: A ColdFusion Tool For Preserving and Reverting Database Table Data

CFML , ColdFusion 2 Comments »

Several months ago, I was doing some functional testing on a web application that was taking forever.  Each run of the test resulted in changes to the data in several tables, and in order to reset the test I had to go into the tables and undo the changes.  It occurred to me that it would be nice to have a tool or script that could preserve the current table data and then later write that version of the data back to the tables.

That marked the beginning of the tableSnapshots tool.

Read more...

Quick Tip: Avoid Joining Query of Queries (QofQs) Within Loops

CFML , ColdFusion 3 Comments »

Every ColdFusion developer who spends a lot of time working with queries knows that if you have to run a unique query for every iteration of a loop, you should (whenever possible) use a <cfquery> to acquire the entire set of records prior to the loop and then query against that recordset using a Query of Queries (QofQ):

<cfquery name="qryMain" datasource="myDatabase">
    select a.field1, a.field2, b.field7 ...
    from table1 a, table2 b
    where a.field1= b.field2
</cfquery>

<cfloop index="j" from="1" to="1000">
    ....
    <cfset calculatedVal= thisVal + thatVal />
    
    <cfquery name="qrySub" dbtype="query">
        select field2, field7 ...
        from qryMain
        where field1= <cfqueryparam value="#calculatedVal#" cfsqltype="cf_sql_numeric" />
    </cfquery>
    ...
</cfloop>

...That way, you're querying the recordset in memory 1,000 times instead of making 1,000 calls to the database.

Yesterday I was asked to look at an old report that wasn't performing well anymore now that the database tables being queried had grown much larger. While it was designed to use QofQ data within the loop, the QofQ in the loop was doing a join between two recordsets stored in memory:

<cfquery name="dbQry1" datasource="myDatabase">
    select a.field1, a.field2, a.field3, b.field4, b.field5
    from table1 a, table2 b
    where a.field1= b.field2
    ...
</cfquery>

<cfquery name="dbQry2" datasource="myDatabase">
    select c.field1, c.field6, d.field9
    from table3 c, table4 d
    where c.field1= d.field3
    ...
</cfquery>

<cfloop index="j" from="1" to="1000">
    ....
    <cfset calculatedVal= thisVal + thatVal />
    
    <cfquery name="qrySub" dbtype="query">
        select dbQry1.field2, dbQry1.field3, dbQry2.field6, dbQry2.field9
        from dbQry1, dbQry2
        where dbQry1.field1= dbQry2.field1
        and dbQry.field2 > <cfqueryparam value="#calculatedVal#" cfsqltype="cf_sql_numeric" />
        ...
    </cfquery>
    ...
</cfloop>

I discovered that if I created a third QofQ that took care of the join outside of the loop, and queried that new recordset within the loop, the per-iteration performance improved dramatically:

<cfquery name="dbQry1" datasource="myDatabase">
    select a.field1, a.field2, a.field3, b.field4, b.field5
    from table1 a, table2 b
    where a.field1= b.field2
    ...
</cfquery>

<cfquery name="dbQry2" datasource="myDatabase">
    select c.field1, c.field6, d.field9
    from table3 c, table4 d
    where c.field1= d.field3
    ...
</cfquery>

<cfquery name="qryMasterSub" dbtype="query">
    select dbQry1.field2, dbQry1.field3, dbQry2.field6, dbQry2.field9
    from dbQry1, dbQry2
    where dbQry1.field1= dbQry2.field1
</cfquery>


<cfloop index="j" from="1" to="1000">
    ....
    <cfset calculatedVal= thisVal + thatVal />
    
    <cfquery name="qrySub" dbtype="query">
        select field2, field3, field6, field9
        from qryMasterSub
        where field2 > <cfqueryparam value="#calculatedVal#" cfsqltype="cf_sql_numeric" />
        ...
    </cfquery>
    ...
</cfloop>

It makes sense when you think about it, but I had just never considered that join operations would affect QofQs so drastically.

Google Plus One Mango Blog Plugin Now Available

ColdFusion , Downloads No Comments »

The other day Lola J. Lee Beno shared on Google+ the link to Google's API page on how to add the Google "+1" button to your site.  It looked simple enough, so I figured I would go ahead and add the code to my blog so folks could "+1" my posts if they wanted to.

Then I remembered that I'm running Mango Blog, and while it's certainly possible to hack (err, "customize") the display files, the proper way to add new features like social networking buttons to the posts is with Mango plugins.

I knew how to install and use Mango plugins, but not how to write them.  What was I about to get myself into?

I found a Mango plugin called Twitter Retweet created by Nick Simone that did the same thing I was trying to do, only with Twitter.  By following his code and consulting the Mango documentation on plugins, I was able to create my Google Plus One plugin in an hour or two.  The only problems I ran into were ones of my own creation (the kinds of mistakes you can make when writing code late at night).  So now I have both the Twitter Retweet and Google Plus One plugins running on my blog.

I've submitted my plugin for consideration for the official Mango Blog plugin list on the Mango Blog site, but until it gets posted there Mango Blog users can download/install the plugin from the following URL:

http://www.thoughtdelimited.org/thoughts/downloads/googlePlusOne.zip

I've also put the code up on Github so that anyone who wants to fork it or improve on it can do so:

https://github.com/bcswartz/googlePlusOne

Integrating Mura with the Jasig Central Authentication Services (CAS)

ColdFusion , Mura 1 Comment »

I've already posted most of this information on the Mura forums, but I wanted to post it here as well for anyone looking for information on this topic.

With the blessings of my boss, I've been playing around with the ColdFusion-powered Mura content management system to see if it might be a good CMS option for us.  From what I've seen so far, Mura is a well-thought out CMS system that is both powerful and easy to use, which is a difficult balancing act.

One of the things my boss wanted me to investigate was whether or not we could tie Mura in with our single sign-on solution, which is CAS (Central Authentication Service), a Jasig project originally created at Yale.  When a user tries to access a page or a site that requires them to authenticate, they are redirected to the CAS server and enters their LDAP-based user id and password on the CAS login page.  If they successfully authenticate, the CAS server redirects them back to the original site and stores a token as a cookie in the user's browser.  If the user visits a different website secured by CAS, the cookie allows them access to that site without the need to log in again.

Mura provides a plugin architecture that allows developers to intercept certain Mura events and run their own code.  A number of Mura shops have created plugins that intercept the Mura login events in order to tie in with their in-house directory and authentication servers, but those login events are triggered by the admin and user login forms built into Mura.  I couldn't go that route:  I needed to circumvent and replace the Mura login form(s) with the CAS login form and have Mura log in the user based on the credential information returned by CAS.

After some digging into the code and some trial-and-error, I came up with a way to authenticate Mura administrators via our CAS system.

Read more...

Pros and Cons of Deploying ColdFusion Apps as EAR Files?

ColdFusion 4 Comments »

I asked this question on CF-Talk, but didn't get any responses, so I'm trying again here...

At work we are beginning the transition from ColdFusion 7 to ColdFusion 9.  As part of the transition, we want to set up a ColdFusion 9 server cluster (using CF 9 Enterprise) to host those ColdFusion applications that need to have a high level of redundancy.  In order to reach this goal, the server admins want any apps hosted in this cluster to be deployed as EAR files.

From what I've read on the subject of EAR deployment, this is a sensible approach for a clustered environment, but it's unfamiliar territory for us.  We're used to having direct access to the application files so we can make minor adjustments rather quickly and I'm worried that adding a packaging and deployment step (even with the use of automation tools like Ant) is really going to slow down our ability to push out changes.  I'm also concerned about the fact that some of the apps in question are not self-contained:  they are integrated into websites that our clients have the ability to edit.  Based on what I've read, it's sounds like that wouldn't be an issue as long as the files and folders within the EAR were deployed in the right place for the client files to access them, but in practice…

So basically, I'm looking for some advice and input from anyone who deploys their apps as EAR files (especially from folks who've made the transition from deploying via file upload to deploying via EAR), anything from how we should plan for this, best practices, things to look out for, etc.

Anyone?