[IMP] registry: add method get_cursor() to simply retrieve a new cursor, and refactor...
[odoo/odoo.git] / openerp / modules / registry.py
index 2db1474..60f56ef 100644 (file)
@@ -75,7 +75,7 @@ class Registry(Mapping):
         # Useful only in a multi-process context.
         self._any_cache_cleared = False
 
-        cr = self.db.cursor()
+        cr = self.get_cursor()
         has_unaccent = openerp.modules.db.has_unaccent(cr)
         if openerp.tools.config['unaccent'] and not has_unaccent:
             _logger.warning("The option --unaccent was given but no unaccent() function was found in database.")
@@ -187,9 +187,14 @@ class Registry(Mapping):
                     r, c)
         return r, c
 
+    def get_cursor(self):
+        """ Return a new cursor for the database. """
+        return self.db.cursor()
+
     @contextmanager
     def cursor(self, auto_commit=True):
-        cr = self.db.cursor()
+        """ Manage a new cursor; commit, rollback and closing are automatic. """
+        cr = self.get_cursor()
         try:
             yield cr
             if auto_commit:
@@ -286,7 +291,7 @@ class RegistryManager(object):
             # Yeah, crazy.
             registry = cls.registries[db_name]
 
-            cr = registry.db.cursor()
+            cr = registry.get_cursor()
             try:
                 registry.do_parent_store(cr)
                 cr.commit()
@@ -342,7 +347,7 @@ class RegistryManager(object):
         changed = False
         if openerp.multi_process and db_name in cls.registries:
             registry = cls.get(db_name)
-            cr = registry.db.cursor()
+            cr = registry.get_cursor()
             try:
                 cr.execute("""
                     SELECT base_registry_signaling.last_value,
@@ -388,7 +393,7 @@ class RegistryManager(object):
             registry = cls.get(db_name)
             if registry.any_cache_cleared():
                 _logger.info("At least one model cache has been cleared, signaling through the database.")
-                cr = registry.db.cursor()
+                cr = registry.get_cursor()
                 r = 1
                 try:
                     cr.execute("select nextval('base_cache_signaling')")
@@ -403,7 +408,7 @@ class RegistryManager(object):
         if openerp.multi_process and db_name in cls.registries:
             _logger.info("Registry changed, signaling through the database")
             registry = cls.get(db_name)
-            cr = registry.db.cursor()
+            cr = registry.get_cursor()
             r = 1
             try:
                 cr.execute("select nextval('base_registry_signaling')")