diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PerDeviceTypePluginDAOImpl.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOImpl.java similarity index 97% rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PerDeviceTypePluginDAOImpl.java rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOImpl.java index 0ed009a07c2..25165378476 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PerDeviceTypePluginDAOImpl.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOImpl.java @@ -36,9 +36,9 @@ import java.util.List; * Implements CRUD for Devices. This holds the generic implementation. An instance of this will be created for * each device type. */ -public class PerDeviceTypePluginDAOImpl implements PluginDAO{ +public class DeviceTypePluginDAOImpl implements PluginDAO{ - private static final Log log = LogFactory.getLog(PerDeviceTypePluginDAOImpl.class); + private static final Log log = LogFactory.getLog(DeviceTypePluginDAOImpl.class); private DeviceTypeDAOHandler deviceTypeDAOHandler; private DeviceDAODefinition deviceDAODefinition; private String selectDBQueryForGetDevice; @@ -47,8 +47,8 @@ public class PerDeviceTypePluginDAOImpl implements PluginDAO{ private String deleteDBQueryToRemoveDevicd; private String selectDBQueryToGetAllDevice; - public PerDeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition, - DeviceTypeDAOHandler deviceTypeDAOHandler) { + public DeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition, + DeviceTypeDAOHandler deviceTypeDAOHandler) { this.deviceTypeDAOHandler = deviceTypeDAOHandler; this.deviceDAODefinition = deviceDAODefinition; initializeDbQueries(); diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java index 8b6589193d7..f8f34fec3e6 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java @@ -29,7 +29,7 @@ public class DeviceTypePluginDAOManager { public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) { deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName); - deviceTypePluginDAO = new PerDeviceTypePluginDAOImpl(deviceDAODefinition, deviceTypeDAOHandler); + deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition, deviceTypeDAOHandler); } public DeviceTypePluginDAOManager(String deviceType, DeviceDetails deviceDetails) { diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PropertyBasedPluginDAOImpl.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PropertyBasedPluginDAOImpl.java index 3f27023d334..61c1d567849 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PropertyBasedPluginDAOImpl.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/PropertyBasedPluginDAOImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceDetails; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException; @@ -63,9 +64,11 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { try { conn = deviceTypeDAOHandler.getConnection(); stmt = conn.prepareStatement( - "SELECT * FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND DEVICE_IDENTIFICATION = ?"); + "SELECT * FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND DEVICE_IDENTIFICATION = ? " + + "AND TENANT_ID = ?"); stmt.setString(1, deviceType); stmt.setString(2, deviceId); + stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); resultSet = stmt.executeQuery(); device = new Device(); device.setDeviceIdentifier(deviceId); @@ -98,12 +101,13 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { conn = deviceTypeDAOHandler.getConnection(); stmt = conn.prepareStatement( "INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " + - "PROPERTY_VALUE) VALUES (?, ?, ?, ?)"); + "PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?, ?)"); for (String propertyKey : deviceProps) { stmt.setString(1, deviceType); stmt.setString(2, device.getDeviceIdentifier()); stmt.setString(3, propertyKey); stmt.setString(4, getPropertyValue(device.getProperties(), propertyKey)); + stmt.setInt(5, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); stmt.addBatch(); } stmt.executeBatch(); @@ -127,13 +131,14 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { conn = deviceTypeDAOHandler.getConnection(); stmt = conn.prepareStatement( "UPDATE DM_DEVICE_PROPERTIES SET PROPERTY_VALUE = ? WHERE DEVICE_TYPE_NAME = ? AND " + - "DEVICE_IDENTIFICATION = ? AND PROPERTY_NAME = ?"); + "DEVICE_IDENTIFICATION = ? AND PROPERTY_NAME = ? AND TENANT_ID= ?"); for (Device.Property property : device.getProperties()) { stmt.setString(1, getPropertyValue(device.getProperties(), property.getValue())); stmt.setString(1, deviceType); stmt.setString(2, device.getDeviceIdentifier()); stmt.setString(3, property.getName()); + stmt.setInt(4, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); stmt.addBatch(); } stmt.executeBatch(); @@ -162,9 +167,10 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { try { conn = deviceTypeDAOHandler.getConnection(); stmt = conn.prepareStatement("DELETE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? " + - "AND DEVICE_IDENTIFICATION = ?"); + "AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?"); stmt.setString(1, deviceType); stmt.setString(2, deviceId); + stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; @@ -191,9 +197,10 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { Map deviceMap = new HashMap<>(); try { conn = deviceTypeDAOHandler.getConnection(); - stmt = conn.prepareStatement("SELECT DEVICE_IDENTIFICATION, PROPERTY_NAME" + - ", PROPERTY_VALUE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ?"); + stmt = conn.prepareStatement("SELECT DEVICE_IDENTIFICATION, PROPERTY_NAME, PROPERTY_VALUE FROM " + + "DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND TENANT_ID = ?"); stmt.setString(1, deviceType); + stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); resultSet = stmt.executeQuery(); while (resultSet.next()) { String deviceId = resultSet.getString("DEVICE_IDENTIFICATION");