Commits

Mike Bayer committed 0791f03

modifcation to unitofwork to not maintain ordering within the
"new" list or within the UOWTask "objects" list; instead, new objects
are tagged with an ordering identifier as they are registered as new
with the session, and the INSERT statements are then sorted within the
mapper save_obj. the INSERT ordering has basically been pushed allthe way
to the end of the flush cycle. that way the various sorts and
organizations occuring within UOWTask (particularly the circular task
sort) dont have to worry about maintaining order (which they werent anyway)

Comments (0)

Files changed (3)

 by not raising an error when redundant mappers were set up, fixed
 - added allow_null_pks option to Mapper, allows rows where some
 primary key columns are null (i.e. when mapping to outer joins etc)
+- modifcation to unitofwork to not maintain ordering within the
+"new" list or within the UOWTask "objects" list; instead, new objects
+are tagged with an ordering identifier as they are registered as new
+with the session, and the INSERT statements are then sorted within the 
+mapper save_obj.  the INSERT ordering has basically been pushed all
+the way to the end of the flush cycle. that way the various sorts and 
+organizations occuring within UOWTask (particularly the circular task 
+sort) dont have to worry about maintaining order (which they werent anyway)
 - fixed reflection of foreign keys to autoload the referenced table
 if it was not loaded already
 - [ticket:256] - pass URL query string arguments to connect() function

lib/sqlalchemy/orm/mapper.py

 
             if len(insert):
                 statement = table.insert()
+                def comparator(a, b):
+                    return cmp(a[0]._sa_insert_order, b[0]._sa_insert_order)
+                insert.sort(comparator)
                 for rec in insert:
                     (obj, params) = rec
                     c = connection.execute(statement, params)

lib/sqlalchemy/orm/unitofwork.py

         else:
             self.identity_map = weakref.WeakValueDictionary()
             
-        self.new = util.OrderedSet()
+        self.new = util.Set() #OrderedSet()
         self.dirty = util.Set()
         
         self.deleted = util.Set()
         if not hasattr(obj, '_instance_key'):
             mapper = object_mapper(obj)
             obj._instance_key = mapper.instance_key(obj)
+        try:
+            delattr(obj, '_sa_insert_order')
+        except AttributeError:
+            pass
         self.identity_map[obj._instance_key] = obj
         attribute_manager.commit(obj)
         
             raise InvalidRequestError("Object '%s' already has an identity - it cant be registered as new" % repr(obj))
         if obj not in self.new:
             self.new.add(obj)
+            obj._sa_insert_order = len(self.new)
         self.unregister_deleted(obj)
         
     def register_dirty(self, obj):
         mapper = object_mapper(obj)
         self.mappers.add(mapper)
         task = self.get_task_by_mapper(mapper)
-
         if postupdate:
             mod = task.append_postupdate(obj)
             if mod: self._mark_modified()
         # deleted by this UOWTask's Mapper.
         # in the case of the row-based "circular sort", the UOWTaskElement may
         # also reference further UOWTasks which are dependent on that UOWTaskElement.
-        self.objects = util.OrderedDict()
+        self.objects = {} #util.OrderedDict()
         
         # a list of UOWDependencyProcessors which are executed after saves and
         # before deletes, to synchronize data to dependent objects
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.