X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fqueries%2FConnectionPointMapOfResource.java;fp=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fqueries%2FConnectionPointMapOfResource.java;h=2dff0a74006baa38fe9f1669ff5a037f60e2fde0;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionPointMapOfResource.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionPointMapOfResource.java new file mode 100644 index 000000000..2dff0a740 --- /dev/null +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionPointMapOfResource.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * 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.structural2.queries; + +import gnu.trove.map.hash.THashMap; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; +import org.simantics.db.common.request.TransientResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PropertyInfo; +import org.simantics.db.request.RequestFlags; +import org.simantics.db.service.QueryControl; + +public class ConnectionPointMapOfResource extends TransientResourceRead> { + + public ConnectionPointMapOfResource(ReadGraph graph, Resource resource) throws DatabaseException { + super(graph, resource); + } + + public ConnectionPointMapOfResource(ReadGraph graph, QueryControl qc, Resource resource) throws DatabaseException { + super(graph, qc, resource); + } + + @Override + public Map perform(ReadGraph graph, Resource resource) throws DatabaseException { + + Collection predicates = graph.getPredicates(resource); + + THashMap result = null; + + for(Resource predicate : predicates) { + + PropertyInfo info = graph.syncRequest(new PossibleConnectionPointInfo(predicate), TransientCacheAsyncListener.instance()); + if(info != null) { + if (result == null) result = new THashMap(predicates.size()); + if (result.put(info.name, predicate) != null) + System.err.println(this + ": The database contains siblings with the same name " + info.name + " (resource=$" + resource.getResourceId() + ")."); + } + + } + + if(result != null) return result; + + else return Collections.emptyMap(); + + } + + @Override + public int getType() { + return RequestFlags.INVALIDATE; + } + +}