On Apr 5, 2006, at 8:12 AM, Qvx wrote:


Good as long as this connection is now accessible only to it's caller. Once I get connection it is *mine* and there are no surprise operations carried out over this connection by some other parts of the system. This connection must be used only in places where I explicitly use it be it via using(), set_current() or some other ways.

Once I'm done with it, how do I release such connection back to pool so it can be used by other parts of the system?


yes, its unique to you owning it. to release it, you just let go of it. The pooling module works based on the Connection object falling out of scope, which is what will ultimately occur.

# 4. natural nesting behavior

As always, begin/commit/rollback uses the "outermost nested" idea,
where "nested" calls to begin/commit dont affect the single
"outermost" transaction.

e = create_engine('foo')
trans = e.begin()
try:
     mytable.update().execute()

     # then in some other function..
     trans2 = e.begin()
     try:
         myothertable.update.execute()
         trans2.commit()   # doesnt commit
     except:
         trans2.rollback()   # rolls trans2, trans

     trans.commit()   # commits mytable, myothertable
except:
     trans.rollback()  # rolls back trans

"trans2.rollback()" will also roll back "mytable.update().execute ()". On Oracle you would have to issue savepoint and then rollback to this savepoint in order to achieve partial rollback. On other databases this is perhaps handled differently.


the point is, there is only one real transaction occuring above. the second call to begin() returns a no-op, as does the commit() on trans2.


Yes, but  in my case it is more like this:

trans_mssql = engine_mssql.begin()
trans_oracle = engine_oracle.begin()
trans_mysql = engine_mysql.begin()
try:
    #...
    trans_mssql.commit()
    trans_oracle.commit()
    trans_mysql.commit()
except:
    trans_mssql.rollback()
    trans_oracle.rollback()
    trans_mysql.rollback()


you need something else, which I havent gotten into with this proposal, which is a TransactionManager. youd gather up all your ConnectionProxy objects and register them with a TransactionManager that does a pattern like the above. This is something I could take a stab at, but its not something I have deep experience with (also the JTA docs, which describe the J2EE standard for this sort of thing, are somewhat daunting)...it would be a little simplistic to start out. Or folks could contribute such a thing, theyre likely to put more thought into it than me.





-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to