def execute_dependencies(self, trans, task, isdelete=None): if isdelete is not True: for dep in task.polymorphic_dependencies: self.execute_dependency(trans, dep, False) if isdelete is not False: for dep in util.reversed(list(task.polymorphic_dependencies)): self.execute_dependency(trans, dep, True)
def execute(self, trans, tasks, isdelete=None): if isdelete is not True: for task in tasks: self.execute_save_steps(trans, task) if isdelete is not False: for task in util.reversed(tasks): self.execute_delete_steps(trans, task)
def execute(self, trans, tasks, isdelete=None): if isdelete is not True: for task in tasks: self._execute(trans, task, False) if isdelete is not False: for task in util.reversed(tasks): self._execute(trans, task, True)
def delete_obj(self, objects, uow): """called by a UnitOfWork object to delete objects, which involves a DELETE statement for each table used by this mapper, for each object in the list.""" for table in util.reversed(self.tables): if not self._has_pks(table): continue delete = [] for obj in objects: params = {} if not hasattr(obj, "_instance_key"): continue else: delete.append(params) for col in self.pks_by_table[table]: params[col.key] = self._getattrbycolumn(obj, col) if self.version_id_col is not None: params[self.version_id_col.key] = self._getattrbycolumn( obj, self.version_id_col) self.extension.before_delete(self, obj) if len(delete): clause = sql.and_() for col in self.pks_by_table[table]: clause.clauses.append( col == sql.bindparam(col.key, type=col.type)) if self.version_id_col is not None: clause.clauses.append(self.version_id_col == sql.bindparam( self.version_id_col.key, type=self.version_id_col.type)) statement = table.delete(clause) c = statement.execute(*delete) if c.supports_sane_rowcount() and c.rowcount != len(delete): raise CommitError( "ConcurrencyError - updated rowcount %d does not match number of objects updated %d" % (c.cursor.rowcount, len(delete)))
def _organize_as_tree(nodes): """Given a list of nodes from a topological sort, organize the nodes into a tree structure, with as many non-dependent nodes set as siblings to each other as possible. returns nodes as 3-tuples (item, cycles, children). """ if not nodes: return None # a list of all currently independent subtrees as a tuple of # (root_node, set_of_all_tree_nodes, set_of_all_cycle_nodes_in_tree) # order of the list has no semantics for the algorithmic independents = [] # in reverse topological order for node in util.reversed(nodes): # nodes subtree and cycles contain the node itself subtree = util.Set([node]) if node.cycles is not None: cycles = util.Set(node.cycles) else: cycles = util.Set() # get a set of dependent nodes of node and its cycles nodealldeps = node.all_deps() if nodealldeps: # iterate over independent node indexes in reverse order so we can efficiently remove them for index in xrange(len(independents)-1,-1,-1): child, childsubtree, childcycles = independents[index] # if there is a dependency between this node and an independent node if (childsubtree.intersection(nodealldeps) or childcycles.intersection(node.dependencies)): # prepend child to nodes children # (append should be fine, but previous implemetation used prepend) node.children[0:0] = [(child.item, [n.item for n in child.cycles or []], child.children)] # merge childs subtree and cycles subtree.update(childsubtree) cycles.update(childcycles) # remove the child from list of independent subtrees independents[index:index+1] = [] # add node as a new independent subtree independents.append((node,subtree,cycles)) # choose an arbitrary node from list of all independent subtrees head = independents.pop()[0] # add all other independent subtrees as a child of the chosen root # used prepend [0:0] instead of extend to maintain exact behaviour of previous implementation head.children[0:0] = [(i[0].item, [n.item for n in i[0].cycles or []], i[0].children) for i in independents] return (head.item, [n.item for n in head.cycles or []], head.children)
def sort_tables(tables, reverse=False): tuples = [] class TVisitor(schema.SchemaVisitor): def visit_foreign_key(_self, fkey): if fkey.use_alter: return parent_table = fkey.column.table if parent_table in tables: child_table = fkey.parent.table tuples.append((parent_table, child_table)) vis = TVisitor() for table in tables: vis.traverse(table) sequence = topological.sort(tuples, tables) if reverse: return util.reversed(sequence) else: return sequence
def sort_tables(tables, reverse=False): """sort a collection of Table objects in order of their foreign-key dependency.""" tuples = [] class TVisitor(schema.SchemaVisitor): def visit_foreign_key(_self, fkey): if fkey.use_alter: return parent_table = fkey.column.table if parent_table in tables: child_table = fkey.parent.table tuples.append( ( parent_table, child_table ) ) vis = TVisitor() for table in tables: vis.traverse(table) sequence = topological.sort(tuples, tables) if reverse: return util.reversed(sequence) else: return sequence