def reset(self): self._dsn_cache = {} self._dsn_cache_lock = threading.Lock() try: self._default_dsn = utils.get_config('dsn') except utils.ConfigurationError: raise utils.ConfigurationError('No database configuration found.')
def __init__(self): # Session information is stored independently for each thread. # SQLAlchemy does provide this in a way with scoped_session, but # it seems sane to be independent here self._threadstore = threading.local() self._dsn_cache = {} self._dsn_cache_lock = threading.Lock() try: self._default_dsn = utils.get_config('dsn') except utils.ConfigurationError: raise utils.ConfigurationError('No database configuration found.')
def __init__(self): # Session information is stored independently for each thread. # SQLAlchemy does provide this in a way with scoped_session, but # it seems sane to be independent here self._threadstore = threading.local() self._dsn_cache = {} self._dsn_cache_lock = threading.Lock() try: self._default_dsn = utils.get_config("dsn") except utils.ConfigurationError: raise utils.ConfigurationError("No database configuration found.")
def get_dsn(self, site): """ Returns the DSN for the given site. Will look for those dsns in the zope.conf which is preferrably modified using buildout's <product-config> construct. See database.cfg.example for more info. """ site_id = site and site.id or "__no_site__" if site_id not in self._dsn_cache: specific = utils.get_config("dsn-%s" % site_id) assert specific or self._default_dsn, "no dsn config found, did you define a dsn in database.cfg?" dsn = (specific or self._default_dsn).replace("{*}", site_id) self._dsn_cache_lock.acquire() try: self._dsn_cache[site_id] = assert_dsn(dsn) finally: self._dsn_cache_lock.release() return self._dsn_cache[site_id]
def get_dsn(self, site): """ Returns the DSN for the given site. Will look for those dsns in the zope.conf which is preferrably modified using buildout's <product-config> construct. See database.cfg.example for more info. """ site_id = site and site.id or '__no_site__' if site_id not in self._dsn_cache: specific = utils.get_config('dsn-%s' % site_id) assert (specific or self._default_dsn), \ "no dsn config found, did you define a dsn in database.cfg?" dsn = (specific or self._default_dsn).replace('{*}', site_id) self._dsn_cache_lock.acquire() try: self._dsn_cache[site_id] = assert_dsn(dsn) finally: self._dsn_cache_lock.release() return self._dsn_cache[site_id]