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/config/DeviceDetails.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/config/DeviceDetails.java index 6428bf097fe..4939557863e 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/config/DeviceDetails.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/config/DeviceDetails.java @@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.XmlValue; /** @@ -44,61 +44,61 @@ import javax.xml.bind.annotation.XmlValue; */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "DeviceDetails", propOrder = { - "value" + "properties" }) public class DeviceDetails { - @XmlValue - protected String value; @XmlAttribute(name = "table-id") protected String tableId; + @XmlElement(name = "Properties", required = true) + protected Properties properties; /** - * Gets the value of the value property. + * Gets the value of the tableId property. * * @return * possible object is * {@link String } * */ - public String getValue() { - return value; + public String getTableId() { + return tableId; } /** - * Sets the value of the value property. + * Sets the value of the tableId property. * * @param value * allowed object is * {@link String } * */ - public void setValue(String value) { - this.value = value; + public void setTableId(String value) { + this.tableId = value; } /** - * Gets the value of the tableId property. - * + * Gets the value of the properties property. + * * @return * possible object is - * {@link String } - * + * {@link Properties } + * */ - public String getTableId() { - return tableId; + public Properties getProperties() { + return properties; } /** - * Sets the value of the tableId property. - * + * Sets the value of the properties property. + * * @param value * allowed object is - * {@link String } - * + * {@link Properties } + * */ - public void setTableId(String value) { - this.tableId = value; + public void setProperties(Properties value) { + this.properties = value; } } 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/config/Properties.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/config/Properties.java new file mode 100644 index 00000000000..f2be9763bf8 --- /dev/null +++ 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/config/Properties.java @@ -0,0 +1,76 @@ + +package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for Properties complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="Properties">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="Property" maxOccurs="unbounded" minOccurs="0">
+ *           <simpleType>
+ *             <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *               <enumeration value="attr1"/>
+ *               <enumeration value="attr2"/>
+ *             </restriction>
+ *           </simpleType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Properties", propOrder = { + "property" +}) +public class Properties { + + @XmlElement(name = "Property") + protected List property; + + /** + * Gets the value of the property property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the property property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getProperty().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getProperty() { + if (property == null) { + property = new ArrayList(); + } + return this.property; + } + +} 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/DeviceTypeManager.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/DeviceTypeManager.java index 98c5ef28708..87e0d072d99 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/DeviceTypeManager.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/DeviceTypeManager.java @@ -155,6 +155,11 @@ public class DeviceTypeManager implements DeviceManager { } finally { PrivilegedCarbonContext.endTenantFlow(); } + } else { + if (deviceDetails.getProperties() != null && deviceDetails.getProperties().getProperty() != null + && deviceDetails.getProperties().getProperty().size() > 0 ) { + deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceType, 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/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 10a9b018b38..8b6589193d7 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 @@ -19,17 +19,25 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao; +import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceDetails; + public class DeviceTypePluginDAOManager { - private DeviceTypePluginDAO deviceTypePluginDAO; + private PluginDAO deviceTypePluginDAO; private DeviceTypeDAOHandler deviceTypeDAOHandler; + private static String DEFAULT_DATASOURCE_NAME = "jdbc/DM_DS"; public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) { deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName); - deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, deviceTypeDAOHandler); + deviceTypePluginDAO = new PerDeviceTypePluginDAOImpl(deviceDAODefinition, deviceTypeDAOHandler); + } + + public DeviceTypePluginDAOManager(String deviceType, DeviceDetails deviceDetails) { + deviceTypeDAOHandler = new DeviceTypeDAOHandler(DEFAULT_DATASOURCE_NAME); + deviceTypePluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails, deviceTypeDAOHandler, deviceType); } - public DeviceTypePluginDAO getDeviceDAO() { + public PluginDAO getDeviceDAO() { return deviceTypePluginDAO; } 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/DeviceTypePluginDAO.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/PerDeviceTypePluginDAOImpl.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/DeviceTypePluginDAO.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/PerDeviceTypePluginDAOImpl.java index 163ac647114..0ed009a07c2 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/DeviceTypePluginDAO.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/PerDeviceTypePluginDAOImpl.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 DeviceTypePluginDAO { +public class PerDeviceTypePluginDAOImpl implements PluginDAO{ - private static final Log log = LogFactory.getLog(DeviceTypePluginDAO.class); + private static final Log log = LogFactory.getLog(PerDeviceTypePluginDAOImpl.class); private DeviceTypeDAOHandler deviceTypeDAOHandler; private DeviceDAODefinition deviceDAODefinition; private String selectDBQueryForGetDevice; @@ -47,8 +47,8 @@ public class DeviceTypePluginDAO { private String deleteDBQueryToRemoveDevicd; private String selectDBQueryToGetAllDevice; - public DeviceTypePluginDAO(DeviceDAODefinition deviceDAODefinition, - DeviceTypeDAOHandler deviceTypeDAOHandler) { + public PerDeviceTypePluginDAOImpl(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/PluginDAO.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/PluginDAO.java new file mode 100644 index 00000000000..85029371d96 --- /dev/null +++ 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/PluginDAO.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException; +import java.util.List; + +public interface PluginDAO { + + Device getDevice(String deviceId) throws DeviceTypeMgtPluginException; + + boolean addDevice(Device device) throws DeviceTypeMgtPluginException; + + boolean updateDevice(Device device) throws DeviceTypeMgtPluginException; + + boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException; + + List getAllDevices() throws DeviceTypeMgtPluginException; +} 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 new file mode 100644 index 00000000000..3f27023d334 --- /dev/null +++ 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 @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +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.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; +import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implements CRUD for Devices. This holds the generic implementation. An instance of this will be created for + * each device type. + */ +public class PropertyBasedPluginDAOImpl implements PluginDAO { + + private static final Log log = LogFactory.getLog(PropertyBasedPluginDAOImpl.class); + private DeviceTypeDAOHandler deviceTypeDAOHandler; + private List deviceProps; + private String deviceType; + private static final String PROPERTY_KEY_COLUMN_NAME = "PROPERTY_NAME"; + private static final String PROPERTY_VALUE_COLUMN_NAME = "PROPERTY_VALUE"; + + public PropertyBasedPluginDAOImpl(DeviceDetails deviceDetails, + DeviceTypeDAOHandler deviceTypeDAOHandler, String deviceType) { + this.deviceTypeDAOHandler = deviceTypeDAOHandler; + this.deviceProps = deviceDetails.getProperties().getProperty(); + this.deviceType = deviceType; + } + + public Device getDevice(String deviceId) throws DeviceTypeMgtPluginException { + Connection conn = null; + PreparedStatement stmt = null; + Device device = null; + ResultSet resultSet = null; + try { + conn = deviceTypeDAOHandler.getConnection(); + stmt = conn.prepareStatement( + "SELECT * FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND DEVICE_IDENTIFICATION = ?"); + stmt.setString(1, deviceType); + stmt.setString(2, deviceId); + resultSet = stmt.executeQuery(); + device = new Device(); + device.setDeviceIdentifier(deviceId); + device.setType(deviceType); + List properties = new ArrayList<>(); + while (resultSet.next()) { + Device.Property property = new Device.Property(); + property.setName(resultSet.getString(PROPERTY_KEY_COLUMN_NAME)); + property.setValue(resultSet.getString(PROPERTY_VALUE_COLUMN_NAME)); + properties.add(property); + } + device.setProperties(properties); + } catch (SQLException e) { + String msg = "Error occurred while fetching device : '" + deviceId + "' type " + deviceType; + log.error(msg, e); + throw new DeviceTypeMgtPluginException(msg, e); + } finally { + DeviceTypeUtils.cleanupResources(stmt, resultSet); + deviceTypeDAOHandler.closeConnection(); + } + + return device; + } + + public boolean addDevice(Device device) throws DeviceTypeMgtPluginException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = deviceTypeDAOHandler.getConnection(); + stmt = conn.prepareStatement( + "INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " + + "PROPERTY_VALUE) 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.addBatch(); + } + stmt.executeBatch(); + status = true; + } catch (SQLException e) { + String msg = "Error occurred while adding the device '" + + device.getDeviceIdentifier() + "' to the type " + deviceType + " db."; + log.error(msg, e); + throw new DeviceTypeMgtPluginException(msg, e); + } finally { + DeviceTypeUtils.cleanupResources(stmt, null); + } + return status; + } + + public boolean updateDevice(Device device) throws DeviceTypeMgtPluginException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = deviceTypeDAOHandler.getConnection(); + stmt = conn.prepareStatement( + "UPDATE DM_DEVICE_PROPERTIES SET PROPERTY_VALUE = ? WHERE DEVICE_TYPE_NAME = ? AND " + + "DEVICE_IDENTIFICATION = ? AND PROPERTY_NAME = ?"); + + 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.addBatch(); + } + stmt.executeBatch(); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("device " + device.getDeviceIdentifier() + " data has been modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while modifying the device '" + + device.getDeviceIdentifier() + "' data on" + deviceType; + log.error(msg, e); + throw new DeviceTypeMgtPluginException(msg, e); + } finally { + DeviceTypeUtils.cleanupResources(stmt, null); + } + return status; + } + + public boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = deviceTypeDAOHandler.getConnection(); + stmt = conn.prepareStatement("DELETE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? " + + "AND DEVICE_IDENTIFICATION = ?"); + stmt.setString(1, deviceType); + stmt.setString(2, deviceId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("device " + deviceId + " data has deleted from the " + + deviceType + " table."); + } + } + } catch (SQLException e) { + String msg = + "Error occurred while deleting " + deviceType + " device " + deviceId; + log.error(msg, e); + throw new DeviceTypeMgtPluginException(msg, e); + } finally { + DeviceTypeUtils.cleanupResources(stmt, null); + } + return status; + } + + public List getAllDevices() throws DeviceTypeMgtPluginException { + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + 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.setString(1, deviceType); + resultSet = stmt.executeQuery(); + while (resultSet.next()) { + String deviceId = resultSet.getString("DEVICE_IDENTIFICATION"); + Device deviceInMap = deviceMap.get(deviceId); + if (deviceInMap == null) { + deviceInMap = new Device(); + deviceInMap.setDeviceIdentifier(deviceId); + deviceInMap.setType(deviceType); + List properties = new ArrayList<>(); + deviceInMap.setProperties(properties); + deviceMap.put(deviceId, deviceInMap); + } + Device.Property prop = new Device.Property(); + prop.setName(resultSet.getString(PROPERTY_KEY_COLUMN_NAME)); + prop.setName(resultSet.getString(PROPERTY_VALUE_COLUMN_NAME)); + deviceInMap.getProperties().add(prop); + } + if (log.isDebugEnabled()) { + log.debug( + "All device details have fetched from " + deviceType + " table."); + } + return Arrays.asList((Device[])deviceMap.values().toArray()); + } catch (SQLException e) { + String msg = + "Error occurred while fetching all " + deviceType + " device data'"; + log.error(msg, e); + throw new DeviceTypeMgtPluginException(msg, e); + } finally { + DeviceTypeUtils.cleanupResources(stmt, resultSet); + deviceTypeDAOHandler.closeConnection(); + } + } + + private String getPropertyValue(List properties, String propertyName) { + for (Device.Property property : properties) { + if (property.getName() != null && property.getName().equals(propertyName)) { + return property.getValue(); + } + } + return null; + } + +} \ No newline at end of file diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml index 414bcaa8ddf..8adefb2207d 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml @@ -19,7 +19,16 @@ --> - + + + + + + attr1 + attr2 + + + @@ -38,28 +47,28 @@ - - - temperature sensor fitted - org.wso2.temperature.stream - this is a sensor - - celcius - atmeggga11234 - - - - temperature sensor fitted - org.wso2.temperature.stream - this is a sensor - - celcius - - - - - - + + + + + + + + + + + + + + + + + + + + + + false diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 498a439c076..b8107880c83 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -39,6 +39,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( CONSTRAINT uk_DM_DEVICE UNIQUE (NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( + DEVICE_TYPE_NAME VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME) +); + CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index ed33177429d..2d52f05a196 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -52,6 +52,15 @@ CREATE TABLE DM_DEVICE ( REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_PROPERTIES]') AND TYPE IN (N'U')) +CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( + DEVICE_TYPE_NAME VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME) +); + IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_GROUP_MAP]') AND TYPE IN (N'U')) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 6bec98fc5b4..5a71ad0c217 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -46,6 +46,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( CREATE INDEX IDX_DM_DEVICE ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID); +CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( + DEVICE_TYPE_NAME VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME) +)ENGINE = InnoDB; + CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 4bd5f55de94..00419049bc3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -97,6 +97,16 @@ WHEN (NEW.ID IS NULL) END; / +CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( + DEVICE_TYPE_NAME VARCHAR2(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR2(300) NOT NULL, + PROPERTY_NAME VARCHAR2(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR2(100) DEFAULT NULL, + CONSTRAINT PK_DM_DEVICE_PROPERTY PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME) +) +/ + + CREATE TABLE DM_DEVICE_GROUP_MAP ( ID NUMBER(10) NOT NULL, DEVICE_ID NUMBER(10) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index a4f07d7781f..d0bd24dac7d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -38,6 +38,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( + DEVICE_TYPE_NAME VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME) +); + CREATE INDEX IDX_DM_DEVICE ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID); CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (