Refactoring and formatting

feature/appm-store/pbac
inoshperera 5 years ago
parent e3aca342ad
commit b0f7cfdf61

@ -47,7 +47,7 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl {
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId; int operationId = 0;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
operationId = super.addOperation(operation); operationId = super.addOperation(operation);
@ -58,7 +58,9 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl {
stmt.setBinaryStream(2, toByteArrayInputStream(operation)); stmt.setBinaryStream(2, toByteArrayInputStream(operation));
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding command operation", e); String msg = "Error occurred while adding command operation " + operationId;
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
} }
@ -113,8 +115,6 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl {
ResultSet rs = null; ResultSet rs = null;
ConfigOperation configOperation = null; ConfigOperation configOperation = null;
ByteArrayInputStream bais;
ObjectInputStream ois;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_CONFIG FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?"; String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_CONFIG FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?";
@ -129,9 +129,10 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl {
configOperation.setEnabled(rs.getBoolean("ENABLED")); configOperation.setEnabled(rs.getBoolean("ENABLED"));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL Error occurred while retrieving the policy operation " + String msg = "SQL Error occurred while retrieving the policy operation object available for the id '"
"object available for the id '" + operationId;
+ operationId, e); log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -139,15 +140,13 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status)
Operation.Status status) throws OperationManagementDAOException { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ConfigOperation configOperation; ConfigOperation configOperation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<>();
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT co.OPERATION_ID, co.OPERATION_CONFIG FROM DM_CONFIG_OPERATION co " + String sql = "SELECT co.OPERATION_ID, co.OPERATION_CONFIG FROM DM_CONFIG_OPERATION co " +
@ -167,23 +166,11 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl {
operations.add(configOperation); operations.add(configOperation);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " + String msg = "SQL error occurred while retrieving the operation available " +
"for the device'" + enrolmentId + "' with status '" + status.toString(), e); "for the device'" + enrolmentId + "' with status '" + status.toString();
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} finally { } finally {
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
} }
return operations; return operations;

Loading…
Cancel
Save