[TransWarp] SQL Connection doesn't join Transaction

Ulrich Eck ueck at net-labs.de
Wed Mar 5 07:20:29 EST 2003


Hi Phillip,

as i'm building a sqlschema with python-code generator i found out
that sql-connections don't join a transaction in some cases.

here is an example of the code i use:
------------------------------------------------------------------------
from peak.api import *
from TST import TST

class app(storage.TransactionComponent):
    connection = binding.bindTo('sapdb://JACK:TEST@srv03.net-labs.dev/TST',
                                provides=storage.ISQLConnection)
    db = binding.New(TST)

a = app()
storage.begin(a)


x = a.db.persons.newItem()
x.id = 3
x.lastname = 'Eck'
x.firstname = 'Ulrich'
x.title = 'Herr'
x.dateOfBirth = None
x.dateOfEntry = None
x.dateOfExit = None
x.modificationDate = None
storage.commit(a)
--------------------------------------------------------------------------

before i do a commit, only the person Datamanger (a.db.persons) is a
transaction participant:
.....
>>> x.modificationDate = None
>>> t = storage.getTransaction(a)
>>> t.state
<peak.storage.transactions.TransactionState object at 0x8420114>
>>> t.state.participants
[<TST.PersonDM object at 0x841f934>]
>>> x._p_jar
<TST.PersonDM object at 0x841f934>
>>> x._p_jar.flush()
Mar 05 12:05:21 emf2 PEAK[8536]: _new (3,), [3, 'Eck', 'Ulrich', 'Herr', None, None, None, None]
Mar 05 12:05:21 emf2 PEAK[8536]: _new ok
>>> t.state.participants
[<TST.PersonDM object at 0x841f934>]
>>> a.connection.inTransaction
0
>>> a.connection.joinedTxn
<peak.storage.transactions.TransactionService object at 0x81d34a4>
>>> a.connection.inTransaction
1

i needed to add the following line to the __call__ method of ManagedConnection:

    def __call__(self, *args, **kw):

        cursor = self.cursorClass(self, **kw)

        if args:
            # any case where this doesn't work ??
            self.joinedTxn
            ^^^^^^^^^^^^^^
            cursor.execute(*args)

        return cursor

Allthough i don't know it this is really the place where it should be
or if there should be check if this Connection supports transactions.

what is the right way to:
1. use the peak.storage sytem that this change is not needed
or
2. make changes that ensure a connection joins the Transaction
whenever it is used and supports transactions.

cheers


Ulrich Eck
------------------------------------------------------------------------
net-labs Systemhaus GmbH
Ebersberger Str. 46
85570 Markt Schwaben
fon:   +49-8121-4747-11
fax:   +49-8121-4747-77
email: ueck at net-labs.de
http://www.net-labs.de




More information about the PEAK mailing list