provide method to test if an entity instance is stored
Is your feature request related to a problem? Please describe.
I want to write test cases to check if an entity instance is stored. However, it seems that there is no method in eclipse-store to check if an entity instance is stored. Such method can be also useful for other cases.
Describe the solution you'd like
Please provide a method something like
long StorageManager#isStored(Object o), which returns
- 0 if entity instance is not stored
- a UTC timestamp in milliseconds indicating when the data was last saved (or updated).
Small tip: You can use storageManager.persistenceManager().objectRegistry().lookupObjectId(s);. This returns the objectId if the object is stored, and -1 if the object is not in storage yet.
@zdenek-jonas Thanks! I think this solves this issue, but we should keep in mind that in case of lazy storage (which is the default), the object ID is not always returned immediately. However, that's okay as I can switch to eager storage for test cases.
Is there a way to get a UTC timestamp in milliseconds indicating when the data was last saved (or updated) by eclipse-store? Maybe it's already stored somewhere internally for administration.
There is a time stamp but no simple way to get that. We write a time stamp to the storage transaction log file at every store. The time stamp is produced by a org.eclipse.store.storage.types.StorageTimestampProvider. The default implementation is org.eclipse.store.storage.types.StorageTimestampProvider.MonotonicTime.
You may replace that with a custom implementation that allows you to get the last generated value.
The StorageFoundation has a setter to setup that custom one:
EmbeddedStorageFoundation.New()
.setTimestampProvider(...)
There is a time stamp but no simple way to get that.
It would be good if it could be done in a simpler way, for example with a method in storageManger#persistenceManager().objectRegistry():
lastStored(Object o) or getLastSync(Object o) with
- 0 if entity instance is currently not stored
- a UTC timestamp in milliseconds indicating when the data was last saved (or updated).
What do you think?
Many thanks for your proposal.
Adding an object specific time stamp would be a bigger feature that requires a detailed requirement analysis, I doubt that we will implement that in the near future.
I’m not sure if it helps but there is a logger available that can log every object store. To do so you need to enable the ‘org.eclipse.serializer.persistence.binary.types.BinaryStorer’ logger with log level ‘debug’