X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.migration.ui%2Fsrc%2Forg%2Fsimantics%2Fmigration%2Fui%2FMigrationAnalysis.java;h=5e4edbd4a1d67dd03e25ca2db8d3a3cc94a8f258;hb=refs%2Fchanges%2F38%2F238%2F2;hp=7532bb528f51d8b809cdfa45b3ba3ba3af0b95fa;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.migration.ui/src/org/simantics/migration/ui/MigrationAnalysis.java b/bundles/org.simantics.migration.ui/src/org/simantics/migration/ui/MigrationAnalysis.java index 7532bb528..5e4edbd4a 100644 --- a/bundles/org.simantics.migration.ui/src/org/simantics/migration/ui/MigrationAnalysis.java +++ b/bundles/org.simantics.migration.ui/src/org/simantics/migration/ui/MigrationAnalysis.java @@ -1,98 +1,98 @@ -package org.simantics.migration.ui; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.db.request.Read; -import org.simantics.layer0.SoftwareConfigurationResources; - -import gnu.trove.map.hash.THashMap; - -public class MigrationAnalysis { - - public class Update implements Comparable { - Resource updateResource; - Resource parentVersion; - Resource childVersion; - String versionName; - - public Update(Resource updateResource, Resource parentVersion, - Resource childVersion, String versionName) { - this.updateResource = updateResource; - this.parentVersion = parentVersion; - this.childVersion = childVersion; - this.versionName = versionName; - } - - @Override - public int compareTo(Update o) { - return versionName.compareTo(o.versionName); - } - - public void execute(final Resource target) throws DatabaseException { - Update parentUpdate = updates.get(parentVersion); - if(parentUpdate != null) - parentUpdate.execute(target); - - Collection migrateActions = Simantics.getSession().syncRequest(new Read>() { - @Override - public Collection perform(ReadGraph graph) - throws DatabaseException { - SoftwareConfigurationResources SC = SoftwareConfigurationResources.getInstance(graph); - ArrayList result = new ArrayList(); - for(Resource action : graph.getObjects(updateResource, SC.Update_HasMigrationAction)) - result.add(graph.adapt(action, ActionFactory.class).create(target)); - return result; - } - }); - for(Runnable action : migrateActions) - action.run(); - } - - public void updateTargetVersion(final Resource target) throws DatabaseException { - Simantics.getSession().syncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - graph.markUndoPoint(); - SoftwareConfigurationResources SC = SoftwareConfigurationResources.getInstance(graph); - graph.deny(target, SC.IsCompatibleWith, MigrationAnalysis.this.parentVersion); - graph.claim(target, SC.IsCompatibleWith, childVersion); - } - }); - } - } - - Resource parentVersion; - THashMap updates = new THashMap(); - - public MigrationAnalysis(ReadGraph g, Resource parentVersion) throws DatabaseException { - this.parentVersion = parentVersion; - updates.put(parentVersion, null); - findUpdatesFrom(g, parentVersion); - updates.remove(parentVersion); - } - - private void findUpdatesFrom(ReadGraph g, Resource version) throws DatabaseException { - SoftwareConfigurationResources SC = SoftwareConfigurationResources.getInstance(g); - for(Resource update : g.getObjects(version, SC.Version_HasUpdate)) { - Resource to = g.getSingleObject(update, SC.Update_To); - if(!updates.contains(to)) { - String name = NameUtils.getSafeLabel(g, to); - updates.put(to, new Update(update, version, to, name)); - findUpdatesFrom(g, to); - } - } - } - - public Collection getUpdates() { - return updates.values(); - } -} +package org.simantics.migration.ui; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.db.request.Read; +import org.simantics.layer0.SoftwareConfigurationResources; + +import gnu.trove.map.hash.THashMap; + +public class MigrationAnalysis { + + public class Update implements Comparable { + Resource updateResource; + Resource parentVersion; + Resource childVersion; + String versionName; + + public Update(Resource updateResource, Resource parentVersion, + Resource childVersion, String versionName) { + this.updateResource = updateResource; + this.parentVersion = parentVersion; + this.childVersion = childVersion; + this.versionName = versionName; + } + + @Override + public int compareTo(Update o) { + return versionName.compareTo(o.versionName); + } + + public void execute(final Resource target) throws DatabaseException { + Update parentUpdate = updates.get(parentVersion); + if(parentUpdate != null) + parentUpdate.execute(target); + + Collection migrateActions = Simantics.getSession().syncRequest(new Read>() { + @Override + public Collection perform(ReadGraph graph) + throws DatabaseException { + SoftwareConfigurationResources SC = SoftwareConfigurationResources.getInstance(graph); + ArrayList result = new ArrayList(); + for(Resource action : graph.getObjects(updateResource, SC.Update_HasMigrationAction)) + result.add(graph.adapt(action, ActionFactory.class).create(target)); + return result; + } + }); + for(Runnable action : migrateActions) + action.run(); + } + + public void updateTargetVersion(final Resource target) throws DatabaseException { + Simantics.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + SoftwareConfigurationResources SC = SoftwareConfigurationResources.getInstance(graph); + graph.deny(target, SC.IsCompatibleWith, MigrationAnalysis.this.parentVersion); + graph.claim(target, SC.IsCompatibleWith, childVersion); + } + }); + } + } + + Resource parentVersion; + THashMap updates = new THashMap(); + + public MigrationAnalysis(ReadGraph g, Resource parentVersion) throws DatabaseException { + this.parentVersion = parentVersion; + updates.put(parentVersion, null); + findUpdatesFrom(g, parentVersion); + updates.remove(parentVersion); + } + + private void findUpdatesFrom(ReadGraph g, Resource version) throws DatabaseException { + SoftwareConfigurationResources SC = SoftwareConfigurationResources.getInstance(g); + for(Resource update : g.getObjects(version, SC.Version_HasUpdate)) { + Resource to = g.getSingleObject(update, SC.Update_To); + if(!updates.contains(to)) { + String name = NameUtils.getSafeLabel(g, to); + updates.put(to, new Update(update, version, to, name)); + findUpdatesFrom(g, to); + } + } + } + + public Collection getUpdates() { + return updates.values(); + } +}