self._instance(row, imap, result)
# store new stuff in the identity map
- for key, value in imap.iteritems():
- objectstore.put(key, value)
+ for value in imap.values():
+ objectstore.uow().register_clean(value)
return result
return None
def put(self, instance):
- key = objectstore.get_id_key(tuple([self._getattrbycolumn(instance, column) for column in self.primary_keys[self.selectable]]), self.class_, self.table)
+ key = self.identity_key(instance)
objectstore.put(key, instance, self.scope)
return key
+ def identity_key(self, instance):
+ return objectstore.get_id_key(tuple([self._getattrbycolumn(instance, column) for column in self.primary_keys[self.selectable]]), self.class_, self.table)
+
def compile(self, whereclause = None, **options):
"""works like select, except returns the SQL statement object without
compiling or executing it"""
# been exposed to being modified by the application.
identitykey = self._identity_key(row)
if objectstore.has_key(identitykey):
+ instance = objectstore.get(identitykey)
if result is not None:
- result.append_nohistory(objectstore.get(identitykey))
- else:
- return instance
+ result.append_nohistory(instance)
+
+ return instance
# look in result-local identitymap for it.
exists = imap.has_key(identitykey)
if not exists:
instance = self.class_()
instance._mapper = self.hashkey
+ instance._instance_key = identitykey
+
imap[identitykey] = instance
isnew = True
else:
for child in childlist.added_items():
associationrow = {}
self.primaryjoin.accept_visitor(setter)
- uow.register_saved(childlist)
+ uow.register_saved_object(childlist)
# TODO: deleted items
elif self.foreignkey.table == self.parent.table:
for child in deplist:
for obj in childlist.added_items():
associationrow = {}
self.primaryjoin.accept_visitor(setter)
- uow.register_saved(childlist)
+ uow.register_saved_object(childlist)
# TODO: deleted items
else:
raise " no foreign key ?"
def __init__(self, obj, items = None):
util.HistoryArraySet.__init__(self, items)
self.obj = weakref.ref(obj)
- self.list = UOWListElement
def _setrecord(self, item):
res = util.HistoryArraySet._setrecord(self, item)
if res:
- uow().modified_lists.append(self.list)
+ uow().modified_lists.append(self)
return res
def _delrecord(self, item):
res = util.HistoryArraySet._delrecord(self, item)
if res:
- uow().modified_lists.append(self.list)
+ uow().modified_lists.append(self)
return res
class UnitOfWork(object):
except KeyError:
pass
put(obj._instance_key, obj, scope=scope)
+ # TODO: get lists off the object and make sure theyre clean too ?
def register_new(self, obj):
self.new.append(obj)
for item in self.modified_lists:
obj = item.obj()
self.commit_context.append_task(obj)
+ print "obj: " + repr(id(obj)) + obj.__class__.__name__
for task in self.commit_context.tasks.values():
- task.mapper.register_dependencies(util.HashSet(task.objects + task.lists), self)
+ task.mapper.register_dependencies(task.objects, self)
mapperlist = self.commit_context.tasks.values()
def compare(a, b):
self.register_clean(obj)
for obj in self.commit_context.saved_lists:
- del self.modified_lists[obj]
+ try:
+ del self.modified_lists[obj]
+ except KeyError:
+ pass
self.commit_context = None
# TODO: deleted stuff
task = self.commit_context.get_task_by_mapper(mapper)
if processor is not None:
task.dependencies.append((processor, stuff_to_process))
-
class UOWTransaction(object):
def __init__(self):
class UOWTask(object):
def __init__(self, mapper):
self.mapper = mapper
- self.objects = []
- self.lists = []
+ self.objects = util.HashSet()
self.dependencies = []
uow = util.ScopedRegistry(lambda: UnitOfWork(), "thread")
\ No newline at end of file
objectstore.uow().register_new(u)
+ objectstore.uow().commit(u)
+ print "OK"
objectstore.uow().commit()
# assert the first one retreives the same from the identity map