From 728147df5d63a3333daff3d8c0e9bfd4f5597e3a Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 16 Sep 2016 11:14:02 +0300 Subject: [PATCH] Sync git svn branch with SVN repository r33199. refs #6694 --- .../modeling/ui/actions/ModeledActions.java | 2 +- .../src/org/simantics/modeling/SCL.java | 2 +- .../management/ServerManagerFactory.java | 10 +++---- .../internal/SimanticsWorkbenchAdvisor.java | 16 +++--------- .../src/org/simantics/Simantics.java | 26 ++++++++++++++++++- .../src/org/simantics/SimanticsPlatform.java | 14 +++++----- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java index ba53b9223..47d5643a1 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java @@ -54,7 +54,7 @@ public class ModeledActions extends DynamicMenuContribution implements IExecutab protected Set browseContexts = defaultBrowseContexts; - protected static final Comparator ACTION_COMPARATOR = new Comparator() { + public static final Comparator ACTION_COMPARATOR = new Comparator() { @Override public int compare(Action o1, Action o2) { String t1 = o1.getText(); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java index 691d82961..555401327 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java @@ -44,7 +44,7 @@ public class SCL { SimanticsPlatform.INSTANCE.shutdown(null); } public static void reconnectPlatform() throws Exception { - SimanticsPlatform.INSTANCE.reconnect(null); + SimanticsPlatform.INSTANCE.reconnect(Simantics.getDefaultDatabaseDriver()); } public static void synchronizeOntologies() throws Exception { SimanticsPlatform.INSTANCE.synchronizeOntologies(new NullProgressMonitor(), OntologyRecoveryPolicy.Merge, true); diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/ServerManagerFactory.java b/bundles/org.simantics.project/src/org/simantics/project/management/ServerManagerFactory.java index 3bde5dc42..bbeb7541e 100644 --- a/bundles/org.simantics.project/src/org/simantics/project/management/ServerManagerFactory.java +++ b/bundles/org.simantics.project/src/org/simantics/project/management/ServerManagerFactory.java @@ -30,12 +30,12 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.utils.FileUtils; public class ServerManagerFactory { - public static ServerManager create(String databaseId, String address) throws IOException, DatabaseException { - Driver driver = Manager.getDriver(databaseId); + public static ServerManager create(String databaseDriverId, String address) throws IOException, DatabaseException { + Driver driver = Manager.getDriver(databaseDriverId); if (driver == null) - throw new IllegalArgumentException("Database driver for ID " + databaseId + " Could not be found!"); - System.out.println("ServerManagerFactory.create called with databaseId=" + databaseId + " and driver is " + driver.toString()); - DatabaseUserAgent agent = Manager.getUserAgent(databaseId); + throw new IllegalArgumentException("Database driver for ID " + databaseDriverId + " Could not be found!"); + System.out.println("ServerManagerFactory.create called with databaseId=" + databaseDriverId + " and driver is " + driver.toString()); + DatabaseUserAgent agent = Manager.getUserAgent(databaseDriverId); if (agent != null) driver.setDatabaseUserAgent(address, agent); return new ServerManager(driver); diff --git a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java index 2d054eaa7..67a8101cf 100644 --- a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java +++ b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java @@ -61,7 +61,6 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IPerspectiveDescriptor; -import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.IWorkbenchConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; @@ -98,7 +97,6 @@ import org.simantics.db.common.Indexing; import org.simantics.db.indexing.DatabaseIndexing; import org.simantics.db.procore.server.environment.RebootRequiredException; import org.simantics.db.procore.server.environment.windows.Product; -import org.simantics.db.procore.ui.ProCoreUserAgent; import org.simantics.internal.TimedSessionCache; import org.simantics.project.IProject; import org.simantics.project.ProjectKeys; @@ -131,11 +129,6 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor { */ private static final String INSTALLED_FEATURES = "installedFeatures"; //$NON-NLS-1$ - /** - * Default database ID - */ - private static final String DEFAULT_DATABASE_ID = "procore"; - /** * The arguments received by the application. */ @@ -428,17 +421,16 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor { throw new PlatformException("Argument not supported: " + SimanticsArguments.SERVER + " " + serverAddress); } - // TODO: Default to procore for now; - String databaseId = DEFAULT_DATABASE_ID; + String databaseDriverId = Simantics.getDefaultDatabaseDriver(); if (args.contains(SimanticsArguments.DATABASE_ID)) { - databaseId = args.get(SimanticsArguments.DATABASE_ID); + databaseDriverId = args.get(SimanticsArguments.DATABASE_ID); + Simantics.setDefaultDatabaseDriver(databaseDriverId); } IProgressMonitor mon = null; if (PROFILE_PLATFORM_STARTUP) mon = new TimingProgressMonitor(); - IWorkbench wb = PlatformUI.getWorkbench(); - SimanticsPlatform.INSTANCE.startUp(databaseId, mon, workspacePolicy, ontologyPolicy, requireSynchronize, new JFaceUserAgent()); + SimanticsPlatform.INSTANCE.startUp(databaseDriverId, mon, workspacePolicy, ontologyPolicy, requireSynchronize, new JFaceUserAgent()); // Make sure that the default perspective comes from the project if // the project has set ProjectKeys#DEFAULT_PERSPECTIVE. diff --git a/bundles/org.simantics/src/org/simantics/Simantics.java b/bundles/org.simantics/src/org/simantics/Simantics.java index 1e01acf71..50110cb03 100644 --- a/bundles/org.simantics/src/org/simantics/Simantics.java +++ b/bundles/org.simantics/src/org/simantics/Simantics.java @@ -68,9 +68,33 @@ import org.simantics.utils.threads.ThreadUtils; */ public class Simantics { + /** + * Default database driver ID + */ + private static final String DEFAULT_DATABASE_DRIVER_ID = "procore"; + + private static String defaultDatabaseDriverId = DEFAULT_DATABASE_DRIVER_ID; + private static ISessionContextProviderSource providerSource = null; private static volatile FileServiceImpl fileService = null; + /** + * Sets the database driver to be used by the platform. To have any effect, + * this must be set before platform startup. + * + * @param id driver id + */ + public static void setDefaultDatabaseDriver(String id) { + defaultDatabaseDriverId = id; + } + + /** + * Returns currently set default database driver id. + */ + public static String getDefaultDatabaseDriver() { + return defaultDatabaseDriverId; + } + /** * @param args * @param progress @@ -142,7 +166,7 @@ public class Simantics { if (progress == null) progress = new NullProgressMonitor(); - return SimanticsPlatform.INSTANCE.startUp(null, progress, workspacePolicy, ontologyPolicy, true, new ConsoleUserAgent()); + return SimanticsPlatform.INSTANCE.startUp(defaultDatabaseDriverId, progress, workspacePolicy, ontologyPolicy, true, new ConsoleUserAgent()); } /** diff --git a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java index 89a5d3dbd..40bbc04ed 100644 --- a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java +++ b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java @@ -39,8 +39,6 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.osgi.service.resolver.BundleDescription; -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; @@ -199,13 +197,13 @@ public class SimanticsPlatform implements LifecycleListener { return application != null ? application : UUID.randomUUID().toString(); } - private Session setupDatabase(String databaseId, IProgressMonitor progressMonitor, RecoveryPolicy workspacePolicy, PlatformUserAgent userAgent) throws PlatformException { + private Session setupDatabase(String databaseDriverId, IProgressMonitor progressMonitor, RecoveryPolicy workspacePolicy, PlatformUserAgent userAgent) throws PlatformException { if (progressMonitor == null) progressMonitor = new NullProgressMonitor(); File dbLocation = Platform.getLocation().append("db").toFile(); ServerManager serverManager; try { - serverManager = ServerManagerFactory.create(databaseId, dbLocation.getAbsolutePath()); + serverManager = ServerManagerFactory.create(databaseDriverId, dbLocation.getAbsolutePath()); } catch (DatabaseException | IOException e) { throw new PlatformException("Failed to initialize Server Manager", e); } @@ -702,7 +700,7 @@ public class SimanticsPlatform implements LifecycleListener { * startup or null to resort to default measures * @throws PlatformException */ - public SessionContext startUp(String databaseId, IProgressMonitor progressMonitor, RecoveryPolicy workspacePolicy, + public SessionContext startUp(String databaseDriverId, IProgressMonitor progressMonitor, RecoveryPolicy workspacePolicy, OntologyRecoveryPolicy ontologyPolicy, boolean requireSynchronize, PlatformUserAgent userAgent) throws PlatformException { @@ -729,7 +727,7 @@ public class SimanticsPlatform implements LifecycleListener { VariableRepository.clear(); // 1. Assert there is a database at /db - session = setupDatabase(databaseId, progressMonitor, workspacePolicy, userAgent); + session = setupDatabase(databaseDriverId, progressMonitor, workspacePolicy, userAgent); TimeLogger.log("Database setup complete"); // 2. Assert all graphs, and correct versions, are installed to the database @@ -1014,9 +1012,9 @@ public class SimanticsPlatform implements LifecycleListener { return false; } - public void reconnect(String databaseId) throws Exception { + public void reconnect(String databaseDriverId) throws Exception { // Starts database server. - SimanticsPlatform.INSTANCE.startUp(databaseId, null, RecoveryPolicy.ThrowError, OntologyRecoveryPolicy.ThrowError, true, null); + SimanticsPlatform.INSTANCE.startUp(databaseDriverId, null, RecoveryPolicy.ThrowError, OntologyRecoveryPolicy.ThrowError, true, null); } private void dumpPlatformBundleState() { -- 2.43.2