Hi,
Am 22.04.15 um 22:48 schrieb Alexander Kiel:
> I often need a conditional PUT to prevent my users from the lost update
> problem. I use etags in conjuction with the If-Match header to implement
> conditional updates with PUT. Liberator however separates the
> decision etag-matches-for-if-match? from the put! action. The Datomic
> transaction will be executed inside the put! action. That means that I
> have to calculate the etag outside a Datomic transaction. But doing so
> is not correct. Calculating the etag based on the most current database
> known to the peer right before sending the transaction is just wrong.
> One has to calculate the etag based on the database provided inside a
> transaction function because that is the only database which will stay
> current until the transaction completes. All other databases could be
> superseded in the meantime by other transactions.
I would use a transaction function that checks and maintains a version
of the entity. Like the built-in function :db.fn/cas but for the entity,
not a single attribute. This is like optimistic concurrency is typically
handled in a SQL database. For your resource implementation that means
it would look up the current version attribute in :etag. In :conflict?
you'd do the actual update with the transaction function which should
fail in case of an interim change and make :conflict? return true.
-billy.
--
Philipp Meier