Commit c60fc5a5 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

ZMySQLDA: support isolation level per connector.

parent 07496d63
...@@ -2291,7 +2291,8 @@ class ERP5Generator(PortalGenerator): ...@@ -2291,7 +2291,8 @@ class ERP5Generator(PortalGenerator):
# The only difference compared to activity connection is the # The only difference compared to activity connection is the
# minus prepended to the connection string. # minus prepended to the connection string.
if id == 'erp5_sql_transactionless_connection': if id == 'erp5_sql_transactionless_connection':
connection_string = '-' + p.cmf_activity_sql_connection_string index = [i for i, x in enumerate(p.cmf_activity_sql_connection_string.split()) if not x[0] in ('%', '*', '!')][0]
connection_string = ' '.join('-' + x if i == index else x for i, x in enumerate(p.cmf_activity_sql_connection_string.split()))
else: else:
connection_string = getattr(p, id + '_string') connection_string = getattr(p, id + '_string')
manage_add(id, title, connection_string, **kw) manage_add(id, title, connection_string, **kw)
......
...@@ -110,8 +110,9 @@ def _getConnectionStringDict(): ...@@ -110,8 +110,9 @@ def _getConnectionStringDict():
connection_string_dict[connection] = connection_string connection_string_dict[connection] = connection_string
connection = 'erp5_sql_transactionless_connection_string' connection = 'erp5_sql_transactionless_connection_string'
if os.environ.get(connection, connection_string): if os.environ.get(connection, connection_string):
index = [i for i, x in enumerate(connection_string.split()) if not x[0] in ('%', '*', '!')][0]
connection_string_dict[connection] = \ connection_string_dict[connection] = \
os.environ.get(connection, '-' + connection_string) connection_string = ' '.join('-' + x if i == index else x for i, x in enumerate(connection_string.split()))
return connection_string_dict return connection_string_dict
def _getConversionServerUrlList(): def _getConversionServerUrlList():
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<dd> <dd>
The connection string used for Z MySQL Database Connection is of the form: The connection string used for Z MySQL Database Connection is of the form:
<br /> <br />
<code>[%ssl_name] [*lock] [+/-][database][@host[:port]] [user [password [unix_socket]]]</code> <code>[%ssl_name] [*lock] [!isolation-level] [+/-][database][@host[:port]] [user [password [unix_socket]]]</code>
<br /> <br />
or typically: or typically:
<br /> <br />
...@@ -103,6 +103,12 @@ ...@@ -103,6 +103,12 @@
you'll get an error in the logs, and inconsistent data. In this you'll get an error in the logs, and inconsistent data. In this
respect, it's equivalent to transactions turned off. respect, it's equivalent to transactions turned off.
</dd> </dd>
<dd>
!<em>isolation_level</em> at the begining of the connection string
will set the transaction isolation level in each transaction. The
value should be one of REPEATABLE-READ, READ-COMMITTED,
READ-UNCOMMITTED or SERIALIZABLE.
</dd>
<dd> <dd>
Transactions are highly recommended. Using a named lock in Transactions are highly recommended. Using a named lock in
conjunctions with transactions is probably pointless. conjunctions with transactions is probably pointless.
...@@ -111,4 +117,4 @@ ...@@ -111,4 +117,4 @@
</main> </main>
<dtml-var manage_page_footer> <dtml-var manage_page_footer>
\ No newline at end of file
...@@ -242,7 +242,7 @@ class DB(TM): ...@@ -242,7 +242,7 @@ class DB(TM):
self._use_TM = transactional or self._mysql_lock self._use_TM = transactional or self._mysql_lock
def _parse_connection_string(self): def _parse_connection_string(self):
self._mysql_lock = self._try_transactions = None self._mysql_lock = self._try_transactions = self._isolation_level = None
self._kw_args = kwargs = {'conv': self.conv} self._kw_args = kwargs = {'conv': self.conv}
items = self._connection.split() items = self._connection.split()
if not items: if not items:
...@@ -260,6 +260,8 @@ class DB(TM): ...@@ -260,6 +260,8 @@ class DB(TM):
del items[0] del items[0]
if items[0][0] == "*": if items[0][0] == "*":
self._mysql_lock = items.pop(0)[1:] self._mysql_lock = items.pop(0)[1:]
if items[0][0] == "!":
self._isolation_level = items.pop(0)[1:]
db = items.pop(0) db = items.pop(0)
if '@' in db: if '@' in db:
db, host = db.split('@', 1) db, host = db.split('@', 1)
...@@ -489,6 +491,8 @@ class DB(TM): ...@@ -489,6 +491,8 @@ class DB(TM):
try: try:
self._transaction_begun = True self._transaction_begun = True
if self._transactions: if self._transactions:
if self._isolation_level:
self._query("SET TRANSACTION ISOLATION LEVEL %s" % self._isolation_level.replace('-', ' '))
self._query("BEGIN", allow_reconnect=True) self._query("BEGIN", allow_reconnect=True)
if self._mysql_lock: if self._mysql_lock:
self._query("SELECT GET_LOCK('%s',0)" % self._mysql_lock, allow_reconnect=not self._transactions) self._query("SELECT GET_LOCK('%s',0)" % self._mysql_lock, allow_reconnect=not self._transactions)
......
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