280 # sql queries cache |
280 # sql queries cache |
281 self._cache = Cache(repo.config['rql-cache-size']) |
281 self._cache = Cache(repo.config['rql-cache-size']) |
282 self._temp_table_data = {} |
282 self._temp_table_data = {} |
283 # we need a lock to protect eid attribution function (XXX, really? |
283 # we need a lock to protect eid attribution function (XXX, really? |
284 # explain) |
284 # explain) |
285 self._eid_creation_lock = Lock() |
285 self._eid_cnx_lock = Lock() |
286 self._eid_creation_cnx = None |
286 self._eid_creation_cnx = None |
287 # (etype, attr) / storage mapping |
287 # (etype, attr) / storage mapping |
288 self._storages = {} |
288 self._storages = {} |
289 # entity types that may be used by other multi-sources instances |
289 # entity types that may be used by other multi-sources instances |
290 self.multisources_etypes = set(repo.config['multi-sources-etypes']) |
290 self.multisources_etypes = set(repo.config['multi-sources-etypes']) |
833 # on commit |
833 # on commit |
834 sql = self.dbhelper.sql_temporary_table(table, schema, False) |
834 sql = self.dbhelper.sql_temporary_table(table, schema, False) |
835 self.doexec(session, sql) |
835 self.doexec(session, sql) |
836 |
836 |
837 def _create_eid_sqlite(self, session): |
837 def _create_eid_sqlite(self, session): |
838 self._eid_creation_lock.acquire() |
838 with self._eid_cnx_lock: |
839 try: |
|
840 for sql in self.dbhelper.sqls_increment_sequence('entities_id_seq'): |
839 for sql in self.dbhelper.sqls_increment_sequence('entities_id_seq'): |
841 cursor = self.doexec(session, sql) |
840 cursor = self.doexec(session, sql) |
842 return cursor.fetchone()[0] |
841 return cursor.fetchone()[0] |
843 finally: |
|
844 self._eid_creation_lock.release() |
|
845 |
842 |
846 |
843 |
847 def create_eid(self, session): |
844 def create_eid(self, session): |
848 # lock needed to prevent 'Connection is busy with results for another command (0)' errors with SQLServer |
845 # lock needed to prevent 'Connection is busy with results for another |
849 self._eid_creation_lock.acquire() |
846 # command (0)' errors with SQLServer |
850 try: |
847 with self._eid_cnx_lock: |
851 return self._create_eid() |
848 return self._create_eid() |
852 finally: |
|
853 self._eid_creation_lock.release() |
|
854 |
849 |
855 def _create_eid(self): |
850 def _create_eid(self): |
856 # internal function doing the eid creation without locking. |
851 # internal function doing the eid creation without locking. |
857 # needed for the recursive handling of disconnections (otherwise we |
852 # needed for the recursive handling of disconnections (otherwise we |
858 # deadlock on self._eid_creation_lock |
853 # deadlock on self._eid_cnx_lock |
859 if self._eid_creation_cnx is None: |
854 if self._eid_creation_cnx is None: |
860 self._eid_creation_cnx = self.get_connection() |
855 self._eid_creation_cnx = self.get_connection() |
861 cnx = self._eid_creation_cnx |
856 cnx = self._eid_creation_cnx |
862 try: |
857 try: |
863 cursor = cnx.cursor() |
858 cursor = cnx.cursor() |