Remote Synthesis
Search my blog:
Viewing By Entry / Main
Aug 03, 2006

New Open-Source Component Generator

Many months back, I wrote a post showing you how to create your own code generator using XSL stylesheets and the admin API for database introspection. There were a couple of issues with it: 1) the generated code sucked (hey, I was very new to the OO stuff) 2) it wasn't very extensible as everything was handled through a single template. Since then, I have had the opportunity to update the generator and am finally releasing it as the Illudium PU-36 Code Generator (any Looney Tunes fans out there?) as a new open-source project under an Apache 2.0 license. You can download the code via the Subversion repository by going here (note: I plan to have a project page on this site soon). Keep in mind, this is alpha software, so there are likely bugs in there.So what has changed since my original post? Quite a bit. First, I think the generated code is much cleaner and more practical. By default, it includes templates for your bean, DAO, gateway, service, transfer object and even ColdSpring XML. For items like the bean, DOA, gateway and service that contain a number of methods, I have split out the stylesheets by function to make it far easier to modify them. You can also easily add your own methods - the idea here is that you will customize your templates to suit your needs. You can also easily add entirely new templates; for instance if you wanted to generate a basic form html based on the table metadata. (p.s. if anybody does any of this, feel free to share it so it could be considered for inclusion with the project).

Another feature is that you can override the templates on a per DSN basis. So, if you would like your projectx DSN to use a customized set of stylesheets, you just place those stylesheets in a specified project folder and those will be used by default (see the readme.txt for more details).

However, if you just want to use the built in stylesheets and start generating some of the gruntwork of your daily programming, all you need to do is place the folders somewhere on your web root, set your ColdFusion administrator password in the config and that's it.

So, as you may have guessed, since it uses the admin API, it requires ColdFusion MX 7 - (my original code used the undocumented serviceFactory, but I didn't like the idea of relying on an undocumented feature, but you should be able to update it if necessary as this is used simply to pull a list of DSNs). It is also built using Mach-II, so you will need that as well. Lastly, it is currently set up to work with MySQL 5 (it should work on 4.1 but I haven't tested it) and MSSQL 200 0 (again, should work with 2005 but not tested).

Again, keep in mind this is alpha software and I am still testing it - so feel free to email me if you enounter an issue. I am also happy to entertain ideas on how I can improve the generated code (or any additions to the templates that you may have). And if this saves you hours of work, you can simply send me a thanks :)

Download the project at: http://code.google.com/p/cfcgenerator/source

Comments
Lola Lee Beno
Question - by admin password you mean the one used for CF Admin, right? Or for CF RDS? Tried both - dsn picklist isn't populated.


Brian Rinaldi
It should be the CF administrator password. The wrong password actually generates an error because the admin api will fail. The list is filtered by mysql and mssql DSNs - do you have some of one or both? Are you just seeing an empty list?


Lola Lee Beno
I have mysql DSNs. Running Mysql 5.0.17-max. I'm just seeing an empty list.


Matt Williams
I'm not sure the Open-Source list man should be contributing also. Now I'll think the list is biased. :)

Very nice. I put in my CF Admin password and my list of DSNs came up no problem (Win XP, MS SQL 2000). The default templates look pretty in line with how I do things. But I love that you made them customizable.

One specific thing I do slightly different is my Service layer search function (GetTableNames - plural) does not list all of the fields individually. It accepts a structure. Passing the form structure to the service works well. As does passing all event arguments from MachII or Model Glue. This way if I add or change a field name, I only have to make changes in the DAO and Gateway.

So I guess the next step would be to write MG Controllers or MachII Listeners. Then the event handlers. Then... can you say scaffolds?


Brian Rinaldi
Lola, I made a quick update that *should* fix your issue. The only updated file is /views/frm_DSN.cfm and it now checks the class as well as the driver key in the dsn structure. Let me know if that works for you.

Matt, thanks for the positive comments. Funny enough, it isn't even on the list yet ;). If you make any customizations or new templates you wish to share, please do. Perhaps we can add a library of templates and variations in there since, obviously, there is no one right way to do this.


Matt Williams
Just made one minor edit. In the various templates, I wasn't getting returns between the functions. So the end of the start of the DAO Read function started immediately after the create function like so..
</cffunction> <cffunction name="read"

I made an edit it XSLService.cfc to add 2 returns on line 58:
<cfset innerXSL = innerXSL & CHR(13) & CHR(13) & tmpXSL />

FYI: As I work on a project this morning, I'm already putting it to use! Of course this means you'll have to get yourself an Amazon wish list. Or just post your iTunes ID so we can get you gift certs.


Brian Rinaldi
Thanks Matt. I had actually intended to make that correction and totally lost track of it...so I'm glad you reminded me. Its in and committed. Glad to hear you are finding it useful already (and if you do feel so inclined, you can find me on itunes by my email address :)


Edward T
Thank you, Brian - I love it! It just *works*!


Kevin Roche
Brian,

This is just what I was looking for. I am planning to write a scaffolding lexicon for Fusebox 5 and reading your code has shown me how to do it.

Kevin


Aaron Rouse
Has anyone gotten this to work with MSSQL 2005?


Brian Rinaldi
I don't have mssql 2005 installed, but what is happening? Is it just not listing the 2005 databases on the list? If so, that is just probably an issue on how it filters the list by driver. Send me more info and I would be glad to help - or post bugs to the the bug tracker on the google code site.


Aaron Rouse
I will run it again when I get home tonight then post it in the bug tracker.

Here is what I recall though. Initially when I setup MSSQL 2005 as a datasource I used MS's driver, so it never shows up "Add New Data Source > Driver" drop down within the CF Admin menu. Another result is those datasources would not show up in Illudium's drop down. So what I did is I setup a test datasource using CF's Microsoft SQL Server driver. At this point Illudium's drop down then showed the test datasource but when I tried to run against it, it would error out with missing some stored procedure.

I was wondering what it would take to port the code over to work with Oracle as well. Hoping to get time this week to look at the code and see what that might take.


Brian Rinaldi
Looking forward to getting the details. There is a bug already logged about it not showing on the list when you use any other than the provided drivers in CF. The only stored procedure I still use is the sp_keys one to determine the primary keys...is that the one that is failing?


Aaron Rouse
Sorry for the delay, had some CF Server issues on my dev box that I had to resolve first.

This is the error I am getting:

[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'master.dbo.spt_datatype_info'.


Brian Rinaldi
Sorry for the delay, but I have just committed a bunch of changes - particularly to the mssql.cfc that should resolve the compatibility issues. I do not have SQL Server 2005, so please let me know if this works.


Aaron Rouse
I just did a quick test and that seems to have fixed the 2005 issues. After glancing at the DB specific CFCs I think I could easily get an Oracle one made. If/when I get the time to get to it, I will send the file to you.


dan
Brian,
I really love the code generator. Most of all it is very easy to use and customize. Everyone breaks down components in their applications differently so I was wondering if you have an example app of using the generated cfcs. Just a small application that incorporates the generated cfc's and coldspring. It may help me to uderstand the usage for all of the different cfcs. Thanks!!!


Brian Rinaldi
Dan, good idea. I did however update some methods of the service component and it should make more sense now. Sorry for any confusion this may have caused...I didn't actually use the service that was generated, but now it should make more sense (and be more usable).


Travis A.
I'm trying to populate a ComboBox in Flex with a list of DSNs, like you have in your app, using the cfide.adminapi.datasource api. I get an error saying that the cfc cannot be accesses remotely. I'm using remote object to get the data. I downloaded your code, but the mxml code is not part of the download. Would it be possible for you to show what needs to be done in mxml to populate the ComboBox. Thanks.


Brian Rinaldi
Is your method set to access="remote"? For what its worth, the Flex code is available via SVN. Keep in mind its several years old but if all you want is to populate a list of DSN's you can easily take all the code you want.


Write your comment



(it will not be displayed)