summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/unitofwork.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-08-14 15:38:30 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-08-15 15:52:35 -0400
commit191fd3e27e3ef90190f8315c33ba6eb97aeaf5d2 (patch)
treed9d5465928cf1c99deabdc345f3577f0c5fd7960 /lib/sqlalchemy/orm/unitofwork.py
parent652a24f0303b9bb0e7a326b05709d7660793f90b (diff)
downloadsqlalchemy-191fd3e27e3ef90190f8315c33ba6eb97aeaf5d2.tar.gz
- proof of concept
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index 71e61827b..8df24e95a 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -16,6 +16,7 @@ organizes them in order of dependency, and executes.
from .. import util, event
from ..util import topological
from . import attributes, persistence, util as orm_util
+import itertools
def track_cascade_events(descriptor, prop):
@@ -379,14 +380,37 @@ class UOWTransaction(object):
execute() method has succeeded and the transaction has been committed.
"""
+ if not self.states:
+ return
+
states = set(self.states)
isdel = set(
s for (s, (isdelete, listonly)) in self.states.items()
if isdelete
)
other = states.difference(isdel)
- self.session._remove_newly_deleted(isdel)
- self.session._register_newly_persistent(other)
+ if isdel:
+ self.session._remove_newly_deleted(isdel)
+ if other:
+ self.session._register_newly_persistent(other)
+
+ def bulk_save(self, objects):
+ for (base_mapper, in_session), states in itertools.groupby(
+ (attributes.instance_state(obj) for obj in objects),
+ lambda state:
+ (
+ state.mapper.base_mapper,
+ state.key is self.session.hash_key
+ )):
+
+ persistence.save_obj(
+ base_mapper, list(states), self, bookkeeping=in_session)
+
+ if in_session:
+ self.states.update(
+ (state, (False, False))
+ for state in states
+ )
class IterateMappersMixin(object):