blogs
Perfect Unity between Model-glue 1 and 2
Submitted by Doug Sims on Fri, 2006-07-14 18:57. coldfusion | coldspring | modelglue | reactorI have been working on a gigantic Modelglue 2 app at my day job. to aid in information exchange we had been using canvas wiki (thanks Ray! ). We have been using MG2 since its infancy (original semi-public beta in April).
everything has been working better that expected, however, a few SVN updates ago the wiki stopped working with a Bean creation error. Apparently this is due to the reactor config path.
Since our root site is a Unity app, the reactor bean in the coldspring config looks like this:
<constructor-arg name="pathToConfigXml"><value>/config/Reactor.xml</value></constructor-arg>When you try to launch the nested app, it doesnt like the path and gives this error:
Bean creation exception during init() of ModelGlue.unity.eventhandler.EventHandlerFactory
Bean creation exception during init() of ModelGlue.unity.orm.ReactorAdapter
The error occurred in C:\Inetpub\wwwroot\WebFiles\coldspring\beans\DefaultXmlBeanFactory.cfc: line 539
Called from C:\Inetpub\wwwroot\WebFiles\coldspring\beans\DefaultXmlBeanFactory.cfc: line 332
Called from C:\Inetpub\wwwroot\WebFiles\ModelGlue\unity\loader\XmlConfigurationLoader.cfc: line 16
Called from C:\Inetpub\wwwroot\WebFiles\ModelGlue\unity\loader\XmlConfigurationLoader.cfc: line 319
Called from C:\Inetpub\wwwroot\WebFiles\ModelGlue\unity\loader\XmlConfigurationLoader.cfc: line 49
Called from C:\Inetpub\wwwroot\WebFiles\ModelGlue\unity\loader\FrameworkLoader.cfc: line 63
Called from C:\Inetpub\wwwroot\WebFiles\ModelGlue\unity\ModelGlue.cfm: line 48
Called from C:\Inetpub\wwwroot\WebFiles\ModelGlue\ModelGlue.cfm: line 1
Called from C:\Sandboxes\Sandbox2\wiki\index.cfm: line 25
537 : <cfthrow type="coldspring.beanCreationException"
538 : message="Bean creation exception during init() of #beanDef.getBeanClass()#"
539 : detail="#cfcatch.message#">
540 : </cfcatch>
541 : </cftry>How I fixed It
I simply copied the coldspring.xml and reactor.xml to:
webroot/wiki/config
and changed the reactor config constructor-arg to
<constructor-arg name="pathToConfigXml"><value>/wiki/config/Reactor.xml</value></constructor-arg>I did try to make the path relative ("config/reactor.xml" not /config/reactor.xml") but that didn't seem to work either. Please let me know if there is a better fix!
Division By Zero
Submitted by Doug Sims on Thu, 2006-06-29 19:49. coldfusion | mathMy friend and co-worker Doug Boude(dougboude.com)brought up a good point. Why should Division By Zero be illegal in the first place....
Here is a quote from Doug B. himself about the subject:
"Division by zero should be legalized, plain and simple. For TOO LONG we've allowed ourselves to be oppressed by the mathematicians of the world who have taken it upon themselves from every generation until now to dictate what we may and may not use as our divisor. I say that we should perform some kind of mass demonstration...a million man march, camp on the whitehouse lawn...cut off an unneeded digit and send it to Berkley in a small unmarked cardboard box...something to get the attention of the aristocrats who have made themselves our mathematical masters. The time is now: Legalize Division by Zero!"
I would have to agree with his points
extending reactor record objects
Submitted by Doug Sims on Thu, 2006-06-29 15:31. coldfusion | reactorReactor provides a simple mechinism to easily add new functionality to your record objects. The advantage of this is that you dont have to create a seperate CFC, invoke it, pass it the parameters and interprit the results. The reactor record object already has access to its own instance data,and (if you are using reactor) you have already created it and are already calling functions on it.
The base record objects are located in the project/projectname/record/ folder under the reactor folder.
reactor provides you with two CFC's that extend this base record object. these are created in the folder you have set up in the mapping section in the reactor.xml file (or in coldspring.xml if using modelglue 2 unity).
If you are not doing anything that is database specific, use the tablenameRecord.cfc. If you are doing something that is specific to your database convention, use the tablenameRecord?????.cfc.
In my example, we will be performing simple math calculations on several values from our record object, returning a sum total.
Assume I have a table/record called 'Rate' that has the following fields:
RateID (pk)
EmployeeCost
EmployerCost
ThirdPartyCost
In my reactor.xml file I have defined the rate table as an object
<object name="Rate">
</object>Now in a cfm page, I create a reactor rate record
<cfset reator = CreateObject("Component", "reactor.reactorFactory").init(expandPath(".") & "/reactor.xml") />
<CFSET raterecord =reactor.createRecord("Rate")>
<CFSET raterecord.SetRateID(url.RateID)>
<CFSET raterecord.load()>
<CFDUMP var="raterecord#">Afterloading this page, reactor creates my Raterecord CFC's. We can now add our custom function. Open mappingvalue/record/RateRecord.cfc and look for the comment <!--- Place custom code here, it will not be overwritten --->
between this and the closing CFCOMPONENT tag is where I will add my function:
<CFFUNCTION name="CalculateTotalCost" access="public" hint="I am a custom method created to demonstrate how to extend and customize record objects" output="false" returntype="string">
<CFSET var result = "" />
<cfset result = val(getEmployeeCost()) + val(getEmployerCost() + val(getThirdPartyCost() )>
<CFRETURN result />
</CFFUNCTION>Now, going back to my Raterecord, I see I have a new method "CalculateTotalCost". After populating my rateRecord with data, I can access the computed total cost value with this:
<CFSET cost = raterecord.CalculateTotalCost()>Yes I do know I could have calculated this in the view with one line of code, but by placing the logic in the Model, it is in a consistant place to be access by other pages as well as webservices, etc.


delicious
digg
reddit
technorati