Using WDDX as a Datasource

Posted by spiraldev, Posted on September 17, 2009

I did some work for a friend a couple of months ago and he needed me create an XML document to house student information never more than 10 students. So I thought simple of I’ll just create a simple XML Doc and loop through it. And then I remembered that I wasn’t that fond working with XML. So I decided to create a ColdFusion and store it in memory.

I know that wasn’t a good, so I decided to create a ColdFusion query and then turn it into WDDX format then save it to a file.

Now I can just read the file and query and do all the CRUD operations against it the recordset. So now I had the problem how to update the data and what if they want to move to a real DB. Well this is what I did, I created a couple of CFC’s one of which is a base WDDXDAO which has these functions

getWDDXRS This function reads my WDDX xml file and returns a ColdFusion Query

saveWDDXRS This function saves my ColddFusion query into WDDX format

Now I can write my studentDAO which extends wddxDAO here is the init function you’ll notice that it is expecting an argument of dbfile, that is the absolute path to the WDDX file. Also in the init function you’ll notice that I am checking to see if the file exists and if it does I call the saveWDDXRS function from my WDDXDAO.

Next function is getRS this function is really for my Gateway you will see that later.

Create function this function create a new record in our WDDX RS, first we get the query from the WDDXDAO and then we add a new record to it and then save the file.

read function will simply open the WDDX file again and query the RS for the studentID that the user is looking for.

update function here I open the WDDX file and do a listFindNoCase to get the current row number to update.

delete function here I open the WDDX file then query the RS for everything that is not equal to the current studentID and then save that RS.

Exists function this function checks to see if a record exists or not.

save here we call our Exists function and if a record does exists we call the update function and if doesn’t we call the create function.

Here is my my student bean it has one method and extends my base Bean CFC.

Here is my base bean CFC

Here is my gateway CFC.

Now I know this seems to be a bit much for a small website and for 10 students but think in terms of scalability. Now if he comes back to me and says I need to migrate to SQL Server or MySQL all I need to do is create a new Gateway and DAO.

I would love to hear any and all thoughts on this.

  1. Comments
  2. Henry Ho wrote on 09/17/09 5:32 PM

    I'd rather use JSON instead of WDDX, CF8 and up has built-in SerializeJSON() and DeserializeJSON().

    Instead of query into XML, I would rather Deserialize the whole JSON string back to a Query object, and use QueryOfQuery for CRUD. See: http://www.bennadel.com/blog/1707-Running-UPDATE-And-DELETE-SQL-Statements-Using-ColdFusion-Query-Of-Queries.htm

    Or... use built-in Adobe Derby in CF8+?
    1. Comments
    2. spiraldev wrote on 09/17/09 6:33 PM

      @Henry Ho
      Yes I would rather use JSON as well but the task was to use an XML file. And for using Ben Nadel's code to handle CRUD that would be fine to but I was trying to emulate the bean, DAO and Gateway pattern that I would use with a real DB.
      1. Comments
      2. thesis writing wrote on 06/03/10 12:42 AM

        This is an excellent blog,very informative and I really appreciate it. It should be going on. Thanks for the information. Keep posting such good topics. Regards.
      3. Write your comment



        (it will not be displayed)