From 2886ead44b061990795bf4e541a52c07b099d940 Mon Sep 17 00:00:00 2001 From: dilanua Date: Wed, 18 May 2016 14:26:43 +0530 Subject: [PATCH] Adding DataAccessLayerException to wrap SQLException in dashboard analytics feature --- .../dashboard/GadgetDataService.java | 35 ++++---- .../dao/AbstractGadgetDataServiceDAO.java | 59 ++++++++++---- .../dashboard/dao/GadgetDataServiceDAO.java | 53 +++++++----- .../dao/GadgetDataServiceDAOFactory.java | 10 ++- .../exception/DataAccessLayerException.java | 80 +++++++++++++++++++ .../InvalidParameterValueException.java | 4 - .../impl/GenericGadgetDataServiceDAOImpl.java | 18 ++++- .../impl/MSSQLGadgetDataServiceDAOImpl.java | 18 ++++- .../impl/OracleGadgetDataServiceDAOImpl.java | 18 ++++- .../PostgreSQLGadgetDataServiceDAOImpl.java | 18 ++++- .../dashboard/impl/GadgetDataServiceImpl.java | 72 ++++++++++++----- 11 files changed, 290 insertions(+), 95 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/DataAccessLayerException.java 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 c17dcfb263..bfaa2d38ff 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,13 @@ package org.wso2.carbon.device.mgt.analytics.dashboard; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; +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.common.PaginationResult; -import java.sql.SQLException; import java.util.List; /** @@ -31,56 +33,57 @@ import java.util.List; public interface GadgetDataService { @SuppressWarnings("unused") - DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; + DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") - DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException; + DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException; @SuppressWarnings("unused") - List getDeviceCountsByConnectivityStatuses() throws SQLException; + List getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException; @SuppressWarnings("unused") - List getDeviceCountsByPotentialVulnerabilities() throws SQLException; + List getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException; @SuppressWarnings("unused") PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") List getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") List getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") List getDevicesWithDetails(FilterSet filterSet) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; @SuppressWarnings("unused") List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; } 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 c36877d950..861f09d8b3 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 @@ -22,6 +22,7 @@ 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.core.dao.util.DeviceManagementDAOUtil; @@ -37,7 +38,7 @@ import java.util.Map; public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO { @Override - public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { + public DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException { int totalDeviceCount; try { totalDeviceCount = this.getFilteredDeviceCount(null); @@ -55,7 +56,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { int filteredDeviceCount = this.getFilteredDeviceCount(filterSet); @@ -67,7 +68,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD return deviceCountByGroupEntry; } - private int getFilteredDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { + private int getFilteredDeviceCount(FilterSet filterSet) + throws InvalidParameterValueException, DataAccessLayerException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -106,6 +108,9 @@ 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); } @@ -114,7 +119,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -159,6 +164,9 @@ 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); } @@ -172,7 +180,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } @Override - public List getDeviceCountsByConnectivityStatuses() throws SQLException { + public List getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -196,6 +204,9 @@ 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); } @@ -203,7 +214,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } @Override - public List getDeviceCountsByPotentialVulnerabilities() throws SQLException { + public List getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException { // getting non-compliant device count DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry(); nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); @@ -223,7 +234,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD return deviceCountsByPotentialVulnerabilities; } - private int getNonCompliantDeviceCount() throws SQLException { + private int getNonCompliantDeviceCount() throws DataAccessLayerException { FilterSet filterSet = new FilterSet(); filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); try { @@ -233,7 +244,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD } } - private int getUnmonitoredDeviceCount() throws SQLException { + private int getUnmonitoredDeviceCount() throws DataAccessLayerException { FilterSet filterSet = new FilterSet(); filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED); try { @@ -245,7 +256,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -291,6 +302,9 @@ 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); } @@ -300,7 +314,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -351,6 +365,9 @@ 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); } @@ -359,7 +376,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -405,6 +422,9 @@ 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); } @@ -413,8 +433,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List - getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { + getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -465,6 +485,9 @@ 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); } @@ -473,7 +496,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getDevicesWithDetails(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -521,6 +544,9 @@ 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); } @@ -529,7 +555,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD @Override public List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -582,6 +608,9 @@ 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 d95250f1bf..77fb489f50 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,56 +18,67 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; +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.common.PaginationResult; -import java.sql.SQLException; import java.util.List; public interface GadgetDataServiceDAO { - DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; + /** + * This method is used to get device count based on a defined filter set. + * @param filterSet An abstract representation of possible filtering options. + * if this value is simply "null" or no values are set for the defined filtering options, + * this method would return total device count in the system + * wrapped with in the defined return format. + * @return An object of type DeviceCountByGroupEntry. + * @throws InvalidParameterValueException This can occur if and only if potentialVulnerability value of filterSet + * is set with some value other than "NON_COMPLIANT" or "UNMONITORED". + * @throws DataAccessLayerException This can occur due to errors connecting to database, + * executing SQL query and retrieving data. + */ + DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) + throws InvalidParameterValueException, DataAccessLayerException; DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; - /** - * Method to get total device count from a particular tenant. - * - * @return Total device count. - */ - DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException; + DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException; - List getDeviceCountsByConnectivityStatuses() throws SQLException; + List getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException; - List getDeviceCountsByPotentialVulnerabilities() throws SQLException; + List getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException; PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; List getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; List getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, DataAccessLayerException; List getDevicesWithDetails(FilterSet filterSet) - throws InvalidParameterValueException, SQLException; + throws InvalidParameterValueException, DataAccessLayerException; List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java index 43999fc46a..7848c78905 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java @@ -90,7 +90,11 @@ public class GadgetDataServiceDAOFactory { "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + "transaction is already active is a sign of improper transaction handling."); } - conn = dataSource.getConnection(); + try { + conn = dataSource.getConnection(); + } catch (SQLException e) { + + } currentConnection.set(conn); } @@ -109,7 +113,7 @@ public class GadgetDataServiceDAOFactory { if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + "This might have ideally been caused by not properly initiating the transaction via " + - "'beginTransaction'/'openConnection' methods."); + "'beginTransaction'/'openConnection' methods."); } try { conn.close(); @@ -130,7 +134,7 @@ public class GadgetDataServiceDAOFactory { DataSource dataSource = null; if (config == null) { throw new RuntimeException( - "Device Management Repository data source configuration " + "is null and " + + "Device Management Repository data source configuration is null and " + "thus, is not initialized."); } JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); 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/dao/exception/DataAccessLayerException.java new file mode 100644 index 0000000000..ff03f413d4 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/DataAccessLayerException.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception; + +/** + * Custom exception class for communicating data access layer issues + * relevant to Gadget Data Service DAO layer. + * (In this particular instance, SQL exceptions related to database access). + */ +public class DataAccessLayerException extends Exception { + + private String errorMessage; + private static final long serialVersionUID = 2021891706072918864L; + + /** + * Constructs a new exception with the specific error message and nested exception. + * @param errorMessage specific error message. + * @param nestedException Nested exception. + */ + @SuppressWarnings("unused") + public DataAccessLayerException(String errorMessage, Exception nestedException) { + super(errorMessage, nestedException); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message and cause. + * @param errorMessage Specific error message. + * @param cause Cause of this exception. + */ + @SuppressWarnings("unused") + public DataAccessLayerException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message. + * @param errorMessage Specific error message. + */ + public DataAccessLayerException(String errorMessage) { + super(errorMessage); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message and cause. + * @param cause Cause of this exception. + */ + @SuppressWarnings("unused") + public DataAccessLayerException(Throwable cause) { + super(cause); + } + + @SuppressWarnings("unused") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} 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/dao/exception/InvalidParameterValueException.java index c36bf90e7c..a6ae0189f5 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/dao/exception/InvalidParameterValueException.java @@ -29,7 +29,6 @@ public class InvalidParameterValueException extends Exception { /** * Constructs a new exception with the specific error message and nested exception. - * * @param errorMessage specific error message. * @param nestedException Nested exception. */ @@ -41,7 +40,6 @@ public class InvalidParameterValueException extends Exception { /** * Constructs a new exception with the specific error message and cause. - * * @param errorMessage Specific error message. * @param cause Cause of this exception. */ @@ -53,7 +51,6 @@ public class InvalidParameterValueException extends Exception { /** * Constructs a new exception with the specific error message. - * * @param errorMessage Specific error message. */ public InvalidParameterValueException(String errorMessage) { @@ -63,7 +60,6 @@ public class InvalidParameterValueException extends Exception { /** * Constructs a new exception with the specific error message and cause. - * * @param cause Cause of this exception. */ @SuppressWarnings("unused") 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 9c2f693186..f5537b7f89 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 @@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServ 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.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -39,7 +40,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -88,6 +89,9 @@ 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); } @@ -99,7 +103,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -174,6 +178,9 @@ 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); } @@ -185,8 +192,8 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -269,6 +276,9 @@ 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 74f0cc4ee6..38769ac9e1 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 @@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServ 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.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -39,7 +40,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -89,6 +90,9 @@ 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); } @@ -100,7 +104,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -176,6 +180,9 @@ 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); } @@ -187,8 +194,8 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -271,6 +278,9 @@ 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 a4284938d2..5605352d14 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 @@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServ 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.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -39,7 +40,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -89,6 +90,9 @@ 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); } @@ -100,7 +104,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -176,6 +180,9 @@ 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); } @@ -187,8 +194,8 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -271,6 +278,9 @@ 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 e8c8570a0d..aa1a0693d4 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 @@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServ 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.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -39,7 +40,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -88,6 +89,9 @@ 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); } @@ -99,7 +103,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { if (startIndex < 0) { throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); @@ -174,6 +178,9 @@ 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); } @@ -185,8 +192,8 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, DataAccessLayerException { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -269,6 +276,9 @@ 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/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 7c3304bb9e..ac87e46fec 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,7 +20,10 @@ 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.*; +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.common.PaginationResult; @@ -33,11 +36,14 @@ import java.util.List; public class GadgetDataServiceImpl implements GadgetDataService { @Override - public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { + public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) + throws InvalidParameterValueException, DataAccessLayerException { DeviceCountByGroupEntry filteredDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -45,13 +51,15 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { DeviceCountByGroupEntry featureNonCompliantDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); + getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -59,11 +67,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { + public DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException { DeviceCountByGroupEntry totalDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -71,12 +81,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List getDeviceCountsByConnectivityStatuses() throws SQLException { + public List getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException { List deviceCountsByConnectivityStatuses; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses(); + getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses(); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -84,12 +96,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List getDeviceCountsByPotentialVulnerabilities() throws SQLException { + public List getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException { List deviceCountsByPotentialVulnerabilities; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByPotentialVulnerabilities(); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -98,12 +112,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws SQLException, InvalidParameterValueException { + throws InvalidParameterValueException, DataAccessLayerException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -112,12 +128,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { List deviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByPlatforms(filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -126,12 +144,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { List featureNonCompliantDeviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -140,12 +160,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { List deviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByOwnershipTypes(filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -155,12 +177,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws SQLException, InvalidParameterValueException { + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { List featureNonCompliantDeviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -169,12 +193,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, - int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { + int startIndex, int resultCount) throws InvalidParameterValueException, DataAccessLayerException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDevicesWithDetails(filterSet, startIndex, resultCount); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -183,13 +209,15 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, DataAccessLayerException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -198,12 +226,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List getDevicesWithDetails(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + throws InvalidParameterValueException, DataAccessLayerException { List devicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); devicesWithDetails = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); + getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -212,12 +242,14 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException { List featureNonCompliantDevicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet); + } catch (SQLException e) { + throw new DataAccessLayerException("Error in opening database connection.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); }