1 package org.simantics.modeling.tests.commands;
3 import org.simantics.Simantics;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.request.WriteResultRequest;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.testing.common.Command;
10 import org.simantics.db.testing.common.CommandSequenceEnvironment;
11 import org.simantics.modeling.tests.traits.SingleResourceTrait;
12 import org.simantics.modeling.tests.traits.UriResourceTrait;
14 abstract public class ResourceWriteCommand<T extends CommandSequenceEnvironment> extends Command<T> implements SingleResourceTrait {
16 private Resource resource;
19 final public void run(final T environment) throws Exception {
20 resource = runResource(environment);
21 afterRun(environment);
24 public Resource runResource(final T environment) throws Exception {
25 return Simantics.getSession().sync(new WriteResultRequest() {
28 public Resource perform(WriteGraph graph) throws DatabaseException {
29 return ResourceWriteCommand.this.run(graph, environment);
33 public String toString() {
34 return ResourceWriteCommand.this.toString();
40 protected Resource run(WriteGraph graph, T environment) throws DatabaseException {
41 throw new IllegalStateException();
44 protected void afterRun(T environment) throws Exception {
49 public String toString() {
50 return "ResourceWriteCommand " + getClass().getSimpleName();
54 public Resource getResource() throws DatabaseException {
59 public Resource getResource(ReadGraph graph) throws DatabaseException {
64 public SingleResourceTrait child(String path) {
65 return new UriResourceTrait(this, path);