Code cleanup

revert-70aa11f8
prabathabey 9 years ago
parent f66d1dd07b
commit de2c378214

@ -81,7 +81,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
List<Integer> applicationIds = new ArrayList<Integer>(); List<Integer> applicationIds = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " + stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " +
@ -118,13 +118,10 @@ public class ApplicationDAOImpl implements ApplicationDAO {
@Override @Override
public List<Integer> removeApplications(List<Application> apps, int tenantId) throws DeviceManagementDAOException { public List<Integer> removeApplications(List<Application> apps, int tenantId) throws DeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int applicationId = -1; List<Integer> applicationIds = new ArrayList<>();
List<Integer> applicationIds = new ArrayList<Integer>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
@ -144,7 +141,9 @@ public class ApplicationDAOImpl implements ApplicationDAO {
return applicationIds; return applicationIds;
} catch (SQLException e) { } catch (SQLException e) {
try { try {
if (conn != null) {
conn.rollback(); conn.rollback();
}
} catch (SQLException e1) { } catch (SQLException e1) {
log.warn("Error occurred while roll-backing the transaction", e); log.warn("Error occurred while roll-backing the transaction", e);
} }
@ -189,11 +188,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
public List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException { public List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
List<Application> applications = new ArrayList<Application>(); List<Application> applications = new ArrayList<>();
Application application; Application application;
ByteArrayInputStream bais;
ObjectInputStream ois;
try { try {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement("Select ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " + stmt = conn.prepareStatement("Select ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
@ -220,7 +216,6 @@ public class ApplicationDAOImpl implements ApplicationDAO {
} }
private Application loadApplication(ResultSet rs) throws DeviceManagementDAOException { private Application loadApplication(ResultSet rs) throws DeviceManagementDAOException {
ByteArrayInputStream bais; ByteArrayInputStream bais;
ObjectInputStream ois; ObjectInputStream ois;
Properties properties; Properties properties;
@ -246,18 +241,12 @@ public class ApplicationDAOImpl implements ApplicationDAO {
application.setVersion(rs.getString("VERSION")); application.setVersion(rs.getString("VERSION"));
application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER")); application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER"));
}catch (IOException ex){ } catch (IOException e) {
String errorMsg = "IO error occurred fetch at app properties"; throw new DeviceManagementDAOException("IO error occurred fetch at app properties", e);
log.error(errorMsg, ex); } catch (ClassNotFoundException e) {
throw new DeviceManagementDAOException(errorMsg, ex); throw new DeviceManagementDAOException("Class not found error occurred fetch at app properties", e);
}catch (ClassNotFoundException cex){ } catch (SQLException e) {
String errorMsg = "Class not found error occurred fetch at app properties"; throw new DeviceManagementDAOException("SQL error occurred fetch at application", e);
log.error(errorMsg, cex);
throw new DeviceManagementDAOException(errorMsg, cex);
}catch (SQLException ex){
String errorMsg = "SQL error occurred fetch at application";
log.error(errorMsg, ex);
throw new DeviceManagementDAOException(errorMsg, ex);
} }
return application; return application;

@ -38,7 +38,6 @@ import java.util.Properties;
public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
private static final Log log = LogFactory.getLog(ApplicationMappingDAOImpl.class);
@Override @Override
public int addApplicationMapping(int deviceId, int applicationId, public int addApplicationMapping(int deviceId, int applicationId,
int tenantId) throws DeviceManagementDAOException { int tenantId) throws DeviceManagementDAOException {
@ -74,7 +73,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<Integer> mappingIds = new ArrayList<Integer>(); List<Integer> mappingIds = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " + String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " +
@ -102,12 +101,9 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
} }
@Override @Override
public void removeApplicationMapping(int deviceId, List<Integer> appIdList, int tenantId) public void removeApplicationMapping(int deviceId, List<Integer> appIdList,
throws DeviceManagementDAOException { int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
ResultSet rs;
int mappingId = -1;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();

@ -18,8 +18,6 @@
package org.wso2.carbon.device.mgt.core.dao.impl; package org.wso2.carbon.device.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
@ -36,8 +34,6 @@ import java.util.List;
public class DeviceDAOImpl implements DeviceDAO { public class DeviceDAOImpl implements DeviceDAO {
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
@Override @Override
public int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException { public int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
@ -63,8 +59,8 @@ public class DeviceDAOImpl implements DeviceDAO {
} }
return deviceId; return deviceId;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while enrolling device " + throw new DeviceManagementDAOException("Error occurred while enrolling device '" + device.getName() +
"'" + device.getName() + "'", e); "'", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -158,7 +154,7 @@ public class DeviceDAOImpl implements DeviceDAO {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
devices = new ArrayList<Device>(); devices = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
Device device = this.loadDevice(rs); Device device = this.loadDevice(rs);
devices.add(device); devices.add(device);
@ -191,7 +187,7 @@ public class DeviceDAOImpl implements DeviceDAO {
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
devices = new ArrayList<Device>(); devices = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
Device device = this.loadDevice(rs); Device device = this.loadDevice(rs);
devices.add(device); devices.add(device);
@ -208,7 +204,7 @@ public class DeviceDAOImpl implements DeviceDAO {
public List<Device> getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException { public List<Device> getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
List<Device> devices = new ArrayList<Device>(); List<Device> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql =
@ -282,7 +278,7 @@ public class DeviceDAOImpl implements DeviceDAO {
public List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException { public List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
List<Device> devices = new ArrayList<Device>(); List<Device> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql =
@ -491,7 +487,7 @@ public class DeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
List<Device> devices = new ArrayList<Device>(); List<Device> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql =

@ -17,16 +17,12 @@
*/ */
package org.wso2.carbon.device.mgt.core.dao.impl; package org.wso2.carbon.device.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;

@ -35,10 +35,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId = super.addOperation(operation); int operationId;
CommandOperation commandOp = (CommandOperation) operation; CommandOperation commandOp = (CommandOperation) operation;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
operationId = super.addOperation(operation);
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)"); stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)");
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
@ -66,7 +67,6 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
OperationManagementDAOFactory.closeConnection();
} }
} }
@ -75,7 +75,6 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id); super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?"); stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
@ -84,7 +83,6 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e); throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
OperationManagementDAOFactory.closeConnection();
} }
} }
@ -108,7 +106,6 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
"object available for the id '" + id, e); "object available for the id '" + id, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return commandOperation; return commandOperation;
} }
@ -148,7 +145,6 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
"for the device'" + enrolmentId + "' with status '" + status.toString(), e); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return commandOperations; return commandOperations;
} }

@ -41,9 +41,10 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId = super.addOperation(operation); int operationId;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
operationId = super.addOperation(operation);
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID, OPERATION_CONFIG) VALUES(?, ?)"); stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID, OPERATION_CONFIG) VALUES(?, ?)");
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
@ -59,9 +60,9 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
super.deleteOperation(id);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ; stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
stmt.setInt(1, id); stmt.setInt(1, id);
@ -78,8 +79,8 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
super.updateOperation(operation);
try { try {
super.updateOperation(operation);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION O SET O.OPERATION_CONFIG = ? " + stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION O SET O.OPERATION_CONFIG = ? " +
"WHERE O.OPERATION_ID = ?"); "WHERE O.OPERATION_ID = ?");
@ -146,7 +147,6 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
+ operationId, e); + operationId, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return configOperation; return configOperation;
} }
@ -205,7 +205,6 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
} }
} }
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operations; return operations;
} }

@ -189,7 +189,6 @@ public class OperationDAOImpl implements OperationDAO {
"available for the id '" + id, e); "available for the id '" + id, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operation; return operation;
} }
@ -229,7 +228,6 @@ public class OperationDAOImpl implements OperationDAO {
"available for the device'" + enrolmentId + "' with id '" + operationId, e); "available for the device'" + enrolmentId + "' with id '" + operationId, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operation; return operation;
} }
@ -271,7 +269,6 @@ public class OperationDAOImpl implements OperationDAO {
"available for the device'" + enrolmentId + "' with status '" + status.toString(), e); "available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operations; return operations;
} }
@ -311,7 +308,6 @@ public class OperationDAOImpl implements OperationDAO {
"available for the device'" + enrolmentId + "' with status '", e); "available for the device'" + enrolmentId + "' with status '", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operations; return operations;
} }
@ -350,7 +346,6 @@ public class OperationDAOImpl implements OperationDAO {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
} }
@ -393,7 +388,6 @@ public class OperationDAOImpl implements OperationDAO {
"for the device'" + enrolmentId + "' with status '" + status.toString(), e); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operations; return operations;
} }

@ -37,13 +37,14 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId = super.addOperation(operation); int operationId;
PreparedStatement stmt = null;
try {
operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
operation.setId(operationId); operation.setId(operationId);
operation.setEnabled(true); operation.setEnabled(true);
PolicyOperation policyOperation = (PolicyOperation) operation; PolicyOperation policyOperation = (PolicyOperation) operation;
PreparedStatement stmt = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)"); "VALUES(?, ?)");
@ -63,8 +64,8 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
super.updateOperation(operation);
try { try {
super.updateOperation(operation);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION O SET O.OPERATION_DETAILS=? " + stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION O SET O.OPERATION_DETAILS=? " +
"WHERE O.OPERATION_ID=?"); "WHERE O.OPERATION_ID=?");
@ -100,9 +101,9 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int operationId) throws OperationManagementDAOException { public void deleteOperation(int operationId) throws OperationManagementDAOException {
super.deleteOperation(operationId);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(operationId);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_POLICY_OPERATION WHERE OPERATION_ID=?"); stmt = connection.prepareStatement("DELETE DM_POLICY_OPERATION WHERE OPERATION_ID=?");
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
@ -146,7 +147,6 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
"object available for the id '" + operationId + "'", e); "object available for the id '" + operationId + "'", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return policyOperation; return policyOperation;
} }
@ -205,7 +205,6 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
} }
} }
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operations; return operations;
} }

@ -36,14 +36,14 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
private static final Log log = LogFactory.getLog(ProfileOperationDAOImpl.class); private static final Log log = LogFactory.getLog(ProfileOperationDAOImpl.class);
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null;
int operationId = super.addOperation(operation); int operationId;
try {
operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
operation.setId(operationId); operation.setId(operationId);
operation.setEnabled(true); operation.setEnabled(true);
ProfileOperation profileOp = (ProfileOperation) operation; ProfileOperation profileOp = (ProfileOperation) operation;
PreparedStatement stmt = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)"); "VALUES(?, ?)");
@ -60,13 +60,11 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void updateOperation(Operation operation) throws OperationManagementDAOException { public void updateOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
super.updateOperation(operation);
try { try {
super.updateOperation(operation);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_PROFILE_OPERATION O SET O.OPERATION_DETAILS=? " + stmt = connection.prepareStatement("UPDATE DM_PROFILE_OPERATION O SET O.OPERATION_DETAILS=? " +
"WHERE O.OPERATION_ID=?"); "WHERE O.OPERATION_ID=?");
@ -78,7 +76,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
stmt.setBytes(1, bao.toByteArray()); stmt.setBytes(1, bao.toByteArray());
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update operation metadata", e); throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
} catch (IOException e) { } catch (IOException e) {
@ -104,10 +101,9 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
super.deleteOperation(id);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_PROFILE_OPERATION WHERE OPERATION_ID=?"); stmt = connection.prepareStatement("DELETE DM_PROFILE_OPERATION WHERE OPERATION_ID=?");
stmt.setInt(1, id); stmt.setInt(1, id);
@ -120,14 +116,12 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
} }
public Operation getOperation(int id) throws OperationManagementDAOException { public Operation getOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ProfileOperation profileOperation = null; ProfileOperation profileOperation = null;
ByteArrayInputStream bais; ByteArrayInputStream bais;
ObjectInputStream ois; ObjectInputStream ois;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?"; String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?";
@ -142,24 +136,17 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
profileOperation = (ProfileOperation) ois.readObject(); profileOperation = (ProfileOperation) ois.readObject();
} }
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the profile operation object"; throw new OperationManagementDAOException("IO Error occurred while de serialize the profile " +
log.error(errorMsg, e); "operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the profile operation object"; throw new OperationManagementDAOException("Class not found error occurred while de serialize the " +
log.error(errorMsg, e); "profile operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the command operation object " + "available for " + throw new OperationManagementDAOException("SQL Error occurred while retrieving the command " +
"the id '" "operation object " + "available for the id '" + id, e);
+ id;
log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return profileOperation; return profileOperation;
} }
@ -167,7 +154,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ProfileOperation profileOperation; ProfileOperation profileOperation;
@ -200,18 +186,14 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
} }
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the profile operation object"; throw new OperationManagementDAOException("IO Error occurred while de serialize the profile " +
log.error(errorMsg, e); "operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the profile operation object"; throw new OperationManagementDAOException("Class not found error occurred while de serialize the " +
log.error(errorMsg, e); "profile operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"' with status '" + status.toString(); "available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
if (bais != null) { if (bais != null) {
try { try {
@ -228,8 +210,8 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
} }
} }
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operationList;
} }
} }

Loading…
Cancel
Save