Commit 0db5b119 authored by Aurel's avatar Aurel

fix indentation and redefined all needed methods by ZODB which don't

follow the BaseStorage behaviour


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@51 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f117cdaa
...@@ -3,114 +3,139 @@ from ZODB import BaseStorage, ConflictResolution, POSException ...@@ -3,114 +3,139 @@ from ZODB import BaseStorage, ConflictResolution, POSException
from ZODB.utils import p64, u64, cp, z64 from ZODB.utils import p64, u64, cp, z64
class NEOStorageError(POSException.StorageError): class NEOStorageError(POSException.StorageError):
pass pass
class NEOStorageConflictError(NEOStorageError): class NEOStorageConflictError(NEOStorageError):
pass pass
class NEOStorageNotFoundError(NEOStorageError): class NEOStorageNotFoundError(NEOStorageError):
pass pass
class NEOStorage(BaseStorage.BaseStorage, class NEOStorage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage): ConflictResolution.ConflictResolvingStorage):
"""Wrapper class for neoclient.""" """Wrapper class for neoclient."""
def __init__(self, master_addr, master_port, read_only=False, **kw): def __init__(self, master_addr, master_port, read_only=False, **kw):
self._is_read_only = read_only self._is_read_only = read_only
from neo.client.app import Application # here to prevent recursive import from neo.client.app import Application # here to prevent recursive import
self.app = Application(master_addr, master_port) self.app = Application(master_addr, master_port)
def load(self, oid, version=None): def load(self, oid, version=None):
try: try:
self.app.load(oid) self.app.load(oid)
except NEOStorageNotFoundError: except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid) raise POSException.POSKeyError (oid)
def close(self): def close(self):
self.app.close() self.app.close()
def cleanup(self): def cleanup(self):
self.app.cleanup() self.app.cleanup()
def lastSerial(self): def lastSerial(self):
self.app.lastSerial() self.app.lastSerial()
def lastTransaction(self): def lastTransaction(self):
self.app.lastTransaction() self.app.lastTransaction()
def new_oid(self): def new_oid(self):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
self.app.new_oid() self.app.new_oid()
def tpc_begin(self, transaction, tid=None, status=' '): def tpc_begin(self, transaction, tid=None, status=' '):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
self.app.tpc_begin(transaction, tid, status) self.app.tpc_begin(transaction, tid, status)
def tpc_vote(self, transaction): def tpc_vote(self, transaction):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
self.app.tpc_vote(transaction) self.app.tpc_vote(transaction)
def tpc_abort(self, transaction): def tpc_abort(self, transaction):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
self.app.tpc_abort(transaction) self.app.tpc_abort(transaction)
def tpc_finish(self, transaction, f=None): def tpc_finish(self, transaction, f=None):
self.app.tpc_finish(transaction, f) self.app.tpc_finish(transaction, f)
def store(self, oid, serial, data, version, transaction): def store(self, oid, serial, data, version, transaction):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
try: try:
self.app.store(oid, serial, data, version, transaction) self.app.store(oid, serial, data, version, transaction)
except NEOStorageConflictError: except NEOStorageConflictError:
new_data = self.app.tryToResolveConflict(oid, self.app.tid, serial, data) new_data = self.app.tryToResolveConflict(oid, self.app.tid,
if new_data is not None: serial, data)
# try again after conflict resolution if new_data is not None:
self.store(oid, serial, new_data, version, transaction) # try again after conflict resolution
else: self.store(oid, serial, new_data, version, transaction)
raise POSException.ConflictError(oid=oid, else:
serials=(self.app.tid, serial), data=data) raise POSException.ConflictError(oid=oid,
serials=(self.app.tid,
serial),data=data)
def _clear_temp(self): def _clear_temp(self):
self.app._clear_temp() self.app._clear_temp()
# mutliple revisions def getSerial(self, oid):
def loadSerial(self, oid, serial): try:
try: self.app.getSerial(oid)
self.app.loadSerial(oid,serial) except NEOStorageNotFoundError:
except NEOStorageNotFoundError: raise POSException.POSKeyError (oid)
raise POSException.POSKeyError (oid, serial)
def loadBefore(self, oid, tid):
try:
self.app.loadBefore(self, oid, tid)
except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid, tid)
def iterator(self, start=None, stop=None):
self.app.iterator(start, stop)
# undo
def undo(self, transaction_id, txn):
if self._is_read_only:
raise POSException.ReadOnlyError()
self.app.undo(transaction_id, txn)
def undoInfo(self, first=0, last=-20, specification=None):
# XXX is it needed ?
if self._is_read_only:
raise POSException.ReadOnlyError()
self.app.undoInfo(first, last, specification)
def undoLog(self, first, last, filter): # mutliple revisions
if self._is_read_only: def loadSerial(self, oid, serial):
raise POSException.ReadOnlyError() try:
self.app.undoLog(first, last, filter) self.app.loadSerial(oid,serial)
except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid, serial)
def loadBefore(self, oid, tid):
try:
self.app.loadBefore(self, oid, tid)
except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid, tid)
def iterator(self, start=None, stop=None):
raise NotImplementedError
# undo
def undo(self, transaction_id, txn):
if self._is_read_only:
raise POSException.ReadOnlyError()
self.app.undo(transaction_id, txn)
def undoInfo(self, first=0, last=-20, specification=None):
if self._is_read_only:
raise POSException.ReadOnlyError()
self.app.undoInfo(first, last, specification)
def undoLog(self, first, last, filter):
if self._is_read_only:
raise POSException.ReadOnlyError()
# This should not be used by ZODB
# instead it should use undoInfo
# Look at ZODB/interface.py for more info
if filter is not None:
return []
else:
return self.undoInfo(first, last)
def supportsUndo(self):
return 0
def abortVersion(self, src, transaction):
return '', []
def commitVersion(self, src, dest, transaction):
return '', []
def set_max_oid(self, possible_new_max_oid):
# seems to be only use by FileStorage
raise NotImplementedError
def copyTransactionsFrom(self, other, verbose=0):
raise NotImplementedError
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