properly call [re]set_pool, fix connection handling so we have a change to get cw running on top of a sqlite dabase with threads activated stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 08 Jun 2009 20:37:03 +0200
branchstable
changeset 2064 a5cd3a92314a
parent 2063 fe4278b50388
child 2065 f9f4bc048ec5
properly call [re]set_pool, fix connection handling so we have a change to get cw running on top of a sqlite dabase with threads activated
server/sources/native.py
--- a/server/sources/native.py	Mon Jun 08 20:35:26 2009 +0200
+++ b/server/sources/native.py	Mon Jun 08 20:37:03 2009 +0200
@@ -154,6 +154,22 @@
         self._cache = Cache(repo.config['rql-cache-size'])
         self._temp_table_data = {}
         self._eid_creation_lock = Lock()
+        if self.dbdriver == 'sqlite':
+            from cubicweb.server.sources.extlite import ConnectionWrapper
+            self.get_connection = lambda: ConnectionWrapper(self)
+            self.check_connection = lambda cnx: cnx
+            def pool_reset(cnx):
+                if cnx._cnx is not None:
+                    cnx._cnx.close()
+                    cnx._cnx = None
+            self.pool_reset = pool_reset
+
+    @property
+    def _sqlcnx(self):
+        # XXX: sqlite connections can only be used in the same thread, so
+        #      create a new one each time necessary. If it appears to be time
+        #      consuming, find another way
+        return SQLAdapterMixIn.get_connection(self)
 
     def reset_caches(self):
         """method called during test to reset potential source caches"""
@@ -171,21 +187,25 @@
         return self.process_result(cursor)
 
     def init_creating(self):
+        pool = self.repo._get_pool()
+        pool.pool_set()
         # check full text index availibility
-        pool = self.repo._get_pool()
         if not self.indexer.has_fti_table(pool['system']):
             self.error('no text index table')
             self.indexer = None
+        pool.pool_reset()
         self.repo._free_pool(pool)
 
     def init(self):
         self.init_creating()
         pool = self.repo._get_pool()
+        pool.pool_set()
         # XXX cubicweb < 2.42 compat
         if 'deleted_entities' in self.dbhelper.list_tables(pool['system']):
             self.has_deleted_entitites_table = True
         else:
             self.has_deleted_entitites_table = False
+        pool.pool_reset()
         self.repo._free_pool(pool)
 
     # ISource interface #######################################################