Raymond Camden's Blog Rss

Ask a Jedi: Where to use Transfer?

7

Posted in ColdFusion | Posted on 12-08-2008 | 4,091 views

Justin asks:

How do you best recommend setting up your application structure for a Transfer app?

For example let's say I'm building a CMS for blog posts, so there are essentially pages to list, create,update & delete

Would you create a Blog.cfc and call transfer methods from that CFC or would you call the transfer methods directly from the .cfm pages

Is one way better than the other? Is one way more 'proper' than the other?

I hate to get into 'better'/'proper' type things without being real clear up front that this is normally a matter of opinion. Being still new to Transfer, I'd love to hear what others think (whether they use Transfer or Reactor or some other ORM). Here is my opinion.

The ORM you use creates a layer between you and the database. I no longer write a query statement to fetch my blog posts, but instead, ask Transfer to handle the relationship and return to me a set of Blog objects.

That being said, the fact is that you are still getting information. You are still working with a model layer. To me, that is a different concern than your front end. So the short answer is that yes, I do build a CFC that speaks to Transfer. When I did CFLib in Transfer earlier this year, I created a few Services CFCs. The Controller layer speaks to the service and the service handles getting the data.

In theory, I could switch from Transfer to Reactor or even Hibernate. As long as the model layer returned an object that supported the same API as Transfer, I'd be ok. From what I know of Hibernate, that would work for the simple properties (get/setName). I'm not so sure it would work well for related data. So for example, Transfer's automatic method injection for manytomany adds 'getXArray', where X is the name of the property. I'd bet Reactor does this differently. I'm not quite sure how I'd handle such a change, but I'd think it is safe to assume this doesn't happen very often. (So for example, I've probably had 2-3 clients over the past 15 years do complete database platform changes.)

As a last note, my Transfer series of posts did not make use of any type of MVC framework. I wanted to keep things as simple as possible and keep our focus on Transfer itself. So in that regards, the sample code isn't something I'd actually go to production with probably.

Comments

[Add Comment] [Subscribe to Comments]

Ray, to take it one layer further, I have the service layer talking to a gateway layer which contains all the Transfer/SQL code. The service cfc's call get(), set(), getList() functions in gateway cfc's. This has the added advantage of separating the two layers for unit testing purposes. The service cfc's can be tested for application logic and the gateway cfc's can be tested separately for database/Transfer specific logic.

This is needed in the systems I work with since it is a more complex architecture. People can judge whether this extra layer is needed for their particular application.
Good points Bim. CFLib also does service->gateway, but I wanted to keep it simpler in the blog entry above. :)
I am also using a Service Layer for interaction with Transfer, but what I am struggling with is method naming. In theory, I believe the Service Layer's methods shouldn't change and be dependent upon the underlying Gateway's, DAO's, or ORM used. I am using Transfer in my most recent project and having it working pretty well, but when I look at Hibernate's API, I notice that the method names may be different. Therefore, prior to "sealing" the API, I know for myself, I need to look better at both Hibernate and Reactor to make sure my Service Layer API can work with any of those ORMs.
I'm with you TC. I'd name my Service API methods w/o concern to Transfer or any other ORM. Ie, getFoo, getGoo, etc.
This is an issue that is currently hurting my brain!

I'm trying to create a service object for each "business area". These match the packages I've defined in my Transfer.xml config. My service then calls my gateway. The gateway is the only object that talks to transfer, so that I have a consistent API. That's where it gets a bit messy. Do you guys choose to have one gateway per transfer object or one gateway per transfer package?

I'd love to have a look at the code for cflib if it's available!? :)
I normally have a gateway per service.

CFLib is a bit messy right now, code wise. I did it quickly. Not too sure I want to share it globally just yet. ;)
I'm currently building a new app that uses Transfer too. It is a good question on how much do you try to abstract the ORM. To really be independent of an ORM you'd have to take it the lowest common denominators of arrays, structs and queries. As soon as a view calls 'getXArray' you've coupled yourself to Transfer. Whereas if that array was already returned as a variable of some sort you're less coupled.

I don't have a specific question or answer here, just some thoughts as I think ahead for this app.

[Add Comment] [Subscribe to Comments]