Commit d4430574 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorize code checking for read-only status.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1810 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 81901896
...@@ -20,6 +20,13 @@ from ZODB import BaseStorage, ConflictResolution, POSException ...@@ -20,6 +20,13 @@ from ZODB import BaseStorage, ConflictResolution, POSException
from neo.client.app import Application from neo.client.app import Application
from neo.client.exception import NEOStorageNotFoundError from neo.client.exception import NEOStorageNotFoundError
def check_read_only(func):
def wrapped(self, *args, **kw):
if self._is_read_only:
raise POSException.ReadOnlyError()
return func(self, *args, **kw)
return wrapped
class Storage(BaseStorage.BaseStorage, class Storage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage): ConflictResolution.ConflictResolvingStorage):
"""Wrapper class for neoclient.""" """Wrapper class for neoclient."""
...@@ -38,34 +45,29 @@ class Storage(BaseStorage.BaseStorage, ...@@ -38,34 +45,29 @@ class Storage(BaseStorage.BaseStorage,
except NEOStorageNotFoundError: except NEOStorageNotFoundError:
raise POSException.POSKeyError(oid) raise POSException.POSKeyError(oid)
@check_read_only
def new_oid(self): def new_oid(self):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.new_oid() return self.app.new_oid()
@check_read_only
def tpc_begin(self, transaction, tid=None, status=' '): def tpc_begin(self, transaction, tid=None, status=' '):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.tpc_begin(transaction=transaction, tid=tid, return self.app.tpc_begin(transaction=transaction, tid=tid,
status=status) status=status)
@check_read_only
def tpc_vote(self, transaction): def tpc_vote(self, transaction):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.tpc_vote(transaction=transaction, return self.app.tpc_vote(transaction=transaction,
tryToResolveConflict=self.tryToResolveConflict) tryToResolveConflict=self.tryToResolveConflict)
@check_read_only
def tpc_abort(self, transaction): def tpc_abort(self, transaction):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.tpc_abort(transaction=transaction) return self.app.tpc_abort(transaction=transaction)
def tpc_finish(self, transaction, f=None): def tpc_finish(self, transaction, f=None):
return self.app.tpc_finish(transaction=transaction, f=f) return self.app.tpc_finish(transaction=transaction, f=f)
@check_read_only
def store(self, oid, serial, data, version, transaction): def store(self, oid, serial, data, version, transaction):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.store(oid=oid, serial=serial, return self.app.store(oid=oid, serial=serial,
data=data, version=version, transaction=transaction, data=data, version=version, transaction=transaction,
tryToResolveConflict=self.tryToResolveConflict) tryToResolveConflict=self.tryToResolveConflict)
...@@ -93,16 +95,14 @@ class Storage(BaseStorage.BaseStorage, ...@@ -93,16 +95,14 @@ class Storage(BaseStorage.BaseStorage,
return self.app.iterator(start, stop) return self.app.iterator(start, stop)
# undo # undo
@check_read_only
def undo(self, transaction_id, txn): def undo(self, transaction_id, txn):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.undo(transaction_id=transaction_id, txn=txn, return self.app.undo(transaction_id=transaction_id, txn=txn,
tryToResolveConflict=self.tryToResolveConflict) tryToResolveConflict=self.tryToResolveConflict)
@check_read_only
def undoLog(self, first, last, filter=None): def undoLog(self, first, last, filter=None):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.undoLog(first, last, filter) return self.app.undoLog(first, last, filter)
def supportsUndo(self): def supportsUndo(self):
......
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