> GAE only provides transaction at the level of the single record.

Appengine supports transactions at the level of an entity group.

> GAE does not support (and in my view it not support anytime soon)
> multi record transactions (the kind of thing you really need for any
> reliable business app).

An entity group could contain any number of records.  Within a
transaction, you can get(), put(), or delete() by key.

Transactions could be added to web2py dal:

def mytxn(db,id):
  record = db(db.table.id==id).select()[0]    #model.get(id)
  record.update_record(count=record.count+1)  #entity.put()
  return record.count

txn = db.build_transaction(mytxn)

if not txn(id):
  raise Exception("aborted transaction")
print "success"
count = txn.result

The db could be passed into the transaction by default, and the dal
should catch any transaction related exceptions.

db.build_transaction() would be this on GQLDB:

class GQLDB(...):
  def build_transaction(self,txn):
    from google.appengine.ext import db as google_db
    from google.appengine.ext.db import google_exception
    class TryTxn(object):
      def __init__(self,db,txn):
        self.db = db
        self.txn = txn
        self.result = None
      def __call__(self,*args):
        try:
          self.result = google_db.run_in_transaction
(self.txn,self.db,*args)
        except google_exception.TransactionFailedError, e:
          return False
        return True
    return TryTxn(self,txn)

And like this on SQL databases:

class SQLDB(...):
  def build_transaction(self,txn):
    class TryTxn(object):
      def __init__(self,db,txn):
        self.db = db
        self.txn = txn
        self.result = None
      def __call__(self,*args):
        self.result = self.txn(self.db,*args)
        return True
    return TryTxn(self,txn)

For any database it is used like this:

txn = db.build_transaction(mytxn)

if not txn(id):
  raise Exception("aborted transaction")
print "success"
count = txn.result

Calling the txn(...) returns whether the txn suceeded or failed, so
you do not have to handle any custom exceptions outside the dal.  For
SQLDB the txn(...) will allways return True.

Robin

On Jan 18, 12:55 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> GAE only provides transaction at the level of the single record. Robin
> has a patch that allows that and it will be in 1.56. This is only
> usefult for things like incrementing a counter.
>
> GAE does not support (and in my view it not support anytime soon)
> multi record transactions (the kind of thing you really need for any
> reliable business app).
>
> Massimo
>
> On Jan 17, 10:38 pm, Jonathan Benn <jonathan.b...@gmail.com> wrote:
>
> > On Jan 15, 5:10 pm, Robin B <robi...@gmail.com> wrote:
>
> > > Transactions and list properties are also not supported, until
> > > transactions are officially added to web2py, you can still do
> > > transactions this way:
>
> > Woah, transactions are not supported in GAE?  That's news to me!
>
> > From what you're writing, it sounds like this is a limitation with
> > web2py and not with GAE, right?  It's just that we haven't figured out
> > a generic way to do it right in web2py yet?
>
> > Thanks,
>
> > --Jonathan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to