changeset 755:dfdd139397b6

Rename MongoDAOFactory into DAOFactoryImpl There is nothing mongo specific about that factory. It's misleading to have mongo in its name. DAOs aren't DB implementation specific and the factory should reflect this. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-October/003975.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Mon, 29 Oct 2012 18:42:49 +0100
parents 3dc46860f28b
children 998a0bc94088
files agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java common/core/src/main/java/com/redhat/thermostat/common/dao/DAOFactoryImpl.java common/core/src/main/java/com/redhat/thermostat/common/dao/MongoDAOFactory.java common/core/src/test/java/com/redhat/thermostat/common/dao/MongoDAOFactoryTest.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/DbServiceImpl.java
diffstat 6 files changed, 192 insertions(+), 192 deletions(-) [+]
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java	Mon Oct 29 17:49:26 2012 +0100
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java	Mon Oct 29 18:42:49 2012 +0100
@@ -63,7 +63,7 @@
 import com.redhat.thermostat.common.cli.CommandException;
 import com.redhat.thermostat.common.config.InvalidConfigurationException;
 import com.redhat.thermostat.common.dao.DAOFactory;
-import com.redhat.thermostat.common.dao.MongoDAOFactory;
+import com.redhat.thermostat.common.dao.DAOFactoryImpl;
 import com.redhat.thermostat.common.storage.Connection;
 import com.redhat.thermostat.common.storage.Connection.ConnectionListener;
 import com.redhat.thermostat.common.storage.Connection.ConnectionStatus;
@@ -249,7 +249,7 @@
     static class DAOFactoryCreator {
         public DAOFactory create(AgentStartupConfiguration config) {
             StorageProvider connProv = new MongoStorageProvider(config);
-            final DAOFactory daoFactory = new MongoDAOFactory(connProv);
+            final DAOFactory daoFactory = new DAOFactoryImpl(connProv);
             return daoFactory;
         }
     }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java	Mon Oct 29 17:49:26 2012 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java	Mon Oct 29 18:42:49 2012 +0100
@@ -66,7 +66,7 @@
 import com.redhat.thermostat.common.config.ClientPreferences;
 import com.redhat.thermostat.common.config.StartupConfiguration;
 import com.redhat.thermostat.common.dao.DAOFactory;
-import com.redhat.thermostat.common.dao.MongoDAOFactory;
+import com.redhat.thermostat.common.dao.DAOFactoryImpl;
 import com.redhat.thermostat.common.locale.Translate;
 import com.redhat.thermostat.common.storage.Connection;
 import com.redhat.thermostat.common.storage.Connection.ConnectionListener;
@@ -93,7 +93,7 @@
         StartupConfiguration config = new ConnectionConfiguration(prefs);
         StorageProvider connProv = new MongoStorageProvider(config);
 
-        DAOFactory daoFactory = new MongoDAOFactory(connProv);
+        DAOFactory daoFactory = new DAOFactoryImpl(connProv);
         TimerFactory timerFactory = new ThreadPoolTimerFactory(1);
 
         init(OSGIUtils.getInstance(), uiFacadeFactory, daoFactory, timerFactory);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/DAOFactoryImpl.java	Mon Oct 29 18:42:49 2012 +0100
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.common.dao;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceRegistration;
+
+import com.redhat.thermostat.common.storage.Connection;
+import com.redhat.thermostat.common.storage.Storage;
+import com.redhat.thermostat.common.storage.StorageProvider;
+
+public class DAOFactoryImpl implements DAOFactory {
+
+    private final Storage storage;
+    private final BundleContext bundleContext;
+    private final List<ServiceRegistration> registeredServices = new ArrayList<>();
+
+    public DAOFactoryImpl(StorageProvider prov) {
+        this(FrameworkUtil.getBundle(DAOFactoryImpl.class).getBundleContext(), prov);
+    }
+
+    public DAOFactoryImpl(BundleContext bundleContext, StorageProvider prov) {
+        this.bundleContext = bundleContext;
+        storage = prov.createStorage();
+    }
+
+    @Override
+    public Connection getConnection() {
+        return storage.getConnection();
+    }
+
+    @Override
+    public AgentInfoDAO getAgentInfoDAO() {
+        return new AgentInfoDAOImpl(storage);
+    }
+
+    @Override
+    public BackendInfoDAO getBackendInfoDAO() {
+        return new BackendInfoDAOImpl(storage);
+    }
+
+    @Override
+    public HostInfoDAO getHostInfoDAO() {
+        ensureStorageConnected();
+        return new HostInfoDAOImpl(storage, new AgentInfoDAOImpl(storage));
+    }
+
+    @Override
+    public CpuStatDAO getCpuStatDAO() {
+        ensureStorageConnected();
+        return new CpuStatDAOImpl(storage);
+    }
+
+    @Override
+    public MemoryStatDAO getMemoryStatDAO() {
+        ensureStorageConnected();
+        return new MemoryStatDAOImpl(storage);
+    }
+
+    @Override
+    public NetworkInterfaceInfoDAO getNetworkInterfaceInfoDAO() {
+        ensureStorageConnected();
+        return new NetworkInterfaceInfoDAOImpl(storage);
+    }
+
+    @Override
+    public VmInfoDAO getVmInfoDAO() {
+        ensureStorageConnected();
+        return new VmInfoDAOImpl(storage);
+    }
+
+    @Override
+    public VmCpuStatDAO getVmCpuStatDAO() {
+        ensureStorageConnected();
+        return new VmCpuStatDAOImpl(storage);
+    }
+
+    @Override
+    public VmMemoryStatDAO getVmMemoryStatDAO() {
+        ensureStorageConnected();
+        return new VmMemoryStatDAOImpl(storage);
+    }
+
+    @Override
+    public VmClassStatDAO getVmClassStatsDAO() {
+        ensureStorageConnected();
+        return new VmClassStatDAOImpl(storage);
+    }
+
+    @Override
+    public VmGcStatDAO getVmGcStatDAO() {
+        ensureStorageConnected();
+        return new VmGcStatDAOImpl(storage);
+    }
+
+    @Override
+    public Storage getStorage() {
+        return storage;
+    }
+
+    private void ensureStorageConnected() {
+        if (!storage.getConnection().isConnected()) {
+            throw new IllegalStateException("Set up connection before accessing DAO");
+        }
+    }
+
+    @Override
+    public HeapDAO getHeapDAO() {
+        ensureStorageConnected();
+        return new HeapDAOImpl(storage);
+    }
+
+    @Override
+    public void registerDAOsAndStorageAsOSGiServices() {
+        registerAndRecordService(Storage.class, getStorage());
+
+        registerAndRecordService(AgentInfoDAO.class, getAgentInfoDAO());
+        registerAndRecordService(BackendInfoDAO.class, getBackendInfoDAO());
+
+        registerAndRecordService(HostInfoDAO.class, getHostInfoDAO());
+        registerAndRecordService(NetworkInterfaceInfoDAO.class, getNetworkInterfaceInfoDAO());
+        registerAndRecordService(CpuStatDAO.class, getCpuStatDAO());
+        registerAndRecordService(MemoryStatDAO.class, getMemoryStatDAO());
+
+        registerAndRecordService(VmInfoDAO.class, getVmInfoDAO());
+        registerAndRecordService(VmClassStatDAO.class, getVmClassStatsDAO());
+        registerAndRecordService(VmCpuStatDAO.class, getVmCpuStatDAO());
+        registerAndRecordService(VmGcStatDAO.class, getVmGcStatDAO());
+        registerAndRecordService(VmMemoryStatDAO.class, getVmMemoryStatDAO());
+        registerAndRecordService(HeapDAO.class, getHeapDAO());
+    }
+
+    private <K> void registerAndRecordService(Class<K> serviceType, K serviceImplementation) {
+        registeredServices.add(bundleContext.registerService(serviceType, serviceImplementation, null));
+    }
+
+    public void unregisterDAOsAndStorageAsOSGiServices() {
+        Iterator<ServiceRegistration> iter = registeredServices.iterator();
+        while (iter.hasNext()) {
+            ServiceRegistration registration = iter.next();
+            registration.unregister();
+            iter.remove();
+        }
+    }
+
+}
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/MongoDAOFactory.java	Mon Oct 29 17:49:26 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,185 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.common.dao;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceRegistration;
-
-import com.redhat.thermostat.common.storage.Connection;
-import com.redhat.thermostat.common.storage.Storage;
-import com.redhat.thermostat.common.storage.StorageProvider;
-
-public class MongoDAOFactory implements DAOFactory {
-
-    private final Storage storage;
-    private final BundleContext bundleContext;
-    private final List<ServiceRegistration> registeredServices = new ArrayList<>();
-
-    public MongoDAOFactory(StorageProvider prov) {
-        this(FrameworkUtil.getBundle(MongoDAOFactory.class).getBundleContext(), prov);
-    }
-
-    public MongoDAOFactory(BundleContext bundleContext, StorageProvider prov) {
-        this.bundleContext = bundleContext;
-        storage = prov.createStorage();
-    }
-
-    @Override
-    public Connection getConnection() {
-        return storage.getConnection();
-    }
-
-    @Override
-    public AgentInfoDAO getAgentInfoDAO() {
-        return new AgentInfoDAOImpl(storage);
-    }
-
-    @Override
-    public BackendInfoDAO getBackendInfoDAO() {
-        return new BackendInfoDAOImpl(storage);
-    }
-
-    @Override
-    public HostInfoDAO getHostInfoDAO() {
-        ensureStorageConnected();
-        return new HostInfoDAOImpl(storage, new AgentInfoDAOImpl(storage));
-    }
-
-    @Override
-    public CpuStatDAO getCpuStatDAO() {
-        ensureStorageConnected();
-        return new CpuStatDAOImpl(storage);
-    }
-
-    @Override
-    public MemoryStatDAO getMemoryStatDAO() {
-        ensureStorageConnected();
-        return new MemoryStatDAOImpl(storage);
-    }
-
-    @Override
-    public NetworkInterfaceInfoDAO getNetworkInterfaceInfoDAO() {
-        ensureStorageConnected();
-        return new NetworkInterfaceInfoDAOImpl(storage);
-    }
-
-    @Override
-    public VmInfoDAO getVmInfoDAO() {
-        ensureStorageConnected();
-        return new VmInfoDAOImpl(storage);
-    }
-
-    @Override
-    public VmCpuStatDAO getVmCpuStatDAO() {
-        ensureStorageConnected();
-        return new VmCpuStatDAOImpl(storage);
-    }
-
-    @Override
-    public VmMemoryStatDAO getVmMemoryStatDAO() {
-        ensureStorageConnected();
-        return new VmMemoryStatDAOImpl(storage);
-    }
-
-    @Override
-    public VmClassStatDAO getVmClassStatsDAO() {
-        ensureStorageConnected();
-        return new VmClassStatDAOImpl(storage);
-    }
-
-    @Override
-    public VmGcStatDAO getVmGcStatDAO() {
-        ensureStorageConnected();
-        return new VmGcStatDAOImpl(storage);
-    }
-
-    @Override
-    public Storage getStorage() {
-        return storage;
-    }
-
-    private void ensureStorageConnected() {
-        if (!storage.getConnection().isConnected()) {
-            throw new IllegalStateException("Set up connection before accessing DAO");
-        }
-    }
-
-    @Override
-    public HeapDAO getHeapDAO() {
-        ensureStorageConnected();
-        return new HeapDAOImpl(storage);
-    }
-
-    @Override
-    public void registerDAOsAndStorageAsOSGiServices() {
-        registerAndRecordService(Storage.class, getStorage());
-
-        registerAndRecordService(AgentInfoDAO.class, getAgentInfoDAO());
-        registerAndRecordService(BackendInfoDAO.class, getBackendInfoDAO());
-
-        registerAndRecordService(HostInfoDAO.class, getHostInfoDAO());
-        registerAndRecordService(NetworkInterfaceInfoDAO.class, getNetworkInterfaceInfoDAO());
-        registerAndRecordService(CpuStatDAO.class, getCpuStatDAO());
-        registerAndRecordService(MemoryStatDAO.class, getMemoryStatDAO());
-
-        registerAndRecordService(VmInfoDAO.class, getVmInfoDAO());
-        registerAndRecordService(VmClassStatDAO.class, getVmClassStatsDAO());
-        registerAndRecordService(VmCpuStatDAO.class, getVmCpuStatDAO());
-        registerAndRecordService(VmGcStatDAO.class, getVmGcStatDAO());
-        registerAndRecordService(VmMemoryStatDAO.class, getVmMemoryStatDAO());
-        registerAndRecordService(HeapDAO.class, getHeapDAO());
-    }
-
-    private <K> void registerAndRecordService(Class<K> serviceType, K serviceImplementation) {
-        registeredServices.add(bundleContext.registerService(serviceType, serviceImplementation, null));
-    }
-
-    public void unregisterDAOsAndStorageAsOSGiServices() {
-        Iterator<ServiceRegistration> iter = registeredServices.iterator();
-        while (iter.hasNext()) {
-            ServiceRegistration registration = iter.next();
-            registration.unregister();
-            iter.remove();
-        }
-    }
-
-}
--- a/common/core/src/test/java/com/redhat/thermostat/common/dao/MongoDAOFactoryTest.java	Mon Oct 29 17:49:26 2012 +0100
+++ b/common/core/src/test/java/com/redhat/thermostat/common/dao/MongoDAOFactoryTest.java	Mon Oct 29 18:42:49 2012 +0100
@@ -72,7 +72,7 @@
         when(provider.createStorage()).thenReturn(storage);
         hostRef = mock(HostRef.class);
         vmRef = mock(VmRef.class);
-        daoFactory = new MongoDAOFactory(bundleContext, provider);
+        daoFactory = new DAOFactoryImpl(bundleContext, provider);
     }
 
     @Test
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/DbServiceImpl.java	Mon Oct 29 17:49:26 2012 +0100
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/DbServiceImpl.java	Mon Oct 29 18:42:49 2012 +0100
@@ -41,7 +41,7 @@
 import org.osgi.framework.ServiceRegistration;
 
 import com.redhat.thermostat.common.dao.DAOFactory;
-import com.redhat.thermostat.common.dao.MongoDAOFactory;
+import com.redhat.thermostat.common.dao.DAOFactoryImpl;
 import com.redhat.thermostat.common.storage.ConnectionException;
 import com.redhat.thermostat.common.storage.MongoStorageProvider;
 import com.redhat.thermostat.launcher.DbService;
@@ -54,7 +54,7 @@
     private DAOFactory daoFactory;
     
     DbServiceImpl(String username, String password, String dbUrl) {
-        this(new MongoDAOFactory(new MongoStorageProvider(new ConnectionConfiguration(dbUrl, username, password))));
+        this(new DAOFactoryImpl(new MongoStorageProvider(new ConnectionConfiguration(dbUrl, username, password))));
     }
 
     DbServiceImpl(DAOFactory daoFactory) {