Fixed foriegn key violation issue when getting pending operations

merge-requests/7/head
mharindu 9 years ago
parent 575c6d1f8c
commit 9eb2f5df86

@ -456,12 +456,13 @@ public class OperationManagerImpl implements OperationManager {
DeviceManagementDAOFactory.closeConnection();
}
OperationManagementDAOFactory.beginTransaction();
boolean isUpdated = false;
if (operation.getStatus() != null) {
operationDAO.updateOperationStatus(enrolmentId, operationId,
isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
valueOf(operation.getStatus().toString()));
}
if (operation.getOperationResponse() != null) {
if (isUpdated && operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
}
OperationManagementDAOFactory.commitTransaction();

@ -54,7 +54,7 @@ public interface OperationDAO {
Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException;
void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
boolean updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
throws OperationManagementDAOException;
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,

@ -89,9 +89,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
}
public void updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
public boolean updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
throws OperationManagementDAOException {
PreparedStatement stmt = null;
boolean isUpdated = false;
try {
long time = System.currentTimeMillis() / 1000;
Connection connection = OperationManagementDAOFactory.getConnection();
@ -101,14 +102,17 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt.setLong(2, time);
stmt.setInt(3, enrolmentId);
stmt.setInt(4, operationId);
stmt.executeUpdate();
int numOfRecordsUpdated = stmt.executeUpdate();
if (numOfRecordsUpdated != 0) {
isUpdated = true;
}
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
"metadata", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt);
}
return isUpdated;
}
@Override

Loading…
Cancel
Save