]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/migration/AttachCreationInformationStep.java
Added new field TypeId to dependency index for exact type searching
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / migration / AttachCreationInformationStep.java
1 package org.simantics.modeling.migration;
2
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;
18
19 /**
20  * Runs
21  * {@link ModelingUtils#attachCreationInformation(IProgressMonitor, WriteGraph, Resource)}
22  * for all imported models.
23  * 
24  * @author Tuukka Lehtonen
25  */
26 public enum AttachCreationInformationStep implements MigrationStep {
27
28     INSTANCE;
29
30     public static AttachCreationInformationStep get() {
31         return INSTANCE;
32     }
33
34     @Override
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)
38             return;
39
40         session.sync(new DelayedWriteRequest() {
41             @Override
42             public void perform(WriteGraph graph) throws DatabaseException {
43                 attach(monitor, graph, indexRoot);
44             }
45         });
46     }
47
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);
56             }
57         }
58     }
59
60 }