server/migractions.py
branchstable
changeset 2903 043c8fcb3819
parent 2861 9cb3027407aa
child 2920 64322aa83a1d
child 2926 4484387ed012
equal deleted inserted replaced
2897:2658f432284c 2903:043c8fcb3819
   218 
   218 
   219     @property
   219     @property
   220     def session(self):
   220     def session(self):
   221         return self.repo._get_session(self.cnx.sessionid)
   221         return self.repo._get_session(self.cnx.sessionid)
   222 
   222 
   223     @property
       
   224     @cached
       
   225     def rqlcursor(self):
       
   226         """lazy rql cursor"""
       
   227         # should not give session as cnx.cursor(), else we may try to execute
       
   228         # some query while no pool is set on the session (eg on entity attribute
       
   229         # access for instance)
       
   230         return self.cnx.cursor()
       
   231 
       
   232     def commit(self):
   223     def commit(self):
   233         if hasattr(self, '_cnx'):
   224         if hasattr(self, '_cnx'):
   234             self._cnx.commit()
   225             self._cnx.commit()
   235 
   226 
   236     def rollback(self):
   227     def rollback(self):
   260         return context
   251         return context
   261 
   252 
   262     @cached
   253     @cached
   263     def group_mapping(self):
   254     def group_mapping(self):
   264         """cached group mapping"""
   255         """cached group mapping"""
   265         return ss.group_mapping(self.rqlcursor)
   256         self.session.set_pool()
       
   257         return ss.group_mapping(self.session)
   266 
   258 
   267     def exec_event_script(self, event, cubepath=None, funcname=None,
   259     def exec_event_script(self, event, cubepath=None, funcname=None,
   268                           *args, **kwargs):
   260                           *args, **kwargs):
   269         if cubepath:
   261         if cubepath:
   270             apc = osp.join(cubepath, 'migration', '%s.py' % event)
   262             apc = osp.join(cubepath, 'migration', '%s.py' % event)
  1053     def rqlexec(self, rql, kwargs=None, cachekey=None, ask_confirm=True):
  1045     def rqlexec(self, rql, kwargs=None, cachekey=None, ask_confirm=True):
  1054         """rql action"""
  1046         """rql action"""
  1055         if not isinstance(rql, (tuple, list)):
  1047         if not isinstance(rql, (tuple, list)):
  1056             rql = ( (rql, kwargs), )
  1048             rql = ( (rql, kwargs), )
  1057         res = None
  1049         res = None
       
  1050         self.session.set_pool()
  1058         for rql, kwargs in rql:
  1051         for rql, kwargs in rql:
  1059             if kwargs:
  1052             if kwargs:
  1060                 msg = '%s (%s)' % (rql, kwargs)
  1053                 msg = '%s (%s)' % (rql, kwargs)
  1061             else:
  1054             else:
  1062                 msg = rql
  1055                 msg = rql
  1063             if not ask_confirm or self.confirm('execute rql: %s ?' % msg):
  1056             if not ask_confirm or self.confirm('execute rql: %s ?' % msg):
  1064                 try:
  1057                 try:
  1065                     res = self.rqlcursor.execute(rql, kwargs, cachekey)
  1058                     res = self.session.execute(rql, kwargs, cachekey)
  1066                 except Exception, ex:
  1059                 except Exception, ex:
  1067                     if self.confirm('error: %s\nabort?' % ex):
  1060                     if self.confirm('error: %s\nabort?' % ex):
  1068                         raise
  1061                         raise
  1069         return res
  1062         return res
  1070 
  1063 
  1149         else:
  1142         else:
  1150             msg = rql
  1143             msg = rql
  1151         if self.ask_confirm:
  1144         if self.ask_confirm:
  1152             if not self._h.confirm('execute rql: %s ?' % msg):
  1145             if not self._h.confirm('execute rql: %s ?' % msg):
  1153                 raise StopIteration
  1146                 raise StopIteration
       
  1147         self._h.session.set_pool()
  1154         try:
  1148         try:
  1155             rset = self._h.rqlcursor.execute(rql, kwargs)
  1149             rset = self._h.session.execute(rql, kwargs)
  1156         except Exception, ex:
  1150         except Exception, ex:
  1157             if self._h.confirm('error: %s\nabort?' % ex):
  1151             if self._h.confirm('error: %s\nabort?' % ex):
  1158                 raise
  1152                 raise
  1159             else:
  1153             else:
  1160                 raise StopIteration
  1154                 raise StopIteration