From: <jfi...@us...> - 2003-01-08 16:34:20
|
Update of /cvsroot/modus/org/bacfug/modus/persistence In directory sc8-pr-cvs1:/tmp/cvs-serv30120 Modified Files: simplefilesystempersister.cfc Removed Files: simpleobjectinstance.cfc Log Message: Still cleaning out the old code base and adding pieces that didn't make it. Index: simplefilesystempersister.cfc =================================================================== RCS file: /cvsroot/modus/org/bacfug/modus/persistence/simplefilesystempersister.cfc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** simplefilesystempersister.cfc 5 Oct 2002 01:05:12 -0000 1.3 --- simplefilesystempersister.cfc 8 Jan 2003 16:34:16 -0000 1.4 *************** *** 1,62 **** <cfcomponent extends="org.bacfug.modus.persistence.basePersister" displayname="fileSytemByType" hint="The basic component for storing object instances under the WEB-INF directory on the file system."> ! <!--- information about the base directory ---> ! <!--- this should really be in the config!! ---> ! <cfparam name="instance.baseModusDir" default="#expandPath("/WEB-INF/modus/")#"> ! <cfparam name="instance.objectStoreDir" default="#instance.baseModusDir#objectstore/"> ! ! <!--- make sure the base directory exists ---> ! <cfif NOT directoryExists(instance.objectStoreDir)> ! <cfdirectory action="create" directory="#instance.objectStoreDir#"> ! </cfif> ! ! <cffunction name="save" access="public" output="no" returnType="void" hint="The method to save data"> ! <cfargument name="contentObject" required="yes"> ! <cfset var objectToSave = ""> ! <cfset var packet = ""> ! <!--- make sure we're dealing with a contentObject ---> ! <cfif isContentObject(arguments.contentObject)> ! <cfscript> ! //make the storage struct ! packet = contentObjectToWddx(arguments.contentObject); ! </cfscript> ! <!--- write the file ---> ! <cffile action="write" file="#getPathFromObject(arguments.contentObject)#" output="#packet#"> ! <!--- put the object in the cache ---> ! <cfset instance.cache.putObject(arguments.contentObject)> ! <!--- if it's not a good contentObject ---> ! <cfelse> ! <cfthrow type="modus.badContentObject" message="Bad ContentObject" detail="A bad contentObject was passed to save() in #getMetaData(this).name#"> ! </cfif> ! </cffunction> ! <cffunction name="get" access="public" output="no" returnType="org.bacfug.modus.baseContentObject" hint="The method to get a particular data instance"> ! <cfargument name="id" type="string" required="yes"> ! <cfset var objectRetrieved = ""> ! <cfset var getQuery = ""> ! <cfset var packet = ""> ! <cfset var dirToCheck = getBaseStorageDirectory()> ! <!--- if this object is cached, return that one ---> <cfscript> ! if(instance.cache.isObjectCached(arguments.id)){ ! objectRetrieved = instance.cache.getObject(arguments.id); ! if(structCount(arguments) GT 1) ! return contentObjectPopulateFromInstance(arguments[2],objectRetrieved); ! else ! return objectRetrieved; } </cfscript> - <!--- try getting this instance ---> <cfdirectory action="list" directory="#dirToCheck#" name="getQuery" filter="#arguments.id#*"> - <cfscript> //if we found one, grab the object if(getQuery.recordCount){ objectRetrieved = getObjectFromFile(getQuery.name[1]); - //if there is a second argument, it means we need to load that instance - if(structCount(arguments) GT 1){ - contentObjectPopulateFromInstance(arguments[2],objectRetrieved); - } } //if none found, that's a bad error --- 1,35 ---- <cfcomponent extends="org.bacfug.modus.persistence.basePersister" displayname="fileSytemByType" hint="The basic component for storing object instances under the WEB-INF directory on the file system."> ! <!--- information about the base directory ---> ! <!--- this should really be in the config!! ---> ! <cfparam name="instance.baseModusDir" default="#expandPath("/WEB-INF/modus/")#"> ! <cfparam name="instance.objectStoreDir" default="#instance.baseModusDir#objectstore/"> ! <!--- make sure the base directory exists ---> ! <cfif NOT directoryExists(instance.objectStoreDir)> ! <cfdirectory action="create" directory="#instance.objectStoreDir#"> ! </cfif> ! <!--- ! ACCESSORS ! ! ---> ! <cffunction name="get" access="public" output="no" returnType="struct" hint="The method to get a particular data instance"> ! <cfargument name="id" type="string" required="yes"> ! <cfset var objectRetrieved = ""> ! <cfset var getQuery = ""> ! <cfset var packet = ""> ! <cfset var dirToCheck = getBaseStorageDirectory()> ! <cfif len(arguments.id)> <!--- if this object is cached, return that one ---> <cfscript> ! if(instance.cache.isObjectCached(arguments.id, getName())){ ! return instance.cache.getObject(arguments.id, getName()); } </cfscript> <!--- try getting this instance ---> <cfdirectory action="list" directory="#dirToCheck#" name="getQuery" filter="#arguments.id#*"> <cfscript> //if we found one, grab the object if(getQuery.recordCount){ objectRetrieved = getObjectFromFile(getQuery.name[1]); } //if none found, that's a bad error *************** *** 65,161 **** } </cfscript> ! <cfset instance.cache.putObject(objectRetrieved)> <cfreturn objectRetrieved> ! </cffunction> ! ! <cffunction name="getAll" access="public" returntype="array" output="no" hint="The method to get all data instances of a particular type"> ! <cfargument name="type" required="no" default=""> ! <cfset var getQuery = ""> ! <cfset var objectArray = arrayNew(1)> ! <cfset var packet = ""> ! <cfset var filter = "*"> ! <cfset var dirToCheck = getBaseStorageDirectory()> ! <cfset var objectID = ""> ! <cfset var objectInstance = ""> ! <cfscript> ! //if a type is passed, set the filter ! if(len(trim(arguments.type))){ ! filter = "*." & arguments.type; ! } ! </cfscript> ! <!--- get the appropriate files into a query ---> ! <cfdirectory action="list" directory="#dirToCheck#" name="getQuery" filter="#filter#"> ! <!--- loop through files, parsing them and putting the contents into the objectArray ---> ! <cfloop query="getQuery"> ! <cfset objectID = getObjectIDFromFileName(name)> ! <cfif instance.cache.isObjectCached(objectID)> ! <cfset objectInstance = instance.cache.getObject(objectID)> ! <cfelse> ! <cfset objectInstance = getObjectFromFile(name)> ! <cfset instance.cache.putObject(objectInstance)> ! </cfif> ! <cfset objectArray[currentRow] = objectInstance> ! </cfloop> ! <!--- return the array of objects ---> ! <cfreturn objectArray> ! </cffunction> ! ! <!--- a method to get an object from the name of its storage file ---> ! <cffunction name="getObjectFromFile" access="private" returnType="org.bacfug.modus.baseContentObject" output="no" hint="returns an object instance based on the name of the file"> ! <cfargument name="fileName" type="string" required="yes"> ! <cfset var packet = ""> ! <cftry> ! <cffile action="read" file="#getBaseStorageDirectory()##arguments.fileName#" variable="packet"> ! <cfcatch> ! <cfthrow type="modus.badFile" message="File does not exist" detail="The requested file ""#arguments.fileName#"" does not exist."> ! </cfcatch> ! </cftry> ! <!--- if there is a second argument, it means we're loading an existing object ---> ! <cfif structCount(arguments) GT 1> ! <cfreturn wddxToContentObject(packet,arguments[2])> ! <!--- otherwise, just return the object ---> <cfelse> ! <cfreturn wddxToContentObject(packet)> ! </cfif> ! </cffunction> ! ! <!--- a method to get the directory path based on an object ---> ! <cffunction name="getPathFromObject" access="private" returnType="string" output="no" hint="returns a full path based on an object"> ! <cfargument name="contentObject" type="org.bacfug.modus.baseContentObject" required="yes"> ! <cfset var directoryPath = getBaseStorageDirectory()> ! <cfset var fullPath = ""> ! <cfscript> ! //make sure the directory exists ! directoryInit(directoryPath); ! //set the full path ! fullPath = directoryPath & arguments.contentObject.getID() & "." & arguments.contentObject.getType(); ! </cfscript> ! <!--- now, be sure ---> ! <cfreturn fullPath> ! </cffunction> ! <!--- gets the ID from a file name ---> ! <cffunction name="getObjectIDFromFileName" access="private" returnType="string" output="no" hint="returns the ID of an object based on the file in the persistence"> ! <cfargument name="fileName" required="yes" type="string"> ! <cfreturn listFirst(fileName,".")> ! </cffunction> ! <!--- a method to get the base directory for storage ---> ! <cffunction name="getBaseStorageDirectory" access="private" returnType="string" output="no" hint="returns the path to the base storage directory"> ! <cfreturn instance.objectStoreDir> ! </cffunction> ! <!--- a method for make sure directories exist in the storage directory ---> ! <cffunction name="directoryInit" access="private" returnType="void" output="no" hint="a method for make sure directories exist in the storage directory"> ! <cfargument name="directory" required="yes" type="string"> ! <!--- if the directory does not exist, create it ---> ! <cfif NOT directoryExists(arguments.directory)> ! <cfdirectory action="create" directory="#arguments.directory#"> </cfif> ! </cffunction> ! <!--- a method to throw an error (DAMN YOU CFSCRIPT FOR NOT HAVING THIS FUNCTION ALREADY! ---> ! <cffunction name="throwError" access="private" returnType="void" output="no"> ! <cfargument name="type" required="yes"> ! <cfargument name="message" requied="yes"> ! <cfargument name="detail" required="no" default=""> ! <cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#"> ! </cffunction> </cfcomponent> --- 38,141 ---- } </cfscript> ! <!--- put the object in the cache ---> ! <cfset instance.cache.putObject(objectRetrieved, getName())> ! <!--- return the object ---> <cfreturn objectRetrieved> ! <!--- Return a new object ---> ! <cfelse> ! <cfreturn getNewObject()> ! </cfif> ! </cffunction> ! <cffunction name="getAll" access="public" returntype="array" output="no" hint="The method to get all data instances of a particular type"> ! <cfset var getQuery = ""> ! <cfset var objectArray = arrayNew(1)> ! <cfset var packet = ""> ! <cfset var filter = "*." & getName()> ! <cfset var dirToCheck = getBaseStorageDirectory()> ! <cfset var objectID = ""> ! <cfset var objectInstance = ""> ! <!--- get the appropriate files into a query ---> ! <cfdirectory action="list" directory="#dirToCheck#" name="getQuery" filter="#filter#"> ! <!--- loop through files, parsing them and putting the contents into the objectArray ---> ! <cfloop query="getQuery"> ! <cfset objectID = getObjectIDFromFileName(name)> ! <cfif instance.cache.isObjectCached(objectID, getName())> ! <cfset objectInstance = instance.cache.getObject(objectID, getName())> <cfelse> ! <cfset objectInstance = getObjectFromFile(name)> ! <cfset instance.cache.putObject(objectInstance, getName())> </cfif> ! <cfset objectArray[currentRow] = objectInstance> ! </cfloop> ! <!--- return the array of objects ---> ! <cfreturn objectArray> ! </cffunction> ! <!--- ! ! MUTATORS ! ! ---> ! <cffunction name="save" access="public" output="no" returnType="void" hint="The method to save data"> ! <cfargument name="contentObject" required="yes"> ! <cfset var objectToSave = ""> ! <cfset var packet = contentObjectToWDDX(arguments.contentobject)> ! <!--- write the file ---> ! <cffile action="write" file="#getPathFromObject(arguments.contentObject)#" output="#packet#"> ! <!--- put the object in the cache ---> ! <cfset instance.cache.putObject(arguments.contentObject, getName())> ! </cffunction> ! <!--- ! ! PACKAGE AND PRIVATE METHODS FOR INTERNAL WORK ! ! ---> ! <cffunction name="getObjectFromFile" access="private" returnType="struct" output="no" hint="returns an object instance based on the name of the file"> ! <cfargument name="fileName" type="string" required="yes"> ! <cfset var packet = ""> ! <cftry> ! <cffile action="read" file="#getBaseStorageDirectory()##arguments.fileName#" variable="packet"> ! <cfcatch> ! <cfthrow type="modus.badFile" message="File does not exist" detail="The requested file ""#arguments.fileName#"" does not exist."> ! </cfcatch> ! </cftry> ! <cfreturn wddxToContentObject(packet)> ! </cffunction> ! <cffunction name="getPathFromObject" access="private" returnType="string" output="no" hint="returns a full path based on an object"> ! <cfargument name="contentObject" type="struct" required="yes"> ! <cfset var directoryPath = getBaseStorageDirectory()> ! <cfset var fullPath = ""> ! <cfscript> ! //make sure the directory exists ! directoryInit(directoryPath); ! //set the full path ! fullPath = directoryPath & arguments.contentObject.id & "." & getName(); ! </cfscript> ! <!--- now, be sure ---> ! <cfreturn fullPath> ! </cffunction> ! <!--- gets the ID from a file name ---> ! <cffunction name="getObjectIDFromFileName" access="private" returnType="string" output="no" hint="returns the ID of an object based on the file in the persistence"> ! <cfargument name="fileName" required="yes" type="string"> ! <cfreturn listFirst(fileName,".")> ! </cffunction> ! <!--- a method to get the base directory for storage ---> ! <cffunction name="getBaseStorageDirectory" access="private" returnType="string" output="no" hint="returns the path to the base storage directory"> ! <cfreturn instance.objectStoreDir> ! </cffunction> ! <!--- a method for make sure directories exist in the storage directory ---> ! <cffunction name="directoryInit" access="private" returnType="void" output="no" hint="a method for make sure directories exist in the storage directory"> ! <cfargument name="directory" required="yes" type="string"> ! <!--- if the directory does not exist, create it ---> ! <cfif NOT directoryExists(arguments.directory)> ! <cfdirectory action="create" directory="#arguments.directory#"> ! </cfif> ! </cffunction> ! <!--- a method to throw an error (DAMN YOU CFSCRIPT FOR NOT HAVING THIS FUNCTION ALREADY! ---> ! <cffunction name="throwError" access="private" returnType="void" output="no"> ! <cfargument name="type" required="yes"> ! <cfargument name="message" requied="yes"> ! <cfargument name="detail" required="no" default=""> ! <cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#"> ! </cffunction> </cfcomponent> --- simpleobjectinstance.cfc DELETED --- |