]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java
AsyncBarrier.dec runs into refcounting problem
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / Dependencies.java
index bb942c20ca19e34eafebf527f06690748a3cfb22..83837a960a6950888baf3180b664be0fadfb4fbb 100644 (file)
@@ -1,79 +1,90 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.layer0.genericrelation;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.GenericRelationIndex;\r
-import org.simantics.db.service.QueryControl;\r
-import org.simantics.operation.Layer0X;\r
-import org.simantics.scl.runtime.function.FunctionImpl4;\r
-import org.simantics.scl.runtime.function.UnsaturatedFunction2;\r
-\r
-/**\r
- * dependencies:\r
- *      (ReadGraph, Resource model, String query) -> List<Map<String, Object>>\r
- *      (ReadGraph, Resource model, String query, Integer maxResults) -> List<Map<String, Object>>\r
- * \r
- * @author Antti Villberg\r
- */\r
-public class Dependencies extends FunctionImpl4<ReadGraph, Resource, String, Integer, Object> {\r
-\r
-    public static final String FIELD_MODEL    = "Model";\r
-    public static final String FIELD_PARENT   = "Parent";\r
-    public static final String FIELD_RESOURCE = "Resource";\r
-    public static final String FIELD_NAME     = "Name";\r
-    public static final String FIELD_TYPES    = "Types";\r
-    public static final String FIELD_GUID    = "GUID";\r
-\r
-    protected Resource getIndexRelation(ReadGraph graph) {\r
-        return Layer0X.getInstance(graph).DependenciesRelation;\r
-    }\r
-\r
-    protected static String getBindingPattern() {\r
-        return "bfffff";\r
-    }\r
-\r
-    @Override\r
-    public Object apply(ReadGraph p0, Resource p1) {\r
-        return new UnsaturatedFunction2(this, p0, p1);\r
-    }\r
-\r
-    @Override\r
-    public Object apply(ReadGraph p0, Resource p1, String p2) {\r
-        return apply(p0, p1, p2, Integer.MAX_VALUE);\r
-    }\r
-\r
-    @Override\r
-    public Object apply(ReadGraph graph, final Resource model, final String query, Integer _maxResults) {\r
-        \r
-        try {\r
-\r
-            final GenericRelationIndex index = graph.adapt(getIndexRelation(graph), GenericRelationIndex.class);\r
-\r
-            // Listen\r
-            graph.syncRequest(new ExternalRequest(index, model));\r
-            \r
-            final int maxResults = _maxResults != null ? _maxResults : Integer.MAX_VALUE;\r
-            \r
-            QueryControl qc = graph.getService(QueryControl.class);\r
-            return index.query(qc.getIndependentGraph(graph), query, getBindingPattern(), new Object[] { model }, maxResults);\r
-            \r
-        } catch (DatabaseException e) {\r
-            Logger.defaultLogError(e);\r
-            return null;\r
-        }\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * 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<Map<String, Object>>
+ *      (ReadGraph, Resource model, String query, Integer maxResults) -> List<Map<String, Object>>
+ * 
+ * @author Antti Villberg
+ */
+public class Dependencies extends FunctionImpl4<ReadGraph, Resource, String, Integer, Object> {
+
+    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<Object>() {
+                @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;
+        }
+    }
+
+}