コード例 #1
0
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)
コード例 #2
0
                def create_storage(name,
                                   blob_dir,
                                   shared_blob_dir=shared_blob_dir,
                                   keep_history=keep_history,
                                   **kw):
                    if not driver_available:
                        raise unittest.SkipTest(str(driver_available))
                    assert 'driver' not in kw
                    kw['driver'] = driver_available.driver_name
                    db = self.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_maker = self.use_adapter()
                    adapter_maker.driver_name = driver_available.driver_name
                    adapter = adapter_maker.make_adapter(options, db)
                    __traceback_info__ = adapter, options
                    storage = RelStorage(adapter, name=name, options=options)
                    storage.zap_all()
                    return storage
コード例 #3
0
    def make_storage(self, zap=True, **kw):
        from . import util
        from relstorage.storage import RelStorage

        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
        if 'cache_prefix' not in kw:
            kw['cache_prefix'] = type(self).__name__ + self._testMethodName
        if 'cache_local_dir' not in kw:
            # Always use a persistent cache. This helps discover errors in
            # the persistent cache.
            # These tests run in a temporary directory that gets cleaned up, so the CWD is
            # appropriate. BUT: it should be an abspath just in case we change directories
            kw['cache_local_dir'] = os.path.abspath('.')
        if 'commit_lock_timeout' not in kw:
            # Cut this way down so we get better feedback.
            kw['commit_lock_timeout'] = self.DEFAULT_COMMIT_LOCK_TIMEOUT

        assert self.driver_name
        options = Options(keep_history=self.keep_history,
                          driver=self.driver_name,
                          **kw)
        adapter = self.make_adapter(options)
        storage = RelStorage(adapter, options=options)
        if zap:
            storage.zap_all(slow=self.zap_slow)
        return self._wrap_storage(storage)
コード例 #4
0
def getRelstorageConnection(host='localhost',
                            port=3306,
                            user='******',
                            passwd=None,
                            db='zodb',
                            socket=None,
                            keep_history=False):

    from relstorage.storage import RelStorage
    from relstorage.adapters.mysql import MySQLAdapter
    connectionParams = {
        'host': host,
        'port': port,
        'user': user,
        'passwd': passwd,
        'db': db,
    }
    if socket:
        connectionParams['unix_socket'] = socket
    kwargs = {
        'keep_history': keep_history,
    }
    from relstorage.options import Options
    adapter = MySQLAdapter(options=Options(**kwargs), **connectionParams)
    storage = RelStorage(adapter, **kwargs)
    from ZODB import DB
    db = DB(storage, 0)
    return db
コード例 #5
0
 def makeOne(self, adapter=None, **kw):
     from relstorage.storage import RelStorage
     # Constructed so as to avoid the need to use a database connection.
     return RelStorage(adapter or MockAdapter(),
                       create=False,
                       cache_prefix='Mock',
                       **kw)
コード例 #6
0
ファイル: config.py プロジェクト: olst/relstorage
 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)
コード例 #7
0
ファイル: config.py プロジェクト: Cykooz/relstorage
 def open(self):
     config = self.config
     options = Options()
     for key in options.__dict__.keys():
         value = getattr(config, key, None)
         if value is not None:
             setattr(options, key, value)
     adapter = config.adapter.create(options)
     return RelStorage(adapter, name=config.name, options=options)
コード例 #8
0
ファイル: reltestbase.py プロジェクト: Cykooz/relstorage
 def make_storage(self, zap=True, **kw):
     from relstorage.options import Options
     from relstorage.storage import RelStorage
     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
コード例 #9
0
ファイル: config.py プロジェクト: lungj/relstorage
 def open(self):
     config = self.config
     # Hoist the driver setting to the section we really want it.
     config.driver = config.adapter.config.driver
     # But don't remove it or otherwise mutate the config object;
     # that would prevent us from being correctly opened again.
     #config.adapter.config.driver = None
     options = Options.copy_valid_options(config)
     adapter = config.adapter.create(options)
     return RelStorage(adapter, name=config.name, options=options)
コード例 #10
0
ファイル: reltestbase.py プロジェクト: FinnArild/relstorage
 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
コード例 #11
0
 def open(self):
     config = self.config
     # Hoist the driver setting to the section we really want it.
     config.driver = config.adapter.config.driver
     # But don't remove it or otherwise mutate the config object;
     # that would prevent us from being correctly opened again.
     #config.adapter.config.driver = None
     options = Options.copy_valid_options(config)
     options.adapter = config.adapter
     # The adapter factories may modify the global options (or raise an exception)
     # if something at the top-level is specifically not allowed based on
     # their configuration.
     adapter = config.adapter.create(options)
     return RelStorage(adapter, name=config.name, options=options)
コード例 #12
0
def main():
    logging.basicConfig(
        stream=sys.stderr,
        level=logging.DEBUG,
        format='%(asctime)s [%(name)s] %(levelname)s %(message)s')
    log.info("Opening")
    adapter = PostgreSQLAdapter()
    storage = RelStorage(adapter)
    db = DB(storage)
    log.info("Filling")
    fill_db(db)
    log.info("Packing")
    start = time.time()
    db.pack()
    end = time.time()
    log.info("Packed in %0.3f seconds", end - start)
コード例 #13
0
ファイル: nodeops.py プロジェクト: dpedu/docker-nodepupper
    def __init__(self, db_uri):
        uri = urlparse(db_uri)

        self.mysql = MySQLAdapter(host=uri.hostname,
                                  port=uri.port,
                                  user=uri.username,
                                  passwd=uri.password,
                                  db=uri.path[1:],
                                  options=Options(keep_history=False))
        self.storage = RelStorage(adapter=self.mysql)
        self.db = ZODB.DB(self.storage)

        with self.db.transaction() as c:
            if "nodes" not in c.root():
                c.root.nodes = BTrees.OOBTree.BTree()
            if "classes" not in c.root():
                c.root.classes = BTrees.OOBTree.BTree()
コード例 #14
0
ファイル: reltestbase.py プロジェクト: olst/relstorage
    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:
            # XXX: Some ZODB tests, possibly check4ExtStorageThread and
            # check7StorageThreads don't close storages when done with them?
            # This leads to connections remaining open with locks on PyPy, so on PostgreSQL
            # we can't TRUNCATE tables and have to go the slow route.
            storage.zap_all(slow=True)
        return self._wrap_storage(storage)
コード例 #15
0
def testRelstorage():

    import ZODB, transaction
    from ZODB import FileStorage, DB
    from relstorage.adapters.mysql import MySQLAdapter
    from relstorage.storage import RelStorage
    from MySQLdb import OperationalError

    server = 'peat.ucd.ie'
    username = '******'
    password = '******'
    project = 'test'
    port = 8080
    adapter = MySQLAdapter(host=server,
                           user=username,
                           passwd=password,
                           db=project,
                           port=port)
    storage = RelStorage(adapter, shared_blob_dir=False, blob_dir='tempblob')
    db = DB(storage)
    connection = db.open()
    print storage
    connection = db.open()
    dbroot = connection.root()
    data = dbroot['data']
    print data

    def addfile(fname):
        myblob = Blob()
        b = myblob.open('w')
        o = open(fname)
        data = o.read()
        b.write(data)
        print b.name
        b.close()
        return myblob

    '''f='gogh.chambre-arles.jpg'
    b=addfile(f)
    data['aaa'] = FileRecord(name=f,blob=b)'''
    #t = transaction.get()
    #t.commit()
    return
コード例 #16
0
 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.postgresql import PostgreSQLAdapter
     db = db_names[name]
     if not keep_history:
         db += '_hf'
     dsn = ('dbname=%s user=relstoragetest '
            'password=relstoragetest' % db)
     options = Options(keep_history=keep_history,
                       shared_blob_dir=shared_blob_dir,
                       blob_dir=os.path.abspath(blob_dir),
                       **kw)
     adapter = PostgreSQLAdapter(dsn=dsn, options=options)
     storage = RelStorage(adapter, name=name, options=options)
     storage.zap_all()
     return storage
コード例 #17
0
ファイル: testmysql.py プロジェクト: Cykooz/relstorage
 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.mysql import MySQLAdapter
     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 = MySQLAdapter(
         options=options,
         db=db,
         user='******',
         passwd='relstoragetest',
     )
     storage = RelStorage(adapter, name=name, options=options)
     storage.zap_all()
     return storage
コード例 #18
0
 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
コード例 #19
0
ファイル: __init__.py プロジェクト: lungj/relstorage
    def make_storage(self, zap=True, **kw):
        from . import util
        from relstorage.storage import RelStorage

        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
        if 'cache_prefix' not in kw:
            kw['cache_prefix'] = type(self).__name__ + self._testMethodName
        if 'cache_local_dir' not in kw:
            # Always use a persistent cache. This helps discover errors in
            # the persistent cache.
            # These tests run in a temporary directory that gets cleaned up, so the CWD is
            # appropriate. BUT: it should be an abspath just in case we change directories
            kw['cache_local_dir'] = os.path.abspath('.')
        if 'commit_lock_timeout' not in kw:
            # Cut this way down so we get better feedback.
            kw['commit_lock_timeout'] = self.DEFAULT_COMMIT_LOCK_TIMEOUT

        assert self.driver_name
        options = Options(keep_history=self.keep_history,
                          driver=self.driver_name,
                          **kw)
        adapter = self.make_adapter(options)
        storage = RelStorage(adapter, options=options)
        if zap:
            # XXX: Some ZODB tests, possibly check4ExtStorageThread
            # and check7StorageThreads don't close storages when done
            # with them? This leads to connections remaining open with
            # locks on PyPy, so on PostgreSQL we can't TRUNCATE tables
            # and have to go the slow route.
            #
            # As of 2019-06-20 with PyPy 7.1.1, I'm no longer able to replicate
            # a problem like that locally, so we go back to the fast way.
            storage.zap_all()
        return self._wrap_storage(storage)
コード例 #20
0
ファイル: reltestbase.py プロジェクト: c0ns0le/zenoss-4
 def open(self, **kwargs):
     from relstorage.storage import RelStorage
     adapter = self.make_adapter()
     self._storage = RelStorage(adapter, **kwargs)
     self._storage._batcher_row_limit = 1
コード例 #21
0
ファイル: quicktest.py プロジェクト: tseaver/relstorage
import logging
import sys
format = '%(asctime)s [%(name)s] %(levelname)s %(message)s'
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=format)
import transaction
from relstorage.storage import RelStorage
from relstorage.options import Options
from relstorage.adapters.mysql import MySQLAdapter
from ZODB.DB import DB
options = Options()
adapter = MySQLAdapter(db='shane', options=options)
storage = RelStorage(adapter, options=options)
db = DB(storage)
conn = db.open()
root = conn.root()
root['x'] = root.get('x', 0) + 1
transaction.commit()
conn.close()
db.pack()
コード例 #22
0
ファイル: zodburi_resolver.py プロジェクト: olst/relstorage
 def factory():
     adapter = adapter_factory(options)
     storage = RelStorage(adapter=adapter, options=options)
     if demostorage:
         storage = DemoStorage(base=storage)
     return storage
コード例 #23
0
 def factory():
     adapter = adapter_factory(options)
     storage = RelStorage(adapter=adapter, options=options)
     return storage if not demostorage else DemoStorage(base=storage)
コード例 #24
0
        'password=relstoragetest',
        options=Options(keep_history=keep_history),
        )
elif use == 'oracle':
    from relstorage.adapters.oracle import OracleAdapter
    dsn = os.environ.get('ORACLE_TEST_DSN', 'XE')
    a = OracleAdapter(
        user='******',
        password='******',
        dsn=dsn,
        options=Options(keep_history=keep_history),
        )
else:
    raise AssertionError("which database?")

s = RelStorage(a)
d = DB(s)
c = d.open()

print 'size:'
print d.getSize()

if 1:
    print 'initializing...'
    container = PersistentMapping()
    c.root()['container'] = container
    container_size = 10000
    for i in range(container_size):
        container[i] = PersistentMapping()
    transaction.commit()