From: <jfi...@us...> - 2003-01-09 01:53:42
|
Update of /cvsroot/modus/org/bacfug/modus/persistence In directory sc8-pr-cvs1:/tmp/cvs-serv5475/persistence Modified Files: basepersister.cfc Log Message: Whoops, these were the old files - pardon my CVS skills. The new files are now there. Index: basepersister.cfc =================================================================== RCS file: /cvsroot/modus/org/bacfug/modus/persistence/basepersister.cfc,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** basepersister.cfc 30 Oct 2002 03:00:29 -0000 1.11 --- basepersister.cfc 9 Jan 2003 01:53:39 -0000 1.12 *************** *** 1,42 **** ! <cfcomponent displayname="basePersister" hint="The base component for persistence objects"> ! <cfparam name="instance" default="#structNew()#"> ! <cffunction name="init" access="public" hint="The initializer" returnType="org.bacfug.modus.persistence.basePersister" output="no"> ! <cfset var cachePathToUse = getCachePath()> ! <cfscript> ! //the cache we should use ! //if it has been cached, use the cached version ! ! /******************************* ! THIS REALLY IS A GOOD CANDIDATE FOR THE CONFIG DATA! ! ********************************/ ! ! if(NOT structKeyExists(server.modus,cachePathToUse)){ ! instance.cache = createObject("component",getCachePath()).init(); ! server.modus[cachePathToUse] = instance.cache; } ! //otherwise, make a new one ! else{ ! instance.cache = server.modus[cachePathToUse]; ! } ! </cfscript> ! <cfreturn this> ! </cffunction> ! <cffunction name="getCachePath" access="private" returntype="string" output="no" hint="returns a string with the path to the cache component to use. you can override this function in a persister implementation if you want to use a different caching mechanism other than the default."> ! <cfreturn "org.bacfug.modus.caching.serverScopeCache"> ! </cffunction> ! <cffunction name="save" access="public" output="no" hint="The method to save data"> ! <cfthrow message="save() method not implemented!" detail="You must defined a save() method for #getMetaData(this).name#."> ! </cffunction> - <cffunction name="get" access="public" output="no" hint="The method to get a particular data instance"> - <cfthrow message="get() method not implemented!" detail="You must defined a get() method for #getMetaData(this).name#."> - </cffunction> - - <cffunction name="getAll" access="public" output="no" hint="The method to get all data instances of a particular type. Should return an array of contentObjects."> - <cfthrow message="getAll() method not implemented!" detail="You must defined a getAll() method for #getMetaData(this).name#."> - </cffunction> - <!--- a package function to determine if an object passed is, indeed, a baseContentObject ---> <cffunction name="isContentObject" access="package" returnType="boolean" output="no" hint="determines if something is a content object"> --- 1,207 ---- ! <cfcomponent displayname="basePersister" hint=" ! Namespace: org.bacfug.modus.persistence ! XML Declararation (modus_settings.cfm): /modus/contenttypes/contenttype/persister ! Responsibilites: The base component for persistence objects. Moves content objects on and off disk as well as maintains a memory-based cache to speed up response times. ! "> ! <cfparam name="instance" default="#structNew()#"> ! <cffunction name="init" access="public" hint="The initializer" returnType="struct" output="no"> ! <cfargument name="contentType" type="org.bacfug.modus.contenttypes.basecontenttype" required="Yes"> ! <cfargument name="descriptor" required="Yes"> ! <cfargument name="globals" type="struct" required="Yes"> ! <cfargument name="cache" type="org.bacfug.modus.caching.basecache" required="Yes"> ! <cfscript> ! //the contentType component instance ! instance.contentType = arguments.contentType; ! //datasource ! instance.datasource = globals.datasource; ! //cache for this instance ! instance.cache = arguments.cache; ! //utility component reference ! instance.util = server._modus.core[arguments.globals.util]; ! //set field metadata ! instance.fields = instance.contentType.getFields(); ! //set collection metadata ! instance.collections = instance.contentType.getCollections(); ! //get a default object ! instance.defaultObject = initObject(arguments.descriptor); ! </cfscript> ! <cfreturn this> ! </cffunction> ! <!--- ! ! ACCESSORS ! ! ---> ! <cffunction name="get" access="public" output="no" hint="The method to get a particular data instance"> ! <cfthrow message="get() method not implemented!" detail="You must define a get() method for #getMetaData(this).name#."> ! </cffunction> ! <cffunction name="getAll" access="public" output="no" hint="The method to get all data instances of a particular type. Should return an array of contentObjects."> ! <cfthrow message="getAll() method not implemented!" detail="You must defined a getAll() method for #getMetaData(this).name#."> ! </cffunction> ! <cffunction name="getAllSorted" access="package" returntype="array" output="no" hint="The method to get all data instances of a particular type sorted - this method works for the simplefilesystempersister and simpledbpersister. It should be overriden by other implementations."> ! <cfargument name="contentObjects" type="array" required="Yes"> ! <cfargument name="sortFields" type="string" required="yes"> ! <cfset var tempQuery = ""> ! <cfset var sortQuery = ""> ! <cfset var sortedArray = arrayNew(1)> ! <cfset var objectCount = arrayLen(arguments.contentObjects)> ! <cfset var sortFieldsArray = listToArray(arguments.sortFields)> ! <cfset var ii = 0> ! <cfset var ff = 0> ! <cfset var thisObject = ""> ! <cfset var thisFieldName = ""> ! <cfscript> ! //clean the sortFieldsArray, so we can have the sort order in there too ! for(ii = 1; ii LTE arrayLen(sortFieldsArray); ii = ii + 1){ ! sortFieldsArray[ii] = getToken(sortFieldsArray[ii],1); ! } ! //prime the tempQuery ! tempQuery = queryNew("index," & arrayToList(sortFieldsArray)); ! //if there any objects, then loop through and make them ! if(objectCount){ ! //resize the query to however many objects there are ! queryAddRow(tempQuery,objectCount); ! //loop through all objects, populating the appropriate columns of the query ! for(ii = 1; ii LTE objectCount; ii = ii + 1){ ! thisObject = arguments.contentObjects[ii]; ! querySetCell(tempQuery,"index",ii,ii); ! //loop through whatever fields we are sorting on, adding the values of those fields to the query ! for(ff = 1; ff LTE arrayLen(sortFieldsArray); ff = ff + 1){ ! thisFieldName = getToken(sortFieldsArray[ff],1); ! querySetCell(tempQuery,thisFieldName,lcase(thisObject[thisFieldName]),ii); ! } } ! } ! </cfscript> ! <!--- if there are objects to sort, query them, then build the new array ---> ! <cfif objectCount> ! <!--- ok, now let's get the sortedQuery ---> ! <cfquery name="sortQuery" dbtype="query"> ! SELECT * ! FROM tempQuery ! ORDER BY #arguments.sortFields# ! </cfquery> ! <!--- and now, we'll populate the sortedArray ---> ! <cfscript> ! //resize the array, so it doesn't have to keep allocating more memory ! arrayResize(sortedArray,objectCount); ! for(ii = 1; ii LTE objectCount; ii = ii + 1){ ! sortedArray[ii] = arguments.contentObjects[sortQuery.index[ii]]; ! } ! </cfscript> ! </cfif> ! <!--- return the sorted Array ---> ! <cfreturn sortedArray> ! </cffunction> ! <!--- ! ! MUTATORS ! ! ---> ! <cffunction name="save" access="public" output="no" hint="The method to save data"> ! <cfthrow message="save() method not implemented!" detail="You must defined a save() method for #getMetaData(this).name#."> ! </cffunction> ! <!--- ! ! Simple accessors for internal use by Modus components - public but not part of the API ! ! ---> ! <cffunction name="getName" access="public" returntype="string" output="No" hint="get this instance name"> ! <cfreturn instance.contentType.getName()> ! </cffunction> ! <cffunction name="getTableName" access="public" output="No" returnType="string" hint="get the name of the table associated with this content type"> ! <cfreturn instance.tablename> ! </cffunction> ! <!--- ! ! PACKAGE AND PRIVATE METHODS FOR INTERNAL WORK ! ! ---> ! <cffunction name="getNewObject" access="package" returntype="struct" output="No" hint="I construct a new contentObject."> ! <cfset var object = duplicate(instance.defaultObject)> ! <cfset var now = now()> ! <cfscript> ! object.ID = makeID(); ! object.dateModified = createODBCDate(now); ! object.dateCreated = createODBCDate(now); ! //Modus Lib needs to be able to find the contentType, but cfc's can't be cached so just use the component name ! object._modus.contentType = getMetaData(instance.contentType).name; ! //boolean error flag for content object ! object._modus.hasErrors = false; ! //boolean new flag ! object._modus.isNew = true; ! //boolean cache flag - used by collections to determine if the content object has changed ! object._modus.fromCache = false; ! </cfscript> ! <cfreturn object> ! </cffunction> ! <cffunction name="initObject" access="package" returntype="struct" output="No" hint="Create default object, initializing collections and fields."> ! <cfargument name="descriptor" required="Yes"> ! <!--- Local default object to return ---> ! <cfset var object = structNew()> ! <!--- "Private" container for internal reference ---> ! <cfset object._modus = structNew()> ! <!--- Collections container ---> ! <cfset object._modus.collections = structNew()> ! <!--- Append each collection to the default object for internal reference ---> ! <cfset structAppend(object._modus.collections, initCollections())> ! <!--- Append each field to the default object ---> ! <cfset structAppend(object, initFields())> ! <!--- Append each collection to the default object for external reference (new objects have empty collections) ---> ! <cfset structAppend(object, object._modus.collections)> ! <cfreturn object> ! </cffunction> ! <cffunction name="initCollections" access="package" returntype="struct" output="No" hint="Initialize collections. For the default implementation return an empty struct."> ! <cfreturn structNew()> ! </cffunction> ! <cffunction name="initFields" access="package" returntype="struct" output="No" hint="Set up fields and populate default object with default values."> ! <!--- Local struct to hold fields ---> ! <cfset var object = structNew()> ! <cfscript> ! //loop over each field ! for(field in instance.fields){ ! //set each field in the default object to a default value ! object[field] = instance.fields[field].defaultValue; ! } ! </cfscript> ! <cfreturn object> ! </cffunction> ! <cffunction name="makeID" access="package" output="no" returnType="uuid" hint="The mechanism to make a new id. Used in the init() and can be overridden in specific object types to have a different kind of default id"> ! <cfreturn createUUID()> ! </cffunction> ! <cffunction name="wddxToContentObject" access="package" output="no" returnType="struct" hint="takes a WDDX packet and returns a contentObject"> ! <!--- the packet ---> ! <cfargument name="packet" required="yes"> ! <cfset var deserializedObject = ""> ! <!--- deserialize the object packet ---> ! <cftry> ! <cfwddx action="wddx2cfml" input="#arguments.packet#" output="deserializedObject"> ! <cfcatch> ! <cfthrow type="modus.corruptObject" message="object could not be deserialized" detail="The contentObject storage packet appears to be corrupt and could not be deserialized in #getMetaData(this).name#"> ! </cfcatch> ! </cftry> ! <cfreturn deserializedObject> ! </cffunction> ! <cffunction name="contentObjectToWDDX" access="package" output="No" hint="Transform a content object into a wddx packet"> ! <cfargument name="contentObject" type="struct" required="Yes"> ! <cfset arguments.contentObject._modus.isNew = false> ! <cfset arguments.contentObject.dateModified = now()> ! <!--- serialize the contentObject struct ---> ! <cfwddx action="cfml2wddx" input="#arguments.contentObject#" output="packet"> ! <cfreturn packet> ! </cffunction> ! <cffunction name="getUtil" access="package" output="No"> ! <cfreturn instance.util> ! </cffunction> ! </cfcomponent> ! ! <!--- ! ! ************ ! ORIGINAL CODE - may still be useful ! ************ <!--- a package function to determine if an object passed is, indeed, a baseContentObject ---> <cffunction name="isContentObject" access="package" returnType="boolean" output="no" hint="determines if something is a content object"> *************** *** 154,176 **** <cfreturn packet> </cffunction> ! <!--- go from WDDX back to a contentObject ---> ! <cffunction name="wddxToContentObject" access="package" output="no" returnType="org.bacfug.modus.baseContentObject" hint="takes a WDDX packet and returns a contentObject (loaded or created)"> ! <!--- the packet ---> ! <cfargument name="packet" required="yes"> ! <cfset var deserializedObject = ""> ! <!--- deserialize the object packet ---> ! <cftry> ! <cfwddx action="wddx2cfml" input="#arguments.packet#" output="deserializedObject"> ! <cfcatch> ! <cfthrow type="modus.corruptObject" message="object could not be deserialized" detail="The contentObject storage packet appears to be corrupt and could not be deserialized in #getMetaData(this).name#"> ! </cfcatch> ! </cftry> ! ! <cfif structCount(arguments) GT 1> ! <cfreturn contentObjectFromSerializable(deserializedObject,arguments[2])> ! <cfelse> ! <cfreturn contentObjectFromSerializable(deserializedObject)> ! </cfif> ! </cffunction> ! </cfcomponent> ! --- 319,321 ---- <cfreturn packet> </cffunction> ! ---> |