}
public static void asyncRead(final Function f) throws DatabaseException {
- final SCLContext context = SCLContext.getCurrent();
- Object graph = context.get(GRAPH);
- if (graph != null) {
- f.apply(Tuple0.INSTANCE);
- } else {
- Simantics.getSession().asyncRequest(new ReadRequest() {
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
- SCLContext.push(context);
- ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph);
- try {
- f.apply(Tuple0.INSTANCE);
- } finally {
- context.put(GRAPH, oldGraph);
- SCLContext.pop();
- }
+ final SCLContext context = SCLContext.createDerivedContext();
+ Simantics.getSession().asyncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ SCLContext.push(context);
+ context.put(GRAPH, graph);
+ try {
+ f.apply(Tuple0.INSTANCE);
+ } finally {
+ SCLContext.pop();
}
- });
- }
+ }
+ });
}
public static <T> T syncRead(final Function f) throws DatabaseException {
}
public static void asyncWrite(final Function f) throws DatabaseException {
- final SCLContext context = SCLContext.getCurrent();
- Object graph = context.get(GRAPH);
- if (graph != null) {
- f.apply(Tuple0.INSTANCE);
- } else {
- Simantics.getSession().asyncRequest(new WriteRequest() {
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- SCLContext.push(context);
- ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph);
- try {
- f.apply(Tuple0.INSTANCE);
- } finally {
- context.put(GRAPH, oldGraph);
- SCLContext.pop();
- }
+ SCLContext context = SCLContext.createDerivedContext();
+ Simantics.getSession().asyncRequest(new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ SCLContext.push(context);
+ context.put(GRAPH, graph);
+ try {
+ f.apply(Tuple0.INSTANCE);
+ } finally {
+ SCLContext.pop();
}
- });
- }
+ }
+ });
}
public static <T> T syncWrite(final Function f) throws DatabaseException {