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.AsyncReadGraph;
11 import org.simantics.db.ReadGraph;
12 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
13 import org.simantics.db.common.request.AsyncReadRequest;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.layer0.request.VariableRead;
16 import org.simantics.db.layer0.variable.Variable;
17 import org.simantics.db.procedure.AsyncProcedure;
18 import org.simantics.document.server.JSONObject;
20 public class DocumentRequest extends VariableRead<List<JSONObject>> {
22 public static boolean PROFILE = false;
23 // Thresholds in microseconds
24 public static int PROFILE_THRESHOLD_NODEREQUEST = 2000;
25 public static int PROFILE_THRESHOLD_VALUEREQUEST = 500;
27 public DocumentRequest(Variable var) {
32 public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
34 long s = System.nanoTime();
36 Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
37 HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
39 return Collections.emptyList();
43 long dura = System.nanoTime()-s;
44 System.err.println("DocumentRequest1 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
47 graph.syncRequest(new AsyncReadRequest() {
50 public void run(AsyncReadGraph graph) throws DatabaseException {
52 for(Variable node : nodes) {
53 graph.asyncRequest(new NodeRequest(node), new AsyncProcedure<JSONObject> () {
56 public void execute(AsyncReadGraph graph, JSONObject result) {
63 public void exception(AsyncReadGraph graph, Throwable throwable) {
76 long dura = System.nanoTime()-s;
77 System.err.println("DocumentRequest2 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
80 ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
81 Collections.sort(result, new Comparator<JSONObject>() {
84 public int compare(JSONObject o1, JSONObject o2) {
85 return o1.id.compareTo(o2.id);
91 long dura = System.nanoTime()-s;
92 System.err.println("DocumentRequest3 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));