]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db/src/org/simantics/db/Manager.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / Manager.java
index 69b75e33759f43eb99a736e79ab85c36b5411b54..df838eed914accdef7f9aa382bdaf38468716e03 100644 (file)
@@ -1,87 +1,87 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.osgi.framework.BundleContext;\r
-import org.osgi.framework.InvalidSyntaxException;\r
-import org.osgi.framework.ServiceReference;\r
-import org.simantics.db.internal.Activator;\r
-\r
-/**\r
- * @author Antti Villberg\r
- */\r
-public final class Manager {\r
-\r
-    private Manager() {}\r
-\r
-    /**\r
-     * Search for registered database driver by driver id.\r
-     *\r
-     * @param id for database driver.\r
-     * @return database driver or null.\r
-     */\r
-    public static Driver getDriver(String id) {\r
-        Map<String, Driver> drivers = collectDrivers();\r
-        return drivers.get(id);\r
-    }\r
-\r
-    private static Map<String, Driver> collectDrivers() {\r
-        BundleContext context = Activator.getContext();\r
-        Collection<ServiceReference<Driver>> serviceReferences;\r
-        try {\r
-            serviceReferences = context.getServiceReferences(Driver.class, null);\r
-        } catch (InvalidSyntaxException e) {\r
-            e.printStackTrace();\r
-            serviceReferences = Collections.emptyList();\r
-        }\r
-        Map<String, Driver> drivers = new HashMap<>(serviceReferences.size());\r
-        for (ServiceReference<Driver> reference : serviceReferences) {\r
-            Driver driver = context.getService(reference);\r
-            String driverName = driver.getName();\r
-            if (driverName != null && !driverName.isEmpty()) {\r
-                drivers.put(driverName, driver);\r
-            }\r
-        }\r
-        return drivers;\r
-    }\r
-    \r
-    public static DatabaseUserAgent getUserAgent(String id) {\r
-        Map<String, DatabaseUserAgent> agents = collectUserAgents();\r
-        return agents.get(id);\r
-    }\r
-    \r
-    private static Map<String, DatabaseUserAgent> collectUserAgents() {\r
-        BundleContext context = Activator.getContext();\r
-        Collection<ServiceReference<DatabaseUserAgent>> serviceReferences;\r
-        try {\r
-            serviceReferences = context.getServiceReferences(DatabaseUserAgent.class, null);\r
-        } catch (InvalidSyntaxException e) {\r
-            e.printStackTrace();\r
-            serviceReferences = Collections.emptyList();\r
-        }\r
-        Map<String, DatabaseUserAgent> drivers = new HashMap<>(serviceReferences.size());\r
-        for (ServiceReference<DatabaseUserAgent> reference : serviceReferences) {\r
-            DatabaseUserAgent dbua = context.getService(reference);\r
-            String driverName = dbua.getId();\r
-            if (driverName != null && !driverName.isEmpty()) {\r
-                drivers.put(driverName, dbua);\r
-            }\r
-        }\r
-        return drivers;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.simantics.db.internal.Activator;
+
+/**
+ * @author Antti Villberg
+ */
+public final class Manager {
+
+    private Manager() {}
+
+    /**
+     * Search for registered database driver by driver id.
+     *
+     * @param id for database driver.
+     * @return database driver or null.
+     */
+    public static Driver getDriver(String id) {
+        Map<String, Driver> drivers = collectDrivers();
+        return drivers.get(id);
+    }
+
+    private static Map<String, Driver> collectDrivers() {
+        BundleContext context = Activator.getContext();
+        Collection<ServiceReference<Driver>> serviceReferences;
+        try {
+            serviceReferences = context.getServiceReferences(Driver.class, null);
+        } catch (InvalidSyntaxException e) {
+            e.printStackTrace();
+            serviceReferences = Collections.emptyList();
+        }
+        Map<String, Driver> drivers = new HashMap<>(serviceReferences.size());
+        for (ServiceReference<Driver> reference : serviceReferences) {
+            Driver driver = context.getService(reference);
+            String driverName = driver.getName();
+            if (driverName != null && !driverName.isEmpty()) {
+                drivers.put(driverName, driver);
+            }
+        }
+        return drivers;
+    }
+    
+    public static DatabaseUserAgent getUserAgent(String id) {
+        Map<String, DatabaseUserAgent> agents = collectUserAgents();
+        return agents.get(id);
+    }
+    
+    private static Map<String, DatabaseUserAgent> collectUserAgents() {
+        BundleContext context = Activator.getContext();
+        Collection<ServiceReference<DatabaseUserAgent>> serviceReferences;
+        try {
+            serviceReferences = context.getServiceReferences(DatabaseUserAgent.class, null);
+        } catch (InvalidSyntaxException e) {
+            e.printStackTrace();
+            serviceReferences = Collections.emptyList();
+        }
+        Map<String, DatabaseUserAgent> drivers = new HashMap<>(serviceReferences.size());
+        for (ServiceReference<DatabaseUserAgent> reference : serviceReferences) {
+            DatabaseUserAgent dbua = context.getService(reference);
+            String driverName = dbua.getId();
+            if (driverName != null && !driverName.isEmpty()) {
+                drivers.put(driverName, dbua);
+            }
+        }
+        return drivers;
+    }
+
+}