X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fgenericrelation%2FDependencies.java;fp=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fgenericrelation%2FDependencies.java;h=bb942c20ca19e34eafebf527f06690748a3cfb22;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java new file mode 100644 index 000000000..bb942c20c --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.layer0.genericrelation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.GenericRelationIndex; +import org.simantics.db.service.QueryControl; +import org.simantics.operation.Layer0X; +import org.simantics.scl.runtime.function.FunctionImpl4; +import org.simantics.scl.runtime.function.UnsaturatedFunction2; + +/** + * dependencies: + * (ReadGraph, Resource model, String query) -> List> + * (ReadGraph, Resource model, String query, Integer maxResults) -> List> + * + * @author Antti Villberg + */ +public class Dependencies extends FunctionImpl4 { + + public static final String FIELD_MODEL = "Model"; + public static final String FIELD_PARENT = "Parent"; + public static final String FIELD_RESOURCE = "Resource"; + public static final String FIELD_NAME = "Name"; + public static final String FIELD_TYPES = "Types"; + public static final String FIELD_GUID = "GUID"; + + protected Resource getIndexRelation(ReadGraph graph) { + return Layer0X.getInstance(graph).DependenciesRelation; + } + + protected static String getBindingPattern() { + return "bfffff"; + } + + @Override + public Object apply(ReadGraph p0, Resource p1) { + return new UnsaturatedFunction2(this, p0, p1); + } + + @Override + public Object apply(ReadGraph p0, Resource p1, String p2) { + return apply(p0, p1, p2, Integer.MAX_VALUE); + } + + @Override + public Object apply(ReadGraph graph, final Resource model, final String query, Integer _maxResults) { + + try { + + final GenericRelationIndex index = graph.adapt(getIndexRelation(graph), GenericRelationIndex.class); + + // Listen + graph.syncRequest(new ExternalRequest(index, model)); + + final int maxResults = _maxResults != null ? _maxResults : Integer.MAX_VALUE; + + QueryControl qc = graph.getService(QueryControl.class); + return index.query(qc.getIndependentGraph(graph), query, getBindingPattern(), new Object[] { model }, maxResults); + + } catch (DatabaseException e) { + Logger.defaultLogError(e); + return null; + } + } + +}