1 package org.simantics.document.server.handler;
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;
12 public abstract class WriteEventHandler extends AbstractEventHandler {
14 protected abstract CommandResult handle(WriteGraph graph, CommandContext parameters) throws DatabaseException;
16 public CommandResult handle(final CommandContext parameters) {
18 CommandResult response = Simantics.getSession().syncRequest(new WriteResultRequest<CommandResult>() {
20 public CommandResult perform(WriteGraph graph) throws DatabaseException {
21 graph.markUndoPoint();
22 return handle(graph, parameters);
26 if(response instanceof IDelayedResponse && !(((IDelayedResponse)response).hasRun())) {
28 synchronized(response) {
29 response.wait(200000);
31 } catch (InterruptedException e) {
37 } catch (DatabaseException e) {
39 return new Error(e.getMessage()); // Return some error