Remove dead SQLAlchemy code
This code is no longer used, and was leftover from previous changes. Change-Id: Icbd83f826642be82000745f8595816a366008805
This commit is contained in:
parent
8679154ffb
commit
63fb19f323
@ -1,58 +0,0 @@
|
||||
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Author: Kiall Mac Innes <kiall@hp.com>
|
||||
#
|
||||
# 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 sqlalchemy.ext.compiler import compiles
|
||||
from sqlalchemy.sql.expression import Executable, ClauseElement
|
||||
|
||||
|
||||
class InsertFromSelect(Executable, ClauseElement):
|
||||
execution_options = \
|
||||
Executable._execution_options.union({'autocommit': True})
|
||||
|
||||
def __init__(self, table, select, columns=None):
|
||||
self.table = table
|
||||
self.select = select
|
||||
self.columns = columns
|
||||
|
||||
|
||||
@compiles(InsertFromSelect)
|
||||
def visit_insert_from_select(element, compiler, **kw):
|
||||
# NOTE(kiall): SQLA 0.8.3+ has an InsertFromSelect built in:
|
||||
# sqlalchemy.sql.expression.Insert.from_select
|
||||
# This code can be removed once we require 0.8.3+
|
||||
table = compiler.process(element.table, asfrom=True)
|
||||
select = compiler.process(element.select)
|
||||
|
||||
if element.columns is not None:
|
||||
|
||||
columns = [compiler.preparer.format_column(c) for c in element.columns]
|
||||
columns = ", ".join(columns)
|
||||
|
||||
return "INSERT INTO %s (%s) %s" % (
|
||||
table,
|
||||
columns,
|
||||
select
|
||||
)
|
||||
else:
|
||||
return "INSERT INTO %s %s" % (
|
||||
table,
|
||||
select
|
||||
)
|
||||
|
||||
|
||||
# # Dialect specific compilation example, should it be needed.
|
||||
# @compiles(InsertFromSelect, 'postgresql')
|
||||
# def visit_insert_from_select(element, compiler, **kw):
|
||||
# ...
|
@ -1,57 +0,0 @@
|
||||
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Author: Patrick Galbraith <patg@hp.com>
|
||||
#
|
||||
# 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 oslo_db.sqlalchemy import models
|
||||
from oslo_db import exception as oslo_db_exc
|
||||
from sqlalchemy import Column, DateTime
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.types import CHAR
|
||||
|
||||
from designate.openstack.common import timeutils
|
||||
from designate import exceptions
|
||||
|
||||
|
||||
class Base(models.ModelBase):
|
||||
# TODO(ekarlso): Remove me when o.db patch lands for this.
|
||||
def save(self, session):
|
||||
"""Save this object"""
|
||||
session.add(self)
|
||||
|
||||
try:
|
||||
session.flush()
|
||||
except oslo_db_exc.DBDuplicateEntry as e:
|
||||
raise exceptions.Duplicate(str(e))
|
||||
except IntegrityError:
|
||||
raise
|
||||
|
||||
def delete(self, session):
|
||||
session.delete(self)
|
||||
session.flush()
|
||||
|
||||
|
||||
# TODO(ekarlso): Get this into o.db?
|
||||
class SoftDeleteMixin(object):
|
||||
deleted = Column(CHAR(32), nullable=False, default="0", server_default="0")
|
||||
deleted_at = Column(DateTime, nullable=True, default=None)
|
||||
|
||||
def soft_delete(self, session):
|
||||
"""Mark this object as deleted."""
|
||||
self.deleted = self.id.replace('-', '')
|
||||
self.deleted_at = timeutils.utcnow()
|
||||
|
||||
if hasattr(self, 'status'):
|
||||
self.status = "DELETED"
|
||||
|
||||
self.save(session=session)
|
@ -15,9 +15,8 @@
|
||||
# under the License.
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.types import TypeDecorator, CHAR, VARCHAR
|
||||
from sqlalchemy.types import TypeDecorator, CHAR
|
||||
from sqlalchemy.dialects.postgresql import UUID as pgUUID
|
||||
from sqlalchemy.dialects.postgresql import INET as pgINET
|
||||
|
||||
|
||||
class UUID(TypeDecorator):
|
||||
@ -53,19 +52,3 @@ class UUID(TypeDecorator):
|
||||
return value
|
||||
else:
|
||||
return str(uuid.UUID(value))
|
||||
|
||||
|
||||
class Inet(TypeDecorator):
|
||||
impl = VARCHAR
|
||||
|
||||
def load_dialect_impl(self, dialect):
|
||||
if dialect.name == "postgresql":
|
||||
return pgINET()
|
||||
else:
|
||||
return VARCHAR(39) # IPv6 can be up to 39 chars
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if value is None:
|
||||
return value
|
||||
else:
|
||||
return str(value)
|
||||
|
Loading…
Reference in New Issue
Block a user