import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.RealizationVirtualGraph;\r
+import org.simantics.db.layer0.adapter.RemoverUtil;\r
import org.simantics.db.layer0.adapter.ResourceData;\r
import org.simantics.db.layer0.adapter.RuntimeValuations;\r
import org.simantics.db.request.Read;\r
\r
public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {\r
\r
- public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException {\r
- super(session, model, SysdynResource.getInstance(session).HistoryRealization);\r
- }\r
- \r
- @Override\r
- public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException {\r
- \r
- graph.asyncRequest(new Read<Collection<Resource>>() {\r
-\r
- @Override\r
- public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+ public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException {\r
+ super(session, model, SysdynResource.getInstance(session).HistoryRealization);\r
+ }\r
+\r
+ @Override\r
+ public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException {\r
+\r
+ graph.asyncRequest(new Read<Collection<Resource>>() {\r
+\r
+ @Override\r
+ public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
// System.out.println("Compute runs starts");\r
- HashSet<Resource> result = new HashSet<Resource>();\r
- Builtins b = graph.getBuiltins();\r
- for(Resource config : graph.getObjects(model, b.ConsistsOf)) {\r
- if(graph.isInstanceOf(config, b.Experiment)) {\r
- for(Resource run : graph.getObjects(config, b.ConsistsOf)) {\r
- if(graph.isInstanceOf(run, b.Run)) {\r
+ HashSet<Resource> result = new HashSet<Resource>();\r
+ Builtins b = graph.getBuiltins();\r
+ for(Resource config : graph.getObjects(model, b.ConsistsOf)) {\r
+ if(graph.isInstanceOf(config, b.Experiment)) {\r
+ for(Resource run : graph.getObjects(config, b.ConsistsOf)) {\r
+ if(graph.isInstanceOf(run, b.Run)) {\r
// System.out.println("found run " + run);\r
- result.add(run);\r
- }\r
- }\r
- }\r
- }\r
+ result.add(run);\r
+ }\r
+ }\r
+ }\r
+ }\r
// System.out.println("Compute runs ends");\r
- return result;\r
- }\r
- \r
- }, new SingleSetSyncListener<Resource>() {\r
+ return result;\r
+ }\r
\r
- @Override\r
- public void add(ReadGraph graph, final Resource run) throws DatabaseException {\r
+ }, new SingleSetSyncListener<Resource>() {\r
+\r
+ @Override\r
+ public void add(ReadGraph graph, final Resource run) throws DatabaseException {\r
+\r
+ final String experimentName = graph.getPossibleRelatedValue(run, b.HasName, StringBindingDefault.INSTANCE);\r
\r
- final String experimentName = graph.getPossibleRelatedValue(run, b.HasName, StringBindingDefault.INSTANCE);\r
- \r
// System.out.println("RealizationVirtualGraph new experiment " + experimentName);\r
\r
- RuntimeValuations vs = graph.getService(RuntimeValuations.class);\r
- if(vs.supports(experimentName)) {\r
+ RuntimeValuations vs = graph.getService(RuntimeValuations.class);\r
+ if(vs.supports(experimentName)) {\r
\r
// System.out.println("RealizationVirtualGraph scheduling " + experimentName);\r
\r
- graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- \r
+ graph.asyncRequest(new Read<Collection<Resource>>() {\r
+\r
+ @Override\r
+ public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+ HashSet<Resource> result = new HashSet<Resource>();\r
+ Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
+ for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
+ result.add(part);\r
+ }\r
+ return result;\r
+ }\r
+ }, new SingleSetSyncListener<Resource>() {\r
+\r
+ @Override\r
+ public void add(ReadGraph graph, final Resource part) throws DatabaseException {\r
+ graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ int runNode = context.getIndex(run);\r
+ String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
+ if(partName != null) {\r
+ Resource partResource = graph.newResource();\r
+ int partNode = context.getIndex(partResource);\r
+ graph.claim(run, b.ConsistsOf, null, partResource);\r
+ undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
+ }\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void remove(ReadGraph graph, final Resource part) throws DatabaseException {\r
+ \r
+ graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Integer key = null;\r
+ for(int k : undiscovered.keySet()) {\r
+ if (undiscovered.get(k).structureResource.equals(part)) {\r
+ key = k;\r
+ break;\r
+ }\r
+ }\r
+ if(key != null) {\r
+ Resource r = context.getResource(key);\r
+ RemoverUtil.remove(graph, r);\r
+ undiscovered.remove(key);\r
+ \r
+ }\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return false;\r
+ }\r
+\r
+ });\r
+\r
+/*\r
+ graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
// System.out.println("RealizationVirtualGraph about to serve " + experimentName);\r
\r
- int runNode = context.getIndex(run);\r
-\r
- Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
- for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
- String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
- if(partName != null) {\r
- Resource partResource = graph.newResource();\r
- int partNode = context.getIndex(partResource);\r
- graph.claim(run, b.ConsistsOf, null, partResource);\r
- undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
- }\r
- }\r
- \r
- }\r
- });\r
- \r
- }\r
- \r
- }\r
- \r
- @Override\r
- public void exception(ReadGraph graph, Throwable throwable) {\r
- throwable.printStackTrace();\r
- }\r
-\r
- @Override\r
- public boolean isDisposed() {\r
- return false;\r
- }\r
- \r
- });\r
- \r
- \r
- }\r
- \r
+ int runNode = context.getIndex(run);\r
+\r
+ Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
+ for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
+ String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
+ if(partName != null) {\r
+ Resource partResource = graph.newResource();\r
+ int partNode = context.getIndex(partResource);\r
+ graph.claim(run, b.ConsistsOf, null, partResource);\r
+ undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
+ }\r
+ }\r
+\r
+ }\r
+ });\r
+*/\r
+ \r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void exception(ReadGraph graph, Throwable throwable) {\r
+ throwable.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return false;\r
+ }\r
+\r
+ });\r
+\r
+\r
+ }\r
+\r
\r
}\r