EntityNew properties argument

Word Count: 121

This is a going to be a real short post but I think its a great little time saver. In ColdFusion 9.0.1 they added a second argument for the entityNew function. Now you can pass in a structure of properties and the setters will be called when the entity is instantiated. So before we had to write code that looked like this. And now we can write code that looks like this.

Hibernate Statistics in ColdFusion

Word Count: 416

One way to debug Hibernate is to log the generated sql, another way is by enabling live statistics. By default ColdFusion has live statistics disabled and for good reason. This is not something you want running in production and its only meant for development. The easiest way to get statistics out of the Hibernate engine at runtime is the Session Factory. Fortunately for us ColdFusion has exposed this to us by using the ormGetSessionFactory() method.

If you run the following code you will see all of the different statistics methods exposed to you.

There are statistics for things like

  • Global Statistics
  • Entity Statistics for a particular entity
  • Collection Statistics for a particular collection role
  • Query Statistics for SQL & HQL queries
  • Second Level Cache Statistics for detail runtime information about a particular region in the optional second-level cache
If you try and call any of these methods right out of the gate they are not going to work. If you remember I said earlier that statistics are not enabled by default, but we can enable them pretty easily. Now when you call any of the stats methods we will start to see some data. There is also a continent method to find out if they are enabled.

Finally we could take this and add some debugging output to application by using the on request end method in our application. The hibernate_stats.cfm could have some output with any or all of the statistics methods.

ColdFusion ORM Naming Strategy

Word Count: 220

In a perfect world of software development where a database is involved the naming conventions for tables and columns are standard. As you are aware that is not always the case. Sometimes we deal with really long or unconventional naming strategies. Fortunately for us hibernate has a way of dealing with this and ColdFusion, like everything else it does has made this really for us to use.

Let's pretend for our demo here that we are doing some work for ABC Company and that have this weird naming strategy where all of there table names are prefixed with tbl_ and all of their column names are prefixed with col_. I think you get the idea. If we were to create an entity based off of this table we would end up writing code that looked like this.

[More]

Event Handlers & Remote Methods

Word Count: 528

Working on a project today I came across a strange issue so I thought I would get everyones opinion on it. I am not really sure if its something I am doing wrong, a bug or maybe I am just missing something. In this application I have event handling turned on.

So for nothing special and up until this point everything has been working fine. Today I am adding some ajax via everyone's favorite framework (jQuery of course) and I came across something. This is my ajax call to my remote method. And my remote method that does a join to pull all users who have a role id equal to the argument passed.

If you were to turn event handling off this works fine but with it on I am seeing the following error.

coldfusion.runtime.TemplateProxy$InvalidRemoteAccessException: The method 'preLoad' in component D:\websites\extranetsteriscom\cfc\com\*****\*****\events\EventHandler.cfc cannot be accessed remotely.
Now in my event handler I have preLoad defined (because you have to when you implement another component) but it's not doing anything. Am I to believe that If I use event handling in my application I can't use ORM for any remote functions? I can certainly get down and write some sql but thats no fun :) Anyways, just thought I would share this and get your thoughts.

ColdFusion ORM - Attaching calculated values to your entities

Word Count: 308

There will come a time when you need to add a calculated value to your entity. In this example we will look at why you would want to do this and how you can easily accomplish it. I whipped up a very simple user manager example. First we have some orm settings in our application component. The main thing to get out of this is that we are going to be using event handling.

Our user entity is very basic and there is nothing special going on at this point. Now what if we wanted to display the users age somewhere in our code? We could easily do something like this.

[More]

My Abstract Persistence Layer: Take 1

Word Count: 365

So in my last post I was able to get some pretty awesome feedback on some questions I had. I am not going to go over everything about the post so please check it out first and read through the comments. In the end I wanted to find out how I could abstract commons functionality of the persistence layer in my application. What I am starting with here is by no means the *right* answer or my final, just my first stab.

I am going to use the cfbookclub datasource that ships with ColdFusion 9 so you can follow along at home. First we need to setup our application. This is my basic directory structure for the application and below is my Application component.


[More]

ColdFusion Domain Objects, Static Methods & a Common API

Word Count: 432

I decided before Christmas break that I really want to learn a couple new languages. I decided on picking up Groovy/Grails & Python. Now obviously I am not going to pick this up in a week but over the next year I want to get good with both of these languages. This has nothing to do with ColdFusion, in fact my passion for CF is really driving this. It's important to understand how other languages tackle problems in case you find yourself stuck in a similar situation.

I have been doing a lot of work lately with Hibernate in ColdFusion 9. As I write more and more code I realized that I was writing the same functionality over and over for each of my domain objects. For the purpose of this article lets use an e-commerce application. When your working with anytime of application you must identify the domain specific objects in your system. In our e-commerce application we could have (but not limited to) the following objects.

  • Product
  • Category
  • Order
  • Invoice
  • Customer

Now we have an idea of what is going to make up my system I am going to start building out my domain objects and views. To keep it very simple I started out without incorporating any type of framework. For each of my domain objects I found out that there was common functionality between them. Here is a list of (but not limited to) some of the methods I need to perform on each object.

  • New - I will create a new instance of the domain object.
  • Load - I will load an existing object from a database based on the primary key.
  • List - I will give you back a query of all the rows for this domain object.
  • ListBy - I am a dynamic search that allows you to search by fields.
  • Find - I will find rows based on hql
  • FindBy - I am a dynamic finder that allows you to find exact matches dynamically (findByFirstAndLast("Dan","Vega"))
  • Save - I will persist an object to the database.
  • Delete - I will delete a row(s) from the database.

[More]

ColdFusion 9 ORM Event Handlers Use Case

Word Count: 447

I have been doing a ton of work lately with the ORM features in ColdFusion 9. Last night I was reading through my grails book and I came across a feature that I really like. In grails you can automatically have the date created (on insert) and last updated (on update) time stamp added to each table during their respected events. This way you always know when records were created and updated. We can replicate this feature on the entity itself or on all entities in our system and today I will show you how to do both.

First off you need to setup some settings in our application. You need to first setup your normal ORM settings like orm enabled and the data source. In the ORM settings we are going to be working with event handling and event handler. Event handling is false by default and therefor will not broadcast these events that we want to listen for. Also the db create setting must be set to update unless we already have these fields added to our table. Next we are going to create a very basic persistent entity in our model folder called User. As you can see this is no different from most of the entity's you have been building. The only difference is we are going to add 2 fields to our domain model. The date created and last updated should both be set to time stamps.

[More]

Abstract Service Level Demo

Word Count: 41

This is a quick demo of how you can provide common functionality to all of your service level objects using an abstract component. Thanks to everyone who has helped me understand hibernate and to those who have been providing feedback!

What is the Primary Key of this ORM Entity

Word Count: 100

Just a quick little method I thought I would share with everyone. I was working with a ColdFusion ORM entity and I needed to know what field was the primary key. Turns out you can tap into the Session Factory to find this out. This You can also find out the type of the primary key.

More Entries

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.