From: Hannu Niemistö Date: Mon, 2 Jan 2017 13:48:49 +0000 (+0200) Subject: UpdateComponentUids creates a map from old uids to new uids X-Git-Tag: v1.27.0~44 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F43%2F243%2F2;p=simantics%2Fplatform.git UpdateComponentUids creates a map from old uids to new uids The map can be used to migrate also some other structures containing uids. [PRIVATE-12930] Change-Id: I9b621eb83a86dcf424b56010249e170cc4bc8741 --- diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java index d32331152..dad99c8ce 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java @@ -6,12 +6,14 @@ import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; +import gnu.trove.map.hash.THashMap; + /** * Utility for updating UIDs in the given component to correspond * the RVIs of the given variable. This operation is needed when * the mapping is part of a model that is imported to a new database * and resource ids have been changed. - * + * * @author Hannu Niemistö * @author Tuukka Lehtonen */ @@ -21,10 +23,11 @@ public class UpdateComponentUids> { void componentsDone(int components, int componentCount); } + private THashMap oldToNewUids; private IProgressMonitor monitor; private ComponentUpdateProgressMonitor componentMonitor; private ReadGraph graph; - private int componentCount; + private int componentCount; private int counter; private UpdateComponentUids(IProgressMonitor monitor, ReadGraph graph, int componentCount) { @@ -35,7 +38,9 @@ public class UpdateComponentUids> { } private void update(T component, Variable variable) throws DatabaseException { - component.uid = variable.getRVI(graph).toString(); + String newUid = variable.getRVI(graph).toString(); + oldToNewUids.put(component.uid, newUid); + component.uid = newUid; // Handle progress monitoring and cancellation counter++; @@ -54,12 +59,14 @@ public class UpdateComponentUids> { } } - public static > void update(ReadGraph graph, T component, Variable variable) throws DatabaseException { - update(null, graph, component, variable); + public static > THashMap update(ReadGraph graph, T component, Variable variable) throws DatabaseException { + return update(null, graph, component, variable); } - public static > void update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException { - new UpdateComponentUids(monitor, graph, countComponents(component)).update(component, variable); + public static > THashMap update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException { + UpdateComponentUids updateComponentUids = new UpdateComponentUids(monitor, graph, countComponents(component)); + updateComponentUids.update(component, variable); + return updateComponentUids.oldToNewUids; } public static > int countComponents(T component) {