1 package org.simantics.modeling.migration;
3 import org.eclipse.core.runtime.IProgressMonitor;
4 import org.simantics.db.Resource;
5 import org.simantics.db.Session;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.request.DelayedWriteRequest;
8 import org.simantics.db.common.utils.NameUtils;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.migration.MigrationState;
11 import org.simantics.db.layer0.migration.MigrationStep;
12 import org.simantics.db.layer0.migration.MigrationUtils;
13 import org.simantics.db.layer0.util.Layer0Utils;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.modeling.ModelingUtils;
16 import org.simantics.simulation.ontology.SimulationResource;
17 import org.simantics.utils.logging.TimeLogger;
21 * {@link ModelingUtils#attachCreationInformation(IProgressMonitor, WriteGraph, Resource)}
22 * for all imported models.
24 * @author Tuukka Lehtonen
26 public enum AttachCreationInformationStep implements MigrationStep {
30 public static AttachCreationInformationStep get() {
35 public void applyTo(final IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {
36 final Resource indexRoot = MigrationUtils.getResource(monitor, session, state);
37 if (indexRoot == null)
40 session.sync(new DelayedWriteRequest() {
42 public void perform(WriteGraph graph) throws DatabaseException {
43 attach(monitor, graph, indexRoot);
48 private static void attach(IProgressMonitor monitor, WriteGraph graph, Resource indexRoot) throws DatabaseException {
49 Layer0Utils.setDependenciesIndexingDisabled(graph, true);
50 Layer0 L0 = Layer0.getInstance(graph);
51 SimulationResource SIMU = SimulationResource.getInstance(graph);
52 for (Resource model : graph.getObjects(indexRoot, L0.ConsistsOf)) {
53 if (graph.isInstanceOf(model, SIMU.Model)) {
54 TimeLogger.log(AttachCreationInformationStep.class, "attaching creation information to model " + NameUtils.getSafeName(graph, model));
55 ModelingUtils.attachCreationInformation(monitor, graph, model);