Persistent Application Settings In Model-Glue
Posted By : todd sharp Posted At : February 25, 2007 5:22 PM Posted In: Model-Glue, Project Learn, OO
6
My next stumbling block on my journey is the creation and persistence of application level data. Specifically the DSN for my application. Don't worry, when I get over these initial stumbling blocks I'm sure everything will run a lot smoother, but I keep sharing these items for a simple reason. I think these little things are the kind of things that trip up a lot of folks when trying to adopt new concepts and frameworks. I myself have let little things like this discourage me and I move on to things that are familiar and comfortable and forget all about the learning that I had done.
So back to my issue. Model-Glue ships with a way to create simple config beans in the ColdSpring.xml file. Very simple indeed - here's an example.<property name="dsn">
<value>dsn</value>
</property>
<property name="Username">
<value>username</value>
</property>
<property name="Password">
<value>password</value>
</property>
</bean>
<constructor-arg name="dsn"><ref bean="datasource" /></constructor-arg>
</bean>
<cfargument name="dsn" type="ModelGlue.Bean.CommonBeans.Datasource" required="true">
<cfset variables.dsn = arguments.dsn.getDSN()> <cfreturn this>
</cffunction>

<p>For example, say you remodel your database and subsequently need to provide a means to retrieve a default schema for your remodeled datasource.
<p>If you pass a Datasource bean into your userDAO, no problem - just add a getDefaultSchema() method to your Datasource bean and there's no need to edit userDAO (other than to retrieve the value of that method, obviously).
<p>If you're passing Datasource variables as explicit arguments, you've got to modify your userDAO to add a new 'default schema' argument. Since the datasource is likely to be used throughout your application, you probably have to edit another bunch of files to add that argument too...
Part of what I'd like to discuss in my next post though is that there really is no "right way" of doing things - there are best practices, etc but we need to remember that things are cut in stone.
But this method did work. In fact, I've got an email from someone who has created a custom template for the Illudium generator that will create your code to accommodate this style. Looks very interesting and I may re-publish the entire email (with his permission). I hope to dig back in to all this within the next few days! ;)
Thanks for following the series and commenting! It helps reaffirm that "I'm not the only one"!
Woops!