]> gerrit.simantics Code Review - simantics/platform.git/blob
e16e2a3ecd4e3d7f9598c3312fd9ba2e39ef7ded
[simantics/platform.git] /
1 package org.simantics.layer0;
2
3 import org.simantics.db.RequestProcessor;
4 import org.simantics.db.Resource;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.request.Read;
7 import org.simantics.db.Session;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.service.QueryControl;
10
11 public class SoftwareConfigurationResources {
12     
13     public final Resource HasVersion;
14     public final Resource HasVersion_Inverse;
15     public final Resource IsCompatibleWith;
16     public final Resource Product;
17     public final Resource Update;
18     public final Resource Update_From;
19     public final Resource Update_HasMigrationAction;
20     public final Resource Update_To;
21     public final Resource Version;
22     public final Resource Version_HasUpdate;
23     public final Resource Version_Of;
24         
25     public static class URIs {
26         public static final String HasVersion = "http://www.simantics.org/SoftwareConfiguration-1.1/HasVersion";
27         public static final String HasVersion_Inverse = "http://www.simantics.org/SoftwareConfiguration-1.1/HasVersion/Inverse";
28         public static final String IsCompatibleWith = "http://www.simantics.org/SoftwareConfiguration-1.1/IsCompatibleWith";
29         public static final String Product = "http://www.simantics.org/SoftwareConfiguration-1.1/Product";
30         public static final String Update = "http://www.simantics.org/SoftwareConfiguration-1.1/Update";
31         public static final String Update_From = "http://www.simantics.org/SoftwareConfiguration-1.1/Update/From";
32         public static final String Update_HasMigrationAction = "http://www.simantics.org/SoftwareConfiguration-1.1/Update/HasMigrationAction";
33         public static final String Update_To = "http://www.simantics.org/SoftwareConfiguration-1.1/Update/To";
34         public static final String Version = "http://www.simantics.org/SoftwareConfiguration-1.1/Version";
35         public static final String Version_HasUpdate = "http://www.simantics.org/SoftwareConfiguration-1.1/Version/HasUpdate";
36         public static final String Version_Of = "http://www.simantics.org/SoftwareConfiguration-1.1/Version/Of";
37     }
38     
39     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
40         try {
41             return graph.getResource(uri);
42         } catch(DatabaseException e) {
43             System.err.println(e.getMessage());
44             return null;
45         }
46     }
47     
48     public SoftwareConfigurationResources(ReadGraph graph) {
49         HasVersion = getResourceOrNull(graph, URIs.HasVersion);
50         HasVersion_Inverse = getResourceOrNull(graph, URIs.HasVersion_Inverse);
51         IsCompatibleWith = getResourceOrNull(graph, URIs.IsCompatibleWith);
52         Product = getResourceOrNull(graph, URIs.Product);
53         Update = getResourceOrNull(graph, URIs.Update);
54         Update_From = getResourceOrNull(graph, URIs.Update_From);
55         Update_HasMigrationAction = getResourceOrNull(graph, URIs.Update_HasMigrationAction);
56         Update_To = getResourceOrNull(graph, URIs.Update_To);
57         Version = getResourceOrNull(graph, URIs.Version);
58         Version_HasUpdate = getResourceOrNull(graph, URIs.Version_HasUpdate);
59         Version_Of = getResourceOrNull(graph, URIs.Version_Of);
60     }
61     
62     public static SoftwareConfigurationResources getInstance(ReadGraph graph) {
63         Session session = graph.getSession();
64         SoftwareConfigurationResources ret = session.peekService(SoftwareConfigurationResources.class);
65         if(ret == null) {
66             QueryControl qc = graph.getService(QueryControl.class);
67             ret = new SoftwareConfigurationResources(qc.getIndependentGraph(graph));
68             session.registerService(SoftwareConfigurationResources.class, ret);
69         }
70         return ret;
71     }
72     
73     public static SoftwareConfigurationResources getInstance(RequestProcessor session) throws DatabaseException {
74         SoftwareConfigurationResources ret = session.peekService(SoftwareConfigurationResources.class);
75         if(ret == null) {
76             ret = session.syncRequest(new Read<SoftwareConfigurationResources>() {
77                 public SoftwareConfigurationResources perform(ReadGraph graph) throws DatabaseException {
78                     QueryControl qc = graph.getService(QueryControl.class);
79                     return new SoftwareConfigurationResources(qc.getIndependentGraph(graph));
80                 }
81             });
82             session.registerService(SoftwareConfigurationResources.class, ret);
83         }
84         return ret;
85     }
86     
87 }
88