Rip's Domain

ICEGen: Part 4 – exploring the __Customize__.xml file

Posted in ColdFusion, ICEGen by rip747 on July 31, 2007

The heart of ICEGen is the __Customize__.xml file. This is the file that you will want to edit when you first run ICEGen. Essentially this file allows you to customize how ICEGen will generate your code. The file is located within the __ICEGEN__ directory that was created where you told ICEGen to save your generated code.

Upon opening it up will you notice that that the XML is broken down into easy to read sections like so:

<table>
<name>tblContact</name><alias>Contact</alias>
<columns>
<column>
<name>ContactID</name>
<alias>ContactID</alias>
</column>
<column>
<name>creationdate</name>
<alias>creationdate</alias>
<required>1</required>
<default><![CDATA[#Now()#]]></default>
<validateas></validateas>
<unique></unique>
</column>
<column>
<name>email</name>
<alias>email</alias>
<required>0</required>
<default/>
<validateas><![CDATA[email]]></validateas>
<unique>1</unique>
</column>
<column>
<name>FirmID</name>
<alias>FirmID</alias>
<required>1</required>
<default/>
<validateas></validateas>
<unique></unique>
</column>
<column>
<name>firstname</name>
<alias>firstname</alias>
<required>0</required>
<default/>
<validateas></validateas>
<unique></unique>
</column>
<column>
<name>lastname</name>
<alias>lastname</alias>
<required>0</required>
<default/>
</column>
<column>
<name>title</name>
<alias>title</alias>
<required>0</required>
<default/>
<validateas></validateas>
<unique></unique>
</column>
</columns>
</table>

Each table section or node represents a table in your DSN. Within each table node is the columns node which contains a representation of each column in that table.

In the example above I have a table named “tblContact”. To make things easier in my code I’ve decided that I wanted to rename this to “Contact” for my application. By changing the <alias> node within the table node to “Contact”, I’m telling ICEGen to now create a CFC called “Contact” that will represent the “tblContact” table. It’s important that you do not edit the <name> node as this tells ICEGen the original table name that exists inside your DSN that it will externally rename for you.

Also ICEGen allows you to do this for each column within the table also. I usually choose pretty good names for my columns, but suppose I wanted to alias the “creationdate” column by some other name, say “createddate”. All I would have to do is edit the <alias> node for the “creationdate” column and change it to “createddate”. ICEGen would then create a corresponding getter and setter for “createddate” while still internally mapping the alias to the “creationdate” column. This allows you to take badly planned or cryptic column names and turn them into names that you can understand within your model.

Besides the <alias> node, there are a couple of other nodes that you can customize with ICEGen for each column. Here’s what they do:

<required> -This allows you to take a column that normally would accept a null value within your table and make it required within your model. Say for instance that I want to make sure that each contact had a firstname. I would change the required node value to 1 and upon rerunning ICEGen, it would create the corresponding validation making this property required within my model. Valid values are 1 and 0 (default).

<default> – ICEGen tries to translate the default that you have set within your DSN for each column to ColdFusion code. As great as this may sound, there are sometimes where it just can’t do this, since each database server has it own code. This node allows you to do this yourself or change the default to something else. You’ll notice that the “creationdate” column has a default of “#now()#”, this is a default that ICEGen was able to translate from the database. But suppose I want to change this to only write the date and not the time to the column, and example would be “07/30/2007”. What I can do is edit the default for the “creationdate” column and change it to “#DateFormat(now(), ‘mm/dd/yyyy’)#”. Remember that you have to put the pound signs around any CF functions that you are going to be using.

<validateas> – Sometimes just making sure that a value is entered for a property just isn’t enough, you want to make sure that it’s a certain type. Using “validateas” can make that happen. After ICEGen checks to make sure that a value is passed in for the property it will validate as one of the following using IsValid(): creditcard, date, time, email, eurodate, ssn, social_security_number, telephone, url, uuid, usdate or zipcode. In the example abov, I’m telling ICEGen to make sure that any value entered for the email column must also be a valid email address.

<unique> –  ICEGen will make sure that only unique values are entered into this column. In the example above ICEGen will make sure that no two contacts enter in the same email address. Valid values are 1 and 0 (default).

By editing the __Customize__.xml file, you can manipulate the properties for your tables and columns for your current application within having to change the database directly. It’s important that you rerun ICEGen after making any changes to the __Customize__.xml for your changes to take affect. Also ICEGen will NOT delete any of the old CFCs that it created before. This allows you to copy already existing code from an old CFC to the new one without losing anything.

ICEGen: Part 1 – Installation
ICEGen: Part2 – Generation
ICEGen: Part 3 – Directories and Files

2 Responses

Subscribe to comments with RSS.

  1. Joshua said, on September 5, 2007 at 1:46 pm

    How can I exclude tables?
    I customized my Customise xml file and it didn’t exclude the extra tables I had in my db.

  2. rip747 said, on September 7, 2007 at 9:22 am

    I never added that in. If you don’t want to use a DAO that is generated, you don’t have to.


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

%d bloggers like this: