Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.osee.ats.client.demo/src/org/eclipse/osee/ats/client/demo/DemoUtil.java8
-rw-r--r--plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/PopulateDemoDatabaseTest.java29
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/JoinUtility.java4
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeInfo.java97
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SystemPreferencesImpl.java31
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java6
-rw-r--r--plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java8
9 files changed, 95 insertions, 92 deletions
diff --git a/plugins/org.eclipse.osee.ats.client.demo/src/org/eclipse/osee/ats/client/demo/DemoUtil.java b/plugins/org.eclipse.osee.ats.client.demo/src/org/eclipse/osee/ats/client/demo/DemoUtil.java
index 74ab286962b..ead675dbdfe 100644
--- a/plugins/org.eclipse.osee.ats.client.demo/src/org/eclipse/osee/ats/client/demo/DemoUtil.java
+++ b/plugins/org.eclipse.osee.ats.client.demo/src/org/eclipse/osee/ats/client/demo/DemoUtil.java
@@ -48,19 +48,19 @@ public class DemoUtil {
}
public static boolean isDbInitSuccessful() throws OseeCoreException {
- return OseeInfo.isBoolean("DbInitSuccess");
+ return OseeInfo.getValue("DbInitSuccess").equals("true");
}
public static void setDbInitSuccessful(boolean success) throws OseeCoreException {
- OseeInfo.setBoolean("DbInitSuccess", success);
+ OseeInfo.setValue("DbInitSuccess", String.valueOf(success));
}
public static boolean isPopulateDbSuccessful() throws OseeCoreException {
- return OseeInfo.isBoolean("PopulateSuccessful");
+ return OseeInfo.getValue("PopulateSuccessful").equals("true");
}
public static void setPopulateDbSuccessful(boolean success) throws OseeCoreException {
- OseeInfo.setBoolean("PopulateSuccessful", success);
+ OseeInfo.setValue("PopulateSuccessful", String.valueOf(success));
}
public static TeamWorkFlowArtifact getSawCodeCommittedWf() throws OseeCoreException {
diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/PopulateDemoDatabaseTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/PopulateDemoDatabaseTest.java
index 7c423de8be1..6011f651502 100644
--- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/PopulateDemoDatabaseTest.java
+++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/PopulateDemoDatabaseTest.java
@@ -16,6 +16,8 @@ import org.eclipse.osee.ats.client.demo.DemoUtil;
import org.eclipse.osee.ats.client.demo.PopulateDemoActions;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.client.OseeClientSession;
+import org.eclipse.osee.framework.database.core.ConnectionHandler;
+import org.eclipse.osee.framework.database.core.OseeInfo;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
@@ -29,6 +31,9 @@ import org.junit.BeforeClass;
*/
public class PopulateDemoDatabaseTest {
+ private static final String INSERT_KEY_VALUE_SQL = "INSERT INTO osee_info (OSEE_KEY, OSEE_VALUE) VALUES (?, ?)";
+ private static final String DELETE_KEY_SQL = "DELETE FROM osee_info WHERE OSEE_KEY = ?";
+
@BeforeClass
public static void setup() throws Exception {
if (!DemoUtil.isDbInitSuccessful()) {
@@ -64,4 +69,28 @@ public class PopulateDemoDatabaseTest {
}
}
+ @org.junit.Test
+ public void testMaxStaleness() throws InterruptedException {
+
+ ConnectionHandler.runPreparedUpdate(INSERT_KEY_VALUE_SQL, "testKey", "testValue");
+ String value = OseeInfo.getValue("testKey");
+ Assert.assertEquals("testValue", value);
+
+ ConnectionHandler.runPreparedUpdate(DELETE_KEY_SQL, "testKey");
+ ConnectionHandler.runPreparedUpdate(INSERT_KEY_VALUE_SQL, "testKey", "testValue2");
+ // Max Staleness is 3 weeks cached value shouldn't change
+ value = OseeInfo.getValue("testKey");
+ Assert.assertEquals("testValue", value);
+
+ // Max Staleness is 1 second cached value shouldn't change even if we sleep for .8 seconds
+ Thread.sleep(800);
+ value = OseeInfo.getValue("testKey", (long) 1000);
+ Assert.assertEquals("testValue", value);
+
+ // Wait another .2 seconds and max staleness of 1 second will be exceeded and fresh value retrieved from DB
+ Thread.sleep(800);
+ value = OseeInfo.getValue("testKey", (long) 1000);
+ Assert.assertEquals("testValue2", value);
+ }
+
}
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/JoinUtility.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/JoinUtility.java
index 435d268dbe0..0bf2bd576c2 100644
--- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/JoinUtility.java
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/JoinUtility.java
@@ -100,7 +100,7 @@ public class JoinUtility {
private static int getMaxArtifactJoinSize(IOseeDatabaseService service) {
int toReturn = Integer.MAX_VALUE;
- String maxSize = OseeInfo.getCachedValue(service, "artifact.join.max.size");
+ String maxSize = OseeInfo.getValue(service, "artifact.join.max.size");
if (Strings.isNumeric(maxSize)) {
toReturn = Integer.parseInt(maxSize);
}
@@ -112,7 +112,7 @@ public class JoinUtility {
if (actual != null) {
toReturn = actual;
} else {
- String expiration = OseeInfo.getCachedValue(service, defaultKey);
+ String expiration = OseeInfo.getValue(service, defaultKey);
if (Strings.isNumeric(expiration)) {
toReturn = Long.parseLong(expiration);
}
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeInfo.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeInfo.java
index 31b60478ed2..cd333947735 100644
--- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeInfo.java
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeInfo.java
@@ -10,11 +10,12 @@
*******************************************************************************/
package org.eclipse.osee.framework.database.core;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.internal.ServiceUtil;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
/**
* @author Donald G. Dunne
@@ -29,93 +30,45 @@ public class OseeInfo {
public static final String DB_ID_KEY = "osee.db.guid";
public static final String DB_TYPE_KEY = "osee.db.type";
- private static Map<String, String> cache = new HashMap<String, String>();
+ private static Map<String, Pair<Long, String>> cache = new ConcurrentHashMap<String, Pair<Long, String>>();
public static String getValue(String key) throws OseeCoreException {
- return getValue(ConnectionHandler.getDatabase(), key);
+ return getValue(key, (long) Integer.MAX_VALUE);
}
- public static String getValue(IOseeDatabaseService service, String key) throws OseeCoreException {
- String toReturn = service.runPreparedQueryFetchObject("", GET_VALUE_SQL, key);
- cache.put(key, toReturn);
- return toReturn;
+ public static String getValue(String key, Long maxStaleness) throws OseeCoreException {
+ return getValue(ServiceUtil.getDatabaseService(), key, maxStaleness);
}
- public static String getCachedValue(IOseeDatabaseService service, String key) throws OseeCoreException {
- String cacheValue = cache.get(key);
- if (cacheValue == null) {
- cacheValue = getValue(service, key);
- cache.put(key, cacheValue);
- }
-
- return cacheValue;
-
- }
-
- public static String getCachedValue(String key) throws OseeCoreException {
- return getCachedValue(ConnectionHandler.getDatabase(), key);
- }
-
- /**
- * Return true if key is set in osee_info table and value = "true". Return false if key is either not in osee_info
- * table OR value != "true".<br>
- * <br>
- * Note: This call will hit the database every time, so shouldn't be used for often repeated calls. use
- * isCacheEnabled that will cache the value
- */
- public static boolean isEnabled(String key) throws OseeCoreException {
- return isBoolean(key);
- }
-
- /**
- * Return true if key is set in osee_info table and value = "true". Return false if key is either not in osee_info
- * table OR value != "true".<br>
- * <br>
- * Return cached value (value only loaded once per session. Restart will reset value if changed in osee_info
- */
- public static boolean isCacheEnabled(String key) throws OseeCoreException {
- String dbProperty = OseeInfo.getCachedValue(key);
- if (Strings.isValid(dbProperty)) {
- return dbProperty.equals("true");
- }
- return false;
- }
-
- public static void setEnabled(String key, boolean enabled) throws OseeCoreException {
- setBoolean(key, enabled);
+ public static String getValue(IOseeDatabaseService service, String key) {
+ return getValue(service, key, (long) Integer.MAX_VALUE);
}
- public static void setBoolean(String key, boolean value) throws OseeCoreException {
- putValue(key, String.valueOf(value));
-
- }
-
- /**
- * Return true if key is set in osee_info table and value = "true". Return false if key is either not in osee_info
- * table OR value != "true".<br>
- * <br>
- * Note: This call will hit the database every time, so shouldn't be used for often repeated calls. use
- * isBooleanUsingCache that will cache the value
- */
- public static boolean isBoolean(String key) throws OseeCoreException {
- String dbProperty = OseeInfo.getValue(key);
- if (Strings.isValid(dbProperty)) {
- return dbProperty.equals("true");
+ public static String getValue(IOseeDatabaseService service, String key, Long maxStaleness) {
+ Pair<Long, String> pair = cache.get(key);
+ String value;
+ if (pair == null || pair.getFirst() + maxStaleness < System.currentTimeMillis()) {
+ value = service.runPreparedQueryFetchObject("", GET_VALUE_SQL, key);
+ cacheValue(key, value);
+ } else {
+ value = pair.getSecond();
}
- return false;
- }
- public static boolean isBooleanUsingCache(String key) throws OseeCoreException {
- return isCacheEnabled(key);
+ return value;
}
- public static void putValue(String key, String value) throws OseeCoreException {
+ public static void setValue(String key, String value) throws OseeCoreException {
ConnectionHandler.runPreparedUpdate(DELETE_KEY_SQL, key);
ConnectionHandler.runPreparedUpdate(INSERT_KEY_VALUE_SQL, key, value);
- cache.put(key, value);
+ cacheValue(key, value);
}
public static String getDatabaseGuid() throws OseeCoreException {
return getValue(DB_ID_KEY);
}
+
+ private static void cacheValue(String key, String value) {
+ Long time = System.currentTimeMillis();
+ cache.put(key, new Pair<Long, String>(time, value));
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java
index 614820f308a..e7aa5acdead 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java
@@ -124,7 +124,7 @@ public class BranchManager {
}
public static void refreshBranches() throws OseeCoreException {
- String refreshWindow = OseeInfo.getCachedValue("cache.reload.throttle.millis");
+ String refreshWindow = OseeInfo.getValue("cache.reload.throttle.millis");
boolean reload = true;
if (Strings.isNumeric(refreshWindow)) {
long timeInMillis = Long.parseLong(refreshWindow);
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java
index 3eca883b209..bd05eede7a4 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java
@@ -26,6 +26,8 @@ public interface SystemPreferences {
public String getCachedValue(String key) throws OseeCoreException;
+ public String getCachedValue(String key, long maxStaleness) throws OseeCoreException;
+
/**
* Return true if key is set and value = "true". Return false if key is either not set OR value != "true".<br>
* <br>
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SystemPreferencesImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SystemPreferencesImpl.java
index 881af554a2d..2fed19217b5 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SystemPreferencesImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SystemPreferencesImpl.java
@@ -14,6 +14,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.orcs.core.SystemPreferences;
import org.eclipse.osee.orcs.core.ds.DataStoreConstants;
@@ -24,7 +25,7 @@ import org.eclipse.osee.orcs.core.ds.KeyValueDataAccessor;
*/
public class SystemPreferencesImpl implements SystemPreferences {
- private Map<String, String> cache;
+ private static Map<String, Pair<Long, String>> cache;
private KeyValueDataAccessor accessor;
public void setDataAccessor(KeyValueDataAccessor accessor) {
@@ -32,7 +33,7 @@ public class SystemPreferencesImpl implements SystemPreferences {
}
public void start() {
- cache = new ConcurrentHashMap<String, String>();
+ cache = new ConcurrentHashMap<String, Pair<Long, String>>();
}
public void stop() {
@@ -47,19 +48,26 @@ public class SystemPreferencesImpl implements SystemPreferences {
@Override
public String getValue(String key) throws OseeCoreException {
String toReturn = accessor.getValue(key);
- cache.put(key, toReturn);
+ cacheValue(key, toReturn);
return toReturn;
}
@Override
public String getCachedValue(String key) throws OseeCoreException {
- String cacheValue = cache.get(key);
- if (cacheValue == null) {
- cacheValue = getValue(key);
- cache.put(key, cacheValue);
+ return getCachedValue(key, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String getCachedValue(String key, long maxStaleness) throws OseeCoreException {
+ Pair<Long, String> pair = cache.get(key);
+ String value;
+ if (pair == null || pair.getFirst() + maxStaleness < System.currentTimeMillis()) {
+ value = getValue(key);
+ } else {
+ value = pair.getSecond();
}
- return cacheValue;
+ return value;
}
@Override
@@ -103,7 +111,7 @@ public class SystemPreferencesImpl implements SystemPreferences {
@Override
public void putValue(String key, String value) throws OseeCoreException {
accessor.putValue(key, value);
- cache.put(key, value);
+ cacheValue(key, value);
}
@Override
@@ -111,4 +119,9 @@ public class SystemPreferencesImpl implements SystemPreferences {
return accessor.getKeys();
}
+ private static void cacheValue(String key, String value) {
+ Long time = System.currentTimeMillis();
+ cache.put(key, new Pair<Long, String>(time, value));
+ }
+
}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java
index c4ebb069328..d732daa5ccd 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.orcs.db.mocks;
import java.util.Set;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.orcs.core.SystemPreferences;
/**
@@ -74,4 +75,9 @@ public class MockSystemPreferences implements SystemPreferences {
return false;
}
+ @Override
+ public String getCachedValue(String key, long maxStaleness) throws OseeCoreException {
+ return Strings.emptyString();
+ }
+
}
diff --git a/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java b/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java
index e9c4b8dad38..de92d655038 100644
--- a/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java
+++ b/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java
@@ -41,11 +41,11 @@ public class TestUtil {
}
public static boolean isDbInitSuccessful() throws OseeCoreException {
- return OseeInfo.isBoolean("DbInitSuccess");
+ return OseeInfo.getValue("DbInitSuccess").equals("true");
}
public static void setDbInitSuccessful(boolean success) throws OseeCoreException {
- OseeInfo.setBoolean("DbInitSuccess", success);
+ OseeInfo.setValue("DbInitSuccess", String.valueOf(success));
}
/**
@@ -64,11 +64,11 @@ public class TestUtil {
}
public static boolean isDemoDb() throws OseeCoreException {
- return DEMO_DB_TYPE.equals(OseeInfo.getCachedValue(OseeInfo.DB_TYPE_KEY));
+ return DEMO_DB_TYPE.equals(OseeInfo.getValue(OseeInfo.DB_TYPE_KEY));
}
public static void setDemoDb(boolean set) throws OseeCoreException {
- OseeInfo.putValue(OseeInfo.DB_TYPE_KEY, set ? DEMO_DB_TYPE : "");
+ OseeInfo.setValue(OseeInfo.DB_TYPE_KEY, set ? DEMO_DB_TYPE : "");
}
public static void sleep(long milliseconds) {

Back to the top