revert-70aa11f8
milanperera 9 years ago
commit f14ba29d30

@ -36,7 +36,7 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while adding the * @throws OperationManagementException If some unusual behaviour is observed while adding the
* operation * operation
*/ */
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException; public int addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException;
/** /**
* Method to retrieve the list of all operations to a device. * Method to retrieve the list of all operations to a device.

@ -74,7 +74,7 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public boolean addOperation(Operation operation, public int addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) throws OperationManagementException { List<DeviceIdentifier> deviceIds) throws OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -105,7 +105,7 @@ public class OperationManagerImpl implements OperationManager {
} }
} }
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
return true; return operationId;
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();

@ -26,6 +26,9 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOE
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -112,18 +115,43 @@ public class OperationDAOImpl implements OperationDAO {
throws OperationManagementDAOException { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," + stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," +
"OPERATION_RESPONSE) VALUES(?, ?, ?)"); "OPERATION_RESPONSE) VALUES(?, ?, ?)");
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(operationResponse);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2, deviceId); stmt.setInt(2, deviceId);
stmt.setObject(3, operationResponse); stmt.setBytes(3, bao.toByteArray());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while inserting operation response", e); throw new OperationManagementDAOException("Error occurred while inserting operation response", e);
} finally { }catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing policy 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); OperationManagementDAOUtil.cleanupResources(stmt);
} }
} }

@ -501,7 +501,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws public int addOperation(Operation operation, List<DeviceIdentifier> devices) throws
OperationManagementException { OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices); return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
} }
@ -754,7 +754,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
public int getTenantId() {
private int getTenantId() {
ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>(); ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>();
int tenant = 0; int tenant = 0;

Loading…
Cancel
Save