diff options
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/BranchRow.java')
-rw-r--r-- | plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/BranchRow.java | 84 |
1 files changed, 70 insertions, 14 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/BranchRow.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/BranchRow.java index 278a06cfd82..9269a982dd9 100644 --- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/BranchRow.java +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/BranchRow.java @@ -19,6 +19,7 @@ import org.eclipse.osee.framework.core.enums.StorageState; import org.eclipse.osee.framework.core.message.internal.DatabaseService; import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Strings; public final class BranchRow { private final long branchUuid; @@ -74,32 +75,87 @@ public final class BranchRow { } public String[] toArray() { - return new String[] { - getBranchArchived().name(), - String.valueOf(getBranchId()), - getBranchName(), - getBranchState().name(), - getBranchType().name(), - getStorageState().name(), - Boolean.toString(isInheritAccessControl())}; + if (isOseeUsingGuidsForAppServerMessaging()) { + return new String[] { + getBranchArchived().name(), + getBranchGuidLegacy(getBranchId()), + String.valueOf(getBranchId()), + getBranchName(), + getBranchState().name(), + getBranchType().name(), + getStorageState().name(), + Boolean.toString(isInheritAccessControl())}; + } else { + return new String[] { + getBranchArchived().name(), + String.valueOf(getBranchId()), + getBranchName(), + getBranchState().name(), + getBranchType().name(), + getStorageState().name(), + Boolean.toString(isInheritAccessControl())}; + } } public static BranchRow fromArray(String[] data) { BranchArchivedState archived = BranchArchivedState.valueOf(data[0]); long branchUuid = 0; + boolean inheritAccessControl = false; + String branchName = null; + BranchState branchState = null; + BranchType branchType = null; + StorageState storageState = null; if (GUID.isValid(data[1])) { - branchUuid = getBranchIdLegacy(data[1]); + // skip guid + branchUuid = Long.valueOf(data[2]); + branchName = data[3]; + branchState = BranchState.valueOf(data[4]); + branchType = BranchType.valueOf(data[5]); + storageState = StorageState.valueOf(data[6]); } else { branchUuid = Long.valueOf(data[1]); + branchName = data[2]; + branchState = BranchState.valueOf(data[3]); + branchType = BranchType.valueOf(data[4]); + storageState = StorageState.valueOf(data[5]); + inheritAccessControl = Boolean.parseBoolean(data[6]); } - String branchName = data[2]; - BranchState branchState = BranchState.valueOf(data[3]); - BranchType branchType = BranchType.valueOf(data[4]); - StorageState storageState = StorageState.valueOf(data[5]); - boolean inheritAccessControl = Boolean.parseBoolean(data[6]); return new BranchRow(branchUuid, branchName, branchType, branchState, archived, storageState, inheritAccessControl); } + + // Temporary cache till all code uses branch uuid. Remove after 0.17.0 + private static final String SELECT_OSEE_INFO = + "select osee_value from osee_info where osee_key = 'osee.using.guids.for.app.server.messaging'"; + private static Boolean oseeUsingGuidsForAppServerMessaging = null; + + public static boolean isOseeUsingGuidsForAppServerMessaging() { + if (oseeUsingGuidsForAppServerMessaging == null) { + oseeUsingGuidsForAppServerMessaging = + DatabaseService.getDatabaseService().runPreparedQueryFetchObject("", SELECT_OSEE_INFO).equals("true"); + } + return oseeUsingGuidsForAppServerMessaging; + } + + private static final String SELECT_BRANCH_GUID_BY_ID = "select branch_guid from osee_branch where branch_id = ?"; + // Temporary cache till all code uses branch uuid. Remove after 0.17.0 + private static final Map<Long, String> longToGuidCache = new HashMap<Long, String>(50); + + /** + * Temporary method till all code uses branch uuid. Remove after 0.17.0 + */ + public static String getBranchGuidLegacy(long branchUuid) { + String guid = longToGuidCache.get(branchUuid); + if (!Strings.isValid(guid)) { + guid = + DatabaseService.getDatabaseService().runPreparedQueryFetchObject("", SELECT_BRANCH_GUID_BY_ID, branchUuid); + Conditions.checkExpressionFailOnTrue(!Strings.isValid(guid), "Error getting branch_guid for branch: [%d]", + branchUuid); + longToGuidCache.put(branchUuid, guid); + } + return guid; + } + // Temporary cache till all code uses branch uuid. Remove after 0.17.0 private static final String SELECT_BRANCH_ID_BY_GUID = "select branch_id from osee_branch where branch_guid = ?"; // Temporary cache till all code uses branch uuid. Remove after 0.17.0 |