oslo.db: transition from legacy facade
WIP Direct use enginefacade in api module for creation of engines and sessions for use in watcher. Change-Id: I36daf1bb11191583b83264b9ed269a08cbf069ba Closes-Bug: 2056181
This commit is contained in:
parent
9d58a6d457
commit
05a5f5123b
|
@ -22,7 +22,7 @@ import operator
|
|||
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_db.sqlalchemy import session as db_session
|
||||
from oslo_db.sqlalchemy import enginefacade
|
||||
from oslo_db.sqlalchemy import utils as db_utils
|
||||
from oslo_utils import timeutils
|
||||
from sqlalchemy.inspection import inspect
|
||||
|
@ -44,22 +44,32 @@ _FACADE = None
|
|||
def _create_facade_lazily():
|
||||
global _FACADE
|
||||
if _FACADE is None:
|
||||
# FIXME(amoralej): Remove autocommit=True (and ideally use of
|
||||
# LegacyEngineFacade) asap since it's not compatible with SQLAlchemy
|
||||
# 2.0.
|
||||
_FACADE = db_session.EngineFacade.from_config(CONF,
|
||||
autocommit=True)
|
||||
return _FACADE
|
||||
_FACADE = True
|
||||
enginefacade.configure(expire_on_commit=True)
|
||||
|
||||
|
||||
def _get_transaction_context(reader=False):
|
||||
_create_facade_lazily()
|
||||
# TODO(gthiemonge) Create and use new functions to get read-only sessions
|
||||
if reader:
|
||||
context = enginefacade.reader
|
||||
else:
|
||||
context = enginefacade.writer
|
||||
return context
|
||||
|
||||
|
||||
def _get_sessionmaker(reader=False):
|
||||
context = _get_transaction_context(reader)
|
||||
return context.get_sessionmaker()
|
||||
|
||||
|
||||
def get_engine():
|
||||
facade = _create_facade_lazily()
|
||||
return facade.get_engine()
|
||||
context = _get_transaction_context()
|
||||
return context.get_engine()
|
||||
|
||||
|
||||
def get_session(**kwargs):
|
||||
facade = _create_facade_lazily()
|
||||
return facade.get_session(**kwargs)
|
||||
return _get_sessionmaker()(**kwargs)
|
||||
|
||||
|
||||
def get_backend():
|
||||
|
|
Loading…
Reference in New Issue