Commit a94d14a5 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Remove MySQL dependency from CMFActivity. Translate a lock error into...

Remove MySQL dependency from CMFActivity. Translate a lock error into ConflictError in database adapters instead.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20317 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 74711589
......@@ -26,9 +26,8 @@
#
##############################################################################
from _mysql_exceptions import OperationalError
from MySQLdb.constants import ER
from zLOG import LOG, INFO
from ZODB.POSException import ConflictError
class SQLBase:
"""
......@@ -60,12 +59,10 @@ class SQLBase:
while True:
try:
result = method(*args, **kw)
except OperationalError, value:
if isinstance(value, OperationalError) and \
value[0] in (ER.LOCK_WAIT_TIMEOUT, ER.LOCK_DEADLOCK):
except ConflictError:
# Note that this code assumes that a database adapter translates
# a lock error into a conflict error.
LOG('SQLBase', INFO, 'Got a lock error, retrying...')
else:
raise
else:
break
return result
......
......@@ -102,6 +102,7 @@ from MySQLdb.constants import FIELD_TYPE, CR, ER, CLIENT
from Shared.DC.ZRDB.TM import TM
from DateTime import DateTime
from zLOG import LOG, ERROR, INFO
from ZODB.POSException import ConflictError
import string, sys
from string import strip, split, find, upper, rfind
......@@ -117,6 +118,11 @@ query_syntax_error = (
ER.BAD_FIELD_ERROR,
)
lock_error = (
ER.LOCK_WAIT_TIMEOUT,
ER.LOCK_DEADLOCK,
)
key_types = {
"PRI": "PRIMARY KEY",
"MUL": "INDEX",
......@@ -388,6 +394,8 @@ class DB(TM):
except OperationalError, m:
if m[0] in query_syntax_error:
raise OperationalError(m[0], '%s: %s' % (m[1], query))
if m[0] in lock_error:
raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
if ((not force_reconnect) and \
(self._mysql_lock or self._transactions)) or \
m[0] not in hosed_connection:
......
......@@ -100,6 +100,7 @@ from MySQLdb.constants import FIELD_TYPE, CR, ER, CLIENT
from Shared.DC.ZRDB.TM import TM
from DateTime import DateTime
from zLOG import LOG, ERROR, INFO
from ZODB.POSException import ConflictError
import string, sys
from string import strip, split, find, upper, rfind
......@@ -115,6 +116,11 @@ query_syntax_error = (
ER.BAD_FIELD_ERROR,
)
lock_error = (
ER.LOCK_WAIT_TIMEOUT,
ER.LOCK_DEADLOCK,
)
key_types = {
"PRI": "PRIMARY KEY",
"MUL": "INDEX",
......@@ -393,6 +399,8 @@ class DeferredDB(TM):
except OperationalError, m:
if m[0] in query_syntax_error:
raise OperationalError(m[0], '%s: %s' % (m[1], query))
if m[0] in lock_error:
raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
if ((not force_reconnect) and \
(self._mysql_lock or self._transactions)) or \
m[0] not in hosed_connection:
......
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