1 package org.simantics.graph.db;
3 import java.util.HashSet;
5 import org.simantics.db.Session;
6 import org.simantics.db.WriteOnlyGraph;
7 import org.simantics.db.common.request.WriteOnlyRequest;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.service.InitSupport;
10 import org.simantics.db.service.SerialisationSupport;
11 import org.simantics.graph.representation.TransferableGraph1;
12 import org.simantics.scl.reflection.OntologyVersions;
14 public class CoreInitialization {
16 static final public String LAYER0 = OntologyVersions.getInstance().currentVersion("http://www.simantics.org/Layer0-0.0/");
17 static final HashSet<InitSupport.Builtin> BUILTINS =
18 new HashSet<InitSupport.Builtin>();
19 static public HashSet<InitSupport.Builtin> getBuiltins() {
22 private static int builtinId = 0;
23 private static void addBuiltin(String uri) {
24 BUILTINS.add(new InitSupport.Builtin(uri, ++builtinId));
26 private static void addLayer0Builtin(String name) {
27 addBuiltin(LAYER0 + name);
32 // DO NOT alter the order of these definitions in any way
33 // unless you deliberately want to make the system incompatible
34 // with databases that have been created before changing these.
35 addLayer0Builtin("InstanceOf");
36 addLayer0Builtin("Inherits");
37 addLayer0Builtin("SubrelationOf");
38 addLayer0Builtin("InverseOf");
40 addLayer0Builtin("HasName");
41 addLayer0Builtin("NameOf");
43 addLayer0Builtin("ConsistsOf");
44 addLayer0Builtin("PartOf");
46 addLayer0Builtin("String");
47 addLayer0Builtin("Library");
48 addLayer0Builtin("FunctionalRelation");
49 addLayer0Builtin("SuperrelationOf");
50 addLayer0Builtin("Asserts");
51 addLayer0Builtin("HasInstance");
52 addLayer0Builtin("HasPredicate");
53 addLayer0Builtin("HasPredicateInverse");
54 addLayer0Builtin("HasObject");
56 // #7016: This bogus URI replaces the builtin entry
57 // that was originally http://Projects.
59 // addBuiltin("http://Projects") was removed because its existence
60 // resulted in a non-functioning URI space because:
62 // 1. http://Projects was added as a "built-in resource" when the database
63 // is first initialized which means that ReadGraph.getResource("http://Projects")
64 // would succeed even when the resource was not yet properly imported
65 // from the project ontology.
67 // 2. When the project ontology is imported, a new resource is
68 // created to represent http://Projects instead of using the existing
69 // uninitialized "built-in resource". The L0.ExternalEntity changes made
70 // to the standard transferable graph import in this patch caused the
71 // code to find the built-in resource for "http://Projects" and think
72 // that it has to be a resource that's already properly initialized.
73 // This led to the TG import not initializing the resource at all.
74 // Previously there was a bug here as well but it was hidden by the fact
75 // that the system would import the actual/new "http://Projects"
76 // resource from the ontology anyway. This effectively left the
77 // uninitialized built-in resource just hanging in the database as
79 //addBuiltin("http://Projects");
80 addBuiltin("75e23fb39121b4b37cf2e6a26ccb34c52f77522d-do-not-remove");
82 addLayer0Builtin("ExternalEntity");
85 public static void initializeBuiltins(Session session) throws DatabaseException {
86 session.getService(InitSupport.class).addBuiltins(BUILTINS);
89 public static long[] initializeGraph(final Session session, TransferableGraph1 tg) throws DatabaseException {
90 final TransferableGraphImportProcess process = new TransferableGraphImportProcess(tg,
92 session.syncRequest(new WriteOnlyRequest() {
94 public void perform(WriteOnlyGraph graph) throws DatabaseException {
95 graph.markUndoPoint();
98 // session.getService(XSupport.class).setImmutable(session.getRootLibrary(), true);
100 process.initialPrepare(graph);
101 process.write(graph);
102 graph.clearUndoList(this);
106 return process.getResourceIds(
107 session.getService(SerialisationSupport.class)