]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteCommand.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / bundles / org.simantics.db.testing / src / org / simantics / db / testing / common / WriteCommand.java
diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteCommand.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteCommand.java
new file mode 100644 (file)
index 0000000..96d8c65
--- /dev/null
@@ -0,0 +1,41 @@
+package org.simantics.db.testing.common;
+
+import org.simantics.Simantics;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+
+abstract public class WriteCommand<T extends CommandSequenceEnvironment> extends Command<T> {
+
+       @Override
+       public void run(final T environment) throws Exception {
+               Simantics.getSession().sync(new WriteRequest() {
+
+                       @Override
+                       public void perform(WriteGraph graph) throws DatabaseException {
+                               WriteCommand.this.run(graph, environment);
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               return WriteCommand.this.toString();
+                       }
+                       
+               });
+               afterRun(environment);
+       }
+       
+       protected void run(WriteGraph graph, T environment) throws DatabaseException {
+               
+       }
+       
+       protected void afterRun(T environment) throws Exception {
+               
+       }
+
+       @Override
+       public String toString() {
+               return "WriteCommand " + getClass().getSimpleName();
+       }
+       
+}