On Feb 16, 2008, at 4:44 PM, Michael Hipp wrote:
> The problem with a lot of frameworks is that they have wonderful
> save()
> and load() methods and such. But as soon as save() needs to work on
> multiple tables (or even multiple records at one time within one
> table)
> then all of a sudden the built-in helpers are no help and you're
> back to
> writing fully custom SQL and managing transactions and such as if
> there
> was no framework at all.
That is never the case here. As I mentioned in another post, multiple-
related tables are no problem; calling the main bizobj's save()
percolates through the relationships, and a problem at any level will
rollback the entire transaction.
With unrelated bizobjs, you will have to do some of the coding
yourself, since there is no way for a framework to guess what is
supposed to happen. But let's say that you have two sets of unrelated
bizobjs that you want saved within a single transaction. The best way
to do something like this is to make sure that the PrimaryBizobj of
the form has a reference to the other group's "main" bizobj (i.e., the
highest-level parent). So in the setup code in the form:
bluebiz = self.addBizobj(BlueBiz)
redbiz = self.addBizobj(RedBiz)
bluebiz.redbiz = redbiz
In the above, 'bluebiz' is the form's PrimaryBizobj (since it was
added first), and it has a reference to the red bizobj. Now if you
want to save both the blue and red families of bizobjs within a single
transaction, you would have write something like this in the blue
bizobj:
def save(self, startTransaction=True):
isTransactionManager = False
if startTransaction:
isTransactionManager = self._getTransactionToken()
if isTransactionManager:
self._CurrentCursor.beginTransaction()
try:
super(ThisBizobjClass, self).save(startTransaction=False)
except (dException.DBQueryException, dException.dException), e:
self._CurrentCursor.rollbackTransaction()
self._releaseTransactionToken()
# Pass the exception to the UI
raise dException.dException, e
> Knowing that lots of my stuff is just like this, will I be glad I'm in
> Dabo or will it seem like I'm just back to making calls to psycopg2 on
> my own?
You should never have to talk to the database directly in your code.
If you do, it's either because of a poor design in your code, or a bug
in Dabo.
-- Ed Leafe
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]