server/session.py
changeset 8845 667cc27e9d12
parent 8844 168cf5ef21f8
child 8848 08bb2dd18fd2
equal deleted inserted replaced
8844:168cf5ef21f8 8845:667cc27e9d12
   389         #: reentrance handling
   389         #: reentrance handling
   390         self.ctx_count = 0
   390         self.ctx_count = 0
   391 
   391 
   392         #: server.Repository object
   392         #: server.Repository object
   393         self.repo = session.repo
   393         self.repo = session.repo
       
   394         self.vreg = self.repo.vreg
   394 
   395 
   395         #: connection handling mode
   396         #: connection handling mode
   396         self.mode = session.default_mode
   397         self.mode = session.default_mode
   397         #: connection set used to execute queries on sources
   398         #: connection set used to execute queries on sources
   398         self._cnxset = None
   399         self._cnxset = None
   661 
   662 
   662 
   663 
   663     def source_from_eid(self, eid):
   664     def source_from_eid(self, eid):
   664         """return the source where the entity with id <eid> is located"""
   665         """return the source where the entity with id <eid> is located"""
   665         return self.repo.source_from_eid(eid, self)
   666         return self.repo.source_from_eid(eid, self)
       
   667 
       
   668     # resource accessors ######################################################
       
   669 
       
   670     def system_sql(self, sql, args=None, rollback_on_failure=True):
       
   671         """return a sql cursor on the system database"""
       
   672         if sql.split(None, 1)[0].upper() != 'SELECT':
       
   673             self.mode = 'write'
       
   674         source = self.cnxset.source('system')
       
   675         try:
       
   676             return source.doexec(self, sql, args, rollback=rollback_on_failure)
       
   677         except (source.OperationalError, source.InterfaceError):
       
   678             if not rollback_on_failure:
       
   679                 raise
       
   680             source.warning("trying to reconnect")
       
   681             self.cnxset.reconnect(source)
       
   682             return source.doexec(self, sql, args, rollback=rollback_on_failure)
       
   683 
       
   684     def rtype_eids_rdef(self, rtype, eidfrom, eidto):
       
   685         # use type_and_source_from_eid instead of type_from_eid for optimization
       
   686         # (avoid two extra methods call)
       
   687         subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
       
   688         objtype = self.repo.type_and_source_from_eid(eidto, self)[0]
       
   689         return self.vreg.schema.rschema(rtype).rdefs[(subjtype, objtype)]
   666 
   690 
   667 
   691 
   668 def tx_attr(attr_name, writable=False):
   692 def tx_attr(attr_name, writable=False):
   669     """return a property to forward attribute access to transaction.
   693     """return a property to forward attribute access to transaction.
   670 
   694 
  1014             entity._cw_related_cache['%s_%s' % (rtype, role)] = (
  1038             entity._cw_related_cache['%s_%s' % (rtype, role)] = (
  1015                 rset, tuple(entities))
  1039                 rset, tuple(entities))
  1016 
  1040 
  1017     # resource accessors ######################################################
  1041     # resource accessors ######################################################
  1018 
  1042 
  1019     def system_sql(self, sql, args=None, rollback_on_failure=True):
  1043     system_sql = tx_meth('system_sql')
  1020         """return a sql cursor on the system database"""
  1044     deleted_in_transaction = tx_meth('deleted_in_transaction')
  1021         if sql.split(None, 1)[0].upper() != 'SELECT':
  1045     added_in_transaction = tx_meth('added_in_transaction')
  1022             self.mode = 'write'
  1046     rtype_eids_rdef = tx_meth('rtype_eids_rdef')
  1023         source = self.cnxset.source('system')
       
  1024         try:
       
  1025             return source.doexec(self, sql, args, rollback=rollback_on_failure)
       
  1026         except (source.OperationalError, source.InterfaceError):
       
  1027             if not rollback_on_failure:
       
  1028                 raise
       
  1029             source.warning("trying to reconnect")
       
  1030             self.cnxset.reconnect(source)
       
  1031             return source.doexec(self, sql, args, rollback=rollback_on_failure)
       
  1032 
       
  1033     deleted_in_transaction =  tx_meth('deleted_in_transaction')
       
  1034     added_in_transaction   =  tx_meth('added_in_transaction')
       
  1035 
       
  1036     def rtype_eids_rdef(self, rtype, eidfrom, eidto):
       
  1037         # use type_and_source_from_eid instead of type_from_eid for optimization
       
  1038         # (avoid two extra methods call)
       
  1039         subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
       
  1040         objtype = self.repo.type_and_source_from_eid(eidto, self)[0]
       
  1041         return self.vreg.schema.rschema(rtype).rdefs[(subjtype, objtype)]
       
  1042 
  1047 
  1043     # security control #########################################################
  1048     # security control #########################################################
  1044 
  1049 
  1045 
  1050 
  1046     def security_enabled(self, read=None, write=None):
  1051     def security_enabled(self, read=None, write=None):