[SQLObject] Transaction Implementation v2
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Luke O. <lu...@me...> - 2003-05-13 20:47:55
|
Hello all -
Wow. Following Ian's suggestions yesterday, I was able to trim all of
this transaction support down to a one-line addition to SQLObject,
plus the now-combined MemoryTransaction class.
New interface:
m = MemoryTransaction()
a = Person.new(connection=m, ...)
b = Person(2).copyToConnection(m)
m.commit()
Changes to SQLObject necessary:
Same changes as before (in new() and joins), but __new__ no longer
needs useCache argument.
New method:
def copyToConnection(self, conn):
return self.__class__(self.id, connection=conn)
That's it. :)
Cache.py:
Cache.clear() does not behave as I would expect, still leaving
weakrefs around. It's not used at all within SQLObject that I can
find, so I'm assuming I'm safe to change the behavior to be an
overall purge:
def clear(self):
self.lock.acquire()
- for key, value in self.cache.items():
- self.expiredCache[key] = ref(value)
+ self.expiredCache = {}
self.cache = {}
self.lock.release()
(Otherwise my MemoryTransaction cache gets a ref to the new persisted
objects with the wrong connections inside them... could fix this by
making a no-op cache for Memory Transaction, but I have a feeling
this is the expected behavior for Cache.clear())
New version at http://www.amoebagod.com/SQLObject-T2.zip
- Luke
|