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;
21 public DocumentRequest(Variable var) {
26 public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
28 long s = System.nanoTime();
30 Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
31 HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
33 return Collections.emptyList();
37 /*TreeMap<String, Variable> nodeMap = new TreeMap<String, Variable>();
39 for (Variable node : nodes) {
40 nodeMap.put(node.getURI(graph), node);
42 System.out.println("*************************************************************************");
43 for (Variable node : nodeMap.values()) {
44 System.out.println(" " + node.getURI(graph));
47 for(Variable node : nodes) {
48 rs.add(graph.syncRequest(new NodeRequest(node), TransientCacheAsyncListener.<JSONObject>instance()));
51 ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
52 Collections.sort(result, new Comparator<JSONObject>() {
55 public int compare(JSONObject o1, JSONObject o2) {
56 return o1.id.compareTo(o2.id);
62 long dura = System.nanoTime()-s;
63 System.err.println("DocumentRequest " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms.");