Ejemplo n.º 1
0
    def register_object(self, obj, isdelete = False, listonly = False, postupdate=False, post_update_cols=None, **kwargs):
        """Add an object to this ``UOWTransaction`` to be updated in the database.

        This operation has the combined effect of locating/creating an appropriate
        ``UOWTask`` object, and calling its ``append()`` method which then locates/creates
        an appropriate ``UOWTaskElement`` object.
        """

        #print "REGISTER", repr(obj), repr(getattr(obj, '_instance_key', None)), str(isdelete), str(listonly)

        # if object is not in the overall session, do nothing
        if not self.uow._is_valid(obj):
            if logging.is_debug_enabled(self.logger):
                self.logger.debug("object %s not part of session, not registering for flush" % (mapperutil.instance_str(obj)))
            return

        if logging.is_debug_enabled(self.logger):
            self.logger.debug("register object for flush: %s isdelete=%s listonly=%s postupdate=%s" % (mapperutil.instance_str(obj), isdelete, listonly, postupdate))

        mapper = object_mapper(obj)
        task = self.get_task_by_mapper(mapper)
        if postupdate:
            task.append_postupdate(obj, post_update_cols)
            return

        task.append(obj, listonly, isdelete=isdelete, **kwargs)
Ejemplo n.º 2
0
    def _sort_dependencies(self):
        """Create a hierarchical tree of dependent tasks.

        The root node is returned.

        When the root node is executed, it also executes its child
        tasks recursively.
        """
        def sort_hier(node):
            if node is None:
                return None
            task = self.get_task_by_mapper(node.item)
            if node.cycles is not None:
                tasks = []
                for n in node.cycles:
                    tasks.append(self.get_task_by_mapper(n.item))
                task.circular = task._sort_circular_dependencies(self, tasks)
            for child in node.children:
                t = sort_hier(child)
                if t is not None:
                    task.childtasks.append(t)
            return task

        mappers = self._get_noninheriting_mappers()
        head = DependencySorter(self.dependencies,
                                list(mappers)).sort(allow_all_cycles=True)
        if logging.is_debug_enabled(self.logger):
            self.logger.debug("Dependent tuples:\n" + "\n".join([
                "(%s->%s)" % (d[0].class_.__name__, d[1].class_.__name__)
                for d in self.dependencies
            ]))
            self.logger.debug("Dependency sort:\n" + str(head))
        task = sort_hier(head)
        return task
Ejemplo n.º 3
0
    def _sort_dependencies(self):
        """Create a hierarchical tree of dependent UOWTask instances.

        The root UOWTask is returned.  
        
        Cyclical relationships
        within the toplogical sort are further broken down into new
        temporary UOWTask insances which represent smaller sub-groups of objects
        that would normally belong to a single UOWTask.

        """

        def sort_hier(node):
            if node is None:
                return None
            task = self.get_task_by_mapper(node.item)
            if node.cycles is not None:
                tasks = []
                for n in node.cycles:
                    tasks.append(self.get_task_by_mapper(n.item))
                task = task._sort_circular_dependencies(self, tasks)
            for child in node.children:
                t = sort_hier(child)
                if t is not None:
                    task.childtasks.append(t)
            return task

        # get list of base mappers
        mappers = [t.mapper for t in self.tasks.values() if t.base_task is t]
        head = topological.QueueDependencySorter(self.dependencies, mappers).sort(allow_all_cycles=True)
        if logging.is_debug_enabled(self.logger):
            self.logger.debug("Dependent tuples:\n" + "\n".join(["(%s->%s)" % (d[0].class_.__name__, d[1].class_.__name__) for d in self.dependencies]))
            self.logger.debug("Dependency sort:\n"+ str(head))
        task = sort_hier(head)
        return task
Ejemplo n.º 4
0
    def execute(self, source, dest, parent, child, clearkeys):
        # TODO: break the "dictionary" case into a separate method like 'update' above,
        # reduce conditionals
        if source is None:
            if self.issecondary is False:
                source = parent
            elif self.issecondary is True:
                source = child
        if clearkeys or source is None:
            value = None
            clearkeys = True
        else:
            try:
                value = self.source_mapper._get_state_attr_by_column(
                    source, self.source_column)
            except exceptions.UnmappedColumnError:
                self._raise_col_to_prop(False)
        if isinstance(dest, dict):
            dest[self.dest_column.key] = value
        else:
            if clearkeys and self.dest_primary_key():
                raise exceptions.AssertionError(
                    "Dependency rule tried to blank-out primary key column '%s' on instance '%s'"
                    % (str(self.dest_column), mapperutil.state_str(dest)))

            if logging.is_debug_enabled(self.logger):
                self.logger.debug(
                    "execute() instances: %s(%s)->%s(%s) ('%s')" %
                    (mapperutil.state_str(source), str(self.source_column),
                     mapperutil.state_str(dest), str(self.dest_column), value))
            try:
                self.dest_mapper._set_state_attr_by_column(
                    dest, self.dest_column, value)
            except exceptions.UnmappedColumnError:
                self._raise_col_to_prop(True)
Ejemplo n.º 5
0
 def init(self):
     super(DeferredColumnLoader, self).init()
     if hasattr(self.parent_property, 'composite_class'):
         raise NotImplementedError("Deferred loading for composite types not implemented yet")
     self.columns = self.parent_property.columns
     self.group = self.parent_property.group
     self._should_log_debug = logging.is_debug_enabled(self.logger)
Ejemplo n.º 6
0
    def _sort_dependencies(self):
        """Create a hierarchical tree of dependent tasks.

        The root node is returned.

        When the root node is executed, it also executes its child
        tasks recursively.
        """

        def sort_hier(node):
            if node is None:
                return None
            task = self.get_task_by_mapper(node.item)
            if node.cycles is not None:
                tasks = []
                for n in node.cycles:
                    tasks.append(self.get_task_by_mapper(n.item))
                task.circular = task._sort_circular_dependencies(self, tasks)
            for child in node.children:
                t = sort_hier(child)
                if t is not None:
                    task.childtasks.append(t)
            return task

        mappers = self._get_noninheriting_mappers()
        head = DependencySorter(self.dependencies, list(mappers)).sort(allow_all_cycles=True)
        if logging.is_debug_enabled(self.logger):
            self.logger.debug("Dependent tuples:\n" + "\n".join(["(%s->%s)" % (d[0].class_.__name__, d[1].class_.__name__) for d in self.dependencies]))
            self.logger.debug("Dependency sort:\n"+ str(head))
        task = sort_hier(head)
        return task
Ejemplo n.º 7
0
    def execute(self, source, dest, obj, child, clearkeys):
        if source is None:
            if self.issecondary is False:
                source = obj
            elif self.issecondary is True:
                source = child
        if clearkeys or source is None:
            value = None
            clearkeys = True
        else:
            value = self.source_mapper.get_attr_by_column(
                source, self.source_column)
        if isinstance(dest, dict):
            dest[self.dest_column.key] = value
        else:
            if clearkeys and self.dest_primary_key():
                raise exceptions.AssertionError(
                    "Dependency rule tried to blank-out primary key column '%s' on instance '%s'"
                    % (str(self.dest_column), mapperutil.instance_str(dest)))

            if logging.is_debug_enabled(self.logger):
                self.logger.debug(
                    "execute() instances: %s(%s)->%s(%s) ('%s')" %
                    (mapperutil.instance_str(source), str(self.source_column),
                     mapperutil.instance_str(dest), str(
                         self.dest_column), value))
            self.dest_mapper.set_attr_by_column(dest, self.dest_column, value)
Ejemplo n.º 8
0
 def init(self):
     super(DeferredColumnLoader, self).init()
     if hasattr(self.parent_property, 'composite_class'):
         raise NotImplementedError("Deferred loading for composite types not implemented yet")
     self.columns = self.parent_property.columns
     self.group = self.parent_property.group
     self._should_log_debug = logging.is_debug_enabled(self.logger)
Ejemplo n.º 9
0
 def __init__(self, context):
     """ResultProxy objects are constructed via the execute() method on SQLEngine."""
     self.context = context
     self.dialect = context.dialect
     self.closed = False
     self.cursor = context.cursor
     self.__echo = logging.is_debug_enabled(context.engine.logger)
     self._init_metadata()
Ejemplo n.º 10
0
 def init(self):
     super(AbstractRelationLoader, self).init()
     for attr in [
             'primaryjoin', 'secondaryjoin', 'secondary', 'foreign_keys',
             'mapper', 'target', 'table', 'uselist', 'cascade',
             'attributeext', 'order_by', 'remote_side', 'direction'
     ]:
         setattr(self, attr, getattr(self.parent_property, attr))
     self._should_log_debug = logging.is_debug_enabled(self.logger)
Ejemplo n.º 11
0
    def execute(self, source, dest, obj, child, clearkeys):
        if source is None:
            if self.issecondary is False:
                source = obj
            elif self.issecondary is True:
                source = child
        if clearkeys or source is None:
            value = None
            clearkeys = True
        else:
            value = self.source_mapper.get_attr_by_column(source, self.source_column)
        if isinstance(dest, dict):
            dest[self.dest_column.key] = value
        else:
            if clearkeys and self.dest_primary_key():
                raise exceptions.AssertionError("Dependency rule tried to blank-out primary key column '%s' on instance '%s'" % (str(self.dest_column), mapperutil.instance_str(dest)))

            if logging.is_debug_enabled(self.logger):
                self.logger.debug("execute() instances: %s(%s)->%s(%s) ('%s')" % (mapperutil.instance_str(source), str(self.source_column), mapperutil.instance_str(dest), str(self.dest_column), value))
            self.dest_mapper.set_attr_by_column(dest, self.dest_column, value)
Ejemplo n.º 12
0
                current_path = current_path[2:]
                continue

            if prop is None:
                return []
            path = build_path(mapper, prop.key, path)
            l.append(path)
            if getattr(token, '_of_type', None):
                mapper = token._of_type
            else:
                mapper = getattr(prop, 'mapper', None)
        return l


PropertyOption.logger = logging.class_logger(PropertyOption)
PropertyOption._should_log_debug = logging.is_debug_enabled(
    PropertyOption.logger)


class AttributeExtension(object):
    """An abstract class which specifies `append`, `delete`, and `set`
    event handlers to be attached to an object property.
    """
    def append(self, obj, child, initiator):
        pass

    def remove(self, obj, child, initiator):
        pass

    def set(self, obj, child, oldchild, initiator):
        pass
Ejemplo n.º 13
0
 def init(self):
     super(ColumnLoader, self).init()
     self.columns = self.parent_property.columns
     self._should_log_debug = logging.is_debug_enabled(self.logger)
     self.is_composite = hasattr(self.parent_property, 'composite_class')
Ejemplo n.º 14
0
 def init(self):
     super(AbstractRelationLoader, self).init()
     for attr in ['primaryjoin', 'secondaryjoin', 'secondary', 'foreign_keys', 'mapper', 'target', 'table', 'uselist', 'cascade', 'attributeext', 'order_by', 'remote_side', 'direction']:
         setattr(self, attr, getattr(self.parent_property, attr))
     self._should_log_debug = logging.is_debug_enabled(self.logger)
Ejemplo n.º 15
0
 def init(self):
     super(ColumnLoader, self).init()
     self.columns = self.parent_property.columns
     self._should_log_debug = logging.is_debug_enabled(self.logger)
     self.is_composite = hasattr(self.parent_property, 'composite_class')
Ejemplo n.º 16
0
            if current_path and token == current_path[1]:
                current_path = current_path[2:]
                continue
                
            if prop is None:
                return []
            path = build_path(mapper, prop.key, path)
            l.append(path)
            if getattr(token, '_of_type', None):
                mapper = token._of_type
            else:
                mapper = getattr(prop, 'mapper', None)
        return l

PropertyOption.logger = logging.class_logger(PropertyOption)
PropertyOption._should_log_debug = logging.is_debug_enabled(PropertyOption.logger)

class AttributeExtension(object):
    """An abstract class which specifies `append`, `delete`, and `set`
    event handlers to be attached to an object property.
    """

    def append(self, obj, child, initiator):
        pass

    def remove(self, obj, child, initiator):
        pass

    def set(self, obj, child, oldchild, initiator):
        pass
Ejemplo n.º 17
0
 def init(self):
     super(DeferredColumnLoader, self).init()
     self.columns = self.parent_property.columns
     self.group = self.parent_property.group
     self._should_log_debug = logging.is_debug_enabled(self.logger)
Ejemplo n.º 18
0
 def init(self):
     super(DeferredColumnLoader, self).init()
     self.columns = self.parent_property.columns
     self.group = self.parent_property.group
     self._should_log_debug = logging.is_debug_enabled(self.logger)