My First CFDJ Article: Encapsulating Recordsets
Well, my first CFDJ article is now available online. It is a pretty good introduction to the idea of the Iterating Business Object that I've been promoting and how and where you might consider using it.



This looks very cool. I can't wait to dive into the IBO code and gain a full understanding of how it works. Excellent article and explanation. Looking forward to integrating it into some of my own testing.
by the way good article, and the baseObject is very interesting from what i've played around with. A little off topic but I have a query.
Using Lightwire and have a userObject (with the extended baseObject) and what point do I call loadQuery and how should I pass the query in?
Very occasionally comments don't post correctly, so that might have been the problem - sorry about that! I'll be posting a bunch more of integrating LightWire with the IBO (which is part of what will be the LightBase framework - set of base classes for more quickly developing small to mid sized applications.
However, short answer is as follows. I am still experimenting with this, but in current architecture (full implementation), lets say you wanted to load up one or more users and return them in UserObject. You'd get your controller to call UserService - lets say you wanted all users in a single bean, so it'd be UserService.getbyFIlter(). UserService.getbyFilter calls UserDAO.getByFilter() which returns a recordset. UserService calls LightWire.getTransient(UserObject) and then loads the initialized bean.
So UserService.getbyFIlter() looks something like:
var UserQuery = UserDAO.getByFilter();
var UserObject = LightWire.getTransient("UserObject");
UserObject.LoadQuery(UserQuery);
cfreturn UserObject
Of course, this code is really in BaseService.getbyFilter(), so you don't actually have to write anything unless you want to overload it. Same goes for the DAO method.
I'm keeping on playing with this, but this is what I currently have!
Any inputs or improvements appreciated, and expect some bigger sample code over Thanksgiving.
I am trying to show better ways of using OO with large recordsets (see my post: http://www.markdrew.co.uk/blog/index.cfm/2006/11/2...)
Sorry again. Expect code later today as a couple of quick emergencies for clients (as usual!) first.
Many thanks
I've added a "download" link at the top with the cfc zipped up. Please note I had to cut and paste this together as I have two objects - BaseGetSetObject and BaseBusinessObject - the first of which handles generic getters and setters and the second (which extends the first) handles the iterating. Both also have a bunch of other metadata and related features, so I've tried to cut out all the irrelevant methods but haven't had a chance to test the code, so I don't guarantee there isn't an error or two (like a dependency on a method or composed object I've removed), but the methods all work and are the basis of everything I do, and they're simple enough to hack out and reuse as you like, so hopefully they'll be of some use!
Best Wishes,
Peter
loadQuery() takes a query containing a single record and reads/populates the bean? loadStruct() takes a structure which is used for child objects in "has-a" or "has-many" relationships?
Is that right?
I'm not sure because I am also thinking that loadQuery() may be used for collections, in which case the query passed in would contain many records.
Good question. Load query is for loading a recordset containing 0..n records (a collection). The loadstruct is for loading a single record from a structure such as loading a bean from the form scope.
Also, I am getting an error that says MetaData is undefined. MetaData is in the IBO init().
Would you use loadQuery() for child objects in a one-to-many relationship (i.e. user has many addresses - pass a query of addresses filtered by the userid into the user.loadQuery() method)?
You can load straight from the DAO using loadQuery - 0..n records includes the special case where n = 1
Dang - the metadata is a piece I tried to pull out as I happen to use a metadata config object, so you might have to pull out a reference or two to that.
For child objects, you'd create another IBO, loadquery into that and then if you had a child called Addresses, you'd User.set("Addresses", Addresses) to load the sub object.
So in UserService.new() you could call LightWire.getTransient("User") and it'll work.
i'm approaching now with oop, then sorry for my "newbie" questions...
i have to develop an application and i'd like to use your IBO.
my questions are the following:
1)calling the init() method i receive the same error of Aaron (MetaData is undefined),
but i didn't understand how to fix it.
2)when i'm looping over a query (loaded with the loadQuery() method) should i have a code like this?
<cfloop from="1" to="#obj.recordCount()#" index="i">
...
...
<cfset obj.next()>
</cfloop>
3)when could be useful for my applications the setDefaultValues() method?
thank's
Andrea