incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1446485 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct: dbcursor.py env.py
Date Fri, 15 Feb 2013 09:42:04 GMT
Author: jure
Date: Fri Feb 15 09:42:04 2013
New Revision: 1446485

URL: http://svn.apache.org/r1446485
Log:
#288, get_db_cnx and get_read_db properly implemented for ProductEnvironment


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py?rev=1446485&r1=1446484&r2=1446485&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
Fri Feb 15 09:42:04 2013
@@ -23,7 +23,7 @@ import sqlparse
 import sqlparse.tokens as Tokens
 import sqlparse.sql as Types
 
-__all__ = ['BloodhoundIterableCursor']
+__all__ = ['BloodhoundIterableCursor', 'BloodhoundConnectionWrapper', 'ProductEnvContextManager']
 
 SKIP_TABLES = ['system', 'auth_cookie',
                'session', 'session_attribute',
@@ -110,8 +110,27 @@ class BloodhoundConnectionWrapper(object
         return self.connection.executemany(query, params=params)
 
     def cursor(self):
+        return BloodhoundCursorWrapper(self.connection.cursor(), self.env)
+
+class BloodhoundCursorWrapper(object):
+
+    def __init__(self, cursor, env):
+        self.cursor = cursor
+        self.env = env
+
+    def __getattr__(self, name):
+        return getattr(self.cursor, name)
+
+    def __iter__(self):
+        return self.cursor.__iter__()
+
+    def execute(self, sql, args=None):
+        BloodhoundIterableCursor.set_env(self.env)
+        return self.cursor.execute(sql, args=args)
+
+    def executemany(self, sql, args=None):
         BloodhoundIterableCursor.set_env(self.env)
-        return self.connection.cursor()
+        return self.cursor.executemany(sql, args=args)
 
 class ProductEnvContextManager(object):
     """Wrap an underlying database context manager so as to keep track

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py?rev=1446485&r1=1446484&r2=1446485&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
Fri Feb 15 09:42:04 2013
@@ -24,7 +24,7 @@ from sqlite3 import OperationalError
 
 from trac.config import BoolOption, ConfigSection, Option
 from trac.core import Component, ComponentManager, implements
-from trac.db.api import TransactionContextManager, QueryContextManager
+from trac.db.api import TransactionContextManager, QueryContextManager, DatabaseManager
 from trac.util import get_pkginfo, lazy
 from trac.util.compat import sha1
 from trac.versioncontrol import RepositoryManager
@@ -32,7 +32,7 @@ from trac.web.href import Href
 
 from multiproduct.api import MultiProductSystem
 from multiproduct.config import Configuration
-from multiproduct.dbcursor import ProductEnvContextManager
+from multiproduct.dbcursor import ProductEnvContextManager, BloodhoundConnectionWrapper
 from multiproduct.model import Product
 
 import trac.env
@@ -414,8 +414,7 @@ class ProductEnvironment(Component, Comp
            with env.db_query as db:
                ...
         """
-        # share connection pool with global environment
-        return self.parent.get_db_cnx()
+        return BloodhoundConnectionWrapper(DatabaseManager(self).get_connection(), self)
 
     @lazy
     def db_exc(self):
@@ -445,7 +444,7 @@ class ProductEnvironment(Component, Comp
 
         See `trac.db.api.get_read_db` for detailed documentation.
         """
-        raise NotImplementedError('Deprecated method')
+        return BloodhoundConnectionWrapper(DatabaseManager(self).get_connection(readonly=True),
self)
 
     @property
     def db_query(self):



Mime
View raw message