From e8cb8734ba8d3ba2ba23b4b2199e90fc6da8a296 Mon Sep 17 00:00:00 2001 From: donald.g.dunne Date: Tue, 31 Jan 2017 15:59:37 -0700 Subject: bug[ats_ATS344961]: Fix TransactionManager transaction cache Change-Id: Id38d8ad57c728f9fee4253a05a231c934d433df1 --- .../framework/jdk/core/type/HashCollection.java | 23 ++++++++++++++-------- .../core/transaction/TransactionManager.java | 6 +++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java index a9c699a736d..7f86d5cf77a 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -25,7 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; * specified at construction, if desired. All Collections returned by methods are backed by the , so changes to the are * reflected in the Collection, and vice-versa. However, modifications to the Collection outside of this class are * generally discouraged because removal of the last item would then not guarantee removal of the key. - * + * * @author Donald G. Dunne */ public class HashCollection { @@ -96,7 +97,7 @@ public class HashCollection { /** * Creates an unsynchronized Plus using a default Collection type (ArrayList) - * + * * @see HashMap#HashMap(int, float) */ public HashCollection(int initialCapacity, float loadFactor) { @@ -105,7 +106,7 @@ public class HashCollection { /** * Creates an unsynchronized Plus using a default Collection type (ArrayList) - * + * * @see HashMap#HashMap(int) */ public HashCollection(int initialCapacity) { @@ -127,7 +128,7 @@ public class HashCollection { /** * Adds the value to the collection specified by the key. If there is not a collection for the given key, a new * collection is created and added to the hash. - * + * * @param key The key whose collection we will add value to. * @param value The value to be added. * @return the collection containing value and all other items associated with the key. @@ -157,13 +158,19 @@ public class HashCollection { /** * Adds all of the items in the Collection values to the collection for the specified key. - * + * * @param key The key to add the values to - * @param values The values to be added + * @param values The values to be added. Null or empty values will insert empty list in map * @return The collection for the key, containing all values. */ public Collection put(K key, Collection values) { Collection items = null; + if (values == null || values.isEmpty()) { + Collection values2 = this.getValues(key); + if (values2 == null) { + map.put(key, new LinkedList<>()); + } + } for (V value : values) { if (items == null) { items = this.put(key, value); @@ -202,7 +209,7 @@ public class HashCollection { /** * Returns the Collection of items for this key, or null if the key does not exist. - * + * * @return Return value collection reference */ public Collection getValues(K key) { @@ -211,7 +218,7 @@ public class HashCollection { /** * Returns the Collection all items - * + * * @return Return value collection reference */ public List getValues() { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java index db0db64eb5b..c95a53dcc43 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java @@ -136,7 +136,11 @@ public final class TransactionManager { SELECT_COMMIT_TRANSACTIONS, artifact); } Collection transactions = commitArtifactIdMap.getValues(artifact); - return transactions == null ? Collections.emptyList() : transactions; + if (transactions == null) { + transactions = Collections.emptyList(); + commitArtifactIdMap.put(artifact, transactions); + } + return transactions; } /** -- cgit v1.2.3