try:
return self.__transaction
except AttributeError:
- return base.Connection(self.engine, close_with_result=close_with_result)
+ return TLConnection(self, close_with_result=close_with_result)
+ def set_transaction(self, tlconnection, trans):
+ if self.__tcount == 0:
+ self.__transaction = tlconnection
+ self.__trans = trans
+ self.__tcount += 1
def begin(self):
if self.__tcount == 0:
self.__transaction = self.get_connection()
def is_begun(self):
return self.__tcount > 0
-
+class TLConnection(base.Connection):
+ def __init__(self, session, close_with_result):
+ base.Connection.__init__(self, session.engine, close_with_result=close_with_result)
+ self.__session = session
+ # TODO: get begin() to communicate with the Session to maintain the same transactional state
+
class TLEngine(base.ComposedSQLEngine):
"""a ComposedSQLEngine that includes support for thread-local managed transactions. This engine
is better suited to be used with threadlocal Pool object."""
'dbtype:///:memory:',
'dbtype:///foo/bar/im/a/file',
'dbtype:///E:/work/src/LEM/db/hello.db',
- 'dbtype://'
+ 'dbtype://',
+ 'dbtype://username:password@/db'
):
u = url.make_url(text)
print u, text
+ print u.username, u.password, u.database
assert str(u) == text
raise "Invalid"
def do_get(self):
- if getattr(self, 'breakpoint', False):
- raise "breakpoint"
assert self.connection is not None
c = self.connection
self.connection = None
self.assert_(external_connection.scalar("select count(1) from query_users") == 0)
finally:
external_connection.close()
+
+ def testconnections(self):
+ """tests that contextual_connect is threadlocal"""
+ c1 = tlengine.contextual_connect()
+ c2 = tlengine.contextual_connect()
+ assert c1.connection is c2.connection
+ c1.close()
if __name__ == "__main__":
testbase.main()