self.obj = obj
self.key = key
util.HistoryArraySet.__init__(self, items)
- print "listelement init"
+ obj.__dict__[key] = self.data
def list_value_changed(self, obj, key, listval):
pass
if self.orig is not PropHistory.NONE:
self.obj.__dict__[self.key] = self.orig
self.orig = PropHistory.NONE
- def clear_history(self):
+ def commit(self):
self.orig = PropHistory.NONE
def added_items(self):
if self.orig is not PropHistory.NONE:
def delete_list_attribute(self, obj, key):
pass
- def rollback(self, obj):
- try:
- attributes = self.attribute_history[obj]
- for hist in attributes.values():
- hist.rollback()
- except KeyError:
- pass
+ def rollback(self, obj = None):
+ if obj is None:
+ for attr in self.attribute_history.values():
+ for hist in attr.values():
+ hist.rollback()
+ else:
+ try:
+ attributes = self.attribute_history[obj]
+ for hist in attributes.values():
+ hist.rollback()
+ except KeyError:
+ pass
- def clear_history(self, obj):
- try:
- attributes = self.attribute_history[obj]
- for hist in attributes.values():
- hist.clear_history()
- except KeyError:
- pass
+ def commit(self, obj = None):
+ if obj is None:
+ for attr in self.attribute_history.values():
+ for hist in attr.values():
+ hist.commit()
+ else:
+ try:
+ attributes = self.attribute_history[obj]
+ for hist in attributes.values():
+ hist.commit()
+ except KeyError:
+ pass
def get_history(self, obj, key):
try:
def init(self):
[prop.init(key, self) for key, prop in self.props.iteritems()]
- print "well hi!"
+ # TODO: get some notion of "primary mapper" going so multiple mappers dont collide
self.class_._mapper = self.hashkey
def instances(self, cursor, db = None):
result_list = []
setattr(instance, self.key, result_list)
result_list = getattr(instance, self.key)
- result_list.clear_history()
+ result_list.commit()
else:
result_list = getattr(instance, self.key)
else:
for obj in [n for n in self.new] + [d for d in self.dirty]:
commit_context.append_task(obj)
- print "COMMIT append " + obj.__class__.__name__ + " " + repr(id(obj))
for item in self.modified_lists:
obj = item.obj
commit_context.append_task(obj)
except:
for e in engines:
e.rollback()
- if self.parent:
- uow.set(self.parent)
+ if self.parent:
+ self.rollback()
raise
for e in engines:
e.commit()
commit_context.post_exec()
+ self.attributes.commit()
if self.parent:
uow.set(self.parent)
+
+ def rollback(self):
+ if not self.is_begun:
+ raise "UOW transaction is not begun"
+ self.attributes.rollback()
+ uow.set(self.parent)
class UOWTransaction(object):
def __init__(self, uow):
del self.records[item]
except KeyError:
pass
- def clear_history(self):
+ def commit(self):
for key in self.records.keys():
value = self.records[key]
if value is False:
print repr(u.__dict__)
self.assert_(u.user_id == 7 and u.user_name == 'john' and u.email_address == 'lala@123.com')
- manager.clear_history(u)
+ manager.commit(u)
print repr(u.__dict__)
self.assert_(u.user_id == 7 and u.user_name == 'john' and u.email_address == 'lala@123.com')
print repr(u.__dict__)
self.assert_(u.user_id == 7 and u.user_name == 'john' and u.addresses[0].email_address == 'lala@123.com')
- manager.clear_history(u)
+ manager.commit()
print repr(u.__dict__)
self.assert_(u.user_id == 7 and u.user_name == 'john' and u.addresses[0].email_address == 'lala@123.com')
print repr(u.__dict__)
self.assert_(u.user_id == 7 and u.user_name == 'heythere' and u.addresses[0].email_address == 'lala@123.com' and u.addresses[1].email_address == 'foo@bar.com')
- manager.rollback(u)
+ manager.rollback()
print repr(u.__dict__)
+ print repr(u.addresses[0].__dict__)
self.assert_(u.user_id == 7 and u.user_name == 'john' and u.addresses[0].email_address == 'lala@123.com')
if __name__ == "__main__":
u.addresses.append(Address())
u.addresses[1].email_address = 'there'
print repr(u.__dict__)
+ print repr(u.addresses)
m.rollback(u)
print repr(u.__dict__)