From 1ab9807dbdbbadb4c118ace123e6c7e1a0c61fcb Mon Sep 17 00:00:00 2001 From: megala21 Date: Sun, 6 Aug 2017 22:19:43 +0530 Subject: [PATCH] Adding postgre mssql database supports for PlatformManagement --- .../mgt/core/dao/common/DAOFactory.java | 6 +- ...l.java => OracleMsSQLPlatformDAOImpl.java} | 4 +- .../dbscripts/cdm/application-mgt/mssql.sql | 73 ++++++++--------- .../cdm/application-mgt/postgresql.sql | 78 +++++++++---------- 4 files changed, 77 insertions(+), 84 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/{OraclePlatformDAOImpl.java => OracleMsSQLPlatformDAOImpl.java} (96%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index d1f675c838..c70e9c8c00 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -29,7 +29,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.impl.application.H2Applic import org.wso2.carbon.device.application.mgt.core.dao.impl.application.MySQLApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl; -import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OraclePlatformDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; @@ -73,9 +73,11 @@ public class DAOFactory { switch (databaseEngine) { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: + case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: return new GenericPlatformDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: case Constants.DataBaseTypes.DB_TYPE_ORACLE: - return new OraclePlatformDAOImpl(); + return new OracleMsSQLPlatformDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/OraclePlatformDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/OracleMsSQLPlatformDAOImpl.java similarity index 96% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/OraclePlatformDAOImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/OracleMsSQLPlatformDAOImpl.java index 1d6cf0d858..2d9648dab4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/OraclePlatformDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/OracleMsSQLPlatformDAOImpl.java @@ -25,9 +25,9 @@ import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementD import java.util.List; /** - * Oracle specific implementation for Platform DAO. + * Oracle and MsSQL specific implementation for Platform DAO. */ -public class OraclePlatformDAOImpl extends GenericPlatformDAOImpl { +public class OracleMsSQLPlatformDAOImpl extends GenericPlatformDAOImpl { @Override public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index d512eafa36..d8c578a585 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -1,44 +1,35 @@ -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_TYPE ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - DESCRIPTION TEXT, - CODE VARCHAR (255), - PARAMTERS LONGTEXT, - PRIMARY KEY (ID) -)ENGINE INNODB; +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM]') AND TYPE IN (N'U')) +CREATE TABLE APPM_PLATFORM ( + ID INT IDENTITY(1,1) NOT NULL UNIQUE, + IDENTIFIER VARCHAR (100) NOT NULL, + TENANT_ID INT NOT NULL , + NAME VARCHAR (255), + FILE_BASED BIT, + DESCRIPTION VARCHAR(2048), + IS_SHARED BIT, + IS_DEFAULT_TENANT_MAPPING BIT, + ICON_NAME VARCHAR (100), + PRIMARY KEY (IDENTIFIER, TENANT_ID) +); -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - DESCRIPTION TEXT, - PRIMARY KEY (ID) -)ENGINE INNODB; +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM_PROPERTIES]') AND TYPE IN (N'U')) +CREATE TABLE APPM_PLATFORM_PROPERTIES ( +ID INT IDENTITY(1,1) NOT NULL, +PLATFORM_ID INT NOT NULL, +PROP_NAME VARCHAR (100) NOT NULL, +OPTIONAL BIT, +DEFAUL_VALUE VARCHAR (255), +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME) +); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM_TENANT_MAPPING]') AND TYPE IN (N'U')) +CREATE TABLE APPM_PLATFORM_TENANT_MAPPING ( +ID INT IDENTITY(1,1) NOT NULL, +TENANT_ID INT NOT NULL , +PLATFORM_ID INT NOT NULL, +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID) +); -CREATE TABLE IF NOT EXISTS APPM_APPLICATION ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - UUID VARCHAR (255), - DESCRIPTION MEDIUMTEXT, - ICON_NAME VARCHAR (255), - BANNER_NAME VARCHAR (255), - VIDEO_NAME VARCHAR (255), - SCREENSHOTS TEXT, - TAGS TEXT, - APPLICATION_TYPE_ID INTEGER, - CATEGORY_ID INTEGER, - CREATED_AT DATETIME, - MODIFIED_AT DATETIME, - PRIMARY KEY (ID), - FOREIGN KEY (CATEGORY_ID) REFERENCES APPM_APPLICATION_CATEGORY(ID), - FOREIGN KEY (APPLICATION_TYPE_ID) REFERENCES APPM_APPLICATION_TYPE(ID) -)ENGINE INNODB; - - -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_PROPERTIES ( - PROP_KEY VARCHAR (255), - PROP_VAL MEDIUMTEXT, - APPLICATION_ID INTEGER, - PRIMARY KEY (APPLICATION_ID, PROP_KEY), - FOREIGN KEY (APPLICATION_ID) REFERENCES APPM_APPLICATION(ID) -)ENGINE INNODB; \ No newline at end of file +CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC); \ No newline at end of file diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index d512eafa36..96e806a012 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -1,44 +1,44 @@ -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_TYPE ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - DESCRIPTION TEXT, - CODE VARCHAR (255), - PARAMTERS LONGTEXT, - PRIMARY KEY (ID) -)ENGINE INNODB; +DROP TABLE IF EXISTS APPM_PLATFORM; +DROP SEQUENCE IF EXISTS APPM_PLATFORM_PK_SEQ; +CREATE SEQUENCE APPM_PLATFORM_PK_SEQ; -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - DESCRIPTION TEXT, - PRIMARY KEY (ID) -)ENGINE INNODB; +CREATE TABLE APPM_PLATFORM ( +ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PK_SEQ') UNIQUE, +IDENTIFIER VARCHAR (100) NOT NULL, +TENANT_ID INT NOT NULL , +NAME VARCHAR (255), +FILE_BASED BOOLEAN, +DESCRIPTION VARCHAR(2048), +IS_SHARED BOOLEAN, +IS_DEFAULT_TENANT_MAPPING BOOLEAN, +ICON_NAME VARCHAR (100), +PRIMARY KEY (IDENTIFIER, TENANT_ID) +); +DROP TABLE IF EXISTS APPM_PLATFORM_PROPERTIES; +DROP SEQUENCE IF EXISTS APPM_PLATFORM_PROPERTIES_PK_SEQ; +CREATE SEQUENCE APPM_PLATFORM_PROPERTIES_PK_SEQ; -CREATE TABLE IF NOT EXISTS APPM_APPLICATION ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - UUID VARCHAR (255), - DESCRIPTION MEDIUMTEXT, - ICON_NAME VARCHAR (255), - BANNER_NAME VARCHAR (255), - VIDEO_NAME VARCHAR (255), - SCREENSHOTS TEXT, - TAGS TEXT, - APPLICATION_TYPE_ID INTEGER, - CATEGORY_ID INTEGER, - CREATED_AT DATETIME, - MODIFIED_AT DATETIME, - PRIMARY KEY (ID), - FOREIGN KEY (CATEGORY_ID) REFERENCES APPM_APPLICATION_CATEGORY(ID), - FOREIGN KEY (APPLICATION_TYPE_ID) REFERENCES APPM_APPLICATION_TYPE(ID) -)ENGINE INNODB; +CREATE TABLE APPM_PLATFORM_PROPERTIES ( +ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PROPERTIES_PK_SEQ'), +PLATFORM_ID INT NOT NULL, +PROP_NAME VARCHAR (100) NOT NULL, +OPTIONAL BOOLEAN, +DEFAUL_VALUE VARCHAR (255), +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME) +); +DROP TABLE IF EXISTS APPM_PLATFORM_TENANT_MAPPING; +DROP SEQUENCE IF EXISTS APPM_PLATFORM_TENANT_MAPPING_PK_SEQ; +CREATE SEQUENCE APPM_PLATFORM_TENANT_MAPPING_PK_SEQ; -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_PROPERTIES ( - PROP_KEY VARCHAR (255), - PROP_VAL MEDIUMTEXT, - APPLICATION_ID INTEGER, - PRIMARY KEY (APPLICATION_ID, PROP_KEY), - FOREIGN KEY (APPLICATION_ID) REFERENCES APPM_APPLICATION(ID) -)ENGINE INNODB; \ No newline at end of file +CREATE TABLE APPM_PLATFORM_TENANT_MAPPING ( +ID INT DEFAULT NEXTVAL('APPM_PLATFORM_TENANT_MAPPING_PK_SEQ'), +TENANT_ID INT NOT NULL , +PLATFORM_ID INT NOT NULL, +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID) +); + +CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC); \ No newline at end of file