예제 #1
0
 def pack(self, t, referencesf, gc=True):
     # prevent all concurrent commits during packing
     self._commit_lock.acquire()
     try:
         MappingStorage.pack(self, t, referencesf, gc)
     finally:
         self._commit_lock.release()
예제 #2
0
 def __init__(self, name="MVCC Mapping Storage"):
     MappingStorage.__init__(self, name=name)
     # _polled_tid contains the transaction ID at the last poll.
     self._polled_tid = ""
     self._data_snapshot = None  # {oid->(state, tid)}
     self._main_lock_acquire = self._lock_acquire
     self._main_lock_release = self._lock_release
예제 #3
0
 def pack(self, t, referencesf, gc=True):
     # prevent all concurrent commits during packing
     self._commit_lock.acquire()
     try:
         MappingStorage.pack(self, t, referencesf, gc)
     finally:
         self._commit_lock.release()
예제 #4
0
 def __init__(self, name="MVCC Mapping Storage"):
     MappingStorage.__init__(self, name=name)
     # _polled_tid contains the transaction ID at the last poll.
     self._polled_tid = b''
     self._data_snapshot = None  # {oid->(state, tid)}
     self._main_lock_acquire = self._lock_acquire
     self._main_lock_release = self._lock_release
예제 #5
0
def main(args=None, start_serving=True):
    logging.basicConfig(format="%(message)s")

    if faulthandler is not None:
        faulthandler.enable()  # pragma: PY3

    options = parse_args(args)

    db = open_db(options)

    internal_db = DB(MappingStorage())

    configure(options)

    provideUtility(db, IDatabase, name='<target>')

    notify(zope.app.appsetup.interfaces.DatabaseOpened(internal_db))

    start_server(options, internal_db)

    notify(zope.app.appsetup.interfaces.ProcessStarting())

    install_provides_hack()

    if start_serving:
        serve_forever()
예제 #6
0
 def setUp(self):
     self.folder = Folder('folder1')
     manage_addFolder(self.folder, 'folder11')
     manage_addFolder(self.folder, 'folder12')
     manage_addFolder(self.folder, 'folder13')
     self.db = DB(MappingStorage())
     self.connection = self.db.open()
예제 #7
0
def get_db_connection(blob_dir):
    storage = MappingStorage('test')
    blob_storage = BlobStorage(blob_dir, storage)
    db = DB(blob_storage)
    conn = db.open()
    create_app_root(conn)
    return conn
    def checkOldStyleRoot(self):
        # insert the pickle in place of the root
        s = MappingStorage()
        t = Transaction()
        s.tpc_begin(t)
        s.store('\000' * 8, None, pickle, '', t)
        s.tpc_vote(t)
        s.tpc_finish(t)

        db = ZODB.DB(s)
        # If the root can be loaded successfully, we should be okay.
        r = db.open().root()
        # But make sure it looks like a new mapping
        self.assert_(hasattr(r, 'data'))
        self.assert_(not hasattr(r, '_container'))
예제 #9
0
 def test_it(self):
     from pyramid_zodbconn import db_from_uri
     from ZODB.MappingStorage import MappingStorage
     storage = MappingStorage()
     def resolve_uri(uri):
         def storagefactory():
             return storage
         return storagefactory, {}
     db = db_from_uri('whatever', resolve_uri=resolve_uri)
     self.assertEqual(db._storage, storage)
예제 #10
0
    def setUp(self):
        # These defaults only make sense if the default encoding
        # prevents s from being promoted to Unicode.
        self.assertRaises(UnicodeError, unicode, self.s)

        # An object needs to be added to the database to
        self.db = DB(MappingStorage())
        root = self.db.open().root()
        self.bucket = root["bucket"] = Bucket()
        self.set = root["set"] = Set()
        transaction.commit()
예제 #11
0
 def dbopen(self):
     if self.db is None:
         s = MappingStorage()
         self.db = ZODB.DB(s)
     db = self.db
     if self.jar is not None:
         raise RuntimeError, 'test needs to dbclose() before dbopen()'
     jar = db.open()
     self.jar = jar
     if not jar.root().has_key('index'):
         jar.root()['index'] = TextIndex.TextIndex('text')
         transaction.commit()
     return jar.root()['index']
예제 #12
0
 def __init__(self, path=None, zodb_storage=None, connection=None):
     if all([path, zodb_storage, connection]) is False:
         zodb_storage = MappingStorage('test')
     if path is not None:
         zodb_storage = FileStorage(path)
     if zodb_storage is not None:
         self._db = DB(zodb_storage)
         self._zodb_storage = zodb_storage
         self.connection = self._db.open()
     if connection is not None:
         self.connection = connection
         self._db = self.connection._db
     self._root = self.connection.root()
예제 #13
0
    def checkOldStyleRoot(self):
        # The Persistence module doesn't exist in Zope3's idea of what ZODB
        # is, but the global `pickle` references it explicitly.  So just
        # bail if Persistence isn't available.
        try:
            import Persistence
        except ImportError:
            return
        # insert the pickle in place of the root
        s = MappingStorage()
        t = Transaction()
        s.tpc_begin(t)
        s.store('\000' * 8, None, pickle, '', t)
        s.tpc_vote(t)
        s.tpc_finish(t)

        db = ZODB.DB(s)
        # If the root can be loaded successfully, we should be okay.
        r = db.open().root()
        # But make sure it looks like a new mapping
        self.assert_(hasattr(r, 'data'))
        self.assert_(not hasattr(r, '_container'))
예제 #14
0
    def setUp(self):
        from ZODB.DB import DB
        from ZODB.MappingStorage import MappingStorage
        import transaction

        storage = MappingStorage()
        self.db = DB(storage)
        conn = self.db.open()
        root = conn.root()
        root['keepme'] = KeepMe()
        root['keepme']['extra'] = PersistentMapping()
        transaction.commit()
        conn.close()
        conn._resetCache()
    def _persist_zodb(self, obj):
        from ZODB import DB
        from ZODB.MappingStorage import MappingStorage
        import transaction

        db = DB(MappingStorage())
        conn = db.open()
        try:
            conn.root.key = obj

            transaction.commit()
        finally:
            conn.close()
            db.close()
            transaction.abort()
예제 #16
0
    def checkOldStyleRoot(self):
        # The Persistence module doesn't exist in Zope3's idea of what ZODB
        # is, but the global `pickle` references it explicitly.  So just
        # bail if Persistence isn't available.
        try:
            import Persistence
        except ImportError:
            return
        # insert the pickle in place of the root
        s = MappingStorage()
        t = Transaction()
        s.tpc_begin(t)
        s.store('\000' * 8, None, pickle, '', t)
        s.tpc_vote(t)
        s.tpc_finish(t)

        db = ZODB.DB(s)
        # If the root can be loaded successfully, we should be okay.
        r = db.open().root()
        # But make sure it looks like a new mapping
        self.assertTrue(hasattr(r, 'data'))
        self.assertTrue(not hasattr(r, '_container'))
예제 #17
0
    def TODO_checkNewPicklesAreSafe(self):
        s = MappingStorage()
        db = ZODB.DB(s)
        r = db.open().root()
        r[1] = 1
        r[2] = 2
        r[3] = r
        transaction.commit()
        # MappingStorage stores serialno + pickle in its _index.
        root_pickle = s._index['\000' * 8][8:]

        f = cStringIO.StringIO(root_pickle)
        u = cPickle.Unpickler(f)
        klass_info = u.load()
        klass = find_global(*klass_info[0])
        inst = klass.__new__(klass)
        state = u.load()
        inst.__setstate__(state)

        self.assert_(hasattr(inst, '_container'))
        self.assert_(not hasattr(inst, 'data'))
예제 #18
0
def main():
    # Yuck!  Need to cleanup forker so that the API is consistent
    # across Unix and Windows, at least if that's possible.
    if os.name == "nt":
        zaddr, tport, pid = forker.start_zeo_server('MappingStorage', ())

        def exitserver():
            import socket
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(tport)
            s.close()
    else:
        zaddr = '', random.randrange(20000, 30000)
        pid, exitobj = forker.start_zeo_server(MappingStorage(), zaddr)

        def exitserver():
            exitobj.close()

    while 1:
        pid = start_child(zaddr)
        print("started", pid)
        os.waitpid(pid, 0)

    exitserver()
예제 #19
0
 def pack(self, t, referencesf, gc=True):
     # prevent all concurrent commits during packing
     with self._commit_lock:
         MappingStorage.pack(self, t, referencesf, gc)
예제 #20
0
파일: util.py 프로젝트: bendavis78/zope
 def __init__(self, name='ConflictResolvingMappingStorage'):
     MappingStorage.__init__(self, name)
     self._old = {}
예제 #21
0
 def pack(self, t, referencesf, gc=True):
     # prevent all concurrent commits during packing
     with self._commit_lock:
         MappingStorage.pack(self, t, referencesf, gc)
예제 #22
0
파일: util.py 프로젝트: bendavis78/zope
def DB(name='Test', **dbargs):
    return _DB(MappingStorage(name), **dbargs)
예제 #23
0
 def tpc_begin(self, transaction):
     self.test_transaction = transaction
     return MappingStorage.tpc_begin(self, transaction)
예제 #24
0
def create_memory_storage():
    storage = MappingStorage()
    db = DB(storage)
    return db
예제 #25
0
 def tpc_finish(self, transaction, func=lambda tid: None):
     self._data_snapshot = None
     MappingStorage.tpc_finish(self, transaction, func)
예제 #26
0
 def tpc_abort(self, transaction):
     self._data_snapshot = None
     MappingStorage.tpc_abort(self, transaction)
예제 #27
0
 def tpc_finish(self, transaction, func=lambda tid: None):
     self._data_snapshot = None
     MappingStorage.tpc_finish(self, transaction, func)
예제 #28
0
파일: resolvers.py 프로젝트: pyzh/zodburi
 def factory():
     return MappingStorage(*args)
예제 #29
0
 def open(self):
     from ZODB.MappingStorage import MappingStorage
     return MappingStorage(self.config.name)
예제 #30
0
 def _makeBaseStorage(self):
     from ZODB.MappingStorage import MappingStorage
     return MappingStorage()
예제 #31
0
 def tpc_begin(self, transaction):
     self.test_transaction = transaction
     return MappingStorage.tpc_begin(self, transaction)
예제 #32
0
 def tpc_abort(self, transaction):
     self._data_snapshot = None
     MappingStorage.tpc_abort(self, transaction)
예제 #33
0
 def _makeBaseStorage(self):
     from ZODB.MappingStorage import MappingStorage
     return ZODB.tests.hexstorage.HexStorage(MappingStorage())
예제 #34
0
 def factory():
     storage = MappingStorage(*args)
     return DB(storage, **dbkw)
예제 #35
0
class Account(Persistent):
    def __init__(self):
        self.balance = 0.0

    def deposit(self, amount):
        self.balance += amount

    def cash(self, amount):
        assert amount < self.balance
        self.balance -= amount


if False:
    storage = FileStorage('Data.fs')
else:
    storage = MappingStorage()

db = DB(storage)
conn = db.open()
dbroot = conn.root()

print dbroot.keys()

if not dbroot.has_key('subscriptions'):
    print 'initializing subscriptions'
    dbroot['subscriptions'] = OOBTree()
    t = dbroot['subscriptions']
    for b in ['foo', 'bar', 'foobar']:
        BASEURI = "http://example.com/%s" % b
        for i in xrange(5):
            t[BASEURI + '#event%d' % i] = [i, 1, 2, 3]