Thursday March 4, 2010 11:01 AM
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.
Monday January 18, 2010 10:26 AM
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]
Wednesday January 6, 2010 9:28 PM
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]
Wednesday January 6, 2010 9:19 AM
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]
Tuesday December 22, 2009 10:36 PM
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]
Monday December 21, 2009 10:56 PM
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!
Monday December 21, 2009 11:14 AM
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.
Monday December 21, 2009 9:41 AM
Word Count: 354
In part I I took a look at a basic implementation of a dynamic find by method. Tony Nelson was quick to point out that this would not work if you had entity names that contained AND such as Candidate. I went back to the drawing bored and with a nice idea from Tony I cam up with another solution. His example was a little more dynamic ubt please understand this is a stand alone example for a reason. This functionality is going to be created in my abstract service layer. Anything that is going to be common among all service objects should not be repeated.
So how are we going to fix this problem with the AND keyword. The AND join is going to tell us that we need to find rows by 2 different fields. This could be improved upon to handle many ands but I really don't see myself ever needing more than 2 lookups for a find by method. If we know what entity we are working with we can do a lookup for the properties of that entity. In the hard coded example case we know we are working with the Art entity so we can do the following.
Given the fact that we know the valid properties of the entity we can do the following.
- Does any part of the missing method name after findby contain AND
- If no - then just return that as the lone field
- If yes - are the left and right sides of and valid properties? If so we have a join. If not we have a field name.
[More]
Saturday December 19, 2009 1:13 PM
Word Count: 163
So I am working on my abstract service layer and I decided to create a find by method. The idea for this came from a blog post by Joe Rinehart. At the time of writing this his blog was down so I decided to write my own. What this method will allow us to do is provide a generic find by API for our service. Before we get into how it works we should look at what it does. All of my examples are going to use the cfartgallery datasource so you can follow along at home.
In my first example I want to find all art records where the artists name is Michael. We could do something like this.
I just think being able to call any field dynamically is just intuitive and let's face it, FUN!
[More]
Friday December 18, 2009 1:12 PM
Word Count: 433
This is meant as a tutorial and learning process for all including myself. When start getting into relationships its important to notice how to define them and how your going to handle them. In this demo we are going to look at a simple system that uses a product and category object. The basics of hibernate (list/get/save/delete) are pretty easy but when I get into relationships I usually have some questions. Please follow along with my thought process and provide feedback and by all means please tell me when & where I am wrong.
The first object in our system is a product object. I have slimmed down version of the product here but you get the idea.
The object in our system is a category object. The only thing of special note here is the name field. The table that already exists contains the field category and I would like to refer to it as name from here on out.
[More]