Rip's Domain

ICEGen 2.0 preview now available

Posted in ICEGen by rip747 on February 24, 2008

ICEGen v 2.0 preview is now available for download. Below are the changes that have been made, please read them before installing. Report any bugs here. I would like to get a final version out by April 1.

DO NOT use this in production!

Remember that this is a preview, things will and could be added or removed before the final release, only use this for testing. I’m the only one who’s dieting on dog food right now.

SPEED!!!!!!!!!!!!!!!!!!

I never really liked the XSLT way of generating code. A while back (way before I even wrote ICEGen) I downloaded ARF from Joe Rinehart and I loved the way he did the code generation. I used that method when writing this version. Because of the new way ICEGen does the code generation (thanks Joe), the speed increase has been incredible. The speed is now almost 15 fold what the last version was! To give you an idea. My database has 52 tables and it use to take around 70 seconds for it generate the files, now it takes less then 5 seconds!

ICEGen now loads from the Application.cfc

Many people didn’t like the fact that you had to run ICEGen from a browser. I did some reworking and now all you have to do is add one line to your application.cfc in the OnApplicationStart method to get ICEGen up and running. Here is the line I use

<cfset CreateObject(“component”, “icegen.icefactory”).init(“mydsn”, “mssql”, “_model”)>

Basically all you’re doing is calling the icefactory class with the following parameters:

mydsn: The name of a dsn you want ICEGen to generate classes for. You cannot pass a username and password, so you must have those settings configured within your CF Administrator.

mssql: The database type for the dsn. Right now ICEGen only supports MSSQL.

_model: This is the library path you want ICEGen to put the generated files in relative to your webroot. You MUST use dot notation for the path. ie: com.example.model

Removal of __ICEGEN__ folder and XML files

ICEGen no longer creates the __ICEGEN__ folder since it doesn’t need to create XML files any more.

Removal of __Customize__.xml file

Along with the __ICEGEN__ folder removal, the __Customize__.xml has been removed also. If you want to assign defaults to variables, you can do that from within the generated cfcs. Also a note that since this file is removed, you can’t set aliases right now. Once I figure out a good way to do this, I’ll add it back. I don’t use aliases so it doesn’t bother me, but I know some do.

Along with aliases, you will also have to call the _validateunique method yourself in your validate method to validate a unqiue value in a column. Good thing is that now you don’t have to pass the keys, so, for example, if you wanted to validate that usernames entered were unique, you would just write inside the validate method:

<cfset _validateunique(“username”, local.errors, “username_error”, “User Names must be unique”)>

username: the name of the column on the table to check for uniqueness

local.errors: this is the error collection that must be passed in

username_error: an id to add to the collection if an error is found

User Names must be unique: a message stating what the error is. Can be blank.

AWESOME FEATURE: Association of VIEWS with BASE TABLE

Here’s the problem I ran into that spawned this feature. In my test database I have a table called EventBoothNumbers that holds the booths for an event. Now these booths can have a status of either being sold, pending or reserved depending on if someone buys them, puts then into their shopping cart or if they are assigned to sponsorship package.

In order to check the status of the booth from a pure CFC way, I created a method called getstatus on the EventBoothNumbers component. Next I checked the database and depending on which table contained the boothid, I did some logic and got the status. Point being that hitting the database and performing these actions, every time I called the getstatus method was a pain in the ass and SLOW. Plus the fact that if I needed to use this logic within a query for some reason, I would have to create a view and then write another method that would just use the view instead of the base table and return the results.

First off having logic in two places is bound to cause problems at some point and needless to say it isn’t very DRY. Second off using queries defeats that point of using components. What’s the solution? Combing the view along with the base table.

When you create a view that follows the format of __{TABLE NAME}__ within your database, ICEGen will pick this up and merge any fields from that into the generated classes.

So for example. Let’s say you have a Users table with the column firstname, lastname. ICEGen would obviously create a cfc called Users with a getfirstname and getlastname method. Now if you wanted a getfullname method to combine the firstname and lastname, you would have to create that yourself.

With ICEGen all you would have to do is create a view within the database called __Users__ and in the view return the keys that match the underline table (so if the underline table has an PK called userid, the view will have to return that), plus a field called fullname that combine the firstname and lastname. ICEGen would then create the fullname method for you when the Users cfc is created.

Try it out. I know the example above is hard to follow, but trust me, you will flip when you use this feature, since it can really speed your application and development time.

Installation

All you have to do is download the icegen_v2.zip file from the box.net widget and unzip it into your webroot. Add the line to your OnApplicationStart method and you’re ready to go.

Check back here for updates.

BTW

Yes you can and always have been able to use ICEGen with multiple databases. To do this now, just add a second ICEGen load line into your OnApplicationStart method like so:

<cfset CreateObject(“component”, “icegen.icefactory”).init(“mydsn1″, “mssql”, “_model1″)>
<cfset CreateObject(“component”, “icegen.icefactory”).init(“mydsn2″, “mssql”, “_model2″)>

UPDATE:

Here is a video showing the new feature (merging views and base tables) in ICEGen. Please be kind as this is my first screen cast.

About these ads

6 Responses

Subscribe to comments with RSS.

  1. Seb Duggan said, on February 25, 2008 at 12:53 pm

    Great work, Tony. I just have one query about the new views feature.

    If I’m using this in an editing environment, I would:

    * Load the record
    * Use setters to update any fields
    * Save the record

    However, if I’ve updated the first ad last names (to follow your example), if I now call the getFullName() method, it will still return the original, pre-edit full name. I would have to reload the record to get the updated full name – something which I wouldn’t have to do with the traditional getter added to the decorator – which always returns the concatenation of the current first and last names.

    It’s a very neat idea, but this example seems to limit its usefulness in day-to-day use – unless I’ve missed something?

  2. rip747 said, on February 25, 2008 at 4:23 pm

    @seb
    I totally agree with you, the example was very basic, but I only did it to show off the feature.

    I’m actually using this feature now in my application since I have some views that handle a majority of the business logic for the application. This is where the real power of this feature comes into play.

    So yeah… the example in the movie sucked since it’s really not a real world reason to use a view.

  3. Gerald Guido said, on February 12, 2009 at 12:51 pm

    The link for icegen_v2.zip is 404 on box.net

  4. rip747 said, on February 13, 2009 at 6:46 pm

    i’ve corrected the link. I was meaning to it to my github account but i just haven’t gotten the time to do yet.

  5. Randy Leinen said, on June 15, 2009 at 9:30 pm

    I have tried to run icegen, using the following line in an application.cfm file:

    But it gives me the following error: Please help me determine what is wrong. Thanks.

    \u201dcomponent\u201d, on line 1, column 21, is not a valid identifer name.

    The CFML compiler was processing:

    * An expression beginning with CreateObject, on line 1, column 8.This message is usually caused by a problem in the expressions structure.
    * A cfset tag beginning on line 1, column 2.

  6. rip747 said, on June 16, 2009 at 11:38 am

    your example line didn’t get posted, please repost it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: