1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.layer0.genericrelation;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.utils.Logger;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.adapter.GenericRelationIndex;
19 import org.simantics.db.service.QueryControl;
20 import org.simantics.operation.Layer0X;
21 import org.simantics.scl.runtime.function.FunctionImpl4;
22 import org.simantics.scl.runtime.function.UnsaturatedFunction2;
26 * (ReadGraph, Resource model, String query) -> List<Map<String, Object>>
27 * (ReadGraph, Resource model, String query, Integer maxResults) -> List<Map<String, Object>>
29 * @author Antti Villberg
31 public class Dependencies extends FunctionImpl4<ReadGraph, Resource, String, Integer, Object> {
33 public static final String FIELD_MODEL = "Model";
34 public static final String FIELD_PARENT = "Parent";
35 public static final String FIELD_RESOURCE = "Resource";
36 public static final String FIELD_NAME = "Name";
37 public static final String FIELD_TYPES = "Types";
38 public static final String FIELD_GUID = "GUID";
39 public static final String FIELD_NAME_SEARCH = "NameSearch";
40 public static final String FIELD_TYPES_SEARCH = "TypesSearch";
42 protected Resource getIndexRelation(ReadGraph graph) {
43 return Layer0X.getInstance(graph).DependenciesRelation;
46 protected static String getBindingPattern() {
51 public Object apply(ReadGraph p0, Resource p1) {
52 return new UnsaturatedFunction2(this, p0, p1);
56 public Object apply(ReadGraph p0, Resource p1, String p2) {
57 return apply(p0, p1, p2, Integer.MAX_VALUE);
61 public Object apply(ReadGraph graph, final Resource model, final String query, Integer _maxResults) {
65 final GenericRelationIndex index = graph.adapt(getIndexRelation(graph), GenericRelationIndex.class);
68 graph.syncRequest(new ExternalRequest(index, model));
70 final int maxResults = _maxResults != null ? _maxResults : Integer.MAX_VALUE;
72 QueryControl qc = graph.getService(QueryControl.class);
73 return index.query(qc.getIndependentGraph(graph), query, getBindingPattern(), new Object[] { model }, maxResults);
75 } catch (DatabaseException e) {
76 Logger.defaultLogError(e);