diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java index 830f37570..e8851df8a 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java @@ -92,8 +92,13 @@ public class AndroidSenseUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasource); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from ANDROID_SENSE_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasource, e); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java index 91a17cf21..f4207d72e 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java @@ -105,8 +105,13 @@ public class ArduinoUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasource); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from ARDUINO_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasource, e); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java index e2ce1f44a..8bd1b6e2e 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java @@ -94,8 +94,13 @@ public class RaspberrypiUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasource); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from RASPBERRYPI_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasource, e); } catch (Exception e) { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java index 737796735..66d5d7747 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java @@ -99,8 +99,13 @@ public class VirtualFireAlarmUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasourceName); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from VIRTUAL_FIREALARM_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasourceName, e); } catch (Exception e) { diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java index 0f72e82e9..bf1c005c1 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java @@ -93,9 +93,22 @@ public class MobileDeviceManagementDAOUtil { public static void setupMobileDeviceManagementSchema(DataSource dataSource, String pluginType) throws MobileDeviceMgtPluginException { MobileDeviceManagementSchemaInitializer initializer = new MobileDeviceManagementSchemaInitializer(dataSource, pluginType); - log.info("Initializing mobile device management repository database schema for : " + pluginType); + String checkSql = "select * from "; + if (pluginType.equalsIgnoreCase("android")) { + checkSql += "AD_DEVICE"; + } else if (pluginType.equalsIgnoreCase("windows")) { + checkSql += "WIN_DEVICE"; + } else { + checkSql += "IOS_DEVICE"; + } try { - initializer.createRegistryDatabase(); + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing mobile device management repository database schema for : " + pluginType); + initializer.createRegistryDatabase(); + } else { + log.info("Mobile device management repository database for " + pluginType + + " already exists. Not creating a new database."); + } } catch (Exception e) { throw new MobileDeviceMgtPluginException("Error occurred while initializing Mobile Device " + "Management database schema", e);