]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationSequence.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / migration / MigrationSequence.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.migration;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.common.utils.ListUtils;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.utils.logging.TimeLogger;
24
25 public class MigrationSequence implements MigrationStep {
26         
27         final List<MigrationStep> steps;
28         
29         public MigrationSequence(ReadGraph graph, Resource sequence) throws DatabaseException {
30                 steps = new ArrayList<MigrationStep>();
31                 for(Resource step : ListUtils.toList(graph, sequence)) {
32                         MigrationStep ms = graph.adapt(step, MigrationStep.class);
33                         steps.add(ms);
34                 }
35         }
36
37         @Override
38         public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {
39                 TimeLogger.resetTimeAndLog(getClass(), "Running migration sequence");
40                 for(MigrationStep step : steps) {
41                         if(monitor.isCanceled()) return;
42                         TimeLogger.log(getClass(), "Running migration step: " + step.getClass() + " (" + step + ")");
43                         step.applyTo(monitor, session, state);
44                         if (monitor.isCanceled()) {
45                                 TimeLogger.log(getClass(), "Migration cancelled during step: " + step.getClass() + " (" + step + ")");
46                                 return;
47                         }
48                         monitor.subTask("");
49                         TimeLogger.log(getClass(), "Completed migration step: " + step.getClass() + " (" + step + ")");
50                 }
51         }
52
53 }