X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics%2Fsrc%2Forg%2Fsimantics%2FSimanticsPlatform.java;h=c5ed8fd1e6374b70294bf65ecd5a4034b40b2efa;hp=a4206e7da3e677a947a6b1db5e7033f547f32eaa;hb=b402468a5f6a74cce769eedf1d9f9b531b123842;hpb=61f2633b2846d5250f7110676fe72af3880c0e19 diff --git a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java index a4206e7da..c5ed8fd1e 100644 --- a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java +++ b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -45,6 +44,8 @@ import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.resolver.BundleDescription; import org.ini4j.Ini; import org.ini4j.InvalidFileFormatException; +import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy; +import org.simantics.SimanticsPlatform.RecoveryPolicy; import org.simantics.databoard.Bindings; import org.simantics.databoard.Databoard; import org.simantics.datatypes.literal.Font; @@ -59,6 +60,8 @@ import org.simantics.db.SessionModel; import org.simantics.db.UndoContext; import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; +import org.simantics.db.common.processor.MergingDelayedWriteProcessor; +import org.simantics.db.common.processor.MergingGraphRequestProcessor; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.Transaction; @@ -82,6 +85,7 @@ import org.simantics.db.service.QueryControl; import org.simantics.db.service.UndoRedoSupport; import org.simantics.db.service.VirtualGraphSupport; import org.simantics.db.service.XSupport; +import org.simantics.db.services.GlobalServiceInitializer; import org.simantics.graph.db.GraphDependencyAnalyzer; import org.simantics.graph.db.GraphDependencyAnalyzer.IU; import org.simantics.graph.db.GraphDependencyAnalyzer.IdentityNode; @@ -153,7 +157,7 @@ public class SimanticsPlatform implements LifecycleListener { * It is applied when the ontology in the database of a workspace doesn't match * a newer ontology in the Eclipse workspace. */ - public static enum OntologyRecoveryPolicy { ThrowError, Merge, ReinstallDatabase } + public static enum OntologyRecoveryPolicy { ThrowError, Merge, ReinstallDatabase, Bypass} /** * This policy dictates how the Simantics platform startup should react if @@ -234,7 +238,7 @@ public class SimanticsPlatform implements LifecycleListener { if (progressMonitor == null) progressMonitor = new NullProgressMonitor(); Path workspaceLocation = Platform.getLocation().toFile().toPath(); - Path dbLocation = workspaceLocation.resolve("db"); + Path dbLocation = dbLocation(); Path dbIniPath = workspaceLocation.resolve("db.ini"); // The driver file overrides any command line arguments to prevent // using the wrong driver for an existing database directory. @@ -346,7 +350,7 @@ public class SimanticsPlatform implements LifecycleListener { session.getService(XSupport.class).setServiceMode(true, true); // Throw error - if (ontologyPolicy == OntologyRecoveryPolicy.ThrowError) { + if (ontologyPolicy == OntologyRecoveryPolicy.ThrowError || ontologyPolicy == OntologyRecoveryPolicy.Bypass) { StringBuilder sb = new StringBuilder("The following graphs are not installed in the database: "); if (!installTGs.isEmpty()) { int i = 0; @@ -367,8 +371,12 @@ public class SimanticsPlatform implements LifecycleListener { sb.append(" Database/Platform Bundle version mismatch.\n"); } sb.append("Hint: Use -fixErrors to install the graphs."); - throw new PlatformException(sb.toString()); + if (ontologyPolicy == OntologyRecoveryPolicy.ThrowError) + throw new PlatformException(sb.toString()); + else + log.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, sb.toString())); } + // Reinstall database if (ontologyPolicy == OntologyRecoveryPolicy.ReinstallDatabase) { log.log(new Status(IStatus.INFO, Activator.PLUGIN_ID, "Reinstalling the database.")); @@ -383,6 +391,8 @@ public class SimanticsPlatform implements LifecycleListener { throw new PlatformException("Reinstalling Database, NOT IMPLEMENTED"); } + boolean serviceModeEntered = false; + if (ontologyPolicy == OntologyRecoveryPolicy.Merge) { message = "Merging ontology changes"; monitor.subTask(message); @@ -441,6 +451,14 @@ public class SimanticsPlatform implements LifecycleListener { session.getService(XSupport.class).setServiceMode(true, createImmutable); + // Flush all queries once to allow even immutable request results to be invalidated + // because ontology installation affects immutable content and queries related to + // immutable content would not get invalidated at all otherwise. + if (!serviceModeEntered) { + serviceModeEntered = true; + session.getService(QueryControl.class).flush(); + } + // Install TG log.log(new Status(IStatus.INFO, Activator.PLUGIN_ID, "Installing "+tg.toString()+" - "+tg.getName())); ImportResult result = TransferableGraphs.importGraph1(session, new TGTransferableGraphSource(tg.getGraph()), advisor, null); @@ -491,6 +509,11 @@ public class SimanticsPlatform implements LifecycleListener { } } session.getService(XSupport.class).setServiceMode(false, false); + if (serviceModeEntered) { + // Flush all queries to ensure that queries that should now + // be immutable are not left as mutable in the query cache. + session.getService(QueryControl.class).flush(); + } } message = "Ontologies synchronized"; monitor.subTask(message); @@ -669,10 +692,12 @@ public class SimanticsPlatform implements LifecycleListener { } public void resetDatabase(IProgressMonitor monitor) throws PlatformException { - File dbLocation = Platform.getLocation().append("db").toFile(); - if(!dbLocation.exists()) return; + // TODO: fix this to use Path APIs + File dbLocation = dbLocation().toFile(); + if(!dbLocation.exists()) + return; try { // Load driver - Driver driver = Manager.getDriver("procore"); + Driver driver = Manager.getDriver("acorn"); Management management = driver.getManagement(dbLocation.getAbsolutePath(), null); management.delete(); } catch (DatabaseException e) { @@ -711,53 +736,16 @@ public class SimanticsPlatform implements LifecycleListener { return l == null ? null : new File(l.getURL().getPath()).toPath(); } - private Path resolveBaselineFile() throws PlatformException { - String dbBaselineArchive = System.getProperty("org.simantics.db.baseline", null); - if (dbBaselineArchive == null) - return null; - - Path baseline = Paths.get(dbBaselineArchive); - if (baseline.isAbsolute()) { - if (!Files.isRegularFile(baseline)) - throw new PlatformException("Specified database baseline archive " + baseline - + " does not exist. Cannot initialize workspace database from baseline."); - return baseline; - } - - // Relative path resolution order: - // 1. from the platform "install location" - // 2. from working directory - Path installLocation = tryGetInstallLocation(); - if (installLocation != null) { - Path installedBaseline = installLocation.resolve(dbBaselineArchive); - if (Files.isRegularFile(installedBaseline)) - return installedBaseline; - } - if (!Files.isRegularFile(baseline)) - throw new PlatformException("Specified database baseline archive " + baseline - + " does not exist in either the install location (" + installLocation - + ") or the working directory (" + Paths.get(".").toAbsolutePath() - + "). Cannot initialize workspace database."); + public Path databaseExists() { + Path dbLocation = dbLocation(); + if(Files.exists(dbLocation)) + return dbLocation; return null; } - - private boolean handleBaselineDatabase() throws PlatformException { + + public Path dbLocation() { Path workspaceLocation = Platform.getLocation().toFile().toPath(); - Path baselineIndicatorFile = workspaceLocation.resolve(".baselined"); - if (Files.isRegularFile(baselineIndicatorFile)) { - // This means that the workspace has already been initialized from - // a database baseline and further initialization is not necessary. - return true; - } - - Path baseline = resolveBaselineFile(); - if (baseline == null) - return false; - - DatabaseBaselines.validateBaselineFile(baseline); - DatabaseBaselines.validateWorkspaceForBaselineInitialization(workspaceLocation); - DatabaseBaselines.initializeWorkspaceWithBaseline(baseline, workspaceLocation, baselineIndicatorFile); - return true; + return workspaceLocation.resolve("db"); } /** @@ -817,7 +805,7 @@ public class SimanticsPlatform implements LifecycleListener { // 0.3 Handle baseline database before opening db @SuppressWarnings("unused") - boolean usingBaseline = handleBaselineDatabase(); + boolean usingBaseline = DatabaseBaselines.handleBaselineDatabase(tryGetInstallLocation(), databaseExists() != null); // 1. Assert there is a database at /db SessionDescriptor sessionDescriptor = setupDatabase(databaseDriverId, monitor.newChild(200, SubMonitor.SUPPRESS_NONE), workspacePolicy, userAgent); @@ -946,6 +934,13 @@ public class SimanticsPlatform implements LifecycleListener { } + public void registerServices(SessionContext context) { + new GlobalServiceInitializer().initialize(session); + session.registerService(MergingGraphRequestProcessor.class, new MergingGraphRequestProcessor("SessionService", session, 20)); + session.registerService(MergingDelayedWriteProcessor.class, new MergingDelayedWriteProcessor(session, 20)); + } + + public SessionContext createSessionContext(boolean init) throws PlatformException { try { // Construct and initialize SessionContext from Session. @@ -953,7 +948,7 @@ public class SimanticsPlatform implements LifecycleListener { String message = "Session context created"; LOGGER.info(message); if (init) { - sessionContext.registerServices(); + registerServices(sessionContext); message = "Session services registered"; LOGGER.info(message); }