Hi all,

I'm pretty new to the whole MG/framework approach, but with the
invaluable information I find in this group, and on the many blogs,
I'm picking things up quite well, I think. Thanks to all you experts!

OK, my specific question...

I am wondering how you guys handle database transactions within your
MG events. Consider the following example event definition from an
application I'm working on right now:

        <event-handler name="action.clientconfig.addclient" type="secured">
                <broadcasts>
                        <message name="isAuthorized">
                                <argument name="privilege_id" value="14061" />
                        </message>
                        <message name="addClient" />
                        <message name="manageClientLanguages" />
                        <message name="createHostsFileEntry" />
                        <message name="setDefaultLanguage" />
                </broadcasts>
                <results>
                        <result name="notAuthorized" do="unauthorized" 
redirect="true" />
                        <result name="success" do="page.clientconfig" 
redirect="true" />
                        <result name="failure" do="page.clientconfig.addclient"
redirect="true" />
                </results>
        </event-handler>

As you can see, there are several messages broadcast in this event. If
any one of them fails, a 'failure' result is returned, and the app is
redirected back to the form page. This is fine, except that if it is
not the first message that fails, then any database activity from the
previous broadcast(s) will have been committed, and will not roll
back.

One solution I can see is to ensure that all database activity for the
whole event is contained within one broadcast message, and the
relevant controller function makes a call to one function in the model
that wraps multiple queries (within other functions if necessary)
within a <cftransaction> tag. Another solution could be to wrap calls
to multiple model functions within a <cftransaction> tag within the
one controller function. The problem is with both these approaches
IMHO is that they seem to be moving away from the whole point of the
framework's ability to broadcast multiple messages in a single event.

A perfect solution I can see would be if I could do the following:

        <broadcasts>
                <message name="isAuthorized">
                        <argument name="privilege_id" value="14061" />
                </message>
                <message name="beginTransaction" />
                  <message name="addClient" />
                  <message name="manageClientLanguages" />
                  <message name="createHostsFileEntry" />
                  <message name="setDefaultLanguage" />
                <message name="endTransaction" />
        </broadcasts>

However, I'm not sure how to achieve this kind of behavior, or even if
it's possible. I'm not even sure this is the right approach. Any
attempt to separate the opening and closing <cftransaction> tags into
different functions will obviously fail when the code is validated at
compile time.

So, to summarize, and actually ask my question, have you guys come
across this kind of issue in your application development, and if so,
what approaches have you taken to solve this issue?

Many thanks in advance for any advice you can offer.

Mike.

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to