From 851d3d63d340681a010141197d9284d63745ca59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Mon, 2 Jan 2017 15:48:49 +0200 Subject: [PATCH] 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 --- .../base/UpdateComponentUids.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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) { -- 2.43.2