[ZODB-Dev] get_transaction

kapil thangavelu k_vertigo@yahoo.com
Fri, 30 Nov 2001 03:55:46 -0800


i uploaded some code and emailed the list 

http://lists.zope.org/pipermail/zodb-dev/2001-October/001797.html
http://www.zope.org/Members/k_vertigo/Products/FreeTxn

which handles this use case, namely it separates transactions from threads 
and associates them with connections.

to rewrite the below example using the code would look like

from ZODB import FIleStorage, DB

from FreeTxn import install_free_txn
install_free_txn()

storage1 = FileStorage.FileStorage('/tmp/test-filestorage.fs')
db1 = DB(storage1)
conn1 = db1.open()
root1 = conn1.root()

storage2 = FileStorage.FileStorage('/tmp/test-filestorage2.fs')
db2 = DB(storage2)
conn2 = db2.open()
root2 = conn2.root()

root1['foo'] = 'hello world'
root2['bar'] = 'goodbye world'

get_transaction(root1).commit()

root1['foo'] = 'invisible string'
root2['bar'] = 'hello world'

get_transaction(root2).commit()

yielding committed values of 'hello world' for foo and bar in db1, and db2 
respectively. the separation of txn from threads also allows multiple txn 
independent connections to the same db.

pretty much everything is the same except when exercising txn control you 
need to pass in either a persistent object or a connection to 
get_transaction. registration for txn's via get_transaction.register(pobj) is 
the same, non persistent objects need to register by passing in a connection 
or persistent object to get_transaction. more discussion of the approach and 
the caveats is included in the code, the code and the approach have only been 
lightly tested.

i'd welcome any opinions from the zodb gurus that frequent here.

cheers

kapil


On Thursday 29 November 2001 10:11 pm, Bill Anderson wrote:
> On Thu, 2001-11-29 at 14:51, Michel Pelletier wrote:
> > Magnus Heino wrote:
> > > Hi.
> > >
> > > I have  a question about get_transaction()
> > >
> > > ---
> > >
> > > from ZODB import FileStorage, DB
> > >
> > > storage = FileStorage.FileStorage('/tmp/test-filestorage.fs')
> > > db = DB( storage )
> > > conn = db.open()
> > >
> > > root1 = conn.root()
> > > root2 = conn.root()
> > >
> > > root1[1] = 1
> > > root2[2] = 2
> > >
> > > get_transaction().commit()
> > >
> > > ---
> > >
> > > What will be committed? Both connections? Can I control that?
> >
> > There's only one connection, you created two references to the same
> > object.
>
> OK, how about this:
>
> from ZODB import FileStorage, DB
>
> storage1 = FileStorage.FileStorage('/tmp/test-filestorage1.fs')
> db1 = DB( storage1 )
> conn1 = db1.open()
>
> storage2 = FileStorage.FileStorage('/tmp/test-filestorage2.fs')
> db2 = DB( storage2 )
> conn2 = db2.open()
>
> root1 = conn1.root()
> root2 = conn2.root()
>
> root1[1]=1
> root2[2]=2
> get_transaction().commit()
>
> :^)=
>
> ("Don't do that is not exactly an acceptable answer, either. ;) )
>
>
>
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zodb-dev