]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/Simantics.java
Add support for dependency changes in SCL
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / Simantics.java
index 9529628eaee3bab8dc38bec39cd1ee15a6db3e7f..b382fba9151798aa6f414b6b1f65071ebcc21212 100644 (file)
@@ -27,6 +27,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.Indexing;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.RuntimeDatabaseException;
@@ -125,6 +126,16 @@ public class Simantics {
             ontologyPolicy = OntologyRecoveryPolicy.ReinstallDatabase;
         }
 
+        if (args.contains(SimanticsArguments.DISABLE_INDEX)) {
+            Indexing.setDefaultDependenciesIndexingEnabled(false);
+        }
+
+        String databaseDriverId = defaultDatabaseDriverId;
+        if (args.contains(SimanticsArguments.DATABASE_ID)) {
+            databaseDriverId = args.get(SimanticsArguments.DATABASE_ID);
+            Simantics.setDefaultDatabaseDriver(databaseDriverId);
+        }
+
         int localPort = 0;
         if (args.contains(SimanticsArguments.LOCAL_SERVER_PORT)) {
             try {
@@ -144,7 +155,7 @@ public class Simantics {
 //            }
 //        }
 
-        return startUpHeadless(progress, workspacePolicy, ontologyPolicy, localPort /*, remoteDatabase*/);
+        return startUpHeadless(progress, workspacePolicy, ontologyPolicy, localPort, databaseDriverId /*, remoteDatabase*/);
     }
 
     /**
@@ -156,7 +167,7 @@ public class Simantics {
      * @return
      * @throws PlatformException
      */
-    public static ISessionContext startUpHeadless(IProgressMonitor progress, RecoveryPolicy workspacePolicy, OntologyRecoveryPolicy ontologyPolicy, int localPort) throws PlatformException {
+    public static ISessionContext startUpHeadless(IProgressMonitor progress, RecoveryPolicy workspacePolicy, OntologyRecoveryPolicy ontologyPolicy, int localPort, String databaseDriverId) throws PlatformException {
         if (SimanticsPlatform.INSTANCE.sessionContext != null) {
             throw new RuntimeDatabaseException("Simantics is already up and running.");
         }
@@ -169,7 +180,7 @@ public class Simantics {
 
         if (progress == null)
             progress = new NullProgressMonitor();
-        return SimanticsPlatform.INSTANCE.startUp(defaultDatabaseDriverId, progress, workspacePolicy, ontologyPolicy, true, new ConsoleUserAgent());
+        return SimanticsPlatform.INSTANCE.startUp(databaseDriverId, progress, workspacePolicy, ontologyPolicy, true, new ConsoleUserAgent());
     }
 
     /**
@@ -449,20 +460,30 @@ public class Simantics {
 
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-       public static <T> T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
-        SCLContext sclContext = SCLContext.getCurrent();
-           Object oldGraph = sclContext.put("graph", graph);
-               try {
-                       T t = (T)((Function)SCLOsgi.MODULE_REPOSITORY.getValue(module, function)).applyArray(args);
-                       return t;
-               } catch (ValueNotFound e) {
-                       throw new DatabaseException("SCL Value not found: " + e.name);
-               } catch (Throwable t) {
-                       throw new DatabaseException(t);
-               } finally {
-                       sclContext.put("graph", oldGraph);
-               }
+    public static <T> T applySCL(String module, String function, Object ... args) throws DatabaseException {
+        try {
+            T t = (T)((Function)SCLOsgi.MODULE_REPOSITORY.getValue(module, function)).applyArray(args);
+            return t;
+        } catch (ValueNotFound e) {
+            throw new DatabaseException("SCL Value not found: " + e.name);
+        } catch (Throwable t) {
+            throw new DatabaseException(t);
+        }
+    }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public static <T> T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
+        SCLContext sclContext = SCLContext.getCurrent();
+        Object oldGraph = sclContext.put("graph", graph);
+        try {
+            return applySCL(module, function, args);
+        } catch (DatabaseException dbe) {
+            throw dbe;
+        } catch (Throwable t) {
+            throw new DatabaseException(t);
+        } finally {
+            sclContext.put("graph", oldGraph);
+        }
     }
 
     @SuppressWarnings("unchecked")