Olemis Lang avatar Olemis Lang committed 15568c6

BH Multiproduct #288 : Sketch of the first attempt towards translation of SQL statements in global scope

Comments (0)

Files changed (2)

 t288/t288_r1438538_sql_translate_global_env.diff
+t288/t288_r1438538_sql_translate_global_env_pending.diff
 #t115/t115_r1437383_inherit_product_config.diff
 #t333/t333_r1427886_schema_autoinc.diff
 #t333/t333_r1427886_mp_gen_schema.diff

t288/t288_r1438538_sql_translate_global_env_pending.diff

+# HG changeset patch
+# Parent a103a7667c1345b7392b55ee894d699a67c4a7a5
+BH Multiproduct #288 : SQL translate global environment (pending)
+
+diff -r a103a7667c13 bloodhound_multiproduct/multiproduct/api.py
+--- a/bloodhound_multiproduct/multiproduct/api.py	Tue Jan 29 19:47:18 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Tue Jan 29 22:46:55 2013 -0500
+@@ -97,7 +97,7 @@
+         self.log.debug("upgrading existing environment for %s plugin." % 
+                        PLUGIN_NAME)
+         db_installed_version = self.get_version()
+-        with self.env.db_transaction as db:
++        with self.env.db_direct_transaction as db:
+             if db_installed_version < 1:
+                 # Initial installation
+                 db("ALTER TABLE ticket ADD COLUMN product TEXT")
+diff -r a103a7667c13 bloodhound_multiproduct/multiproduct/dbcursor.py
+--- a/bloodhound_multiproduct/multiproduct/dbcursor.py	Tue Jan 29 19:47:18 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/dbcursor.py	Tue Jan 29 22:46:55 2013 -0500
+@@ -37,18 +37,25 @@
+ PRODUCT_COLUMN = 'product'
+ DEFAULT_PRODUCT = ''
+ 
++# Singleton used to mark products as unset
++class empty_product(object):
++    pass
++
++empty_product = empty_product()
++
+ class BloodhoundIterableCursor(trac.db.util.IterableCursor):
+-    __slots__ = trac.db.util.IterableCursor.__slots__ + ['_translator']
++    __slots__ = trac.db.util.IterableCursor.__slots__ + ['_translator', '_product_prefix']
+     _tls = concurrency.ThreadLocal(env=None)
+ 
+     def __init__(self, cursor, log=None):
+         super(BloodhoundIterableCursor, self).__init__(cursor, log=log)
+         self._translator = None
++        self._product_prefix = empty_product
+ 
+     @property
+     def translator(self):
+         if not self._translator:
+-            product_prefix = self.env.product.prefix if (self.env and self.env.product) else DEFAULT_PRODUCT
++            product_prefix = self._product_prefix
+             self._translator = BloodhoundProductSQLTranslate(SKIP_TABLES,
+                                                              TRANSLATE_TABLES,
+                                                              PRODUCT_COLUMN,
+@@ -56,7 +63,14 @@
+         return self._translator
+ 
+     def _translate_sql(self, sql):
+-        return self.translator.translate(sql) if (self.env and self.env.product) else sql
++        if self._product_prefix is empty_product:
++            if self.env is None:
++                self._product_prefix = None
++            else:
++                self._product_prefix = self.env.product.prefix \
++                        if self.env.product else DEFAULT_PRODUCT
++        return self.translator.translate(sql) \
++                if self._product_prefix is not None else sql
+ 
+     def execute(self, sql, args=None):
+         return super(BloodhoundIterableCursor, self).execute(self._translate_sql(sql), args=args)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.