revert-70aa11f8
geethkokila 9 years ago
commit 958288f8ec

@ -18,11 +18,13 @@
package org.wso2.carbon.device.mgt.analytics.dashboard; 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.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.sql.SQLException;
import java.util.List; import java.util.List;
/** /**
@ -31,56 +33,57 @@ import java.util.List;
public interface GadgetDataService { public interface GadgetDataService {
@SuppressWarnings("unused") @SuppressWarnings("unused")
DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException; DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet) List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
} }

@ -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.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; 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.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.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -37,7 +38,7 @@ import java.util.Map;
public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO { public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO {
@Override @Override
public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { public DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException {
int totalDeviceCount; int totalDeviceCount;
try { try {
totalDeviceCount = this.getFilteredDeviceCount(null); totalDeviceCount = this.getFilteredDeviceCount(null);
@ -55,7 +56,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
int filteredDeviceCount = this.getFilteredDeviceCount(filterSet); int filteredDeviceCount = this.getFilteredDeviceCount(filterSet);
@ -67,7 +68,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
return deviceCountByGroupEntry; return deviceCountByGroupEntry;
} }
private int getFilteredDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { private int getFilteredDeviceCount(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -106,6 +108,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
while (rs.next()) { while (rs.next()) {
filteredDeviceCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -114,7 +119,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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()) { while (rs.next()) {
filteredDeviceCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -172,7 +180,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
} }
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -196,6 +204,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
deviceCountByConnectivityStatus.setDeviceCount(rs.getInt("DEVICE_COUNT")); deviceCountByConnectivityStatus.setDeviceCount(rs.getInt("DEVICE_COUNT"));
deviceCountsByConnectivityStatuses.add(deviceCountByConnectivityStatus); deviceCountsByConnectivityStatuses.add(deviceCountByConnectivityStatus);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -203,7 +214,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
} }
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException {
// getting non-compliant device count // getting non-compliant device count
DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry(); DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry();
nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT);
@ -223,7 +234,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
return deviceCountsByPotentialVulnerabilities; return deviceCountsByPotentialVulnerabilities;
} }
private int getNonCompliantDeviceCount() throws SQLException { private int getNonCompliantDeviceCount() throws DataAccessLayerException {
FilterSet filterSet = new FilterSet(); FilterSet filterSet = new FilterSet();
filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT);
try { 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 filterSet = new FilterSet();
filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED); filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED);
try { try {
@ -245,7 +256,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet) public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -291,6 +302,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT")); filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform); filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -300,7 +314,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public List<DeviceCountByGroupEntry> public List<DeviceCountByGroupEntry>
getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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")); filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform); filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -359,7 +376,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet) public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -405,6 +422,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT")); filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType); filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -414,7 +434,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public List<DeviceCountByGroupEntry> public List<DeviceCountByGroupEntry>
getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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")); filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType); filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -473,7 +496,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet) public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -521,6 +544,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -529,7 +555,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
@Override @Override
public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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")); filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -18,56 +18,67 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao; 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.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.sql.SQLException;
import java.util.List; import java.util.List;
public interface GadgetDataServiceDAO { 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, DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
/** DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException;
* Method to get total device count from a particular tenant.
*
* @return Total device count.
*/
DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException;
List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException;
List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException;
PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException;
List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet) List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, DataAccessLayerException;
List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException;
} }

@ -90,7 +90,11 @@ public class GadgetDataServiceDAOFactory {
"this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
"transaction is already active is a sign of improper transaction handling."); "transaction is already active is a sign of improper transaction handling.");
} }
try {
conn = dataSource.getConnection(); conn = dataSource.getConnection();
} catch (SQLException e) {
}
currentConnection.set(conn); currentConnection.set(conn);
} }
@ -130,7 +134,7 @@ public class GadgetDataServiceDAOFactory {
DataSource dataSource = null; DataSource dataSource = null;
if (config == null) { if (config == null) {
throw new RuntimeException( 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."); "thus, is not initialized.");
} }
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();

@ -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;
}
}

@ -29,7 +29,6 @@ public class InvalidParameterValueException extends Exception {
/** /**
* Constructs a new exception with the specific error message and nested exception. * Constructs a new exception with the specific error message and nested exception.
*
* @param errorMessage specific error message. * @param errorMessage specific error message.
* @param nestedException Nested exception. * @param nestedException Nested exception.
*/ */
@ -41,7 +40,6 @@ public class InvalidParameterValueException extends Exception {
/** /**
* Constructs a new exception with the specific error message and cause. * Constructs a new exception with the specific error message and cause.
*
* @param errorMessage Specific error message. * @param errorMessage Specific error message.
* @param cause Cause of this exception. * @param cause Cause of this exception.
*/ */
@ -53,7 +51,6 @@ public class InvalidParameterValueException extends Exception {
/** /**
* Constructs a new exception with the specific error message. * Constructs a new exception with the specific error message.
*
* @param errorMessage Specific error message. * @param errorMessage Specific error message.
*/ */
public InvalidParameterValueException(String errorMessage) { public InvalidParameterValueException(String errorMessage) {
@ -63,7 +60,6 @@ public class InvalidParameterValueException extends Exception {
/** /**
* Constructs a new exception with the specific error message and cause. * Constructs a new exception with the specific error message and cause.
*
* @param cause Cause of this exception. * @param cause Cause of this exception.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")

@ -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.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; 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.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.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -39,7 +40,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -99,7 +103,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -186,7 +193,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -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.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; 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.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.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -39,7 +40,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -100,7 +104,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -188,7 +195,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -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.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; 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.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.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -39,7 +40,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -100,7 +104,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -188,7 +195,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -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.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; 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.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.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -39,7 +40,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -99,7 +103,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (startIndex < 0) { if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -186,7 +193,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); 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()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -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.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; 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.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -33,11 +36,14 @@ import java.util.List;
public class GadgetDataServiceImpl implements GadgetDataService { public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException {
DeviceCountByGroupEntry filteredDeviceCount; DeviceCountByGroupEntry filteredDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -45,13 +51,15 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
DeviceCountByGroupEntry featureNonCompliantDeviceCount; DeviceCountByGroupEntry featureNonCompliantDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -59,11 +67,13 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { public DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException {
DeviceCountByGroupEntry totalDeviceCount; DeviceCountByGroupEntry totalDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount();
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -71,12 +81,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException {
List<DeviceCountByGroupEntry> deviceCountsByConnectivityStatuses; List<DeviceCountByGroupEntry> deviceCountsByConnectivityStatuses;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory. deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses(); getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses();
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -84,12 +96,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException {
List<DeviceCountByGroupEntry> deviceCountsByPotentialVulnerabilities; List<DeviceCountByGroupEntry> deviceCountsByPotentialVulnerabilities;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPotentialVulnerabilities(); getDeviceCountsByPotentialVulnerabilities();
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -98,12 +112,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws SQLException, InvalidParameterValueException { throws InvalidParameterValueException, DataAccessLayerException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -112,12 +128,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet) public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
List<DeviceCountByGroupEntry> deviceCountsByPlatforms; List<DeviceCountByGroupEntry> deviceCountsByPlatforms;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPlatforms(filterSet); getDeviceCountsByPlatforms(filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -126,12 +144,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, public List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByPlatforms; List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByPlatforms;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet); getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -140,12 +160,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet) public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
List<DeviceCountByGroupEntry> deviceCountsByOwnershipTypes; List<DeviceCountByGroupEntry> deviceCountsByOwnershipTypes;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByOwnershipTypes(filterSet); getDeviceCountsByOwnershipTypes(filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -155,12 +177,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<DeviceCountByGroupEntry> public List<DeviceCountByGroupEntry>
getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws SQLException, InvalidParameterValueException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByOwnershipTypes; List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByOwnershipTypes;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet); getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -169,12 +193,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, public PaginationResult getDevicesWithDetails(FilterSet filterSet,
int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { int startIndex, int resultCount) throws InvalidParameterValueException, DataAccessLayerException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDevicesWithDetails(filterSet, startIndex, resultCount); getDevicesWithDetails(filterSet, startIndex, resultCount);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -184,12 +210,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount); getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -198,12 +226,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet) public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, DataAccessLayerException {
List<DetailedDeviceEntry> devicesWithDetails; List<DetailedDeviceEntry> devicesWithDetails;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
devicesWithDetails = GadgetDataServiceDAOFactory. devicesWithDetails = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); getGadgetDataServiceDAO().getDevicesWithDetails(filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -212,12 +242,14 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
List<DetailedDeviceEntry> featureNonCompliantDevicesWithDetails; List<DetailedDeviceEntry> featureNonCompliantDevicesWithDetails;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet); getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }

Loading…
Cancel
Save