Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions dbrow3mapper.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
<cffunction name="init" returntype="dbrow3mapper" output="yes" access="public">
<cfargument name="applicationName" type="string" required="true">
<cfargument name="useCacheFile" type="boolean" required="true">
<cfargument name="deleteCacheFile" type="boolean" required="true" hint="delete first, then rebuild">
<cfargument name="deleteCacheFile" type="boolean" required="true" hint="Regenerate and replace cache">
<cfargument name="cacheDir" type="string" default="#getTempDirectory()#">

<cfset var cacheFile = "#arguments.cacheDir#/dbrow3mapper_#arguments.applicationName#.xml">
<cfset var cacheXML = "">

<cfif arguments.deleteCacheFile>
<cfset deleteFileIfExists(cacheFile)>
</cfif>

<!--- Private variables - leon 12/12/07 --->
<cfset stObjInfo = structNew() />
<cfset stObjInfo.stTableToObject = structNew()>
Expand All @@ -31,29 +27,23 @@
<cfset stObjInfo.stObjectToPath = structNew()>
<cfset stObjInfo.rsTypeTable = QueryNew( "tableName,immutableName,id,objPath" ) >

<!--- Figure out if we should use the cache file instead of instantiating
all of the objects.
This is much faster than instantiation, but won't include objects/
tables created after the cache file was last built. As such, the
default behavior is to not use the cache file. - leon 2/21/11 --->
<cfif arguments.useCacheFile AND NOT Len(Trim(arguments.applicationName))>
<cflog type="warning" text="App indicated that dbrow3mapper cache should be used,
but application.applicationName is not present, so we can't name the cache file and won't use it.">
<cfthrow message="App indicated that dbrow3mapper cache should be used,
but application.applicationName is not present, so we can't name the cache file.">
</cfif>

<cfif arguments.useCacheFile and fileExists(cacheFile)>
<cfif arguments.useCacheFile and not arguments.deleteCacheFile and fileExists(cacheFile)>
<cfset logIt("Reading cache file: #cacheFile#") />
<cffile action="read" file="#cacheFile#" variable="cacheXML" />

<cfset logIt('Deserializing stObjInfo from cache XML') />
<cfwddx action="wddx2cfml" input="#cacheXML#" output="stObjInfo" />

<cfelse>
<cfset logIt('Cache file not present or being ignored. Scanning for objects.') />
<cfset logIt('Cache file not present, being ignored, or being replaced. Scanning for objects.') />
<cfset this.scanForObjects()>

<cfif arguments.useCacheFile>
<cfif arguments.useCacheFile or arguments.deleteCacheFile>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think the use case likely doesn't really exist, given the names of the arguments I think it may be better to have this as:

<cfif arguments.useCacheFile>
//Writing the cache file, as is currently happening
<cfelseif arguments.deleteCacheFile>
//delete the cache file without writing a new one, effectively moving the delete command that used to be up top down here
<cfelse>
//do nothing, as is currently happening

This preserves the previous effective functionality, while still having the benefit of not having a missing cache file while the new copy is being constructed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm intentionally changing the meaning of deleteCacheFile to be "replace cache file". Of the few known apps (2?) that use this library, I don't think there are any use cases that would just want to delete file and not replace it.

<cfset logIt('Serializing stObjInfo scope to XML') />
<cfwddx action="cfml2wddx" input="#stObjInfo#" output="cacheXML" />

Expand Down