Skip to content

Commit

Permalink
[GEOT-4394] ContentEntry used in ContentDataStore is not thread-safe,…
Browse files Browse the repository at this point in the history
… patch by Jan De Moerloose
  • Loading branch information
aaime committed Feb 24, 2013
1 parent 36656cb commit defe3e7
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -18,6 +18,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;

import org.geotools.data.FeatureEvent;
Expand Down Expand Up @@ -83,7 +84,7 @@ public ContentEntry(ContentDataStore dataStore, Name typeName) {
this.typeName = typeName;
this.dataStore = dataStore;

this.state = new HashMap<Transaction, ContentState>();
this.state = new ConcurrentHashMap<Transaction, ContentState>();

//create a state for the auto commit transaction
ContentState autoState = dataStore.createContentState(this);
Expand Down Expand Up @@ -126,13 +127,14 @@ public ContentDataStore getDataStore() {
* @return The state for the transaction.
*/
public ContentState getState(Transaction transaction) {
if (state.containsKey(transaction)) {
if (transaction != null && state.containsKey(transaction)) {
return state.get(transaction);
} else {
ContentState auto = state.get(Transaction.AUTO_COMMIT);
ContentState copy = (ContentState) auto.copy();
copy.setTransaction(transaction != null ? transaction : Transaction.AUTO_COMMIT);
state.put(transaction, copy);
Transaction t = (transaction != null ? transaction : Transaction.AUTO_COMMIT);
copy.setTransaction(t);
state.put(t, copy);

return copy;
}
Expand Down

0 comments on commit defe3e7

Please sign in to comment.