Library for Data Model Framework.
Each Data Model (DM) represents one object persisted in a possibly remote, real-time-updated data source (DS) that supports SQL. It is designed to be:
Each DM is assigned with a universally-unique identifier called DOID (does not necessarily comply with the UUID format) generated (non-cryptographically-secure) randomly.
After a DM is asynchronously requested from the DS, it is cached locally for a period of time. This allows the caller to confidently reuse the objects without asynchronous logic.
If a DM has not been used for a long time, it is removed from the cache. Therefore, under normal circumstances, the data requester should access the DM asynchronously, and should not store a reference to the DM.
Alternatively, the data requester can apply a DataModelUser
on a DM. If there is at least one DataModelUser
active on a DataModel, it is guaranteed to retain in the cache.
Local changes to the DM are saved to the DS in batches. DS changes are also unpacked to the local object periodically. Implementations
Each DM contains a "state" property, which is a unique identifier generated (non-cryptographically-secure) randomly. The state is regenerated every time a batch is saved to the DS, which allows tracking concurrent changes. LibDMF will modify the database only if it is still at the locally-known state. The batch is rejected if the local state is outdated by the time the batch arrives at the DS. This rejection can be handled by the context that created the batch.