summaryrefslogtreecommitdiffstats
path: root/openstack/common/db/sqlalchemy
diff options
context:
space:
mode:
authorZhongyue Luo <zhongyue.nah@intel.com>2013-04-10 17:02:17 +0800
committerZhongyue Luo <zhongyue.nah@intel.com>2013-04-10 17:02:22 +0800
commit73061f2d3e5fdd811a0f02aa969fa62b3454e644 (patch)
treec73067a7b9672726e0c16b81c4b2eced365da765 /openstack/common/db/sqlalchemy
parent9dcf688ea80f52cdb5413514198b2aa81d5a4e09 (diff)
downloadoslo-73061f2d3e5fdd811a0f02aa969fa62b3454e644.tar.gz
oslo-73061f2d3e5fdd811a0f02aa969fa62b3454e644.tar.xz
oslo-73061f2d3e5fdd811a0f02aa969fa62b3454e644.zip
Fixes private functions private
Fixed functions below to private APIs. raise_if_duplicate_entry_error() raise_if_deadlock_error() wrap_db_error() synchronous_switch_listener() add_regexp_listener() greenthread_yield() ping_listener() is_db_connection_error() patch_mysqldb_with_stacktrace_comments() Fixes bug #1119709 Change-Id: I61f700cdbae0126a8b89f6895e4332d695191dd0
Diffstat (limited to 'openstack/common/db/sqlalchemy')
-rw-r--r--openstack/common/db/sqlalchemy/session.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py
index 31e9612..77a1dc8 100644
--- a/openstack/common/db/sqlalchemy/session.py
+++ b/openstack/common/db/sqlalchemy/session.py
@@ -354,7 +354,7 @@ _DUP_KEY_RE_DB = {
}
-def raise_if_duplicate_entry_error(integrity_error, engine_name):
+def _raise_if_duplicate_entry_error(integrity_error, engine_name):
"""
In this function will be raised DBDuplicateEntry exception if integrity
error wrap unique constraint violation.
@@ -396,7 +396,7 @@ _DEADLOCK_RE_DB = {
}
-def raise_if_deadlock_error(operational_error, engine_name):
+def _raise_if_deadlock_error(operational_error, engine_name):
"""
Raise DBDeadlock exception if OperationalError contains a Deadlock
condition.
@@ -410,7 +410,7 @@ def raise_if_deadlock_error(operational_error, engine_name):
raise exception.DBDeadlock(operational_error)
-def wrap_db_error(f):
+def _wrap_db_error(f):
def _wrap(*args, **kwargs):
try:
return f(*args, **kwargs)
@@ -420,7 +420,7 @@ def wrap_db_error(f):
# wrap it by our own DBDuplicateEntry exception. Unique constraint
# violation is wrapped by IntegrityError.
except sqla_exc.OperationalError, e:
- raise_if_deadlock_error(e, get_engine().name)
+ _raise_if_deadlock_error(e, get_engine().name)
# NOTE(comstud): A lot of code is checking for OperationalError
# so let's not wrap it for now.
raise
@@ -430,7 +430,7 @@ def wrap_db_error(f):
# instance_types) there are more than one unique constraint. This
# means we should get names of columns, which values violate
# unique constraint, from error message.
- raise_if_duplicate_entry_error(e, get_engine().name)
+ _raise_if_duplicate_entry_error(e, get_engine().name)
raise exception.DBError(e)
except Exception, e:
LOG.exception(_('DB exception wrapped.'))
@@ -447,12 +447,12 @@ def get_engine():
return _ENGINE
-def synchronous_switch_listener(dbapi_conn, connection_rec):
+def _synchronous_switch_listener(dbapi_conn, connection_rec):
"""Switch sqlite connections to non-synchronous mode."""
dbapi_conn.execute("PRAGMA synchronous = OFF")
-def add_regexp_listener(dbapi_con, con_record):
+def _add_regexp_listener(dbapi_con, con_record):
"""Add REGEXP function to sqlite connections."""
def regexp(expr, item):
@@ -461,7 +461,7 @@ def add_regexp_listener(dbapi_con, con_record):
dbapi_con.create_function('regexp', 2, regexp)
-def greenthread_yield(dbapi_con, con_record):
+def _greenthread_yield(dbapi_con, con_record):
"""
Ensure other greenthreads get a chance to execute by forcing a context
switch. With common database backends (eg MySQLdb and sqlite), there is
@@ -471,7 +471,7 @@ def greenthread_yield(dbapi_con, con_record):
greenthread.sleep(0)
-def ping_listener(dbapi_conn, connection_rec, connection_proxy):
+def _ping_listener(dbapi_conn, connection_rec, connection_proxy):
"""
Ensures that MySQL connections checked out of the
pool are alive.
@@ -489,7 +489,7 @@ def ping_listener(dbapi_conn, connection_rec, connection_proxy):
raise
-def is_db_connection_error(args):
+def _is_db_connection_error(args):
"""Return True if error in connecting to db."""
# NOTE(adam_g): This is currently MySQL specific and needs to be extended
# to support Postgres and others.
@@ -529,24 +529,24 @@ def create_engine(sql_connection):
engine = sqlalchemy.create_engine(sql_connection, **engine_args)
- sqlalchemy.event.listen(engine, 'checkin', greenthread_yield)
+ sqlalchemy.event.listen(engine, 'checkin', _greenthread_yield)
if 'mysql' in connection_dict.drivername:
- sqlalchemy.event.listen(engine, 'checkout', ping_listener)
+ sqlalchemy.event.listen(engine, 'checkout', _ping_listener)
elif 'sqlite' in connection_dict.drivername:
if not CONF.sqlite_synchronous:
sqlalchemy.event.listen(engine, 'connect',
- synchronous_switch_listener)
- sqlalchemy.event.listen(engine, 'connect', add_regexp_listener)
+ _synchronous_switch_listener)
+ sqlalchemy.event.listen(engine, 'connect', _add_regexp_listener)
if (CONF.sql_connection_trace and
engine.dialect.dbapi.__name__ == 'MySQLdb'):
- patch_mysqldb_with_stacktrace_comments()
+ _patch_mysqldb_with_stacktrace_comments()
try:
engine.connect()
except sqla_exc.OperationalError, e:
- if not is_db_connection_error(e.args[0]):
+ if not _is_db_connection_error(e.args[0]):
raise
remaining = CONF.sql_max_retries
@@ -563,7 +563,7 @@ def create_engine(sql_connection):
break
except sqla_exc.OperationalError, e:
if (remaining != 'infinite' and remaining == 0) or \
- not is_db_connection_error(e.args[0]):
+ not _is_db_connection_error(e.args[0]):
raise
return engine
@@ -579,15 +579,15 @@ class Query(sqlalchemy.orm.query.Query):
class Session(sqlalchemy.orm.session.Session):
"""Custom Session class to avoid SqlAlchemy Session monkey patching."""
- @wrap_db_error
+ @_wrap_db_error
def query(self, *args, **kwargs):
return super(Session, self).query(*args, **kwargs)
- @wrap_db_error
+ @_wrap_db_error
def flush(self, *args, **kwargs):
return super(Session, self).flush(*args, **kwargs)
- @wrap_db_error
+ @_wrap_db_error
def execute(self, *args, **kwargs):
return super(Session, self).execute(*args, **kwargs)
@@ -601,7 +601,7 @@ def get_maker(engine, autocommit=True, expire_on_commit=False):
query_cls=Query)
-def patch_mysqldb_with_stacktrace_comments():
+def _patch_mysqldb_with_stacktrace_comments():
"""Adds current stack trace as a comment in queries by patching
MySQLdb.cursors.BaseCursor._do_query.
"""