From defe3e75ce0da744acf1996edc5ac0b1268ba3e0 Mon Sep 17 00:00:00 2001 From: Andrea Aime Date: Sun, 24 Feb 2013 17:08:08 +0100 Subject: [PATCH] [GEOT-4394] ContentEntry used in ContentDataStore is not thread-safe, patch by Jan De Moerloose --- .../java/org/geotools/data/store/ContentEntry.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/library/data/src/main/java/org/geotools/data/store/ContentEntry.java b/modules/library/data/src/main/java/org/geotools/data/store/ContentEntry.java index a1f869903b8..15c50160e8f 100644 --- a/modules/library/data/src/main/java/org/geotools/data/store/ContentEntry.java +++ b/modules/library/data/src/main/java/org/geotools/data/store/ContentEntry.java @@ -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; @@ -83,7 +84,7 @@ public ContentEntry(ContentDataStore dataStore, Name typeName) { this.typeName = typeName; this.dataStore = dataStore; - this.state = new HashMap(); + this.state = new ConcurrentHashMap(); //create a state for the auto commit transaction ContentState autoState = dataStore.createContentState(this); @@ -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; }