Fixed foriegn key violation issue when getting pending operations

revert-70aa11f8
mharindu 8 years ago
parent 575c6d1f8c
commit 9eb2f5df86

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

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

Loading…
Cancel
Save