Illudium generator gotcha!

I know I haven't been writing for a while, however this is something really interesting that happened to us here at work and I figure it may help someone else out there. We are using the well known Illudium PU-36 Code Generator from Brian Rinaldi. I use it for a project that connects to MSSQL and had no trouble generating the code, I even created my own template based on the "Prototype" provided with the generator. It creates nice clean code that we can start working on right away. The problem we had was that we were getting "duplicate parameters" and "duplicate Properties" once we started using any Oracle database. I started digging the code and learned a lot in the process, one thing I noticed is that on the adminAPIFacade.driverOrClassToType() method Brian checks for the datasource's Driver and Class values and if it finds "oracle" then uses "oracle.cfc" to get metadata from the database. If it finds "mssql" then it uses "mssql.cfc" to get the metadata from SQL Server. If nothing is matched then it tries to use the new CF8 for metadata extraction, the component used for that is scorpio.cfc. Well everything looked good there, logic look solid and things were working OK. The problem was on our side. I checked our datasources and every Oracle DSN is using "Other" as the driver. This turns out to be a JDBC connection where the Driver Class is "macromedia.jdbc.MacromediaDriver" and the driver Name is "MacromediaDriver" nowhere in these values you will find the word "Oracle". That's why the adminAPIFacade.driverOrClassToType() method was returning "Scorpio" all the time. Now I don't know why the CF8 tags are returning duplicate information on the metadata but I knew that I needed to find a way to tell the method to start using Oracle.cfc instead of scorpio.cfc. I found the answer on the datasource.url value. Right now it reads JDBC URL : jdbc:macromedia:oracle://[serverName]:1521;ServiceName=[ServiceName];AlternateServers=([ServerName2]:1521);LoadBalancing=true So I added that to the method and now all generated code is coming the way is supposed to be. Final method looks like this. <cffunction name="driverOrClassToType" access="private" output="false" returntype="string"> <cfargument name="datasource" required="true" type="struct" /> <cfif ((arguments.datasource.driver eq "MSSQLServer") or (arguments.datasource.class contains "MSSQLServer") or (arguments.datasource.url contains "MSSQLServer"))> <cfreturn "mssql" /> <cfelseif ((arguments.datasource.driver contains "mySQL") or (arguments.datasource.class contains "mySQL"))> <cfreturn "mysql" /> <cfelseif ((arguments.datasource.driver contains "Oracle") or (arguments.datasource.class contains "Oracle") or (arguments.datasource.url contains "oracle"))> <cfreturn "oracle" /> <!--- if you are running cf8 we can try to leverage db metadata tags ---> <cfelseif listFirst(server.coldfusion.ProductVersion) gte 8 and arguments.datasource.driver neq "MSAccess"><!--- only access with unicode seems to work with dbinfo ---> <cfreturn "scorpio" /> <cfelse> <!--- not a supported type ---> <cfreturn "" /> </cfif> </cffunction> çB^]\..

1 comment:

Anonymous said...

Hey It worked for me. Great. Thanks.
BTW, you missed which file to change, and here it is.
com\cf\model\adminAPI\adminAPIFacade.cfc