Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2013-07-15 14:10:04 -0400
committerRoberto Escobar2013-07-15 16:18:03 -0400
commitf9425112a51d2deded9fac0d4a7c457a1397884c (patch)
treeef72fff0f2457f9b2b6da1f8c4e967365ed882b0
parent80ca58d99d1a51425850781865f475b6245bda70 (diff)
downloadorg.eclipse.osee-f9425112a51d2deded9fac0d4a7c457a1397884c.tar.gz
org.eclipse.osee-f9425112a51d2deded9fac0d4a7c457a1397884c.tar.xz
org.eclipse.osee-f9425112a51d2deded9fac0d4a7c457a1397884c.zip
refactor: Check loaded users prior to querying for all
When searching for users by id or name, first check all users that have been cached for performance. The getAll() causes an artifact query to be executed. Change-Id: I6fce2dae8b55ef70b33e182ea20f42da0aa3ba50
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/users/UserAdminImpl.java45
1 files changed, 35 insertions, 10 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/users/UserAdminImpl.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/users/UserAdminImpl.java
index 784ff7411f..e388c9203e 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/users/UserAdminImpl.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/users/UserAdminImpl.java
@@ -13,7 +13,6 @@ package org.eclipse.osee.framework.skynet.core.internal.users;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import org.eclipse.osee.cache.admin.Cache;
import org.eclipse.osee.cache.admin.CacheAdmin;
import org.eclipse.osee.framework.core.data.IUserToken;
@@ -122,7 +121,7 @@ public class UserAdminImpl implements UserAdmin {
user = cache.get(userId);
} catch (Exception ex) {
UserDataStoreException userEx = unwrapUserException(ex);
- if(userEx != null){
+ if (userEx != null) {
throw userEx;
} else {
OseeExceptions.wrapAndThrow(ex);
@@ -210,12 +209,28 @@ public class UserAdminImpl implements UserAdmin {
public User getUserByName(String name) throws OseeCoreException {
Conditions.checkNotNullOrEmpty(name, "user name");
- for (User tempUser : getUsersAll()) {
+ // check cached users first
+ User toReturn = checkIterableForName(getCache().getAllPresent(), name);
+ if (toReturn == null) {
+ toReturn = checkIterableForName(getUsersAll(), name);
+ }
+
+ if (toReturn == null) {
+ throw new UserNotInDatabase("User requested by name [%s] was not found.", name);
+ }
+
+ return toReturn;
+ }
+
+ private User checkIterableForName(Iterable<User> users, String name) {
+ User toReturn = null;
+ for (User tempUser : users) {
if (name.equals(tempUser.getName())) {
- return tempUser;
+ toReturn = tempUser;
+ break;
}
}
- throw new UserNotInDatabase("User requested by name [%s] was not found.", name);
+ return toReturn;
}
@Override
@@ -251,11 +266,21 @@ public class UserAdminImpl implements UserAdmin {
if (userArtifactId <= 0) {
toReturn = getUser(SystemUser.OseeSystem);
} else {
- for (User tempUser : getUsersAll()) {
- if (userArtifactId == tempUser.getArtId()) {
- toReturn = tempUser;
- break;
- }
+ // check cached users first
+ toReturn = checkIterableForId(getCache().getAllPresent(), userArtifactId);
+ if (toReturn == null) {
+ toReturn = checkIterableForId(getUsersAll(), userArtifactId);
+ }
+ }
+ return toReturn;
+ }
+
+ private User checkIterableForId(Iterable<User> users, int id) {
+ User toReturn = null;
+ for (User tempUser : users) {
+ if (id == tempUser.getArtId()) {
+ toReturn = tempUser;
+ break;
}
}
return toReturn;

Back to the top