Starting A Sample Project With An XML Database

Posted September 19, 2006 at 6:53 PM

Tags: ColdFusion

I have not been able to make the switch over to a real MVC type ColdFusion application architecture. But, I really want to give it a go. I am "learn by doing" type of fellow, and as a result, I am gonna try and build a small XML-database driven application. I figure using XML documents as a means of data persistence will FORCE me to really encapsulate things like data retrieval and data manipulation. Can you image putting XML parsing code all over the ColdFusion application??? Crazy!

So, now I just have to figure out how I want to go about managing data stuff. In past attempts to work with MVC, I have had Data Access Objects (DAO) that each call the database on their own. This is not possible at this point since there is no database. I guess I am gonna have to create another level of data abstraction that the DAO's can call.

Uggg, already my brain hurts :) But if I can figure this out, it's gonna be a sweet ass ColdFusion application.

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page




Reader Comments

Sep 19, 2006 at 10:14 PM // reply »
153 Comments

You may want to look into WDDX (and thus the cfwddx tag) for data storage. In one line of code you can convert a bunch of in-memory queries into an XML file. Sprinkle with a couple cflocks for safety, and all of your code should just magically work. Presuming, of course, that the QoQ engine handles the types of queries you are running.

But, it may also cause the universe to collapse in on itself. YMMV.

(I think I'm one of 4 people left on the planet that use WDDX. It's sad, really.)


Sep 19, 2006 at 10:48 PM // reply »
235 Comments

I worked on a bug traker (original built by a friend) that used WDDX for data storage. It was the original Lighthouse (no pro). What was nice is that you could drop it and run it - no db set up. What was sucky is that it slowed down like heck once you have a lot of bugs. ;)


Sep 20, 2006 at 9:58 AM // reply »
7,572 Comments

Rick, Ray,

I have not worked much with WDDX. My plan right now (and this is all in my head) is to create a DataService component. This data service component will be responsible for maintaining the XML files as well as in-memory ColdFusion queries. I haven't mapped it out yet, but I like where that is going as I can do all my locking in this component.

I figure the Data access objects will need to call functions on this service component like :

GetNewRecord( "tbltablename" )

Then set values on the returned structure, then call something like

InsertRecord( "tbltablename", objNewRecord )

This is going to start confusing me I am sure as the ideas of services, gateways, DAO, etc. already confuses me :) And now, removing a DB... forget about it... but heck, it's gonna be fun!

Then, I figure the gateways will have to get the cached queries and can only run query of query style calls:

GetTable( "tbltablename" )

Which will return a query object. Then the gateway can run off of that.

But this is all VERY preliminary. All in the head, none on the paper. We shall see how it goes.

OHH. but to get back to the WDDX idea... is there any advantage of WDDX over using a combo of CFXML and XMLParse and what not? I guess the WDDX will be small code, but I am hoping to abstract it out so that all the data storage is very simple and generic... something like:

<table>
<columns>
...<c name="id" type="INT" index="c1" />
...<c name="name" type="VARCHAR" index="c2" />
</columns>
<rows>
...<r>
......<c1>DATA HERE</c1>
......<c2>DATA HERE</c2>
...</r>
</rows>
</table>

The idea here is make as little code as possible. So, I am using "c" as the column definition node, "r" as the row definition node. I am also creating column aliases. So, the "name" column is actually "c1" in the rows. Again, all in the head right now. But I figure, I want to keep it really small. This might be a LOT of data even though it will be a fairly simple application.

I will keep you all updated, and would LOVE feedback.


Sep 20, 2006 at 10:41 AM // reply »
153 Comments

The primary advantage of WDDX is that it Just Works. You don't have to worry about escaping your data in CDATA sections, or proper nesting, or writing parsers, or anything like that. Like so:

<cflock name="UserFile" type="EXCLUSIVE" timeout="30">
<cffile action="READ" file="Users.xml" variable="wddxUsers">
<cfwddx action="CFML2WDDX" input="#wddxUsers#" output="qUsers">
<cfset QueryAddRow(qUsers)>
<cfset qUsers.Name[qUsers.RecordCount]="Aristotle">
<cfset qUsers.Password[qUsers.RecordCount]="sophistssuck">
<cfwddx action="WDDX2CFML" input="#qUsers#" output="wddxUsers">
<cffile action="WRITE" file="Users.xml" output="#wddxUsers#">
</cflock>

Otherwise, it's just another XML format.

-R


Sep 20, 2006 at 10:47 AM // reply »
7,572 Comments

Rick,

It looks cool. I just have to do some testing with it. Thanks for the example though. You know, I have read about WDDX a bunch of times, but I don't think I have ever actually tried it.


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 22, 2010 at 7:43 AM
Terms Of Service / Privacy Policy Document Generator
Thankyou for this very helpful form. You've made my life much easier today. I'll have a look around your site... I'm sure there's some more good stuff here..Thanks Dave ... read »
Mar 22, 2010 at 7:21 AM
Encountered "(. Incorrect Select Statement, Expecting a 'FROM', But Encountered '(' Instead, A Select Statement Should Have a 'FROM' Construct.
I got this exception now. In case you're using var-es local struct, CF gives you couple of "new" exceptions: Encountered "local. and Encountered "id. Incorrect Select List, Incorrect select colum ... read »
Mar 22, 2010 at 3:08 AM
Ask Ben: Selecting XML Attributes Given Other XML Attributes
Thanks for the response. I finally discovered that I was getting this error because I had cfsetting enablecfoutputonly="yes" in Application.cfc, and was neither setting it to false elsewhere nor brac ... read »
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »