summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/db/common.py51
-rw-r--r--openstack/common/db/sqlalchemy/session.py28
-rw-r--r--openstack/common/db/sqlalchemy/utils.py7
3 files changed, 28 insertions, 58 deletions
diff --git a/openstack/common/db/common.py b/openstack/common/db/common.py
deleted file mode 100644
index 65f67bc..0000000
--- a/openstack/common/db/common.py
+++ /dev/null
@@ -1,51 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2010 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-# Copyright 2012 Cloudscaling Group, Inc
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from openstack.common.gettextutils import _
-from openstack.common import log as logging
-
-
-LOG = logging.getLogger(__name__)
-
-
-class Invalid(Exception):
- pass
-
-
-class InvalidSortKey(Invalid):
- message = _("Sort key supplied was not valid.")
-
-
-class InvalidUnicodeParameter(Invalid):
- message = _("Invalid Parameter: "
- "Unicode is not supported by the current database.")
-
-
-class DBError(Exception):
- """Wraps an implementation specific exception."""
- def __init__(self, inner_exception=None):
- self.inner_exception = inner_exception
- super(DBError, self).__init__(str(inner_exception))
-
-
-class DBDuplicateEntry(DBError):
- """Wraps an implementation specific exception."""
- def __init__(self, columns=[], inner_exception=None):
- self.columns = columns
- super(DBDuplicateEntry, self).__init__(inner_exception)
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py
index a796b92..99c214b 100644
--- a/openstack/common/db/sqlalchemy/session.py
+++ b/openstack/common/db/sqlalchemy/session.py
@@ -258,7 +258,6 @@ import sqlalchemy.orm
from sqlalchemy.pool import NullPool, StaticPool
from sqlalchemy.sql.expression import literal_column
-import openstack.common.db.common as db_common
from openstack.common import cfg
import openstack.common.log as logging
from openstack.common.gettextutils import _
@@ -338,6 +337,25 @@ def get_session(autocommit=True, expire_on_commit=False):
return session
+class DBError(Exception):
+ """Wraps an implementation specific exception."""
+ def __init__(self, inner_exception=None):
+ self.inner_exception = inner_exception
+ super(DBError, self).__init__(str(inner_exception))
+
+
+class DBDuplicateEntry(DBError):
+ """Wraps an implementation specific exception."""
+ def __init__(self, columns=[], inner_exception=None):
+ self.columns = columns
+ super(DBDuplicateEntry, self).__init__(inner_exception)
+
+
+class InvalidUnicodeParameter(Exception):
+ message = _("Invalid Parameter: "
+ "Unicode is not supported by the current database.")
+
+
# note(boris-42): In current versions of DB backends unique constraint
# violation messages follow the structure:
#
@@ -391,7 +409,7 @@ def raise_if_duplicate_entry_error(integrity_error, engine_name):
columns = columns.strip().split(", ")
else:
columns = get_columns_from_uniq_cons_or_name(columns)
- raise db_common.DBDuplicateEntry(columns, integrity_error)
+ raise DBDuplicateEntry(columns, integrity_error)
def wrap_db_error(f):
@@ -399,7 +417,7 @@ def wrap_db_error(f):
try:
return f(*args, **kwargs)
except UnicodeEncodeError:
- raise db_common.InvalidUnicodeParameter()
+ raise InvalidUnicodeParameter()
# note(boris-42): We should catch unique constraint violation and
# wrap it by our own DBDuplicateEntry exception. Unique constraint
# violation is wrapped by IntegrityError.
@@ -410,10 +428,10 @@ def wrap_db_error(f):
# 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 db_common.DBError(e)
+ raise DBError(e)
except Exception, e:
LOG.exception(_('DB exception wrapped.'))
- raise db_common.DBError(e)
+ raise DBError(e)
_wrap.func_name = f.func_name
return _wrap
diff --git a/openstack/common/db/sqlalchemy/utils.py b/openstack/common/db/sqlalchemy/utils.py
index f7bb2f9..c8ab93e 100644
--- a/openstack/common/db/sqlalchemy/utils.py
+++ b/openstack/common/db/sqlalchemy/utils.py
@@ -22,7 +22,6 @@
import sqlalchemy
-from openstack.common.db import common as db_common
from openstack.common.gettextutils import _
from openstack.common import log as logging
@@ -30,6 +29,10 @@ from openstack.common import log as logging
LOG = logging.getLogger(__name__)
+class InvalidSortKey(Exception):
+ message = _("Sort key supplied was not valid.")
+
+
# copy from glance/db/sqlalchemy/api.py
def paginate_query(query, model, limit, sort_keys, marker=None,
sort_dir=None, sort_dirs=None):
@@ -90,7 +93,7 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
try:
sort_key_attr = getattr(model, current_sort_key)
except AttributeError:
- raise db_common.InvalidSortKey()
+ raise InvalidSortKey()
query = query.order_by(sort_dir_func(sort_key_attr))
# Add pagination