From 9bf0fa553a092afc1b6f4db511a47c044b3ab190 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Wed, 17 May 2023 10:51:01 +0530 Subject: [PATCH] Fix remote session not working with MSSQL --- .../mgt/dao/impl/ConfigOperationMSSQLDAOImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationMSSQLDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationMSSQLDAOImpl.java index dbadde02de5..813d02bbe97 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationMSSQLDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationMSSQLDAOImpl.java @@ -54,12 +54,16 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl { String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; try (PreparedStatement stmt = connection.prepareStatement(sql, new String[]{"id"})) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(operation); + byte[] operationBytes = baos.toByteArray(); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); - stmt.setObject(6, operation); + stmt.setBytes(6, operationBytes); stmt.executeUpdate(); try (ResultSet rs = stmt.getGeneratedKeys()) { int id = -1; @@ -68,6 +72,10 @@ public class ConfigOperationMSSQLDAOImpl extends GenericOperationDAOImpl { } return id; } + } catch (IOException e) { + String msg = "Error when converting operation id " + operation + " to input stream"; + log.error(msg, e); + throw new OperationManagementDAOException(msg, e); } } catch (SQLException e) { String msg = "Error occurred while adding command operation" + operation.getId();