server/hook.py
branchstable
changeset 9267 24d9b86dfa54
parent 8694 d901c36bcfce
child 9283 5f2c5eb1a820
child 9314 178791fde195
equal deleted inserted replaced
9266:e54171abd3ed 9267:24d9b86dfa54
    39 update of an entity / or a relation in the repository) and server events (such
    39 update of an entity / or a relation in the repository) and server events (such
    40 as server startup or shutdown).  In a typical application, most of the hooks are
    40 as server startup or shutdown).  In a typical application, most of the hooks are
    41 defined over data events.
    41 defined over data events.
    42 
    42 
    43 Also, some :class:`~cubicweb.server.hook.Operation` may be registered by hooks,
    43 Also, some :class:`~cubicweb.server.hook.Operation` may be registered by hooks,
    44 which will be fired when the transaction is commited or rollbacked.
    44 which will be fired when the transaction is commited or rolled back.
    45 
    45 
    46 The purpose of data event hooks is usually to complement the data model as
    46 The purpose of data event hooks is usually to complement the data model as
    47 defined in the schema, which is static by nature and only provide a restricted
    47 defined in the schema, which is static by nature and only provide a restricted
    48 builtin set of dynamic constraints, with dynamic or value driven behaviours.
    48 builtin set of dynamic constraints, with dynamic or value driven behaviours.
    49 For instance they can serve the following purposes:
    49 For instance they can serve the following purposes:
   713       for all operations which had their 'precommit' event already fired to let
   713       for all operations which had their 'precommit' event already fired to let
   714       them revert things (including the operation which made the commit fail)
   714       them revert things (including the operation which made the commit fail)
   715 
   715 
   716     * `rollback`:
   716     * `rollback`:
   717 
   717 
   718       the transaction has been either rollbacked either:
   718       the transaction has been either rolled back either:
   719 
   719 
   720        * intentionaly
   720        * intentionaly
   721        * a 'precommit' event failed, in which case all operations are rollbacked
   721        * a 'precommit' event failed, in which case all operations are rolled back
   722          once 'revertprecommit'' has been called
   722          once 'revertprecommit'' has been called
   723 
   723 
   724     * `postcommit`:
   724     * `postcommit`:
   725 
   725 
   726       the transaction is over. All the ORM entities accessed by the earlier
   726       the transaction is over. All the ORM entities accessed by the earlier
   778         should revert pre-commit's changes but take care, they may have not
   778         should revert pre-commit's changes but take care, they may have not
   779         been all considered if it's this operation which failed
   779         been all considered if it's this operation which failed
   780         """
   780         """
   781 
   781 
   782     def rollback_event(self):
   782     def rollback_event(self):
   783         """the observed connections set has been rollbacked
   783         """the observed connections set has been rolled back
   784 
   784 
   785         do nothing by default
   785         do nothing by default
   786         """
   786         """
   787 
   787 
   788     def postcommit_event(self):
   788     def postcommit_event(self):
  1042 class CleanupNewEidsCacheOp(DataOperationMixIn, SingleLastOperation):
  1042 class CleanupNewEidsCacheOp(DataOperationMixIn, SingleLastOperation):
  1043     """on rollback of a insert query we have to remove from repository's
  1043     """on rollback of a insert query we have to remove from repository's
  1044     type/source cache eids of entities added in that transaction.
  1044     type/source cache eids of entities added in that transaction.
  1045 
  1045 
  1046     NOTE: querier's rqlst/solutions cache may have been polluted too with
  1046     NOTE: querier's rqlst/solutions cache may have been polluted too with
  1047     queries such as Any X WHERE X eid 32 if 32 has been rollbacked however
  1047     queries such as Any X WHERE X eid 32 if 32 has been rolled back however
  1048     generated queries are unpredictable and analysing all the cache probably
  1048     generated queries are unpredictable and analysing all the cache probably
  1049     too expensive. Notice that there is no pb when using args to specify eids
  1049     too expensive. Notice that there is no pb when using args to specify eids
  1050     instead of giving them into the rql string.
  1050     instead of giving them into the rql string.
  1051     """
  1051     """
  1052     data_key = 'neweids'
  1052     data_key = 'neweids'
  1053 
  1053 
  1054     def rollback_event(self):
  1054     def rollback_event(self):
  1055         """the observed connections set has been rollbacked,
  1055         """the observed connections set has been rolled back,
  1056         remove inserted eid from repository type/source cache
  1056         remove inserted eid from repository type/source cache
  1057         """
  1057         """
  1058         try:
  1058         try:
  1059             self.session.repo.clear_caches(self.get_data())
  1059             self.session.repo.clear_caches(self.get_data())
  1060         except KeyError:
  1060         except KeyError:
  1064     """on commit of delete query, we have to remove from repository's
  1064     """on commit of delete query, we have to remove from repository's
  1065     type/source cache eids of entities deleted in that transaction.
  1065     type/source cache eids of entities deleted in that transaction.
  1066     """
  1066     """
  1067     data_key = 'pendingeids'
  1067     data_key = 'pendingeids'
  1068     def postcommit_event(self):
  1068     def postcommit_event(self):
  1069         """the observed connections set has been rollbacked,
  1069         """the observed connections set has been rolled back,
  1070         remove inserted eid from repository type/source cache
  1070         remove inserted eid from repository type/source cache
  1071         """
  1071         """
  1072         try:
  1072         try:
  1073             eids = self.get_data()
  1073             eids = self.get_data()
  1074             self.session.repo.clear_caches(eids)
  1074             self.session.repo.clear_caches(eids)