X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fgenericrelation%2FDependencies.java;h=83837a960a6950888baf3180b664be0fadfb4fbb;hp=bb942c20ca19e34eafebf527f06690748a3cfb22;hb=1f4133242efdb193390d76b0952ade00a3a88309;hpb=969bd23cab98a79ca9101af33334000879fb60c5 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 index bb942c20c..83837a960 100644 --- 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 @@ -1,79 +1,90 @@ -/******************************************************************************* - * 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; - } - } - -} +/******************************************************************************* + * 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.request.UniqueRead; +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; +import org.slf4j.LoggerFactory; + +/** + * dependencies: + * (ReadGraph, Resource model, String query) -> List> + * (ReadGraph, Resource model, String query, Integer maxResults) -> List> + * + * @author Antti Villberg + */ +public class Dependencies extends FunctionImpl4 { + + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Dependencies.class); + + 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"; + public static final String FIELD_NAME_SEARCH = "NameSearch"; + public static final String FIELD_TYPES_SEARCH = "TypesSearch"; + public static final String FIELD_TYPE_RESOURCE = "TypeId"; + + protected Resource getIndexRelation(ReadGraph graph) { + return Layer0X.getInstance(graph).DependenciesRelation; + } + + protected static String getBindingPattern() { + return "bffffffff"; + } + + @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 qc.syncRequestIndependent(graph, new UniqueRead() { + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + return index.query(graph, query, getBindingPattern(), new Object[] { model }, maxResults); + } + }); + + } catch (DatabaseException e) { + LOGGER.error("Error while performing index query", e); + return null; + } + } + +}