1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.layer0.migration;
14 import java.util.ArrayList;
15 import java.util.List;
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;
25 public class MigrationSequence implements MigrationStep {
27 final List<MigrationStep> steps;
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);
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 + ")");
49 TimeLogger.log(getClass(), "Completed migration step: " + step.getClass() + " (" + step + ")");