Quick Note

Just a quick note to say that the zip file on RiaForge for ValidatorCFC (http://validatorcfc.riaforge.org/) was incorrect. Thanks to Bill D (http://brainbox.tv) for the head's up.

I also attached it to this post. Use the download link below.

Follow me on Twitter

Update to ValidatorCFC

I released a new version of ValidatorCFC. Aaron Greenlee (http://www.aarongreenlee.com) sent me some changes. With his changes, you can now specify which properties you want validated. So even if in your object you say that last name and first name are required, if you pass in only the last name property, only that field will be validated. There is more info within the CFC itself, and in the test files in the zip. You can download the zip file using the download link on this entry, or from RIAForge.

Transfer Error when using ntext or text and a ManyToMany Relationship

When you set Transfer to use a table that has an ntext or text column on SQL Server 2000 (and perhaps later versions) and also a many to many relationship you may receive the following error when you attempt to retreive the collection for the many to many:
[Macromedia][SQLServer JDBC Driver][SQLServer]Only text pointers are
allowed in work tables, never text, ntext, or image columns. The query
processor produced a query plan that required a text, ntext, or image
column in a work table.
For example I have the following tables set up
Table Name: Table1
id        char(35)    primary key
title        varchar(255)    
description    ntext

Table Name: Table2
id        char(35)    primary key
description    varchar(255)

Table Name: Table1_Table2
table1_id    char(35)    composite key
table2_id    char(35)    composite key
And the following transfer configuration:
<transfer>
    <objectDefinitions>
        <object name="Table1" table="table1">
            <id name="id" type="UUID" generate="true" />
            <property name="title" type="string" nullable="false" />
            <property name="description" type="string" nullable="true" />
            <manytomany name="Relation" table="Table1_Table2" lazy="true">
                <link to="Table1" column="table1_id" />
                <link to="Table2" column="table2_id" />
                <collection type="array">
                    <order property="description" order="asc" />
                </collection>
            </manytomany>    
        </object>
        <object name="Table2" table="Table2">
            <id name="id" type="UUID" generate="true" />
            <property name="description" type="string" nullable="false" />
        </object>
    </objectDefinitions>
</transfer>
So when you call getRelationArray() on a Table1 object. You will receive the error. To correct this I took the following steps: Create a for table 1 with the ntext column casted to varchar: select id,title,cast(description as varchar(8000)) as description from table1 Save this as vwTable1. Change your transfer config to point to the view instead of table one so
<object name="Table1" table="table1">
becomes
<object name="Table1" table="vwTable1">
Now, you wont be able to run it yet because the view is not updatable since you used the casted field. To overcome this we are going to use an INSTEAD OF trigger. You need to create 2 triggers. One will be called whenever UPDATE is called on the vwTable1 and the other will be called when INSERT INTO is called on vwTable1 You can create the triggers as follows, obviously change it to suit your table's needs:
CREATE trigger io_trigger_insert_vwTable1 on vwTable1
instead of insert
as
begin
    set nocount on
    if (not exists (select t.[id] from table1 t, inserted i where t.[id] = i.[id]))
        insert into table1
        select
            [id],
            [title],
            [description]
        from
            inserted
end
create trigger io_trigger_update_vwAd on vwAd
instead of update
as
begin
set nocount on
if (exists (select t.[id] from table1 t, inserted i where t.[id] = i.[id]))
    update
        table1
    set
        title = i.title,
        [description] = i.[description]
    from
        table1 t, inserted i
    where
        t.[id] = i.[id]
end
Once you have created these triggers you should be able to use Transfer as you normally would. Using the casted column in the view will allow you to call the getRelationArray(). The SQL that Transfer creates will no longer be invalid. You may run into a couple of other items though. First, your ntext field is now limited to 8000 characters since you are casting it to varchar. You may be able to increase this, but I haven't tried. Your mileage may vary, but be sure before the value is passed to transfer that it is validated as less than 8000 characters (perhaps in your decorator). Next, if you have any non-null, defaulted columns in your base table (a created date perhaps) you HAVE to provide a value when you call insert into vwTable1. Since Transfer is creating this SQL you have to ensure that Transfer includes that column. This means that you cannot use the ignore-insert="true" option in the transfer configuration. SQL Server will still respect your default value, as long as you provide that column in the sql statement pointed at the view. You can find more information about INSTEAD OF INSERT and INSTEAD OF UPDATE triggers on the MSDN site. I have only used this in a simple application with two base tables and one relationship table, so if your setup is more complex it may not work out for you.

Webservices Change in CF 8.0.1

It seems with the change to 8.0.1 there is a difference in the way CF generates the stubs for a CFC called as a web service. I had a CFC called webservices.cfc and on 8.0 it was working fine calling the methods, but with the 8.0.1 it started throwing a "duplicate file name" error. This seems to be because CF creates its own stub file Webservices.java and also a [cfcname].java file. CF couldn't create both so it threw an error. The solution was to rename my CFC. The stubs can be found in C:\ColdFusion8\stubs\ on windows, and if I remember correctly /Applications/ColdFusion8/stubs/ on Mac OS X.

Issue w/ Eclipse Resource Bundle Editor Plugin and Leopard

There seems to be an issue with the Resource Bundle Editor Plugin for Eclipse. (http://sourceforge.net/projects/eclipse-rbe/)

I installed version 0.7.7 into a fresh install of the Eclipse 3.3 SDK and was unable to open a resource file. I would get the following error:

Can't start the AWT because Java was started on the first thread. Make sure StartOnFirstThread is not specified in your application's Info.plist or on the command line

To fix it I edited the eclipse.ini file (/Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini by default) to add the following line:

-Djava.awt.headless=true

Once I did that it was fine and I was able to edit the resource bundles.

Hope this helps someone searching for the issue!

ColdFusion ORM - Developing the Business Objects First

Since I have transitioned from a world of spaghetti code through the land of the uber-cfc, and finally onto some OO concepts, I have tried to figure out what the best way to create the business objects and persist them to the database. For nearly ever application I have developed, I have created the database first, since, in my mind, understanding the data is the first step to understanding the way the application will function.

However, in the OO world, the primary step is to design the business objects. In my latest project I decided to take one step deeper into the OO world and develop all my business objects forgetting all about how the database would be laid out. I had no problems with this, authoring complex objects containing arrays or instances of other objects without issue.

Then I needed to figure out how to persist them. In the past, each of my business objects directly mapped to a table in my database. This made it easy to build a code generator, read in the DB metadata and, in the words of John Madden, "Boom", I had my beans, DAOs, and Gateways.

Now, I see what Sean Corfield refers to as the "5:1 Syndrome". I have a dumb bean object, a DAO, a Gateway, a Service and, if using Model-Glue, a Controller for nearly every object, and in turn every table in the database. This always seemed like code bloat to me, so I was very happy to see other, like Sean, refer to it as such. There must be a better way!

Trying to avoid this I decided, OK I'll use Reactor. Active Record, generated code, sounds good. Then I realized that I have to create the database first. Back to square one.

Should business objects reflect the organization of the database? They can, but if it doesn't fit the way the business object is used in the application, then no, it shouldn't. Also, from the other way, the best way to organized the business objects is probably not the best way to organize the database. The database should be in 3NF, avoid duplication whereever possible, etc, etc.

Not wanting to trash all the BOs I created already, I decided I would write all the persistance stuff myself. So now that I have some beans, I created a service for each and wired them up in ColdSpring. I put all the methods that would normally go in my DAO (save, new, and CRUD) in my service as well as some getAll() calls.

As a side note, I don't return query objects since, even though they are faster than creating an array of objects, I cant call a complex getter, such as a calculated value easily, and this allows me to use the same calls to get the data for one instance of an object as I do for a collection.

Now I have a BO and a service that is completely separate from the DB. Persisting complex objects is a bit more complicated than using the 1:1 BO to DB mapping, but it works. The only issue is, I don't want to have to maintain all this manually. I wish we had a mapping tool to handle persistance from BO to DB without requiring that the DB reflect the BO or vice versa.

Java has Hibernate to handle this issue. With CF8 we can now use Hibernate with a Java model, but what if we want to model using CFCs? cfHibernate attempted to do this and seems to have run into some issues. Can we use Hibernate to map CF objects to the DB? I am going to attempt to find an answer for this in the next few weeks for my current project. Hopefully I can find a solution.

ColdFusion 8 Released!

Just a quick note that CF8 has been released by Adobe. If you haven't seen the new features, download a copy and see for yourself.

ValidatorCFC

This component validates the data in an object according to custom rules you set up. It is especially created to determine data validity for a data store (DBMS, etc) rather than for business rules, but you can set up your own complex rules. Some may be out of its scope, however.

I just uploaded version 0.1.000. It is very much a work in progress and I welcome feedback.

Take a look and let me know what you think. You can find it at http://validatorCFC.riaforge.org or at the download link below.

Here is a rundown of an example usage:

[More]

Technorati

Look for me on Technorati! My Technorati Profile

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9.3.006. Contact Blog Owner