From 8dbdde8223e0e080b1e2027a3e769cd163e3b456 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 27 Mar 2015 19:40:09 +0530 Subject: [PATCH] Create Plugin Data bases at startup --- ...bileDeviceManagementSchemaInitializer.java | 34 +++++++------ .../main/resources/dbscripts/plugins/h2.sql | 44 ---------------- .../resources/dbscripts/plugins/mysql.sql | 51 ------------------- .../src/main/resources/p2.inf | 2 +- 4 files changed, 19 insertions(+), 112 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java index 1d04f6059..a4ed5011e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.mobile.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.dbcreator.DatabaseCreator; @@ -33,21 +34,22 @@ import java.io.File; */ public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator { - private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class); - private static final String setupSQLScriptBaseLocation = - CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + - File.separator + "plugins" + File.separator ; - - public MobileDeviceManagementSchemaInitializer(DataSource dataSource) { - super(dataSource); - } - - protected String getDbScriptLocation(String databaseType) { - String scriptName = databaseType + ".sql"; - if (log.isDebugEnabled()) { - log.debug("Loading database script from :" + scriptName); - } - return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName; - } + private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class); + private static final String setupSQLScriptBaseLocation = + CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + + MobilePluginConstants.MOBILE_DB_SCRIPTS_FOLDER + + File.separator + "plugins" + File.separator; + + public MobileDeviceManagementSchemaInitializer(DataSource dataSource) { + super(dataSource); + } + + protected String getDbScriptLocation(String databaseType) { + String scriptName = databaseType + ".sql"; + if (log.isDebugEnabled()) { + log.debug("Loading database script from :" + scriptName); + } + return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName; + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql index 2df2ee2f3..e63252d4a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql @@ -30,50 +30,6 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( `DESCRIPTION` VARCHAR(200) NULL , PRIMARY KEY (`FEATURE_ID`) ); --- ----------------------------------------------------- --- Table `MBL_OPERATION` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( - `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , - `FEATURE_CODE` VARCHAR(45) NOT NULL , - `CREATED_DATE` BIGINT NULL , - PRIMARY KEY (`OPERATION_ID`)); - --- ----------------------------------------------------- --- Table `MBL_DEVICE_OPERATION_MAPPING` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( - `DEVICE_ID` VARCHAR(45) NOT NULL , - `OPERATION_ID` INT NOT NULL , - `SENT_DATE` BIGINT NULL , - `RECEIVED_DATE` BIGINT NULL , - `STATUS` VARCHAR(10) NOT NULL , - PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , - CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` - FOREIGN KEY (`DEVICE_ID` ) - REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); - --- ----------------------------------------------------- --- Table `MBL_OPERATION_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( - `OPERATION_ID` INT NOT NULL , - `PROPERTY` VARCHAR(45) NOT NULL , - `VALUE` TEXT NULL , - PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , - CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); - -- ----------------------------------------------------- -- Table `MBL_FEATURE_PROPERTY` -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql index 641f7f4dc..e69dc48ad 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql @@ -31,57 +31,6 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( PRIMARY KEY (`FEATURE_ID`)) ENGINE = InnoDB; - --- ----------------------------------------------------- --- Table `MBL_OPERATION` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( - `OPERATION_ID` INT NOT NULL AUTO_INCREMENT, - `FEATURE_CODE` VARCHAR(45) NULL, - `CREATED_DATE` INT NULL, - PRIMARY KEY (`OPERATION_ID`)) -ENGINE = InnoDB; - - --- ----------------------------------------------------- --- Table `MBL_DEVICE_OPERATION_MAPING` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( - `DEVICE_ID` VARCHAR(45) NOT NULL, - `OPERATION_ID` INT NOT NULL, - `SENT_DATE` INT NULL, - `RECEIVED_DATE` INT NULL, - `STATUS` VARCHAR(10) NOT NULL, - PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`), - INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC), - CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` - FOREIGN KEY (`DEVICE_ID`) - REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID`) - REFERENCES `MBL_OPERATION` (`OPERATION_ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) -ENGINE = InnoDB; - - --- ----------------------------------------------------- --- Table `MBL_OPERATION_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( - `OPERATION_ID` INT NULL, - `PROPERTY` VARCHAR(45) NOT NULL ,, - `VALUE` TEXT NULL, - PRIMARY KEY (`OPERATION_ID`, `PROPERTY`), - CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID`) - REFERENCES `MBL_OPERATION` (`OPERATION_ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) -ENGINE = InnoDB; - -- ----------------------------------------------------- -- Table `MBL_FEATURE_PROPERTY` -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf index 3e76789f8..0dab9e7d2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf @@ -1,3 +1,3 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins,overwrite:true);\