1 package org.simantics.district.network.techtype.requests;
5 import org.simantics.Simantics;
6 import org.simantics.db.Resource;
7 import org.simantics.db.WriteGraph;
8 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
9 import org.simantics.db.common.request.WriteRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.request.PossibleActiveModel;
12 import org.simantics.district.network.ontology.DistrictNetworkResource;
13 import org.simantics.layer0.Layer0;
15 public final class WriteTechTypeTableRequest extends WriteRequest {
16 private final String data;
17 private final Resource componentType;
19 public WriteTechTypeTableRequest(Resource componentType, String data) {
21 this.componentType = componentType;
25 public void perform(WriteGraph graph) throws DatabaseException {
26 Layer0 L0 = Layer0.getInstance(graph);
27 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
29 Resource model = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
31 throw new DatabaseException("No active model for storing tech type data");
33 Resource ttt = graph.syncRequest(new PossibleTechTypeTable(model, componentType), TransientCacheListener.instance());
36 ttt = graph.newResource();
37 graph.claim(ttt, L0.InstanceOf, DN.TechType_TechTypeTable);
38 graph.claimLiteral(ttt, L0.HasName, UUID.randomUUID().toString());
39 graph.claim(model, L0.ConsistsOf, ttt);
40 graph.claim(ttt, DN.TechType_TechTypeTable_HasComponentType, componentType);
43 graph.claimLiteral(ttt, DN.TechType_TechTypeTable_HasData, data);