Illudium PU-36 Code Generator with Oracle Schemas
Brian Rinaldi's Illudium PU-36 Code Generator (cfcgenerator) is a wonderful tool that can save many hours of tedious work. I typically use it for generating DAOs, gateways, starter services, beans and ColdSpring configs. But, it does so much more.
Depending on the size and setup of your shop, you may regularly use Oracle schemas to qualify your table names. One thing missing from the latest version is the ability to use Oracle schemas when automagically generating your code.
Here is an update that will allow your schemas show up in the list of tables through the PU-36 interface as well as in your generated code. Also, don't worry about overly complex changes to multiple fles. Thanks to Brian, interaction with the database is all located within the same CFC.
Simply replace the following functions within Oracle.cfc:
<cfset var qAllTables = "" />
<cfset objTable = "" />
<cfset arrReturn = arrayNew(1) />
<cfif not len(variables.dsn)>
<cfthrow message="you must provide a dsn" />
</cfif>
<cfquery name="qAllTables" datasource="#variables.dsn#">
SELECT owner
, TABLE_NAME
, 'TABLE' TABLE_TYPE
FROM all_tables
order by owner, TABLE_NAME
</cfquery>
<cfloop query="qAllTables">
<!--- modified by Phil Hulsey --->
<cfset objTable = createObject("component","cfcgenerator.com.cf.model.datasource.table.table").init(qAllTables.owner & "." & qAllTables.table_name,qAllTables.table_type) />
<!--- end modification --->
<cfset arrayAppend(arrReturn,objTable) />
</cfloop>
<cfreturn arrReturn />
</cffunction>
<cfargument name="table" type="string" required="true" />
<!--- modified by Phil Hulsey --->
<cfif listlen(arguments.table,".") gt 1>
<cfset variables.schema = listfirst(arguments.table,".") />
<cfset variables.table = listlast(arguments.table,".") />
<cfelse>
<cfset variables.table = arguments.table />
</cfif>
<!--- end modification --->
<cfset setTableMetadata() />
<cfset setPrimaryKeyList() />
</cffunction>
<cfset var xmlTable = "" />
<!--- convert the table data into an xml format --->
<!--- added listfirst to the sql_type because identity is sometimes appended --->
<cfxml variable="xmlTable">
<cfoutput>
<root>
<bean name="#listLast(variables.componentPath,'.')#" path="#variables.componentPath#">
<!--- modified by Phil Hulsey --->
<dbtable name="<cfif isDefined("variables.schema")>#variables.schema#.</cfif>#variables.table#">
<!--- end modification --->
<cfloop query="variables.tableMetadata">
<column name="#variables.tableMetadata.column_name#"
type="<cfif variables.tableMetadata.type_name EQ 'varchar2' AND variables.tableMetadata.length EQ 35 AND listFind(variables.primaryKeyList,variables.tableMetadata.column_name)>uuid<cfelse>#translateDataType(listFirst(variables.tableMetadata.type_name," "))#</cfif>"
cfSqlType="#translateCfSqlType(listFirst(variables.tableMetadata.type_name," "))#"
required="#yesNoFormat(variables.tableMetadata.nullable-1)#"
length="#variables.tableMetadata.length#"
primaryKey="#yesNoFormat(listFind(variables.primaryKeyList,variables.tableMetadata.column_name))#"
identity="#variables.tableMetadata.identity#" />
</cfloop>
</dbtable>
</bean>
</root>
</cfoutput>
</cfxml>
<cfreturn xmlTable />
</cffunction>
That's it!

Comments
There are no comments for this entry.
[Add Comment]