Ejemplo n.º 1
0
def _postfetch(mapper, uowtransaction, table, 
                state, dict_, prefetch_cols, postfetch_cols,
                            params, value_params):
    """Expire attributes in need of newly persisted database state,
    after an INSERT or UPDATE statement has proceeded for that
    state."""

    if mapper.version_id_col is not None:
        prefetch_cols = list(prefetch_cols) + [mapper.version_id_col]

    for c in prefetch_cols:
        if c.key in params and c in mapper._columntoproperty:
            mapper._set_state_attr_by_column(state, dict_, c, params[c.key])

    if postfetch_cols:
        state.expire_attributes(state.dict, 
                            [mapper._columntoproperty[c].key 
                            for c in postfetch_cols if c in 
                            mapper._columntoproperty]
                        )

    # synchronize newly inserted ids from one table to the next
    # TODO: this still goes a little too often.  would be nice to
    # have definitive list of "columns that changed" here
    for m, equated_pairs in mapper._table_to_equated[table]:
        sync.populate(state, m, state, m, 
                                        equated_pairs, 
                                        uowtransaction,
                                        mapper.passive_updates)
Ejemplo n.º 2
0
    def _synchronize(self,
                     state,
                     child,
                     associationrow,
                     clearkeys,
                     uowcommit,
                     operation=None):
        if state is None or \
            (not self.post_update and uowcommit.is_deleted(state)):
            return

        if operation is not None and \
            child is not None and \
            not uowcommit.session._contains_state(child):
            util.warn(
                "Object of type %s not in session, %s "
                "operation along '%s' won't proceed" %
                (mapperutil.state_class_str(child), operation, self.prop))
            return

        if clearkeys or child is None:
            sync.clear(state, self.parent, self.prop.synchronize_pairs)
        else:
            self._verify_canload(child)
            sync.populate(child, self.mapper, state, self.parent,
                          self.prop.synchronize_pairs, uowcommit, False)
Ejemplo n.º 3
0
 def test_populate_flag_cascaded(self):
     uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
     pairs = [(a_mapper.c.id, b_mapper.c.id)]
     a1.obj().id = 7
     assert 'id' not in b1.obj().__dict__
     sync.populate(a1, a_mapper, b1, b_mapper, pairs, uowcommit, True)
     eq_(b1.obj().id, 7)
     eq_(b1.obj().__dict__['id'], 7)
     eq_(uowcommit.attributes[("pk_cascaded", b1, b_mapper.c.id)], True)
Ejemplo n.º 4
0
 def test_populate_flag_cascaded(self):
     uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
     pairs = [(a_mapper.c.id, b_mapper.c.id)]
     a1.obj().id = 7
     assert "id" not in b1.obj().__dict__
     sync.populate(a1, a_mapper, b1, b_mapper, pairs, uowcommit, True)
     eq_(b1.obj().id, 7)
     eq_(b1.obj().__dict__["id"], 7)
     eq_(uowcommit.attributes[("pk_cascaded", b1, b_mapper.c.id)], True)
Ejemplo n.º 5
0
 def test_populate(self):
     uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
     pairs = [(a_mapper.c.id, b_mapper.c.id)]
     a1.obj().id = 7
     assert 'id' not in b1.obj().__dict__
     sync.populate(a1, a_mapper, b1, b_mapper, pairs, uowcommit, False)
     eq_(b1.obj().id, 7)
     eq_(b1.obj().__dict__['id'], 7)
     assert ("pk_cascaded", b1, b_mapper.c.id) not in uowcommit.attributes
Ejemplo n.º 6
0
    def _synchronize(self, state, child, associationrow, clearkeys, uowcommit):
        if state is None or (not self.post_update and uowcommit.is_deleted(state)):
            return

        if clearkeys or child is None:
            sync.clear(state, self.parent, self.prop.synchronize_pairs)
        else:
            self._verify_canload(child)
            sync.populate(child, self.mapper, state, self.parent, self.prop.synchronize_pairs)
Ejemplo n.º 7
0
    def _synchronize(self, state, child, associationrow, clearkeys, uowcommit):
        if state is None or (not self.post_update and uowcommit.is_deleted(state)):
            return

        if clearkeys or child is None:
            sync.clear(state, self.parent, self.prop.synchronize_pairs)
        else:
            self._verify_canload(child)
            sync.populate(child, self.mapper, state, self.parent, self.prop.synchronize_pairs)
Ejemplo n.º 8
0
 def _synchronize(self, state, child, associationrow, clearkeys, uowcommit):
     source = state
     dest = child
     if dest is None or (not self.post_update and uowcommit.is_deleted(dest)):
         return
     self._verify_canload(child)
     if clearkeys:
         sync.clear(dest, self.mapper, self.prop.synchronize_pairs)
     else:
         sync.populate(source, self.parent, dest, self.mapper, self.prop.synchronize_pairs)
Ejemplo n.º 9
0
 def _synchronize(self, state, child, associationrow, clearkeys, uowcommit):
     source = state
     dest = child
     if dest is None or (not self.post_update and uowcommit.is_deleted(dest)):
         return
     self._verify_canload(child)
     if clearkeys:
         sync.clear(dest, self.mapper, self.prop.synchronize_pairs)
     else:
         sync.populate(source, self.parent, dest, self.mapper, self.prop.synchronize_pairs)
Ejemplo n.º 10
0
 def _process_key_switches(self, deplist, uowcommit):
     switchers = set(s for s in deplist if self._pks_changed(uowcommit, s))
     if switchers:
         # yes, we're doing a linear search right now through the UOW.  only
         # takes effect when primary key values have actually changed.
         # a possible optimization might be to enhance the "hasparents" capability of
         # attributes to actually store all parent references, but this introduces
         # more complicated attribute accounting.
         for s in [elem for elem in uowcommit.session.identity_map.all_states()
             if issubclass(elem.class_, self.parent.class_) and
                 self.key in elem.dict and
                 elem.dict[self.key] is not None and 
                 attributes.instance_state(elem.dict[self.key]) in switchers
             ]:
             uowcommit.register_object(s, listonly=self.passive_updates)
             sync.populate(attributes.instance_state(s.dict[self.key]), self.mapper, s, self.parent, self.prop.synchronize_pairs)
Ejemplo n.º 11
0
 def _process_key_switches(self, deplist, uowcommit):
     switchers = set(s for s in deplist if self._pks_changed(uowcommit, s))
     if switchers:
         # yes, we're doing a linear search right now through the UOW.  only
         # takes effect when primary key values have actually changed.
         # a possible optimization might be to enhance the "hasparents" capability of
         # attributes to actually store all parent references, but this introduces
         # more complicated attribute accounting.
         for s in [elem for elem in uowcommit.session.identity_map.all_states()
             if issubclass(elem.class_, self.parent.class_) and
                 self.key in elem.dict and
                 elem.dict[self.key] is not None and 
                 attributes.instance_state(elem.dict[self.key]) in switchers
             ]:
             uowcommit.register_object(s)
             sync.populate(attributes.instance_state(s.dict[self.key]), self.mapper, s, self.parent, self.prop.synchronize_pairs)
Ejemplo n.º 12
0
 def _process_key_switches(self, deplist, uowcommit):
     switchers = self._key_switchers(uowcommit, deplist)
     if switchers:
         # if primary key values have actually changed somewhere, perform
         # a linear search through the UOW in search of a parent.
         # note that this handler isn't used if the many-to-one
         # relationship has a backref.
         for state in uowcommit.session.identity_map.all_states():
             if not issubclass(state.class_, self.parent.class_):
                 continue
             dict_ = state.dict
             related = dict_.get(self.key)
             if related is not None:
                 related_state = attributes.instance_state(dict_[self.key])
                 if related_state in switchers:
                     uowcommit.register_object(state, False,
                                               self.passive_updates)
                     sync.populate(related_state, self.mapper, state,
                                   self.parent, self.prop.synchronize_pairs,
                                   uowcommit, self.passive_updates)
Ejemplo n.º 13
0
 def _process_key_switches(self, deplist, uowcommit):
     switchers = self._key_switchers(uowcommit, deplist)
     if switchers:
         # if primary key values have actually changed somewhere, perform
         # a linear search through the UOW in search of a parent.
         for state in uowcommit.session.identity_map.all_states():
             if not issubclass(state.class_, self.parent.class_):
                 continue
             dict_ = state.dict
             related = state.get_impl(self.key).get(
                 state, dict_, passive=self.passive_updates)
             if related is not attributes.PASSIVE_NO_RESULT and \
                 related is not None:
                 related_state = attributes.instance_state(dict_[self.key])
                 if related_state in switchers:
                     uowcommit.register_object(state, False,
                                               self.passive_updates)
                     sync.populate(related_state, self.mapper, state,
                                   self.parent, self.prop.synchronize_pairs,
                                   uowcommit, self.passive_updates)
Ejemplo n.º 14
0
 def _process_key_switches(self, deplist, uowcommit):
     switchers = self._key_switchers(uowcommit, deplist)
     if switchers:
         # if primary key values have actually changed somewhere, perform
         # a linear search through the UOW in search of a parent.
         for state in uowcommit.session.identity_map.all_states():
             if not issubclass(state.class_, self.parent.class_):
                 continue
             dict_ = state.dict
             related = state.get_impl(self.key).get(state, dict_,
                     passive=self._passive_update_flag)
             if related is not attributes.PASSIVE_NO_RESULT and \
                 related is not None:
                 related_state = attributes.instance_state(dict_[self.key])
                 if related_state in switchers:
                     uowcommit.register_object(state, 
                                                 False, 
                                                 self.passive_updates)
                     sync.populate(
                                 related_state, 
                                 self.mapper, state, 
                                 self.parent, self.prop.synchronize_pairs, 
                                 uowcommit, self.passive_updates)
Ejemplo n.º 15
0
 def _process_key_switches(self, deplist, uowcommit):
     switchers = self._key_switchers(uowcommit, deplist)
     if switchers:
         # if primary key values have actually changed somewhere, perform
         # a linear search through the UOW in search of a parent.
         # note that this handler isn't used if the many-to-one 
         # relationship has a backref.
         for state in uowcommit.session.identity_map.all_states():
             if not issubclass(state.class_, self.parent.class_):
                 continue
             dict_ = state.dict
             related = dict_.get(self.key)
             if related is not None:
                 related_state = attributes.instance_state(dict_[self.key])
                 if related_state in switchers:
                     uowcommit.register_object(state, 
                                                 False, 
                                                 self.passive_updates)
                     sync.populate(
                                 related_state, 
                                 self.mapper, state, 
                                 self.parent, self.prop.synchronize_pairs, 
                                 uowcommit, self.passive_updates)
Ejemplo n.º 16
0
    def _synchronize(self, state, child, associationrow,
                                        clearkeys, uowcommit, operation=None):
        if state is None or \
            (not self.post_update and uowcommit.is_deleted(state)):
            return

        if operation is not None and \
            child is not None and \
            not uowcommit.session._contains_state(child):
            util.warn(
                "Object of type %s not in session, %s "
                "operation along '%s' won't proceed" % 
                (mapperutil.state_class_str(child), operation, self.prop))
            return

        if clearkeys or child is None:
            sync.clear(state, self.parent, self.prop.synchronize_pairs)
        else:
            self._verify_canload(child)
            sync.populate(child, self.mapper, state, 
                            self.parent, 
                            self.prop.synchronize_pairs, 
                            uowcommit,
                            False)