Commit 728f19ec authored by Vincent Pelletier's avatar Vincent Pelletier

Make getConnection, cleanupConnections, getFinishedOrAborted,...

Make getConnection, cleanupConnections, getFinishedOrAborted, setFinishedOrAborted, forceReconnection, closeConnection private methods.
Remove useless try block in _finish.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13697 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b39af268
...@@ -187,7 +187,7 @@ class DB(TM): ...@@ -187,7 +187,7 @@ class DB(TM):
self.kwargs = self._parse_connection_string(connection) self.kwargs = self._parse_connection_string(connection)
self.db = {} self.db = {}
self._finished_or_aborted = {} self._finished_or_aborted = {}
db = self.getConnection() db = self._getConnection()
transactional = db.server_capabilities & CLIENT.TRANSACTIONS transactional = db.server_capabilities & CLIENT.TRANSACTIONS
if self._try_transactions == '-': if self._try_transactions == '-':
transactional = 0 transactional = 0
...@@ -198,31 +198,31 @@ class DB(TM): ...@@ -198,31 +198,31 @@ class DB(TM):
self._use_TM = 1 self._use_TM = 1
def __del__(self): def __del__(self):
self.cleanupConnections() self._cleanupConnections()
def getFinishedOrAborted(self): def _getFinishedOrAborted(self):
return self._finished_or_aborted[get_ident()] return self._finished_or_aborted[get_ident()]
def setFinishedOrAborted(self, value): def _setFinishedOrAborted(self, value):
self._finished_or_aborted[get_ident()] = value self._finished_or_aborted[get_ident()] = value
def cleanupConnections(self): def _cleanupConnections(self):
for db in self.db.itervalues(): for db in self.db.itervalues():
db.close() db.close()
def forceReconnection(self): def _forceReconnection(self):
db = apply(self.Database_Connection, (), self.kwargs) db = apply(self.Database_Connection, (), self.kwargs)
self.db[get_ident()] = db self.db[get_ident()] = db
return db return db
def getConnection(self): def _getConnection(self):
ident = get_ident() ident = get_ident()
db = self.db.get(ident) db = self.db.get(ident)
if db is None: if db is None:
db = self.forceReconnection() db = self._forceReconnection()
return db return db
def closeConnection(self): def _closeConnection(self):
ident = get_ident() ident = get_ident()
db = self.db.get(ident) db = self.db.get(ident)
if db is not None: if db is not None:
...@@ -270,7 +270,7 @@ class DB(TM): ...@@ -270,7 +270,7 @@ class DB(TM):
_care=('TABLE', 'VIEW')): _care=('TABLE', 'VIEW')):
r=[] r=[]
a=r.append a=r.append
db = self.getConnection() db = self._getConnection()
db.query("SHOW TABLES") db.query("SHOW TABLES")
result = db.store_result() result = db.store_result()
row = result.fetch_row(1) row = result.fetch_row(1)
...@@ -282,7 +282,7 @@ class DB(TM): ...@@ -282,7 +282,7 @@ class DB(TM):
def columns(self, table_name): def columns(self, table_name):
from string import join from string import join
try: try:
db = self.getConnection() db = self._getConnection()
db.query('SHOW COLUMNS FROM %s' % table_name) db.query('SHOW COLUMNS FROM %s' % table_name)
c = db.store_result() c = db.store_result()
except: except:
...@@ -328,7 +328,7 @@ class DB(TM): ...@@ -328,7 +328,7 @@ class DB(TM):
self._use_TM and self._register() self._use_TM and self._register()
desc=None desc=None
result=() result=()
db = self.getConnection() db = self._getConnection()
try: try:
if 1: if 1:
for qs in filter(None, map(strip,split(query_string, '\0'))): for qs in filter(None, map(strip,split(query_string, '\0'))):
...@@ -351,7 +351,7 @@ class DB(TM): ...@@ -351,7 +351,7 @@ class DB(TM):
except OperationalError, m: except OperationalError, m:
if m[0] not in hosed_connection: raise if m[0] not in hosed_connection: raise
# Hm. maybe the db is hosed. Let's restart it. # Hm. maybe the db is hosed. Let's restart it.
self.forceReconnection() self._forceReconnection()
return self.query(query_string, max_rows) return self.query(query_string, max_rows)
if desc is None: return (),() if desc is None: return (),()
...@@ -369,11 +369,11 @@ class DB(TM): ...@@ -369,11 +369,11 @@ class DB(TM):
return items, result return items, result
def string_literal(self, s): def string_literal(self, s):
return self.getConnection().string_literal(s) return self._getConnection().string_literal(s)
def _begin(self, *ignored): def _begin(self, *ignored):
try: try:
db = self.getConnection() db = self._getConnection()
if self._transactions: if self._transactions:
db.query("BEGIN") db.query("BEGIN")
db.store_result() db.store_result()
...@@ -384,30 +384,25 @@ class DB(TM): ...@@ -384,30 +384,25 @@ class DB(TM):
LOG('ZMySQLDA', ERROR, "exception during _begin", LOG('ZMySQLDA', ERROR, "exception during _begin",
error=sys.exc_info()) error=sys.exc_info())
raise raise
self.setFinishedOrAborted(False) self._setFinishedOrAborted(False)
def _finish(self, *ignored): def _finish(self, *ignored):
if self.getFinishedOrAborted(): if self._getFinishedOrAborted():
return return
self.setFinishedOrAborted(True) self._setFinishedOrAborted(True)
try: db = self._getConnection()
db = self.getConnection()
if self._mysql_lock: if self._mysql_lock:
db.query("SELECT RELEASE_LOCK('%s')" % self._mysql_lock) db.query("SELECT RELEASE_LOCK('%s')" % self._mysql_lock)
db.store_result() db.store_result()
if self._transactions: if self._transactions:
db.query("COMMIT") db.query("COMMIT")
db.store_result() db.store_result()
except:
LOG('ZMySQLDA', ERROR, "exception during _finish",
error=sys.exc_info())
raise
def _abort(self, *ignored): def _abort(self, *ignored):
if self.getFinishedOrAborted(): if self._getFinishedOrAborted():
return return
self.setFinishedOrAborted(True) self._setFinishedOrAborted(True)
db = self.getConnection() db = self._getConnection()
if self._mysql_lock: if self._mysql_lock:
db.query("SELECT RELEASE_LOCK('%s')" % self._mysql_lock) db.query("SELECT RELEASE_LOCK('%s')" % self._mysql_lock)
db.store_result() db.store_result()
......
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