]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.server/src/org/simantics/document/server/handler/WriteEventHandler.java
Do not override jersey in p2.site pom.xml as release/1.43.0 is jdk8
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / handler / WriteEventHandler.java
1 package org.simantics.document.server.handler;
2
3 import org.simantics.Simantics;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.common.request.WriteResultRequest;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.document.server.io.CommandContext;
8 import org.simantics.document.server.io.CommandResult;
9 import org.simantics.document.server.serverResponse.Error;
10 import org.simantics.document.server.serverResponse.IDelayedResponse;
11
12 public abstract class WriteEventHandler extends AbstractEventHandler {
13
14     protected abstract CommandResult handle(WriteGraph graph, CommandContext parameters) throws DatabaseException;
15
16     public CommandResult handle(final CommandContext parameters) {
17         try {
18                 CommandResult response = Simantics.getSession().syncRequest(new WriteResultRequest<CommandResult>() {
19                 @Override
20                 public CommandResult perform(WriteGraph graph) throws DatabaseException {
21                     graph.markUndoPoint();
22                     return handle(graph, parameters);
23                 }
24             });
25
26             if(response instanceof IDelayedResponse && !(((IDelayedResponse)response).hasRun())) {
27                 try {
28                     synchronized(response) {
29                         response.wait(200000);
30                     }
31                 } catch (InterruptedException e) {
32                     e.printStackTrace();
33                 }
34             }
35             
36             return response;
37         } catch (DatabaseException e) {
38             e.printStackTrace();
39             return new Error(e.getMessage()); // Return some error
40         }
41     }
42
43
44 }