Esempio n. 1
0
    def per_property_flush_actions(self, uow):
        after_save = unitofwork.ProcessAll(uow, self, False, True)
        before_delete = unitofwork.ProcessAll(uow, self, True, True)

        parent_saves = unitofwork.SaveUpdateAll(
                                        uow,
                                        self.parent.primary_base_mapper
                                        )
        child_saves = unitofwork.SaveUpdateAll(
                                        uow,
                                        self.mapper.primary_base_mapper
                                        )

        parent_deletes = unitofwork.DeleteAll(
                                        uow,
                                        self.parent.primary_base_mapper
                                        )
        child_deletes = unitofwork.DeleteAll(
                                        uow,
                                        self.mapper.primary_base_mapper
                                        )

        self.per_property_dependencies(uow,
                                        parent_saves,
                                        child_saves,
                                        parent_deletes,
                                        child_deletes,
                                        after_save,
                                        before_delete
                                        )
Esempio n. 2
0
 def per_property_flush_actions(self, uow):
     parent_saves = unitofwork.SaveUpdateAll(
                                     uow,
                                     self.parent.base_mapper)
     after_save = unitofwork.ProcessAll(uow, self, False, False)
     uow.dependencies.update([
         (parent_saves, after_save)
     ])
Esempio n. 3
0
    def per_state_flush_actions(self, uow, states, isdelete):
        """establish actions and dependencies related to a flush.
        
        These actions will operate on all relevant states 
        individually.    This occurs only if there are cycles
        in the 'aggregated' version of events.
        
        """

        parent_base_mapper = self.parent.primary_base_mapper
        child_base_mapper = self.mapper.primary_base_mapper
        child_saves = unitofwork.SaveUpdateAll(uow, child_base_mapper)
        child_deletes = unitofwork.DeleteAll(uow, child_base_mapper)

        # locate and disable the aggregate processors
        # for this dependency

        if isdelete:
            before_delete = unitofwork.ProcessAll(uow, self, True, True)
            before_delete.disabled = True
        else:
            after_save = unitofwork.ProcessAll(uow, self, False, True)
            after_save.disabled = True

        # check if the "child" side is part of the cycle

        if child_saves not in uow.cycles:
            # based on the current dependencies we use, the saves/
            # deletes should always be in the 'cycles' collection
            # together.   if this changes, we will have to break up
            # this method a bit more.
            assert child_deletes not in uow.cycles

            # child side is not part of the cycle, so we will link per-state
            # actions to the aggregate "saves", "deletes" actions
            child_actions = [(child_saves, False), (child_deletes, True)]
            child_in_cycles = False
        else:
            child_in_cycles = True

        # check if the "parent" side is part of the cycle
        if not isdelete:
            parent_saves = unitofwork.SaveUpdateAll(uow,
                                                    self.parent.base_mapper)
            parent_deletes = before_delete = None
            if parent_saves in uow.cycles:
                parent_in_cycles = True
        else:
            parent_deletes = unitofwork.DeleteAll(uow, self.parent.base_mapper)
            parent_saves = after_save = None
            if parent_deletes in uow.cycles:
                parent_in_cycles = True

        # now create actions /dependencies for each state.
        for state in states:
            # detect if there's anything changed or loaded
            # by a preprocessor on this state/attribute.  if not,
            # we should be able to skip it entirely.
            sum_ = uow.get_attribute_history(state, self.key,
                                             passive=True).sum()
            if not sum_:
                continue

            if isdelete:
                before_delete = unitofwork.ProcessState(uow, self, True, state)
                if parent_in_cycles:
                    parent_deletes = unitofwork.DeleteState(
                        uow, state, parent_base_mapper)
            else:
                after_save = unitofwork.ProcessState(uow, self, False, state)
                if parent_in_cycles:
                    parent_saves = unitofwork.SaveUpdateState(
                        uow, state, parent_base_mapper)

            if child_in_cycles:
                child_actions = []
                for child_state in sum_:
                    if child_state is None:
                        continue
                    if child_state not in uow.states:
                        child_action = (None, None)
                    else:
                        (deleted, listonly) = uow.states[child_state]
                        if deleted:
                            child_action = (unitofwork.DeleteState(
                                uow, child_state, child_base_mapper), True)
                        else:
                            child_action = (unitofwork.SaveUpdateState(
                                uow, child_state, child_base_mapper), False)
                    child_actions.append(child_action)

            # establish dependencies between our possibly per-state
            # parent action and our possibly per-state child action.
            for child_action, childisdelete in child_actions:
                self.per_state_dependencies(uow, parent_saves, parent_deletes,
                                            child_action, after_save,
                                            before_delete, isdelete,
                                            childisdelete)