Posts with the tag 'cf'


Using CFQuery for executing stored procedure

Something that all of us wants to avoid is server slow down and crash in the event of application load and that’s what motivates us to look at code optimization, refactoring, frameworks, database optimization etc.

There are various steps that can be taken for application optimization and to have uninterruptible application availability, but for the moment I am just going to focus on database side. This wont be the first time you are hearing about database/query optimization for having a healthy application, and assuming you have the best optimization done there are still times when unthinkable happens i.e. network connection to database is slow, database transaction log is full, query is running without using a index etc. The point being unforeseen issue can happen with database and it can bring your site to its knees, and your customers have to suffer.

Many of the large scale application uses stored procedure instead of inline SQL queries in CF code and therefore CFStoreproc tag is the ideal choice for running Stored procedure. But one of the biggest disadvantages of using CFStoredproce is the missing timeout attribute, which can lead to slow sites and complete crapping out of server. For whatever reason if the stored procedure executing time goes up then normal expectancy its going to slow down the page processing and eventually result in request queuing for high traffic site and the unavailable server crash.

If you are concerned about Stored procedure taking long time then normal, then use CFQuery tag with “timeout” attribute where you can set the timeout to be the normal expect Query executing time + some extra buffer. When the code gets executed the timeout is going to free the connection if SP takes longer then you have anticipated and you can graciously handle the error, rather then letting the page spin forever. Think about the scenario where the lots of users are hitting the same page (without the timeout), whosoever comes first will have the page still loading and basically holding the CF execution thread and other users request will be queued up in CF server which is going to slow down the server and as the queue size increases the server is going to become unstable. Whereas if the timeout was introduced its going to clear the request immediately with some error message to user, and therefore the server will continue processing request as they arrive.

CFQuery “timeout” attribute should not only be used for stored procedures, it should also be used for regular inline query, doing so will save your application from coming to a screeching hold in case of database outage.

<cfquery name=”name” timeout=”10″>
Query / Store procedure
</cfquery>

Add comment January 2nd, 2008

Prototype Pattern in ColdFusion 8

The prototype means making a clone. This implies cloning of an object to avoid creation. If the cost of creating a new object is large and creation is resource intensive, we clone the object. This article explains how this pattern can be used in coldfusion

I set out tonight to determine if the Prototype design pattern would be useful in object factories in ColdFusion 8. The Prototype pattern, in a nutshell, is to create a new instance of an object by copying an existing object instantiation. The object to copy is an object instantiated once and then used as a blueprint for future objects of the same type. The thought is that copying an object holds a lesser cost than instantiating a new object.

Read the full Article

Add comment December 26th, 2007

DAOs and Gateways in ColdFusion

Brief introduction of DAO and Gateway pattern for coldfusion audience

Data Access Object and Gateways are the names given to ColdFusion components that access information from a database or other external data source. Within the ColdFusion community DAOs and Gateways have pretty much taken on the meaning as follows

Read the full Article

Add comment December 22nd, 2007

Object Factory in Coldfusion

Factory method pattern implementation in coldfusion along with working sample code, This pattern helps to model an interface for creating an object which at creation time can let its subclasses decide which class to instantiate.

For those of you new to this concept, an object factory is nothing but a component whose sole job is to create components. An object factory is quite simple and small. Its main role is to collect the information necessary to create an instance of the intended object’s class and then to invoke that class’s constructor

Read the full Article

Add comment December 16th, 2007

Command Pattern in Coldfusion

Object in command pattern are used to represent action and can be used effectively in coldfusion, this Article explains the command pattern by building a demo application.

The tutorial is simple in its presentation but gets the job done and includes a full working application putting everything to good use. You’ll be creating a home automation Remote Control for the appliances in your house. My remote has simple on/off buttons and and undo button but the tutorial will teach you to do more

Read the full Article

Add comment December 10th, 2007

Implement the State pattern with ColdFusion Components

State Pattern implementation in coldfusion to maintain the various state of an object. The article provides step by step implementation along with downloadable code for future reference.

The introduction of ColdFusion Components (CFCs) in ColdFusion MX opened the door to more object-oriented programming in CF. When application developers start thinking about OOP, the idea of design patterns almost always comes up. In that context, Brian Kotek discusses the State pattern: its purpose, the problems it can solve, and how you can implement it using CFCs.

http://articles.techrepublic.com.com/5100-3513_11-6167539.html

Add comment December 4th, 2007

Singleton Pattern in Coldfusion

Coldfusion implementation of singleton pattern to restrict instantiation of class to one object. Singleton Pattern is useful when exactly one object is needed to coordinate actions across the system. Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist

Singletons are perhaps one of the most simple Design Patterns. For those who don’t know sigletons are a class that can only have one instance. They can be thought of as a glorified global variable - but are a lot more useful.

Read the full Article

Add comment November 27th, 2007

Strategy pattern Example for Coldfusion

Demo application with source code showing the usage of strategy pattern to dynamically select/change the class behavior at runtime and without having to lock the class to a specific behavior

As I make my way through Head First Design Patterns, which I am starting to agree is a “must” on a developer’s bookshelf, I decided I would work out some of the exercises in ColdFusion code. It is geared towards Java, but the principles carry over into OOP practices in ColdFusion as well.

Read the full Article

Add comment November 23rd, 2007

Using Composite pattern in Coldfusion

Brendan O’Hare has written an excellent article explaining the Composite Design Pattern and its implementation in ColdFusion by using CFC (ColdFusion Components)

“As ColdFusion developers, we tend to build applications based on pages that display information and queries to retrieve information and save information. We tend to think solely of how we are going to implement the code required to perform a certain function. Many times we are not able to consider the commonality of a certain problem and whether an already established design exists somewhere.

Often we are not able to set aside time to do this research. Knowing and utilizing design patterns allows us to think in a common language, with an ever-expanding library of well thought out solutions to consider when architecting an application. Recognition of these patterns in our everyday jobs can make us significantly more productive and seem even smarter than we are.”

Read the Full Article

Add comment November 19th, 2007


 Subscribe in a RSS reader

Tags

Calendar

November 2008
M T W T F S S
« Jun    
 12
3456789
10111213141516
17181920212223
24252627282930

Posts by Month

Posts by Category