Commit 6d7aa44f authored by Aurel's avatar Aurel

remove all use of u64 and p64 as it is useless

manage exception in all methods


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@116 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f99797e4
...@@ -20,6 +20,8 @@ NEO_ERROR = 'neo_error' ...@@ -20,6 +20,8 @@ NEO_ERROR = 'neo_error'
NEO_CONFLICT_ERROR = 'neo_conflict_error' NEO_CONFLICT_ERROR = 'neo_conflict_error'
NEO_NOT_FOUND_ERROR = 'neo_not_found_error' NEO_NOT_FOUND_ERROR = 'neo_not_found_error'
import logging
class NEOStorage(BaseStorage.BaseStorage, class NEOStorage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage): ConflictResolution.ConflictResolvingStorage):
"""Wrapper class for neoclient.""" """Wrapper class for neoclient."""
...@@ -51,11 +53,11 @@ class NEOStorage(BaseStorage.BaseStorage, ...@@ -51,11 +53,11 @@ class NEOStorage(BaseStorage.BaseStorage,
message_queue, request_queue) message_queue, request_queue)
def load(self, oid, version=None): def load(self, oid, version=None):
r = self.app.process_method('load', oid=u64(oid)) r = self.app.process_method('load', oid=oid)
if r == NEO_NOT_FOUND_ERROR: if r == NEO_NOT_FOUND_ERROR:
raise POSException.POSKeyError (oid) raise POSException.POSKeyError (oid)
else: else:
return r return r[0], r[1]
def close(self): def close(self):
return self.app.process_method('close') return self.app.process_method('close')
...@@ -74,41 +76,60 @@ class NEOStorage(BaseStorage.BaseStorage, ...@@ -74,41 +76,60 @@ class NEOStorage(BaseStorage.BaseStorage,
def new_oid(self): def new_oid(self):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
return self.app.process_method('new_oid') r = self.app.process_method('new_oid')
if r in (NEO_ERROR, NEO_NOT_FOUND_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
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._txn_lock_acquire() self._txn_lock_acquire()
return self.app.process_method('tpc_begin', transaction=transaction, tid=tid, status=status) r = self.app.process_method('tpc_begin', transaction=transaction, tid=tid, status=status)
if r in (NEO_ERROR, NEO_NOT_FOUND_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
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()
return self.app.process_method('tpc_vote', transaction=transaction) r = self.app.process_method('tpc_vote', transaction=transaction)
if r in (NEO_ERROR, NEO_NOT_FOUND_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
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()
try: try:
return self.app.process_method('tpc_abort', transaction=transaction) r = return self.app.process_method('tpc_abort', transaction=transaction)
except: if r in (NEO_ERROR, NEO_NOT_FOUND_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
finally:
self._txn_lock_release() self._txn_lock_release()
def tpc_finish(self, transaction, f=None): def tpc_finish(self, transaction, f=None):
try: try:
return self.app.process_method('tpc_finish', transaction=transaction, f=f) r = self.app.process_method('tpc_finish', transaction=transaction, f=f)
except: if r in (NEO_ERROR, NEO_NOT_FOUND_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
finally:
self._txn_lock_release() self._txn_lock_release()
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: r = self.app.process_method('store', oid=oid, serial=serial, data=data,
return self.app.process_method('store', oid=oid, serial=serial, data=data, version=version, transaction=transaction)
version=version, transaction=transaction) if r == NEO_CONFLICT_ERROR:
except NEOStorageConflictError, conflict_serial: if self.app.conflict_serial <= self.app.tid:
if conflict_serial <= self.app.tid:
# Try to resolve conflict only if conflicting serial is older # Try to resolve conflict only if conflicting serial is older
# than the current transaction ID # than the current transaction ID
new_data = self.tryToResolveConflict(oid, self.app.tid, new_data = self.tryToResolveConflict(oid, self.app.tid,
...@@ -119,28 +140,41 @@ class NEOStorage(BaseStorage.BaseStorage, ...@@ -119,28 +140,41 @@ class NEOStorage(BaseStorage.BaseStorage,
raise POSException.ConflictError(oid=oid, raise POSException.ConflictError(oid=oid,
serials=(self.app.tid, serials=(self.app.tid,
serial),data=data) serial),data=data)
elif r in (NEO_ERROR, NEO_NOT_FOUND_ERROR):
raise NEOStorageError
else:
return r
def _clear_temp(self): def _clear_temp(self):
raise NotImplementedError raise NotImplementedError
def getSerial(self, oid): def getSerial(self, oid):
try: r = self.app.process_method('getSerial', oid=oid)
return self.app.process_method('getSerial', oid=oid) if r == NEO_NOT_FOUND_ERROR:
except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid) raise POSException.POSKeyError (oid)
elif r in (NEO_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
# mutliple revisions # mutliple revisions
def loadSerial(self, oid, serial): def loadSerial(self, oid, serial):
try: r = self.app.process_method('loadSerial', oid=oid, serial=serial)
return self.app.process_method('loadSerial', oid=u64(oid), serial=u64(serial)) if r == NEO_NOT_FOUND_ERROR:
except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid, serial) raise POSException.POSKeyError (oid, serial)
elif r in (NEO_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
def loadBefore(self, oid, tid): def loadBefore(self, oid, tid):
try: r = self.app.process_method('loadBefore', oid=oid, tid=tid)
return self.app.process_method('loadBefore', oid=u64(oid), tid=u64(tid)) if r == NEO_NOT_FOUND_ERROR:
except NEOStorageNotFoundError:
raise POSException.POSKeyError (oid, tid) raise POSException.POSKeyError (oid, tid)
elif r in (NEO_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
def iterator(self, start=None, stop=None): def iterator(self, start=None, stop=None):
raise NotImplementedError raise NotImplementedError
...@@ -151,14 +185,24 @@ class NEOStorage(BaseStorage.BaseStorage, ...@@ -151,14 +185,24 @@ class NEOStorage(BaseStorage.BaseStorage,
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
self._txn_lock_acquire() self._txn_lock_acquire()
try: try:
return self.app.process_method('undo', transaction_id=transaction_id, txn=txn, wrapper=self) r = self.app.process_method('undo', transaction_id=transaction_id, txn=txn, wrapper=self)
except: if r == NEO_CONFLICT_ERROR:
raise POSException.ConflictError
elif r in (NEO_ERROR, NOT_FOUND_ERROR):
raise NEOStorageError
else:
return r
finally:
self._txn_lock_release() self._txn_lock_release()
def undoLog(self, first, last, filter): def undoLog(self, first, last, filter):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
return self.undoLog(first, last, filter) r = self.undoLog(first, last, filter)
if r in (NEO_ERROR, NEO_NOT_FOUND_ERROR, NEO_CONFLICT_ERROR):
raise NEOStorageError
else:
return r
def supportsUndo(self): def supportsUndo(self):
return 0 return 0
......
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