X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Ftechtype%2Frequests%2FWriteTechTypeTable.java;fp=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Ftechtype%2Frequests%2FWriteTechTypeTable.java;h=1f85c5a43a039ba1fec5da57090eb86ee4c480b0;hb=96d2122ccc3a7d3503d0bf2ab121eb8fd2186323;hp=0000000000000000000000000000000000000000;hpb=40d019be6ff00ecec1c3250a03bb5c046ad98182;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/WriteTechTypeTable.java b/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/WriteTechTypeTable.java new file mode 100644 index 00000000..1f85c5a4 --- /dev/null +++ b/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/WriteTechTypeTable.java @@ -0,0 +1,45 @@ +package org.simantics.district.network.techtype.requests; + +import java.util.UUID; + +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.TransientCacheListener; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PossibleActiveModel; +import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.layer0.Layer0; + +public final class WriteTechTypeTable extends WriteRequest { + private final String data; + private final Resource componentType; + + public WriteTechTypeTable(Resource componentType, String data) { + this.data = data; + this.componentType = componentType; + } + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + + Resource model = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource())); + if (model == null) + throw new DatabaseException("No active model for storing tech type data"); + + Resource ttt = graph.syncRequest(new PossibleTechTypeTable(model, componentType), TransientCacheListener.instance()); + + if (ttt == null) { + ttt = graph.newResource(); + graph.claim(ttt, L0.InstanceOf, DN.TechType_TechTypeTable); + graph.claimLiteral(ttt, L0.HasName, UUID.randomUUID().toString()); + graph.claim(model, L0.ConsistsOf, ttt); + graph.claim(ttt, DN.TechType_TechTypeTable_HasComponentType, componentType); + } + + graph.claimLiteral(ttt, DN.TechType_TechTypeTable_HasData, data); + } +} \ No newline at end of file