From 975a3b915f8dc632966bf593f0fff39edb4af2cb Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 22 May 2016 08:12:25 +0530 Subject: [PATCH] Properly layering beans and custom exceptions in dashboard analytics feature --- .../pom.xml | 4 +- .../dashboard/GadgetDataService.java | 10 +-- .../{dao => }/bean/DetailedDeviceEntry.java | 2 +- .../bean/DeviceCountByGroupEntry.java | 2 +- .../dashboard/{dao => }/bean/FilterSet.java | 2 +- .../dao/AbstractGadgetDataServiceDAO.java | 72 ++++++------------- .../dashboard/dao/GadgetDataServiceDAO.java | 42 +++++------ .../impl/GenericGadgetDataServiceDAOImpl.java | 24 ++----- .../impl/MSSQLGadgetDataServiceDAOImpl.java | 24 ++----- .../impl/OracleGadgetDataServiceDAOImpl.java | 26 +++---- .../PostgreSQLGadgetDataServiceDAOImpl.java | 24 ++----- .../exception/DataAccessLayerException.java | 2 +- .../InvalidParameterValueException.java | 2 +- .../dashboard/impl/GadgetDataServiceImpl.java | 52 +++++++++----- 14 files changed, 117 insertions(+), 171 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/{dao => }/bean/DetailedDeviceEntry.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/{dao => }/bean/DeviceCountByGroupEntry.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/{dao => }/bean/FilterSet.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/{dao => }/exception/DataAccessLayerException.java (97%) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/{dao => }/exception/InvalidParameterValueException.java (97%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml index 35aa312a0f..b04c273a3f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml @@ -64,8 +64,8 @@ org.wso2.carbon.device.mgt.analytics.dashboard, - org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception, - org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean + org.wso2.carbon.device.mgt.analytics.dashboard.exception, + org.wso2.carbon.device.mgt.analytics.dashboard.bean org.osgi.framework, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java index 6cd23d2727..031252d5c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java @@ -18,11 +18,11 @@ package org.wso2.carbon.device.mgt.analytics.dashboard; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.DataAccessLayerException; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DetailedDeviceEntry.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DetailedDeviceEntry.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DetailedDeviceEntry.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DetailedDeviceEntry.java index 307a202ba3..b12c242a11 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DetailedDeviceEntry.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DetailedDeviceEntry.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; +package org.wso2.carbon.device.mgt.analytics.dashboard.bean; public class DetailedDeviceEntry { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroupEntry.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroupEntry.java index e7dc9909f6..85ecfe349c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroupEntry.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; +package org.wso2.carbon.device.mgt.analytics.dashboard.bean; public class DeviceCountByGroupEntry { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/FilterSet.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/FilterSet.java index a9a775a08e..701b571877 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/FilterSet.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; +package org.wso2.carbon.device.mgt.analytics.dashboard.bean; public class FilterSet { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/AbstractGadgetDataServiceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/AbstractGadgetDataServiceDAO.java index c5e2b8398a..177b7868e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/AbstractGadgetDataServiceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/AbstractGadgetDataServiceDAO.java @@ -19,11 +19,10 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import java.sql.Connection; @@ -38,7 +37,7 @@ import java.util.Map; public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO { @Override - public DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException { + public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { int totalDeviceCount; try { totalDeviceCount = this.getFilteredDeviceCount(null); @@ -56,7 +55,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { int filteredDeviceCount = this.getFilteredDeviceCount(filterSet); @@ -69,7 +68,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } private int getFilteredDeviceCount(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -80,8 +79,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD int filteredDeviceCount = 0; try { con = this.getConnection(); - String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " + GadgetDataServiceDAOConstants.DatabaseView. - DEVICES_VIEW_1 + " WHERE TENANT_ID = ?"; + String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " + + GadgetDataServiceDAOConstants.DatabaseView.DEVICES_VIEW_1 + " WHERE TENANT_ID = ?"; // appending filters to support advanced filtering options // [1] appending filter columns if (filters != null && filters.size() > 0) { @@ -109,9 +108,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD while (rs.next()) { filteredDeviceCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -120,7 +116,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -135,8 +131,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD int filteredDeviceCount = 0; try { con = this.getConnection(); - String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " + GadgetDataServiceDAOConstants.DatabaseView. - DEVICES_VIEW_2 + " WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; + String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " + + GadgetDataServiceDAOConstants.DatabaseView.DEVICES_VIEW_2 + " WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; // appending filters to support advanced filtering options // [1] appending filter columns if (filters != null && filters.size() > 0) { @@ -165,9 +161,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD while (rs.next()) { filteredDeviceCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -181,7 +174,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } @Override - public List getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException { + public List getDeviceCountsByConnectivityStatuses() throws SQLException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -206,9 +199,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD deviceCountByConnectivityStatus.setDeviceCount(rs.getInt("DEVICE_COUNT")); deviceCountsByConnectivityStatuses.add(deviceCountByConnectivityStatus); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -216,7 +206,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } @Override - public List getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException { + public List getDeviceCountsByPotentialVulnerabilities() throws SQLException { // getting non-compliant device count DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry(); nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); @@ -236,7 +226,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD return deviceCountsByPotentialVulnerabilities; } - private int getNonCompliantDeviceCount() throws DataAccessLayerException { + private int getNonCompliantDeviceCount() throws SQLException { FilterSet filterSet = new FilterSet(); filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); try { @@ -246,7 +236,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } } - private int getUnmonitoredDeviceCount() throws DataAccessLayerException { + private int getUnmonitoredDeviceCount() throws SQLException { FilterSet filterSet = new FilterSet(); filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED); try { @@ -258,7 +248,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -304,9 +294,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -316,7 +303,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -368,9 +355,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -379,7 +363,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -426,9 +410,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -438,7 +419,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -490,9 +471,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -501,7 +479,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getDevicesWithDetails(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -549,9 +527,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDevicesWithDetails.add(filteredDeviceWithDetails); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -560,7 +535,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -614,9 +589,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDevicesWithDetails.add(filteredDeviceWithDetails); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java index 9bb3b26b32..9a727df1e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java @@ -18,55 +18,55 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; +import java.sql.SQLException; import java.util.List; public interface GadgetDataServiceDAO { DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException; + throws InvalidParameterValueException, SQLException; - DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; + DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) + throws InvalidParameterValueException, SQLException; - DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException; + DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException; - List getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException; + List getDeviceCountsByConnectivityStatuses() throws SQLException; - List getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException; + List getDeviceCountsByPotentialVulnerabilities() throws SQLException; PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException; + throws InvalidParameterValueException, SQLException; List getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException; + throws InvalidParameterValueException, SQLException; List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; List getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException; + throws InvalidParameterValueException, SQLException; List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException; + throws InvalidParameterValueException, SQLException; PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException; + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException; List getDevicesWithDetails(FilterSet filterSet) - throws InvalidParameterValueException, DataAccessLayerException; + throws InvalidParameterValueException, SQLException; List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GenericGadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GenericGadgetDataServiceDAOImpl.java index de4eb05fae..87e48e363f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GenericGadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GenericGadgetDataServiceDAOImpl.java @@ -19,13 +19,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -41,7 +40,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -94,9 +93,6 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA while (rs.next()) { totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -108,7 +104,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -187,9 +183,6 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -202,7 +195,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -288,9 +281,6 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/MSSQLGadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/MSSQLGadgetDataServiceDAOImpl.java index 97e8c48cc2..528cef64df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/MSSQLGadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/MSSQLGadgetDataServiceDAOImpl.java @@ -19,13 +19,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -41,7 +40,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -94,9 +93,6 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO while (rs.next()) { totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -108,7 +104,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -187,9 +183,6 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -202,7 +195,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -288,9 +281,6 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/OracleGadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/OracleGadgetDataServiceDAOImpl.java index 7761200762..a600059196 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/OracleGadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/OracleGadgetDataServiceDAOImpl.java @@ -19,13 +19,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -41,7 +40,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -96,9 +95,6 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO while (rs.next()) { totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -110,7 +106,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -191,9 +187,6 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -205,8 +198,8 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -292,9 +285,6 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/PostgreSQLGadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/PostgreSQLGadgetDataServiceDAOImpl.java index 3fb005c1fb..34b90bafa7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/PostgreSQLGadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/PostgreSQLGadgetDataServiceDAOImpl.java @@ -19,13 +19,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -41,7 +40,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -95,9 +94,6 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic while (rs.next()) { totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -109,7 +105,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { throw new InvalidParameterValueException("Start index should be equal to " + @@ -189,9 +185,6 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -204,7 +197,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, DataAccessLayerException { + throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -290,9 +283,6 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic while (rs.next()) { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } - } catch (SQLException e) { - throw new DataAccessLayerException("Error in either getting database connection, " + - "running SQL query or fetching results.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/DataAccessLayerException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/DataAccessLayerException.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/DataAccessLayerException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/DataAccessLayerException.java index ff03f413d4..69bd5a9f6a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/DataAccessLayerException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/DataAccessLayerException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception; +package org.wso2.carbon.device.mgt.analytics.dashboard.exception; /** * Custom exception class for communicating data access layer issues diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterValueException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidParameterValueException.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterValueException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidParameterValueException.java index a6ae0189f5..1cf485b4d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterValueException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidParameterValueException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception; +package org.wso2.carbon.device.mgt.analytics.dashboard.exception; /** * Custom exception class for catching invalid parameter issues, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java index a7a635427d..e92dee1d31 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java @@ -20,11 +20,11 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.impl; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry; +import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.DataAccessLayerException; +import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; @@ -43,7 +43,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { GadgetDataServiceDAOFactory.openConnection(); filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -59,7 +60,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -73,7 +75,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { GadgetDataServiceDAOFactory.openConnection(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -88,7 +91,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory. getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses(); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -103,7 +107,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByPotentialVulnerabilities(); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -119,7 +124,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -135,7 +141,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByPlatforms(filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -151,7 +158,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -167,7 +175,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByOwnershipTypes(filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -184,7 +193,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -200,7 +210,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDevicesWithDetails(filterSet, startIndex, resultCount); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -217,7 +228,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -233,7 +245,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { devicesWithDetails = GadgetDataServiceDAOFactory. getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -249,7 +262,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet); } catch (SQLException e) { - throw new DataAccessLayerException("Error in opening database connection.", e); + throw new DataAccessLayerException("Error in either opening a database connection or " + + "accessing the database to fetch corresponding results.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); }