add tenancy to property table

revert-70aa11f8
ayyoob 8 years ago
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
* 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,7 +47,7 @@ public class PerDeviceTypePluginDAOImpl implements PluginDAO{
private String deleteDBQueryToRemoveDevicd;
private String selectDBQueryToGetAllDevice;
public PerDeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition,
public DeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition,
DeviceTypeDAOHandler deviceTypeDAOHandler) {
this.deviceTypeDAOHandler = deviceTypeDAOHandler;
this.deviceDAODefinition = deviceDAODefinition;

@ -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) {

@ -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<String, Device> 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");

Loading…
Cancel
Save