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=aa0b503dace880ca7c18d86dd1584f944a18260e;hp=7839ce70db31de7b0de4dc80d6725e8dc603b505;hb=e460fd6f0af60314e2ca28391ef7ff2043016d97;hpb=159d04234f7fbf7554910a154b29a5dd7bbc6068 diff --git a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java index 7839ce70d..aa0b503da 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; @@ -239,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. @@ -392,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); @@ -450,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); @@ -500,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); @@ -678,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) { @@ -720,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"); } /** @@ -826,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); @@ -1033,6 +1012,11 @@ public class SimanticsPlatform implements LifecycleListener { } catch (Throwable t) { LOGGER.error("Failed to flush index caches.", t); } + + if("true".equals(System.getProperty("org.simantics.db.persistQueries"))) { + progress.subTask("Saving Queries"); + Simantics.saveQueries(s); + } } progress.subTask("Close Database Session");