]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Sep 2005 06:05:40 +0000 (06:05 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Sep 2005 06:05:40 +0000 (06:05 +0000)
lib/sqlalchemy/mapper.py
lib/sqlalchemy/objectstore.py
test/mapper.py

index b7d2d96e98685758b81c9de80716ab88769d4eef..b5598b955306d6792fb8981062e96638d5ed05d5 100644 (file)
@@ -164,8 +164,8 @@ class Mapper(object):
             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
 
@@ -190,10 +190,13 @@ class Mapper(object):
                 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"""
@@ -319,16 +322,19 @@ class Mapper(object):
         # 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:
@@ -547,7 +553,7 @@ class PropertyLoader(MapperProperty):
                 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:
@@ -555,7 +561,7 @@ class PropertyLoader(MapperProperty):
                 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 ?"
index 8b64091c07ddc1f35dcb9fe3ffa6534c17939343..7a7634f2516ddbda354a754de23dd41b1028709c 100644 (file)
@@ -103,17 +103,16 @@ class UOWListElement(util.HistoryArraySet):
     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):
@@ -197,6 +196,7 @@ 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)
@@ -233,9 +233,10 @@ class UnitOfWork(object):
             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):
@@ -264,7 +265,10 @@ class UnitOfWork(object):
             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
@@ -284,7 +288,6 @@ class UnitOfWork(object):
         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):
@@ -308,8 +311,7 @@ class UOWTransaction(object):
 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
index 59967673ecc87c1642448297ba7b756eda2153f5..46cc211a896265ab09d7f093de5c3ae5b2d86d3c 100644 (file)
@@ -310,6 +310,8 @@ class SaveTest(AssertMixin):
 
         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