hooks/integrity.py
branchstable
changeset 5448 9bf648d678cd
parent 5426 0d4853a6e5ee
child 5449 a7e1b316af03
--- a/hooks/integrity.py	Thu Apr 29 07:03:08 2010 +0200
+++ b/hooks/integrity.py	Fri Apr 30 16:39:50 2010 +0200
@@ -163,25 +163,28 @@
     """check a new relation satisfy its constraints
     """
     def precommit_event(self):
-        eidfrom, rtype, eidto = self.rdef
-        # first check related entities have not been deleted in the same
-        # transaction
-        if self.session.deleted_in_transaction(eidfrom):
-            return
-        if self.session.deleted_in_transaction(eidto):
-            return
-        for constraint in self.constraints:
-            # XXX
-            # * lock RQLConstraint as well?
-            # * use a constraint id to use per constraint lock and avoid
-            #   unnecessary commit serialization ?
-            if isinstance(constraint, RQLUniqueConstraint):
-                _acquire_unique_cstr_lock(self.session)
-            try:
-                constraint.repo_check(self.session, eidfrom, rtype, eidto)
-            except NotImplementedError:
-                self.critical('can\'t check constraint %s, not supported',
-                              constraint)
+        session = self.session
+        for values in session.transaction_data['check_constraints_op']:
+            eidfrom, rtype, eidto = values[:3]
+            # first check related entities have not been deleted in the same
+            # transaction
+            if session.deleted_in_transaction(eidfrom):
+                return
+            if session.deleted_in_transaction(eidto):
+                return
+            constraints = values[3:]
+            for constraint in constraints:
+                # XXX
+                # * lock RQLConstraint as well?
+                # * use a constraint id to use per constraint lock and avoid
+                #   unnecessary commit serialization ?
+                if isinstance(constraint, RQLUniqueConstraint):
+                    _acquire_unique_cstr_lock(session)
+                try:
+                    constraint.repo_check(session, eidfrom, rtype, eidto)
+                except NotImplementedError:
+                    self.critical('can\'t check constraint %s, not supported',
+                                  constraint)
 
     def commit_event(self):
         pass
@@ -201,8 +204,9 @@
         constraints = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
                                                 'constraints')
         if constraints:
-            _CheckConstraintsOp(self._cw, constraints=constraints,
-                               rdef=(self.eidfrom, self.rtype, self.eidto))
+            hook.set_operation(self._cw, 'check_constraints_op',
+                               (self.eidfrom, self.rtype, self.eidto) + tuple(constraints),
+                               _CheckConstraintsOp)
 
 
 class CheckAttributeConstraintHook(IntegrityHook):
@@ -221,8 +225,9 @@
                 constraints = [c for c in eschema.rdef(attr).constraints
                                if isinstance(c, (RQLUniqueConstraint, RQLConstraint))]
                 if constraints:
-                    _CheckConstraintsOp(self._cw, constraints=constraints,
-                                        rdef=(self.entity.eid, attr, None))
+                    hook.set_operation(self._cw, 'check_constraint_op',
+                                       (self.entity.eid, attr, None) + tuple(constraints),
+                                       _CheckConstraintsOp)
 
 
 class CheckUniqueHook(IntegrityHook):