1 package org.simantics.document.server.request;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Comparator;
6 import java.util.HashSet;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.request.VariableRead;
14 import org.simantics.db.layer0.variable.Variable;
15 import org.simantics.document.server.JSONObject;
17 public class DocumentRequest extends VariableRead<List<JSONObject>> {
19 public static boolean PROFILE = false;
20 // Thresholds in microseconds
21 public static int PROFILE_THRESHOLD_NODEREQUEST = 2000;
22 public static int PROFILE_THRESHOLD_VALUEREQUEST = 500;
24 public DocumentRequest(Variable var) {
29 public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
31 long s = System.nanoTime();
33 Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
34 HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
36 return Collections.emptyList();
40 /*TreeMap<String, Variable> nodeMap = new TreeMap<String, Variable>();
42 for (Variable node : nodes) {
43 nodeMap.put(node.getURI(graph), node);
45 System.out.println("*************************************************************************");
46 for (Variable node : nodeMap.values()) {
47 System.out.println(" " + node.getURI(graph));
50 for(Variable node : nodes) {
51 rs.add(graph.syncRequest(new NodeRequest(node), TransientCacheAsyncListener.<JSONObject>instance()));
54 ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
55 Collections.sort(result, new Comparator<JSONObject>() {
58 public int compare(JSONObject o1, JSONObject o2) {
59 return o1.id.compareTo(o2.id);
65 long dura = System.nanoTime()-s;
66 System.err.println("DocumentRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));