X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics%2Fsrc%2Forg%2Fsimantics%2FSimantics.java;h=35808bd929fa74d63f18f860bdc51680abeababf;hp=9529628eaee3bab8dc38bec39cd1ee15a6db3e7f;hb=e460fd6f0af60314e2ca28391ef7ff2043016d97;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics/src/org/simantics/Simantics.java b/bundles/org.simantics/src/org/simantics/Simantics.java index 9529628ea..35808bd92 100644 --- a/bundles/org.simantics/src/org/simantics/Simantics.java +++ b/bundles/org.simantics/src/org/simantics/Simantics.java @@ -24,9 +24,11 @@ import org.simantics.SimanticsPlatform.RecoveryPolicy; import org.simantics.application.arguments.IArguments; import org.simantics.application.arguments.SimanticsArguments; import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; 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; @@ -42,6 +44,7 @@ import org.simantics.db.management.SessionContextProvider; import org.simantics.db.management.SingleSessionContextProviderSource; import org.simantics.db.request.ReadInterface; import org.simantics.db.request.WriteInterface; +import org.simantics.db.service.XSupport; import org.simantics.internal.FileServiceImpl; import org.simantics.layer0.Layer0; import org.simantics.project.IProject; @@ -125,6 +128,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 +157,7 @@ public class Simantics { // } // } - return startUpHeadless(progress, workspacePolicy, ontologyPolicy, localPort /*, remoteDatabase*/); + return startUpHeadless(progress, workspacePolicy, ontologyPolicy, localPort, databaseDriverId /*, remoteDatabase*/); } /** @@ -156,7 +169,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 +182,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()); } /** @@ -272,6 +285,14 @@ public class Simantics { throw new IllegalStateException("Session unavailable, no database session open"); return ctx.getSession(); } + + public static RequestProcessor getAvailableRequestProcessor() { + Object graph = SCLContext.getCurrent().get("graph"); + if(graph instanceof ReadGraph) + return (RequestProcessor)graph; + else + return Simantics.getSession(); + } /** * Returns the database Session bound to the currently active context. @@ -447,22 +468,41 @@ public class Simantics { } } + public static void saveQueries(Session session) { + try { + XSupport xs = session.getService(XSupport.class); + xs.saveQueries(); + } catch (Exception e) { + LOGGER.error("Saving database queries failed.", e); + } + } @SuppressWarnings({ "unchecked", "rawtypes" }) - public static 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 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) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; + throw new DatabaseException(t); + } + } + public static 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") @@ -472,6 +512,8 @@ public class Simantics { try { return (T)f.applyArray(args); } catch (Throwable t) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; throw new DatabaseException(t); } finally { sclContext.put("graph", oldGraph); @@ -485,6 +527,8 @@ public class Simantics { try { return (T)f.applyArray(args); } catch (Throwable t) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; throw new DatabaseException(t); } finally { sclContext.put("graph", oldGraph); @@ -497,6 +541,8 @@ public class Simantics { try { return function.apply(p0); } catch (Throwable t) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; throw new DatabaseException(t); } finally { sclContext.put("graph", oldGraph); @@ -509,6 +555,8 @@ public class Simantics { try { return function.apply(p0); } catch (Throwable t) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; throw new DatabaseException(t); } finally { sclContext.put("graph", oldGraph); @@ -521,6 +569,8 @@ public class Simantics { try { return function.apply(p0, p1); } catch (Throwable t) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; throw new DatabaseException(t); } finally { sclContext.put("graph", oldGraph);