Views are now rollbacked if an error occurs, and unfinished views and
columns are deleted when an OBIDMS is opened.
This commit is contained in:
@ -102,6 +102,10 @@ cdef extern from "obiview.h" nogil:
|
||||
|
||||
int obi_save_and_close_view(Obiview_p view)
|
||||
|
||||
int obi_clean_unfinished_views(OBIDMS_p dms)
|
||||
|
||||
int obi_rollback_view(Obiview_p view)
|
||||
|
||||
|
||||
# OBI_INT
|
||||
int obi_set_int_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
|
@ -28,11 +28,11 @@ from .object import OBIWrapper
|
||||
|
||||
cdef class DMS(OBIWrapper):
|
||||
|
||||
cdef inline OBIDMS_p pointer(self):
|
||||
cdef inline OBIDMS_p pointer(self) :
|
||||
return <OBIDMS_p>(self._pointer)
|
||||
|
||||
@staticmethod
|
||||
def obi_atexit():
|
||||
def obi_atexit() :
|
||||
atexit(obi_close_atexit)
|
||||
|
||||
@staticmethod
|
||||
@ -50,7 +50,7 @@ cdef class DMS(OBIWrapper):
|
||||
return dms
|
||||
|
||||
@staticmethod
|
||||
def exists(object dms_name):
|
||||
def exists(object dms_name) :
|
||||
cdef bytes dms_name_b = tobytes(dms_name)
|
||||
cdef int rep
|
||||
rep = obi_dms_exists(dms_name_b)
|
||||
@ -90,7 +90,6 @@ cdef class DMS(OBIWrapper):
|
||||
The `close` method is automatically called by the object destructor.
|
||||
'''
|
||||
cdef OBIDMS_p pointer = self.pointer()
|
||||
|
||||
if self.active() :
|
||||
OBIWrapper.close(self)
|
||||
if (obi_close_dms(pointer)) < 0 :
|
||||
|
@ -1,2 +1,3 @@
|
||||
from .view import View # @UnresolvedImport
|
||||
from .view import Line_selection # @UnresolvedImport
|
||||
from .view import RollbackException # @UnresolvedImport
|
@ -10,6 +10,7 @@ from ..capi.obiview cimport Alias_column_pair_p, \
|
||||
obi_new_view, \
|
||||
obi_open_view, \
|
||||
obi_clone_view, \
|
||||
obi_rollback_view, \
|
||||
obi_save_and_close_view, \
|
||||
obi_view_get_pointer_on_column_in_view, \
|
||||
obi_view_delete_column, \
|
||||
@ -69,7 +70,7 @@ cdef class View(OBIWrapper) :
|
||||
|
||||
cdef bytes view_name_b = tobytes(view_name)
|
||||
cdef bytes comments_b
|
||||
cdef str message
|
||||
cdef str message
|
||||
cdef void* pointer
|
||||
|
||||
cdef View view # @DuplicatedSignature
|
||||
@ -103,7 +104,7 @@ cdef class View(OBIWrapper) :
|
||||
cdef bytes view_name_b = tobytes(view_name)
|
||||
cdef bytes comments_b
|
||||
cdef void* pointer
|
||||
cdef View view
|
||||
cdef View view
|
||||
|
||||
if not self.active() :
|
||||
raise OBIDeactivatedInstanceError()
|
||||
@ -231,8 +232,8 @@ cdef class View(OBIWrapper) :
|
||||
|
||||
# Remove the column from the view which closes the C structure
|
||||
if obi_view_delete_column(self.pointer(), column_name_b) < 0 :
|
||||
raise Exception("Problem deleting column %s from a view",
|
||||
bytes2str(column_name_b))
|
||||
raise RollbackException("Problem deleting column %s from a view",
|
||||
bytes2str(column_name_b), self)
|
||||
|
||||
|
||||
cpdef rename_column(self,
|
||||
@ -249,9 +250,9 @@ cdef class View(OBIWrapper) :
|
||||
if (obi_view_create_column_alias(self.pointer(),
|
||||
tobytes(current_name_b),
|
||||
tobytes(new_name_b)) < 0) :
|
||||
raise Exception("Problem in renaming column %s to %s" % (
|
||||
raise RollbackException("Problem in renaming column %s to %s" % (
|
||||
bytes2str(current_name_b),
|
||||
bytes2str(new_name_b)))
|
||||
bytes2str(new_name_b)), self)
|
||||
|
||||
|
||||
# TODO warning, not multithreading compliant
|
||||
@ -434,7 +435,7 @@ cdef class Line :
|
||||
|
||||
if column_name_b not in self._view :
|
||||
if value == None :
|
||||
raise Exception("Trying to create a column from a None value (can't guess type)")
|
||||
raise RollbackException("Trying to create a column from a None value (can't guess type)", self)
|
||||
value_type = type(value)
|
||||
if value_type == int :
|
||||
value_obitype = OBI_INT
|
||||
@ -454,7 +455,7 @@ cdef class Line :
|
||||
elif (len(value) > 1) :
|
||||
value_obitype = OBI_STR
|
||||
else :
|
||||
raise Exception("Could not guess the type of a value to create a new column")
|
||||
raise RollbackException("Could not guess the type of a value to create a new column", self)
|
||||
|
||||
Column.new_column(self._view, column_name_b, value_obitype)
|
||||
|
||||
@ -622,6 +623,19 @@ cdef class Line_selection(list):
|
||||
#############################################################
|
||||
|
||||
|
||||
class RollbackException(Exception):
|
||||
def __init__(self, message, View view):
|
||||
super(RollbackException, self).__init__(message)
|
||||
if obi_rollback_view(<Obiview_p>(view.pointer())) < 0 :
|
||||
raise Exception("Error rollbacking view")
|
||||
if view.active() :
|
||||
view._dms.unregister(view)
|
||||
OBIWrapper.close(view)
|
||||
|
||||
|
||||
#############################################################
|
||||
|
||||
|
||||
cdef register_view_class(bytes view_type_name,
|
||||
type view_class):
|
||||
'''
|
||||
|
Reference in New Issue
Block a user