[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 - db.py:1.2 storage.py:1.2
Shane Hathaway
shane@zope.com
Tue, 29 Apr 2003 18:12:22 -0400
Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv9561/zodb3
Modified Files:
db.py storage.py
Log Message:
- Added IGatewayEvent, the base interface for ILoadEvent and
IStoreEvent.
- Filesystem gateways no longer refer directly to a connection. They
get the connection from the event. This is to permit replacing the
connection with a zip/tar file reader/writer or some other interesting
thing.
- Added checkConnection() to gateways for checking the connection
configuration early.
- Added ConfigurationError and changed some places that were raising
RuntimeError to raise ConfigurationError instead.
- Changed some calls to getKeyChain()[-1] to simply getKey()
- Updated module import style in some places
- Various other style improvements
=== Products/Ape/lib/apelib/zodb3/db.py 1.1 => 1.2 ===
--- Products/Ape/lib/apelib/zodb3/db.py:1.1 Wed Apr 9 23:09:58 2003
+++ Products/Ape/lib/apelib/zodb3/db.py Tue Apr 29 18:11:51 2003
@@ -19,6 +19,7 @@
from ZODB.DB import DB, Transaction, cPickle, cStringIO, allocate_lock
from apelib.core.interfaces import IMapper
+from apelib.core.exceptions import ConfigurationError
from connection import ApeConnection
from storage import ApeStorage
from oidencoder import OIDEncoder
@@ -31,7 +32,8 @@
"""
pos = factory.rfind('.')
if pos < 0:
- raise ValueError('factory must be a string containing <module>.<name>')
+ raise ConfigurationError(
+ 'factory must be a string containing <module>.<name>')
module = factory[:pos]
name = factory[pos + 1:]
m = __import__(module, {}, {}, (name,))
@@ -62,7 +64,7 @@
if mapper_resource is None:
if factory is not None:
# Use a mapper factory
- mapper, tpc_conns = callMapperFactory(factory)
+ mapper, connections = callMapperFactory(factory)
assert IMapper.isImplementedBy(mapper)
mapper_resource = StaticResource(mapper)
else:
@@ -70,7 +72,7 @@
# Use the mapper from the storage
mapper_resource = storage.getMapperResource()
else:
- raise RuntimeError('No mapper or factory specified')
+ raise ConfigurationError('No mapper or factory specified')
else:
# mapper_resource was specified
assert IResourceAccess.isImplementedBy(mapper_resource)
=== Products/Ape/lib/apelib/zodb3/storage.py 1.1 => 1.2 ===
--- Products/Ape/lib/apelib/zodb3/storage.py:1.1 Wed Apr 9 23:09:58 2003
+++ Products/Ape/lib/apelib/zodb3/storage.py Tue Apr 29 18:11:51 2003
@@ -24,7 +24,7 @@
from apelib.core.events import MapperEvent, LoadEvent, StoreEvent
from apelib.core.interfaces import ITPCConnection
-from apelib.core.exceptions import NoStateFoundError
+from apelib.core.exceptions import NoStateFoundError, ConfigurationError
from consts import HASH0, HASH1, DEBUG
from oidencoder import OIDEncoder
from interfaces import IResourceAccess, IOIDEncoder
@@ -32,8 +32,14 @@
class ApeStorage(BaseStorage.BaseStorage):
- def __init__(self, mapper_resource, tpc_conns=(),
+ def __init__(self, mapper_resource, connections,
oid_encoder=None, name=''):
+ """Initializes an ApeStorage.
+
+ mapper_resource is a resource for loading the mapper.
+ connections is a mapping that maps names to ITPCConnections.
+ oid_encoder is an IOIDEncoder.
+ """
assert IResourceAccess.isImplementedBy(mapper_resource)
self._mapper_resource = mapper_resource
if oid_encoder is None:
@@ -41,23 +47,32 @@
else:
assert IOIDEncoder.isImplementedBy(oid_encoder)
self._oid_encoder = oid_encoder
- self._tpc_conns = tpc_conns
+ self._conn_map = connections
sort_keys = []
names = []
try:
- opened = []
- for c in tpc_conns:
+ opened = [] # [(sort_key, conn),]
+ for c in connections.values():
if not ITPCConnection.isImplementedBy(c):
- raise RuntimeError('%s is not an ITPCConnection' % repr(c))
+ raise ConfigurationError(
+ '%s does not implement ITPCConnection' % repr(c))
+ sort_key = c.sortKey()
+ sort_keys.append(sort_key)
c.connect()
- opened.append(c)
- sort_keys.append(c.sortKey())
+ opened.append((sort_key, c))
names.append(c.getName())
except:
- for c in opened:
+ for sort_key, c in opened:
c.close()
raise
self._sort_key = tuple(sort_keys)
+
+ opened.sort()
+ conn_list = []
+ for sort_key, c in opened:
+ conn_list.append(c)
+ self._conn_list = conn_list
+
if not name:
name = 'ApeStorage: ' + ', '.join(names)
BaseStorage.BaseStorage.__init__(self, name)
@@ -95,11 +110,11 @@
k = keychain[:i + 1]
cfr = mapper.getClassifier()
assert cfr is not None, keychain
- event = LoadEvent(mapper, k)
+ event = LoadEvent(mapper, k, self._conn_map)
classification, sub_mapper_name = cfr.classifyState(event)
mapper_names.append(sub_mapper_name)
mapper = mapper.getSubMapper(sub_mapper_name)
- event = LoadEvent(mapper, keychain)
+ event = LoadEvent(mapper, keychain, self._conn_map)
if hash_only:
event.hash_only = 1
full_state, hash_value = mapper.getGateway().load(event)
@@ -180,7 +195,7 @@
for mapper_name in mapper_names:
cfr = mapper.getClassifier()
mapper = mapper.getSubMapper(mapper_name)
- event = StoreEvent(mapper, keychain)
+ event = StoreEvent(mapper, keychain, self._conn_map)
new_hash = mapper.getGateway().store(event, state)
if cfr is not None:
cfr.store(event, classification)
@@ -204,19 +219,19 @@
pass
def _abort(self):
- for c in self._tpc_conns:
+ for c in self._conn_list:
c.abort()
def _begin(self, tid, u, d, e):
- for c in self._tpc_conns:
+ for c in self._conn_list:
c.begin()
def _finish(self, tid, user, desc, ext):
- for c in self._tpc_conns:
+ for c in self._conn_list:
c.finish()
def _vote(self):
- for c in self._tpc_conns:
+ for c in self._conn_list:
c.vote()
def pack(self, t, referencesf):
@@ -228,7 +243,7 @@
return ''
def close(self):
- for c in self._tpc_conns:
+ for c in self._conn_list:
c.close()
self._mapper_resource.release(self)