changeset 958:66f3c55d7692

Delete DAOFactory (for real this time) It turns out DAOFactory was left behind unused after removing its use everywhere. This stems from a merge mishap that went unnoticed. Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005517.html
author Elliott Baron <ebaron@redhat.com>
date Thu, 07 Feb 2013 14:31:37 -0500
parents 1a1c6524e05b
children 28153814751f
files agent/core/src/main/java/com/redhat/thermostat/backend/Backend.java storage/core/src/main/java/com/redhat/thermostat/storage/dao/DAOFactory.java storage/core/src/main/java/com/redhat/thermostat/storage/dao/DAOFactoryImpl.java storage/core/src/test/java/com/redhat/thermostat/storage/dao/DAOFactoryTest.java
diffstat 4 files changed, 0 insertions(+), 366 deletions(-) [+]
line wrap: on
line diff
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/Backend.java	Thu Feb 07 14:20:59 2013 -0500
+++ b/agent/core/src/main/java/com/redhat/thermostat/backend/Backend.java	Thu Feb 07 14:31:37 2013 -0500
@@ -44,7 +44,6 @@
 import com.redhat.thermostat.common.LaunchException;
 import com.redhat.thermostat.common.Ordered;
 import com.redhat.thermostat.storage.core.Storage;
-import com.redhat.thermostat.storage.dao.DAOFactory;
 
 /**
  * Represents a plugin that runs on the agent and performs monitoring of host
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/dao/DAOFactory.java	Thu Feb 07 14:20:59 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright 2012, 2013 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.storage.dao;
-
-import com.redhat.thermostat.storage.core.Connection;
-import com.redhat.thermostat.storage.core.Storage;
-
-public interface DAOFactory {
-
-    // TODO this is temporary until DAO is made for those that are still using Storage directly.
-    public Storage getStorage();
-
-    public Connection getConnection();
-
-    public AgentInfoDAO getAgentInfoDAO();
-
-    public BackendInfoDAO getBackendInfoDAO();
-
-    public HostInfoDAO getHostInfoDAO();
-
-    public NetworkInterfaceInfoDAO getNetworkInterfaceInfoDAO();
-
-    public VmInfoDAO getVmInfoDAO();
-
-    public void registerDAOsAndStorageAsOSGiServices();
-    public void unregisterDAOsAndStorageAsOSGiServices();
-
-}
-
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/dao/DAOFactoryImpl.java	Thu Feb 07 14:20:59 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/*
- * Copyright 2012, 2013 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.storage.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.storage.core.Connection;
-import com.redhat.thermostat.storage.core.Storage;
-import com.redhat.thermostat.storage.core.StorageProvider;
-import com.redhat.thermostat.storage.internal.dao.AgentInfoDAOImpl;
-import com.redhat.thermostat.storage.internal.dao.BackendInfoDAOImpl;
-import com.redhat.thermostat.storage.internal.dao.HostInfoDAOImpl;
-import com.redhat.thermostat.storage.internal.dao.NetworkInterfaceInfoDAOImpl;
-import com.redhat.thermostat.storage.internal.dao.VmInfoDAOImpl;
-
-/*
- * TODO: This class should go away, but is still used in AgentApplication and (client) Main classes.
- */
-public class DAOFactoryImpl implements DAOFactory {
-
-    private final Storage storage;
-    private final BundleContext bundleContext;
-    @SuppressWarnings("rawtypes")
-    private final List<ServiceRegistration> registeredServices = new ArrayList<>();
-    private AgentInfoDAO agentDAO;
-    private BackendInfoDAO backendInfoDAO;
-    private HostInfoDAO hostInfoDAO;
-    private NetworkInterfaceInfoDAO networkInfoDAO;
-    private VmInfoDAO vmInfoDAO;
-
-    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() {
-        ensureStorageConnected();
-        return agentDAO;
-    }
-
-    @Override
-    public BackendInfoDAO getBackendInfoDAO() {
-        ensureStorageConnected();
-        return backendInfoDAO;
-    }
-
-    @Override
-    public HostInfoDAO getHostInfoDAO() {
-        ensureStorageConnected();
-        return hostInfoDAO;
-    }
-
-    @Override
-    public NetworkInterfaceInfoDAO getNetworkInterfaceInfoDAO() {
-        ensureStorageConnected();
-        return networkInfoDAO;
-    }
-
-    @Override
-    public VmInfoDAO getVmInfoDAO() {
-        ensureStorageConnected();
-        return vmInfoDAO;
-    }
-
-    @Override
-    public Storage getStorage() {
-        return storage;
-    }
-
-    private void ensureStorageConnected() {
-        if (!storage.getConnection().isConnected()) {
-            throw new IllegalStateException("Set up connection before accessing DAO");
-        }
-    }
-
-    @Override
-    public void registerDAOsAndStorageAsOSGiServices() {
-        ensureStorageConnected();
-        createDAOs();
-        registerAndRecordService(Storage.class, getStorage());
-
-        registerAndRecordService(AgentInfoDAO.class, getAgentInfoDAO());
-        registerAndRecordService(BackendInfoDAO.class, getBackendInfoDAO());
-
-        registerAndRecordService(HostInfoDAO.class, getHostInfoDAO());
-        registerAndRecordService(NetworkInterfaceInfoDAO.class, getNetworkInterfaceInfoDAO());
-
-        registerAndRecordService(VmInfoDAO.class, getVmInfoDAO());
-    }
-
-    /*
-     * Pre: Db connected
-     */
-    void createDAOs() {
-        agentDAO = new AgentInfoDAOImpl(storage);
-        backendInfoDAO = new BackendInfoDAOImpl(storage);
-        hostInfoDAO = new HostInfoDAOImpl(storage, agentDAO);
-        networkInfoDAO = new NetworkInterfaceInfoDAOImpl(storage);
-        vmInfoDAO = new VmInfoDAOImpl(storage);
-    }
-
-    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/storage/core/src/test/java/com/redhat/thermostat/storage/dao/DAOFactoryTest.java	Thu Feb 07 14:20:59 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/*
- * Copyright 2012, 2013 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.storage.dao;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.redhat.thermostat.storage.core.Connection;
-import com.redhat.thermostat.storage.core.Storage;
-import com.redhat.thermostat.storage.core.StorageProvider;
-import com.redhat.thermostat.storage.dao.AgentInfoDAO;
-import com.redhat.thermostat.storage.dao.BackendInfoDAO;
-import com.redhat.thermostat.storage.dao.DAOFactory;
-import com.redhat.thermostat.storage.dao.DAOFactoryImpl;
-import com.redhat.thermostat.storage.dao.HostInfoDAO;
-import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO;
-import com.redhat.thermostat.storage.dao.VmInfoDAO;
-import com.redhat.thermostat.testutils.StubBundleContext;
-
-public class DAOFactoryTest {
-
-    private StubBundleContext bundleContext;
-    private Storage storage;
-    private Connection connection;
-    private StorageProvider provider;
-    private DAOFactory daoFactory;
-
-    @Before
-    public void setUp() {
-        bundleContext = new StubBundleContext();
-
-        storage = mock(Storage.class);
-        connection = mock(Connection.class);
-        when(storage.getConnection()).thenReturn(connection);
-        when(connection.isConnected()).thenReturn(true);
-        provider = mock(StorageProvider.class);
-        when(provider.createStorage()).thenReturn(storage);
-        daoFactory = new DAOFactoryImpl(bundleContext, provider);
-        ((DAOFactoryImpl)daoFactory).createDAOs();
-    }
-
-    @Test
-    public void testGetConnection() {
-        assertSame(storage, daoFactory.getStorage());
-    }
-
-    @Test
-    public void testGetAgentInfoDAO() {
-        AgentInfoDAO dao = daoFactory.getAgentInfoDAO();
-        assertNotNull(dao);
-    }
-
-    @Test
-    public void testGetBackendInfoDAO() {
-        BackendInfoDAO dao = daoFactory.getBackendInfoDAO();
-        assertNotNull(dao);
-    }
-
-    @Test
-    public void testGetVmInfoDAO() {
-        VmInfoDAO dao = daoFactory.getVmInfoDAO();
-        assertNotNull(dao);
-    }
-
-    @Test
-    public void testGetHostInfoDAO() {
-        HostInfoDAO dao = daoFactory.getHostInfoDAO();
-        assertNotNull(dao);
-    }
-
-    @Test
-    public void testGetNetworkInterfaceInfoDAO() {
-        NetworkInterfaceInfoDAO dao = daoFactory.getNetworkInterfaceInfoDAO();
-        assertNotNull(dao);
-    }
-
-    @Test
-    public void testServiceRegistration() {
-        assertEquals(0, bundleContext.getAllServices().size());
-
-        daoFactory.registerDAOsAndStorageAsOSGiServices();
-
-        // currently 6 DAOs and Storage are registered
-        assertEquals(6, bundleContext.getAllServices().size());
-    }
-
-    @Test
-    public void testServiceDeregistration() {
-        daoFactory.registerDAOsAndStorageAsOSGiServices();
-        daoFactory.unregisterDAOsAndStorageAsOSGiServices();
-
-        assertEquals(0, bundleContext.getAllServices().size());
-        assertEquals(0, bundleContext.getServiceListeners().size());
-    }
-}
-