Commit b6fbf49e authored by Vincent Pelletier's avatar Vincent Pelletier

Update ZMySQLDDA to be compatible with customized ZMySQLDA:

  Remove locking.
  Pool scheduled queries.
  Use self._query instead of database's query.
Remove unused variables.
Remove LOGs which occur on normal execution path.
Remove commented out LOGs.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13706 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 01c50b14
...@@ -95,90 +95,52 @@ class DeferredDB(DB): ...@@ -95,90 +95,52 @@ class DeferredDB(DB):
def __init__(self,connection): def __init__(self,connection):
DB.__init__(self, connection) DB.__init__(self, connection)
self.sql_string_list = [] self._sql_string_list_dict = {}
def query(self,query_string, max_rows=1000): def query(self,query_string, max_rows=1000):
self._use_TM and self._register() self._use_TM and self._register()
desc=None for qs in filter(None, map(strip,split(query_string, '\0'))):
result=() qtype = upper(split(qs, None, 1)[0])
db=self.db if qtype == "SELECT":
try: raise NotSupportedError, "can not SELECT in deferred connections"
self._lock.acquire() self._appendToSQLStringList(qs)
for qs in filter(None, map(strip,split(query_string, '\0'))):
qtype = upper(split(qs, None, 1)[0])
if qtype == "SELECT":
raise NotSupportedError, "can not SELECT in deferred connections"
#LOG('ZMySQLDDA', 0, "insert string %s" % qs )
self.sql_string_list.append(qs)
finally:
self._lock.release()
return (),() return (),()
def _emptySQLStringList(self):
self._sql_string_list_dict[get_ident()] = []
def _appendToSQLStringList(self, value):
self._sql_string_list_dict[get_ident()].append(value)
def _getSQLStringList(self):
return self._sql_string_list_dict[get_ident()]
def _begin(self, *ignored): def _begin(self, *ignored):
from thread import get_ident
self._tlock.acquire()
self._tthread = get_ident()
# The Deferred DB instance is sometimes used for several # The Deferred DB instance is sometimes used for several
# transactions, so it is required to clear the sql_string_list # transactions, so it is required to clear the sql_string_list
# each time a transaction starts # each time a transaction starts
self.sql_string_list = [] self._emptySQLStringList()
self._setFinishedOrAborted(False)
def _finish(self, *ignored): def _finish(self, *ignored):
from thread import get_ident if self._getFinishedOrAborted():
if not self._tlock.locked() or self._tthread != get_ident(): return
LOG('ZMySQLDA', INFO, "ignoring _finish") self._setFinishedOrAborted(True)
return # Ping the database to reconnect if connection was lost.
# BEGIN commit self._query("SELECT 1", force_reconnect=True)
#LOG('ZMySQLDDA', INFO, "BEGIN commit") if self._transactions:
try: self._query("BEGIN")
if self._transactions: if self._mysql_lock:
self.db.query("BEGIN") self._query("SELECT GET_LOCK('%s',0)" % self._mysql_lock)
self.db.store_result() for qs in self._getSQLStringList():
if self._mysql_lock: self._query(qs)
self.db.query("SELECT GET_LOCK('%s',0)" % self._mysql_lock) if self._mysql_lock:
self.db.store_result() self._query("SELECT RELEASE_LOCK('%s')" % self._mysql_lock)
except: if self._transactions:
LOG('ZMySQLDDA', ERROR, "exception during _begin", self._query("COMMIT")
error=sys.exc_info())
self._tlock.release()
raise
# Execute SQL
db = self.db
for qs in self.sql_string_list:
try:
db.query(qs)
c=db.store_result()
except OperationalError, m:
if m[0] not in hosed_connection: raise
# Hm. maybe the db is hosed. Let's restart it.
db=self.db=apply(self.Database_Connection, (), self.kwargs)
try:
db.query(qs)
c=db.store_result()
except OperationalError, m:
raise
#LOG('ZMySQLDDA', INFO, "Execute %s" % qs)
# Finish commit
#LOG('ZMySQLDDA', INFO, "FINISH commit")
try:
try:
if self._mysql_lock:
self.db.query("SELECT RELEASE_LOCK('%s')" % self._mysql_lock)
self.db.store_result()
if self._transactions:
self.db.query("COMMIT")
self.db.store_result()
except:
LOG('ZMySQLDDA', ERROR, "exception during _finish",
error=sys.exc_info())
raise
finally:
self._tlock.release()
def _abort(self, *ignored): def _abort(self, *ignored):
from thread import get_ident self._setFinishedOrAborted(True)
if not self._tlock.locked() or self._tthread != get_ident(): pass
LOG('ZMySQLDDA', INFO, "ignoring _abort")
return
self._tlock.release()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment