SQLFeatureStore: Fix lost updates in multi-part transactions #521
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this patch, multi-part transactions against the SQLFeatureStore could lead to lost updates. Here's an example of such a transaction (in the form of a WFS 2.0 transaction):
For this example, the first update was lost and only the second one was applied. This has been observed for BLOB mode.
The cause for the problem was that the SQLFeatureStore always acquired a new JDBC connection, even when being used by an SQLFeatureStoreTransaction object as part of the transaction. After the patch, the SQLFeatureStore uses a ThreadLocal object to determine if the current thread has an active transaction and uses it, if this is the case.
It may not be ideal to limit the use of an SQLFeatureStoreTransaction instance to a single thread, but IMHO, there is no realistic use case for using it from multiple threads. Therefore, I consider the patch to be "good enough", unless somebody wants to fully correct and refactor the design of SQLFeatureStore and SQLFeatureStoreTransaction (which would involve a lot of changes).