X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FDependentInstances3.java;fp=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FDependentInstances3.java;h=e0e53493774fb81e4242f9d4cb8798213b2cce06;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=9ef98c8bbec771ec968dad0fbad1753f87a2d8a3;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/DependentInstances3.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/DependentInstances3.java index 9ef98c8bb..e0e534937 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/DependentInstances3.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/DependentInstances3.java @@ -1,84 +1,84 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.common.request; - -import java.util.Set; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Statement; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.service.CollectionSupport; -import org.simantics.layer0.Layer0; -import org.simantics.utils.Development; - -import gnu.trove.map.hash.THashMap; - -public class DependentInstances3 extends ResourceRead { - - private static final boolean DEBUG = false; - - private static ThreadLocal> workArea = new ThreadLocal>() { - protected gnu.trove.map.hash.THashMap initialValue() { - return new THashMap<>(); - } - }; - - public DependentInstances3(Resource resource) { - super(resource); - } - - @Override - public ResourceSetGraph perform(ReadGraph graph) throws DatabaseException { - - if(resource.equals(graph.getRootLibrary())) return new ResourceSetGraph(graph, resource); - - if(Development.DEVELOPMENT) - if(graph.isImmutable(resource)) - System.err.println("Immutable resource in DependentInstances3: " + NameUtils.getSafeName(graph, resource, true)); - - // This is a loop - THashMap workingSet = workArea.get(); - ResourceSetGraph result = workingSet.get(this); - if(result != null) return result; - - result = new ResourceSetGraph(graph, resource); - - workingSet.put(this, result); - - CollectionSupport cs = graph.getService(CollectionSupport.class); - Set objects = cs.createSet(); - - Layer0 L0 = Layer0.getInstance(graph); - for(Statement dep : graph.getStatements(resource, L0.IsDependencyOf)) { - if(graph.isSubrelationOf(dep.getPredicate(), L0.HasPrevious)) continue; - Resource object = dep.getObject(); - if(graph.isImmutable(object)) continue; - objects.add(object); - } - - for(Resource object : objects ) { - if(DEBUG) - System.err.println(NameUtils.getSafeName(graph, object, true) + " depends on " + NameUtils.getSafeName(graph, resource, true)); - DependentInstances3 query = new DependentInstances3(object); - ResourceSetGraph instances = workingSet.get(query); - if(instances == null) instances = graph.syncRequest(query); - result.references.add(instances); - } - - workingSet.remove(this); - return result; - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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.common.request; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.CollectionSupport; +import org.simantics.layer0.Layer0; +import org.simantics.utils.Development; + +import gnu.trove.map.hash.THashMap; + +public class DependentInstances3 extends ResourceRead { + + private static final boolean DEBUG = false; + + private static ThreadLocal> workArea = new ThreadLocal>() { + protected gnu.trove.map.hash.THashMap initialValue() { + return new THashMap<>(); + } + }; + + public DependentInstances3(Resource resource) { + super(resource); + } + + @Override + public ResourceSetGraph perform(ReadGraph graph) throws DatabaseException { + + if(resource.equals(graph.getRootLibrary())) return new ResourceSetGraph(graph, resource); + + if(Development.DEVELOPMENT) + if(graph.isImmutable(resource)) + System.err.println("Immutable resource in DependentInstances3: " + NameUtils.getSafeName(graph, resource, true)); + + // This is a loop + THashMap workingSet = workArea.get(); + ResourceSetGraph result = workingSet.get(this); + if(result != null) return result; + + result = new ResourceSetGraph(graph, resource); + + workingSet.put(this, result); + + CollectionSupport cs = graph.getService(CollectionSupport.class); + Set objects = cs.createSet(); + + Layer0 L0 = Layer0.getInstance(graph); + for(Statement dep : graph.getStatements(resource, L0.IsDependencyOf)) { + if(graph.isSubrelationOf(dep.getPredicate(), L0.HasPrevious)) continue; + Resource object = dep.getObject(); + if(graph.isImmutable(object)) continue; + objects.add(object); + } + + for(Resource object : objects ) { + if(DEBUG) + System.err.println(NameUtils.getSafeName(graph, object, true) + " depends on " + NameUtils.getSafeName(graph, resource, true)); + DependentInstances3 query = new DependentInstances3(object); + ResourceSetGraph instances = workingSet.get(query); + if(instances == null) instances = graph.syncRequest(query); + result.references.add(instances); + } + + workingSet.remove(this); + return result; + + } + +}