X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fmigration%2FOrderedSetToListMigrationStep.java;h=d4fad58a27cfb65d0f2139cae0d63ada183f804b;hb=aea3e7b117a8398471f10c31844efffc8026f815;hp=b7180b7a0559b40ceaf686d6d66efdf3017c10ae;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OrderedSetToListMigrationStep.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OrderedSetToListMigrationStep.java index b7180b7a0..d4fad58a2 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OrderedSetToListMigrationStep.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OrderedSetToListMigrationStep.java @@ -1,89 +1,89 @@ -/******************************************************************************* - * Copyright (c) 2012 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.layer0.migration; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.Instances; -import org.simantics.layer0.Layer0; - -public class OrderedSetToListMigrationStep implements MigrationStep { - - final ArrayList rules; - - private class OrderedSetToListMapping { - public Resource entityType, orderedSet, orderedSetRelation, list, listRelation; - } - - public OrderedSetToListMigrationStep(ReadGraph graph, Resource step) throws DatabaseException { - rules = new ArrayList(); - Layer0 L0 = Layer0.getInstance(graph); - for(Resource change : ListUtils.toList(graph, step)) { - String entityType = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_entityType, Bindings.STRING); - String orderedSet = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetType, Bindings.STRING); - String orderedSetRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetRelation, Bindings.STRING); - String list = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listType, Bindings.STRING); - String listRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listRelation, Bindings.STRING); - - if(orderedSet != null && orderedSetRelation != null && list != null && listRelation != null) { - OrderedSetToListMapping mapping = new OrderedSetToListMapping(); - mapping.entityType = graph.getResource(entityType); - mapping.orderedSet = graph.getResource(orderedSet); - mapping.orderedSetRelation = graph.getResource(orderedSetRelation); - mapping.list = graph.getResource(list); - mapping.listRelation = graph.getResource(listRelation); - rules.add(mapping); - } - } - } - - @Override - public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException { - final Resource resource = MigrationUtils.getResource(monitor, session, state); - - if(resource != null) { - session.syncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - for(OrderedSetToListMapping mapping : rules) { - Instances entityFinder = graph.adapt(mapping.entityType, Instances.class); - for(Resource entity : entityFinder.find(graph, resource)) { - Resource orderedSet = graph.syncRequest(new PossibleObjectWithType(entity, mapping.orderedSetRelation, mapping.orderedSet)); - if(orderedSet != null) { - Collection list = OrderedSetUtils.toList(graph, orderedSet); - graph.deny(entity, mapping.orderedSetRelation, orderedSet); - graph.claim(entity, mapping.listRelation, ListUtils.create(graph, mapping.list, list)); - } - } - - } - } - }); - } - - } - - -} +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.layer0.migration; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Instances; +import org.simantics.layer0.Layer0; + +public class OrderedSetToListMigrationStep implements MigrationStep { + + final ArrayList rules; + + private class OrderedSetToListMapping { + public Resource entityType, orderedSet, orderedSetRelation, list, listRelation; + } + + public OrderedSetToListMigrationStep(ReadGraph graph, Resource step) throws DatabaseException { + rules = new ArrayList(); + Layer0 L0 = Layer0.getInstance(graph); + for(Resource change : ListUtils.toList(graph, step)) { + String entityType = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_entityType, Bindings.STRING); + String orderedSet = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetType, Bindings.STRING); + String orderedSetRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetRelation, Bindings.STRING); + String list = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listType, Bindings.STRING); + String listRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listRelation, Bindings.STRING); + + if(orderedSet != null && orderedSetRelation != null && list != null && listRelation != null) { + OrderedSetToListMapping mapping = new OrderedSetToListMapping(); + mapping.entityType = graph.getResource(entityType); + mapping.orderedSet = graph.getResource(orderedSet); + mapping.orderedSetRelation = graph.getResource(orderedSetRelation); + mapping.list = graph.getResource(list); + mapping.listRelation = graph.getResource(listRelation); + rules.add(mapping); + } + } + } + + @Override + public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException { + final Resource resource = MigrationUtils.getResource(monitor, session, state); + + if(resource != null) { + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + for(OrderedSetToListMapping mapping : rules) { + Instances entityFinder = graph.adapt(mapping.entityType, Instances.class); + for(Resource entity : entityFinder.find(graph, resource)) { + Resource orderedSet = graph.syncRequest(new PossibleObjectWithType(entity, mapping.orderedSetRelation, mapping.orderedSet)); + if(orderedSet != null) { + Collection list = OrderedSetUtils.toList(graph, orderedSet); + graph.deny(entity, mapping.orderedSetRelation, orderedSet); + graph.claim(entity, mapping.listRelation, ListUtils.create(graph, mapping.list, list)); + } + } + + } + } + }); + } + + } + + +}