def _test_lock_database_and_move_ends_critical_section_on_commit( self, commit): from relstorage.options import Options options = Options() options.driver = 'gevent sqlite3' adapter = self._makeOne(None) conn = MockConnection() assert conn.in_critical_phase result = adapter.lock_database_and_move(conn, MockBlobHelper(), (b'username', b'desc', b'ext'), commit=commit) self.assertIsNotNone(result) self.assertEqual(conn.in_critical_phase, not commit)
def RelStorageConfigurationFactory(key, dbconfig): if not RELSTORAGE: raise Exception("You must install the relstorage package before you can use " "it as a dabase adapter.") config = dbconfig.get('configuration', {}) options = Options(**dbconfig['options']) if dbconfig['type'] == 'postgres': from relstorage.adapters.postgresql import PostgreSQLAdapter dsn = "dbname={dbname} user={username} host={host} password={password} port={port}".format(**dbconfig['dsn']) # noqa adapter = PostgreSQLAdapter(dsn=dsn, options=options) rs = RelStorage(adapter=adapter, options=options) db = DB(rs) try: conn = db.open() rootobj = conn.root() if not IDatabase.providedBy(rootobj): alsoProvides(rootobj, IDatabase) transaction.commit() except: pass finally: rootobj = None conn.close() db.close() rs = RelStorage(adapter=adapter, options=options) db = RequestAwareDB(rs, **config) return Database(key, db)
def open(self): config = self.config # Hoist the driver setting to the section we really want it. config.driver = config.adapter.config.driver config.adapter.config.driver = None options = Options.copy_valid_options(config) adapter = config.adapter.create(options) return RelStorage(adapter, name=config.name, options=options)
def _storage_from_dsn(dsn, options, w_prefix): if not relstorage: raise NotImplementedError( "Must have relstorage installed to use dsns.") from relstorage.options import Options from relstorage.storage import RelStorage from relstorage.adapters.postgresql import PostgreSQLAdapter options = Options(**{ 'blob_dir': options[w_prefix('blob_cache')], 'shared_blob_dir': False, 'keep_history': options.get(w_prefix('keep_history'), False), 'blob_cache_size': 10 * 1<<20 # 10 MB }) adapter = PostgreSQLAdapter(dsn, options=options) storage = RelStorage(adapter, options=options) return storage
def test_call_adapter_options(self): from relstorage.options import Options resolver = self._makeOne() factory, _dbkw = resolver(self.prefix + '://someuser:somepass@somehost:5432/somedb' '?read_only=1&connect_timeout=10') factory() expected_options = Options(read_only=1) self.DBAdapter.assert_called_once_with( options=expected_options, **self._format_db(connect_timeout=10)) self.RelStorage.assert_called_once_with(adapter=self.DBAdapter(), options=expected_options)
def make_storage(self, zap=True, **kw): if ('cache_servers' not in kw and 'cache_module_name' not in kw and kw.get('share_local_cache', True)): if util.CACHE_SERVERS and util.CACHE_MODULE_NAME: kw['cache_servers'] = util.CACHE_SERVERS kw['cache_module_name'] = util.CACHE_MODULE_NAME kw['cache_prefix'] = type(self).__name__ + self._testMethodName options = Options(keep_history=self.keep_history, **kw) adapter = self.make_adapter(options) storage = RelStorage(adapter, options=options) storage._batcher_row_limit = 1 if zap: storage.zap_all() return storage
def create_storage(name, blob_dir, shared_blob_dir=shared_blob_dir, keep_history=keep_history, **kw): from relstorage.storage import RelStorage from relstorage.adapters.oracle import OracleAdapter db = db_names[name] if not keep_history: db += '_hf' options = Options( keep_history=keep_history, shared_blob_dir=shared_blob_dir, blob_dir=os.path.abspath(blob_dir), **kw) adapter = OracleAdapter( user=db, password='******', dsn=dsn, options=options, ) storage = RelStorage(adapter, name=name, options=options) storage.zap_all() return storage