Refactored ApplicationMapping and ProfileOperation DAO classes

4.x.x
Dileesha Rajapakse 9 years ago
parent 27254cc922
commit 91d9db1ffa

@ -73,7 +73,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Integer> mappingIds = new ArrayList<>();
try {
conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " +

@ -37,22 +37,46 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
public int addOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
int operationId;
try {
operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
operation.setId(operationId);
operation.setEnabled(true);
ProfileOperation profileOp = (ProfileOperation) operation;
//ProfileOperation profileOp = (ProfileOperation) operation;
Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)");
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(operation);
stmt.setInt(1, operationId);
stmt.setObject(2, profileOp);
stmt.setBytes(2, bao.toByteArray());
stmt.executeUpdate();
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding profile operation", e);
} catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
} finally {
if (bao != null) {
try {
bao.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
OperationManagementDAOUtil.cleanupResources(stmt);
}
return operationId;

Loading…
Cancel
Save