Persistent Application Settings In Model-Glue

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.

<bean id="datasource" class="ModelGlue.Bean.CommonBeans.Datasource" singleton="true">
   <property name="dsn">
      <value>dsn</value>
   </property>
   <property name="Username">
      <value>username</value>
   </property>
   <property name="Password">
      <value>password</value>
   </property>
</bean>

Simple enough. Now I can simply pass this bean to anything that needs it like so:

<bean id="userDAO" class="model.user.userDAO">
   <constructor-arg name="dsn"><ref bean="datasource" /></constructor-arg>
</bean>

This requires a little modification to the userDAO that Illudium generated for me since the constructor that it created expected a simple string for the dsn. In my case I modified the argument to except the datasource bean itself (ModelGlue.Bean.CommonBeans.Datasource) and used the getDSN() method of that to set the dsn.

<cffunction name="init" access="public" output="false" returntype="model.user.userDAO">
   <cfargument name="dsn" type="ModelGlue.Bean.CommonBeans.Datasource" required="true">
   <cfset variables.dsn = arguments.dsn.getDSN()>       <cfreturn this>
</cffunction>

I'm not 100% positive this is the best way to handle things. Time to hit the docs to confirm. Stay tuned.

Comments
Gosh, that seems so much more intuitive than cfset application.dsn = 'fooBar'
# Posted By Fredo | 2/25/07 7:48 PM
The benefit of using the Datasource bean is that you get DSN, username and password which you need in your query code on certain systems (for example, on HostMySite by default, DSNs do not have username / password in them as a security precaution so you need to put them in your own code). I've gotten into the habit now of *always* using username / password in my query code (and both Reactor and Transfer support this out of the box).
# Posted By Sean Corfield | 2/25/07 9:21 PM
Being pragmatic, another advantage of passing beans is that you can add methods to your Datasource bean without needing to modify the arguments of your userDAO.
<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...
# Posted By ed | 2/26/07 9:39 AM
Have you got this process confirmed? Got it working for you?
# Posted By Lola LB | 2/28/07 10:59 AM
Lola: Yes it does work well. I've been meaning to get another post up on this topic just been busy on a complete rebuild at work.

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"!
# Posted By todd sharp | 2/28/07 11:18 AM
Things are **NOT** cut in stone :D

Woops!
# Posted By todd sharp | 2/28/07 11:18 AM

Calendar

Sun Mon Tue Wed Thu Fri Sat
     12
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff misc model-glue off topic personal project learn slidesix sql

Recent Comments

Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

BlogCFC Survey #2
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

Most Difficult Captcha Of All Time
kokkooo said: [url=http://synchrophase.info/...]消費者金融 ブラック[/url] [url=http://geji-geji.com/]消費者金融ブラック[/url] [url=http... [More]

Most Difficult Captcha Of All Time
kokkooo said: <a href="http://synchrophase.info/...">消費者金融 ブラック</a> <a href="http://gej... [More]

Using A PlayStation 2 HDD In Your PC
Vodin said: Well dang. Thanks man, my uncle who owns a Video Game shop had a PS2 harddrive in the junk box, I sn... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com