Commit 2db8f91c authored by Christian Theune's avatar Christian Theune

- added test for getSize()

 - fixed problem handling data manager registrations for non-default 
   transaction managers
parent 88a40ec1
......@@ -26,6 +26,12 @@ class Blob(Persistent):
# blobs here.
_p_blob_manager = None
# Blobs need to participate in transactions even when not connected to
# a database yet. If you want to use a non-default transaction manager,
# you can override it via _p_blob_transaction. This is currently
# required for unit testing.
_p_blob_transaction = None
def open(self, mode="r"):
""" Returns a file(-like) object representing blob data. This
method will either return the file object, raise a BlobError
......@@ -75,7 +81,7 @@ class Blob(Persistent):
# Re-use existing working copy
uncommitted = BlobFile(self._p_blob_uncommitted, mode, self)
self._p_blob_writers +=1
self._p_blob_writers += 1
result = uncommitted
else:
......@@ -92,7 +98,21 @@ class Blob(Persistent):
if self._p_blob_manager is None:
dm = BlobDataManager(self, result)
transaction.get().register(dm)
# Blobs need to always participate in transactions.
if self._p_jar:
# If we are connected to a database, then we register
# with the transaction manager for that.
self._p_jar.transaction_manager.get().register(dm)
else:
# If we are not connected to a database, we check whether
# we have been given an explicit transaction manager
if self._p_blob_transaction:
self._p_blob_transaction.get().register(dm)
else:
# Otherwise we register with the default
# transaction manager as an educated guess.
transaction.get().register(dm)
else:
# each blob data manager should manage only the one blob
# assert that this is the case and it is the correct blob
......
......@@ -170,11 +170,21 @@ connections should result in a write conflict error.
>>> blob1c3fh1.write('this is from connection 3')
>>> blob1c4fh1.write('this is from connection 4')
>>> tm1.get().commit()
>>> root3['blob1'].open('r').read()
'this is blob 1woot!this is from connection 3'
>>> tm2.get().commit()
Traceback (most recent call last):
...
ConflictError: database conflict error (oid 0x01, class ZODB.Blobs.Blob.Blob)
BlobStorages implementation of getSize() includes the blob data and adds it to
the underlying storages result of getSize():
>>> underlying_size = base_storage.getSize()
>>> blob_size = blob_storage.getSize()
>>> blob_size - underlying_size
91L
We don't need the storage directory and databases anymore:
>>> import shutil
......@@ -182,3 +192,4 @@ We don't need the storage directory and databases anymore:
>>> tm1.get().abort()
>>> tm2.get().abort()
>>> database.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment