mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
add tenancy to property table
This commit is contained in:
parent
fbb5f5ae88
commit
1955b028d2
@ -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
|
* Implements CRUD for Devices. This holds the generic implementation. An instance of this will be created for
|
||||||
* each device type.
|
* 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 DeviceTypeDAOHandler deviceTypeDAOHandler;
|
||||||
private DeviceDAODefinition deviceDAODefinition;
|
private DeviceDAODefinition deviceDAODefinition;
|
||||||
private String selectDBQueryForGetDevice;
|
private String selectDBQueryForGetDevice;
|
||||||
@ -47,8 +47,8 @@ public class PerDeviceTypePluginDAOImpl implements PluginDAO{
|
|||||||
private String deleteDBQueryToRemoveDevicd;
|
private String deleteDBQueryToRemoveDevicd;
|
||||||
private String selectDBQueryToGetAllDevice;
|
private String selectDBQueryToGetAllDevice;
|
||||||
|
|
||||||
public PerDeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition,
|
public DeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition,
|
||||||
DeviceTypeDAOHandler deviceTypeDAOHandler) {
|
DeviceTypeDAOHandler deviceTypeDAOHandler) {
|
||||||
this.deviceTypeDAOHandler = deviceTypeDAOHandler;
|
this.deviceTypeDAOHandler = deviceTypeDAOHandler;
|
||||||
this.deviceDAODefinition = deviceDAODefinition;
|
this.deviceDAODefinition = deviceDAODefinition;
|
||||||
initializeDbQueries();
|
initializeDbQueries();
|
||||||
@ -29,7 +29,7 @@ public class DeviceTypePluginDAOManager {
|
|||||||
|
|
||||||
public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
|
public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
|
||||||
deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName);
|
deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName);
|
||||||
deviceTypePluginDAO = new PerDeviceTypePluginDAOImpl(deviceDAODefinition, deviceTypeDAOHandler);
|
deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition, deviceTypeDAOHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceTypePluginDAOManager(String deviceType, DeviceDetails deviceDetails) {
|
public DeviceTypePluginDAOManager(String deviceType, DeviceDetails deviceDetails) {
|
||||||
|
|||||||
@ -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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceDetails;
|
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceDetails;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
||||||
@ -63,9 +64,11 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
|
|||||||
try {
|
try {
|
||||||
conn = deviceTypeDAOHandler.getConnection();
|
conn = deviceTypeDAOHandler.getConnection();
|
||||||
stmt = conn.prepareStatement(
|
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(1, deviceType);
|
||||||
stmt.setString(2, deviceId);
|
stmt.setString(2, deviceId);
|
||||||
|
stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
device = new Device();
|
device = new Device();
|
||||||
device.setDeviceIdentifier(deviceId);
|
device.setDeviceIdentifier(deviceId);
|
||||||
@ -98,12 +101,13 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
|
|||||||
conn = deviceTypeDAOHandler.getConnection();
|
conn = deviceTypeDAOHandler.getConnection();
|
||||||
stmt = conn.prepareStatement(
|
stmt = conn.prepareStatement(
|
||||||
"INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " +
|
"INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " +
|
||||||
"PROPERTY_VALUE) VALUES (?, ?, ?, ?)");
|
"PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?, ?)");
|
||||||
for (String propertyKey : deviceProps) {
|
for (String propertyKey : deviceProps) {
|
||||||
stmt.setString(1, deviceType);
|
stmt.setString(1, deviceType);
|
||||||
stmt.setString(2, device.getDeviceIdentifier());
|
stmt.setString(2, device.getDeviceIdentifier());
|
||||||
stmt.setString(3, propertyKey);
|
stmt.setString(3, propertyKey);
|
||||||
stmt.setString(4, getPropertyValue(device.getProperties(), propertyKey));
|
stmt.setString(4, getPropertyValue(device.getProperties(), propertyKey));
|
||||||
|
stmt.setInt(5, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
@ -127,13 +131,14 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
|
|||||||
conn = deviceTypeDAOHandler.getConnection();
|
conn = deviceTypeDAOHandler.getConnection();
|
||||||
stmt = conn.prepareStatement(
|
stmt = conn.prepareStatement(
|
||||||
"UPDATE DM_DEVICE_PROPERTIES SET PROPERTY_VALUE = ? WHERE DEVICE_TYPE_NAME = ? AND " +
|
"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()) {
|
for (Device.Property property : device.getProperties()) {
|
||||||
stmt.setString(1, getPropertyValue(device.getProperties(), property.getValue()));
|
stmt.setString(1, getPropertyValue(device.getProperties(), property.getValue()));
|
||||||
stmt.setString(1, deviceType);
|
stmt.setString(1, deviceType);
|
||||||
stmt.setString(2, device.getDeviceIdentifier());
|
stmt.setString(2, device.getDeviceIdentifier());
|
||||||
stmt.setString(3, property.getName());
|
stmt.setString(3, property.getName());
|
||||||
|
stmt.setInt(4, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
@ -162,9 +167,10 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
|
|||||||
try {
|
try {
|
||||||
conn = deviceTypeDAOHandler.getConnection();
|
conn = deviceTypeDAOHandler.getConnection();
|
||||||
stmt = conn.prepareStatement("DELETE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? " +
|
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(1, deviceType);
|
||||||
stmt.setString(2, deviceId);
|
stmt.setString(2, deviceId);
|
||||||
|
stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
@ -191,9 +197,10 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
|
|||||||
Map<String, Device> deviceMap = new HashMap<>();
|
Map<String, Device> deviceMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
conn = deviceTypeDAOHandler.getConnection();
|
conn = deviceTypeDAOHandler.getConnection();
|
||||||
stmt = conn.prepareStatement("SELECT DEVICE_IDENTIFICATION, PROPERTY_NAME" +
|
stmt = conn.prepareStatement("SELECT DEVICE_IDENTIFICATION, PROPERTY_NAME, PROPERTY_VALUE FROM " +
|
||||||
", PROPERTY_VALUE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ?");
|
"DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND TENANT_ID = ?");
|
||||||
stmt.setString(1, deviceType);
|
stmt.setString(1, deviceType);
|
||||||
|
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
String deviceId = resultSet.getString("DEVICE_IDENTIFICATION");
|
String deviceId = resultSet.getString("DEVICE_IDENTIFICATION");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user