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()
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
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
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()
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()
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'))
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)
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()
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']
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()
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'))
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()
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'))
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'))
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()
def pack(self, t, referencesf, gc=True): # prevent all concurrent commits during packing with self._commit_lock: MappingStorage.pack(self, t, referencesf, gc)
def __init__(self, name='ConflictResolvingMappingStorage'): MappingStorage.__init__(self, name) self._old = {}
def DB(name='Test', **dbargs): return _DB(MappingStorage(name), **dbargs)
def tpc_begin(self, transaction): self.test_transaction = transaction return MappingStorage.tpc_begin(self, transaction)
def create_memory_storage(): storage = MappingStorage() db = DB(storage) return db
def tpc_finish(self, transaction, func=lambda tid: None): self._data_snapshot = None MappingStorage.tpc_finish(self, transaction, func)
def tpc_abort(self, transaction): self._data_snapshot = None MappingStorage.tpc_abort(self, transaction)
def factory(): return MappingStorage(*args)
def open(self): from ZODB.MappingStorage import MappingStorage return MappingStorage(self.config.name)
def _makeBaseStorage(self): from ZODB.MappingStorage import MappingStorage return MappingStorage()
def _makeBaseStorage(self): from ZODB.MappingStorage import MappingStorage return ZODB.tests.hexstorage.HexStorage(MappingStorage())
def factory(): storage = MappingStorage(*args) return DB(storage, **dbkw)
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]