Skip to content
Snippets Groups Projects

Feature/couchdb update commit

Closed Sebastian Heppner requested to merge feature/couchdb_update_commit into master
3 unresolved threads
Files
3
+ 56
3
@@ -427,7 +427,45 @@ class CouchDBObjectStore(model.AbstractObjectStore):
@@ -427,7 +427,45 @@ class CouchDBObjectStore(model.AbstractObjectStore):
# #################################################################################################
# #################################################################################################
# Special object classes for Identifiable PyI40AAS objects retrieved from the CouchDBObjectStore
# Special object classes for Identifiable PyI40AAS objects retrieved from the CouchDBObjectStore
class CouchDBIdentifiable(model.Identifiable, metaclass=abc.ABCMeta):
class CouchDBReferable(model.Referable, metaclass=abc.ABCMeta):
    • How is this class used? As far as I can see, this base class is not applied to the Referable objects which are returned from the CouchDB. However, this is required to make the implemented functionality work.

Please register or sign in to reply
 
"""
 
Special base class for Referable PyI40AAs retrieved from the CouchDBObjectStore, allowing to write back (commit)
 
and update changes to and from the database.
 
 
This is an abstract base class. For each Referable AAS object type, there is one subclass, inheriting from this
 
abstract base class and the appropriate aas.model class.
 
"""
 
def __init__(self) -> None:
 
super().__init__()
 
self._store: Optional[CouchDBObjectStore] = None
 
self.couchdb_revision: Optional[str] = None
 
 
def commit(self) -> None:
 
if self._store is None:
 
raise ValueError("CouchDBIdentifiable is not associated with a store")
 
if not self.parent:
 
raise ValueError("Object does not have a parent") # todo: What happens if object has no parent?
 
if isinstance(self.parent, model.Referable):
 
self.parent.commit()
 
 
def update(self, timeout: float = 0) -> None:
 
"""
 
Updates the Referable from the CouchDB
 
 
:param timeout:
 
"""
 
if self._store is None:
 
raise ValueError("CouchDBIdentifiable is not associated with a store")
 
if isinstance(self, CouchDBIdentifiable):
 
self.update(timeout)
 
else:
 
if not self.parent:
 
raise ValueError("Object does not have a parent")
 
if isinstance(self.parent, model.Referable): # which should be always the case
 
self.parent.update(timeout)
 
 
 
class CouchDBIdentifiable(CouchDBReferable, model.Identifiable, metaclass=abc.ABCMeta):
"""
"""
Special base class for Identifiable PyI40AAS retrieved from the CouchDBObjectStore, allowing to write back (commit)
Special base class for Identifiable PyI40AAS retrieved from the CouchDBObjectStore, allowing to write back (commit)
changes to the database.
changes to the database.
@@ -435,7 +473,7 @@ class CouchDBIdentifiable(model.Identifiable, metaclass=abc.ABCMeta):
@@ -435,7 +473,7 @@ class CouchDBIdentifiable(model.Identifiable, metaclass=abc.ABCMeta):
This is an abstract base class. For each Identifiable AAS object type, there is one subclass, inheriting from this
This is an abstract base class. For each Identifiable AAS object type, there is one subclass, inheriting from this
abstract base class and the appropriate aas.model class.
abstract base class and the appropriate aas.model class.
This base class provides the `commit_changes()` method and the `_store` and `couchdb_revision` attributes required
This base class provides the `commit()` method and the `_store` and `couchdb_revision` attributes required
to perform the commit action. `_store` holds a reference to the CouchDBObjectStore instance; `couchdb_revision`
to perform the commit action. `_store` holds a reference to the CouchDBObjectStore instance; `couchdb_revision`
contains the CouchDB document revision token of the latest object revision in the database. It is transferred to
contains the CouchDB document revision token of the latest object revision in the database. It is transferred to
CouchDB when committing changes to check for editing conflicts.
CouchDB when committing changes to check for editing conflicts.
@@ -446,11 +484,26 @@ class CouchDBIdentifiable(model.Identifiable, metaclass=abc.ABCMeta):
@@ -446,11 +484,26 @@ class CouchDBIdentifiable(model.Identifiable, metaclass=abc.ABCMeta):
self._store: Optional[CouchDBObjectStore] = None
self._store: Optional[CouchDBObjectStore] = None
self.couchdb_revision: Optional[str] = None
self.couchdb_revision: Optional[str] = None
def commit_changes(self) -> None:
def commit(self) -> None:
 
"""
 
Commits the changes made to the Identifiable to the CouchDB
 
 
todo: does one have docstrings as well?
 
"""
if self._store is None:
if self._store is None:
raise ValueError("CouchDBIdentifiable is not associated with a store")
raise ValueError("CouchDBIdentifiable is not associated with a store")
self._store.commit(self)
self._store.commit(self)
 
def update(self, timeout: float = 0) -> None:
 
"""
 
Updates the Identifiable from the CouchDB
 
 
:param timeout:
 
"""
 
if self._store is None:
 
raise ValueError("CouchDBIdentifiable is not associated with a store")
 
self.update_from(self._store.get_identifiable(self.identification))
 
class CouchDBAssetAdministrationShell(model.AssetAdministrationShell, CouchDBIdentifiable):
class CouchDBAssetAdministrationShell(model.AssetAdministrationShell, CouchDBIdentifiable):
pass
pass
Loading