コード例 #1
0
    def enqueue_any(self, event):
        """Enqueue event.

        Processing rules is a bit different than processing atoms
        in that they generate additional events that we want
        to process either before the rule is deleted or after
        it is inserted.  PROCESS_QUEUE is similar but assumes
        that only the data will cause propagations (and ignores
        included theories).
        """
        # Note: all included theories must define MODIFY
        formula = event.formula
        if formula.is_atom():
            self.log(formula.tablename(), "compute/enq: atom %s", formula)
            assert not self.is_view(
                formula.table.table), ("Cannot directly modify tables" +
                                       " computed from other tables")
            # self.log(formula.table, "%s: %s", text, formula)
            self.enqueue(event)
            return []
        else:
            # rules do not need to talk to included theories because they
            #   only generate events for views
            # need to eliminate self-joins here so that we fill all
            #   the tables introduced by self-join elimination.
            for rule in DeltaRuleTheory.eliminate_self_joins([formula]):
                new_event = compile.Event(formula=rule,
                                          insert=event.insert,
                                          target=event.target)
                self.enqueue(new_event)
            return []
コード例 #2
0
    def process_new_bindings(self, bindings, atom, insert, original_rule):
        """Process new bindings.

        For each of BINDINGS, apply to ATOM, and enqueue it as an insert if
        INSERT is True and as a delete otherwise.
        """
        # for each binding, compute generated tuple and group bindings
        #    by the tuple they generated
        new_atoms = {}
        for binding in bindings:
            new_atom = atom.plug(binding)
            if new_atom not in new_atoms:
                new_atoms[new_atom] = []
            new_atoms[new_atom].append(
                database.Database.Proof(binding, original_rule))
        self.log(atom.table.table, "new tuples generated: %s",
                 utility.iterstr(new_atoms))

        # enqueue each distinct generated tuple, recording appropriate bindings
        for new_atom in new_atoms:
            # self.log(event.table, "new_tuple %s: %s", new_tuple,
            #          new_tuples[new_tuple])
            # Only enqueue if new data.
            # Putting the check here is necessary to support recursion.
            self.enqueue(
                compile.Event(formula=new_atom,
                              proofs=new_atoms[new_atom],
                              insert=insert))
コード例 #3
0
 def insert(self, formula):
     return self.update([compile.Event(formula=formula, insert=True)])
コード例 #4
0
 def delete(self, formula):
     return self.update([compile.Event(formula=formula, insert=False)])
コード例 #5
0
 def delete(self, rule):
     changes = self.update([compile.Event(formula=rule, insert=False)])
     return [event.formula for event in changes]
コード例 #6
0
 def insert(self, rule):
     changes = self.update([compile.Event(formula=rule, insert=True)])
     return [event.formula for event in changes]
コード例 #7
0
 def define(self, rules):
     """Empties and then inserts RULES."""
     self.empty()
     return self.update(
         [compile.Event(formula=rule, insert=True) for rule in rules])
コード例 #8
0
 def delete(self, atom, proofs=None):
     """Deletes ATOM from the DB.  Returns changes."""
     return self.modify(compile.Event(formula=atom, insert=False,
                                      proofs=proofs))
コード例 #9
0
 def insert(self, atom, proofs=None):
     """Inserts ATOM into the DB.  Returns changes."""
     return self.modify(compile.Event(formula=atom, insert=True,
                                      proofs=proofs))