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/GenericPlatformDAOImpl.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/GenericPlatformDAOImpl.java index de980fd5ed0..360eb49cbaf 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/GenericPlatformDAOImpl.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/GenericPlatformDAOImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import java.sql.Connection; @@ -78,6 +79,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD preparedStatement.execute(); } } + //Adding tags to the database. + Boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported(); + String insertTags = "INSERT INTO APPM_PLATFORM_TAG (NAME, PLATFORM_ID) VALUES (?, ?)"; + preparedStatement = connection.prepareStatement(insertTags); + if (platform.getTags() != null) { + for (String tag : platform.getTags()) { + preparedStatement.setString(1, tag); + preparedStatement.setInt(2, platformId); + + if (isBatchExecutionSupported) { + preparedStatement.addBatch(); + } + else { + preparedStatement.execute(); + } + } + if (isBatchExecutionSupported) { + preparedStatement.executeBatch(); + } + } + } else { String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, FILE_BASED, IS_SHARED, " @@ -486,6 +508,18 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD platform.setShared(rs.getBoolean(8)); platform.setDefaultTenantMapping(rs.getBoolean(9)); platform.setId(rs.getInt(4)); + //Getting tags + sql = "SELECT * FROM APPM_PLATFORM_TAG WHERE PLATFORM_ID=?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, rs.getInt(4)); + ResultSet rsTags = stmt.executeQuery(); + + List tags = new ArrayList<>(); + while (rsTags.next()) { + tags.add(rsTags.getString("NAME")); + } + platform.setTags(tags); + if (!platform.isFileBased()) { platform.setName(rs.getString(5)); platform.setDescription(rs.getString(6)); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index f8596375b34..3d5e3c4fc4e 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -292,8 +292,8 @@ CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TAG ( CONSTRAINT fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1 FOREIGN KEY (PLATFORM_ID) REFERENCES APPM_PLATFORM (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION); + ON DELETE CASCADE + ON UPDATE CASCADE); CREATE INDEX FK_PLATFORM_TAGS_PLATFORM ON APPM_PLATFORM_TAG(PLATFORM_ID ASC); 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 42fd4cb36b0..8fa1a42b4be 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 @@ -32,4 +32,12 @@ FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID) ); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM_TAG]') AND TYPE IN (N'U')) +CREATE TABLE APPM_PLATFORM_TAG ( +NAME VARCHAR (100) NOT NULL , +PLATFORM_ID INT NOT NULL, +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (PLATFORM_ID, NAME) +); + 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/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index a5f5bbd5a51..3e378c09e06 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -327,8 +327,8 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TAG` ( CONSTRAINT `fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1` FOREIGN KEY (`PLATFORM_ID`) REFERENCES `APPM_PLATFORM` (`ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) + ON DELETE CASCADE + ON UPDATE CASCADE) ENGINE = InnoDB COMMENT = 'This table contains the data related to the app platform tag'; diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index 174b1d6fc5d..b1b0e88842e 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -353,3 +353,15 @@ CREATE TABLE APPM_APPLICATION_TAG ( CREATE INDEX FK_APPM_APP_TAG_APP ON APPM_APPLICATION_TAG(APPLICATION_ID ASC) / + +CREATE TABLE APPM_PLATFORM_TAG ( + NAME VARCHAR(100) NOT NULL, + PLATFORM_ID INT NOT NULL, + PRIMARY KEY (PLATFORM_ID, NAME), + CONSTRAINT FK_APPM_PLATFORM_TAG_APP + FOREIGN KEY (PLATFORM_ID) + REFERENCES APPM_PLATFORM (ID)) +/ + +CREATE INDEX FK_APPM_PLATFORM_TAG_APP ON APPM_PLATFORM_TAG(PLATFORM_ID ASC) +/ 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 7259c736bf5..5937f68d08e 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 @@ -203,6 +203,16 @@ CREATE TABLE IF NOT EXISTS APPM_APPLICATION_TAG ( CREATE INDEX IF NOT EXISTS FK_APPLICATION_TAG_APPLICATION ON APPM_APPLICATION_TAG(APPLICATION_ID ASC); +CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TAG ( + NAME VARCHAR(100) NOT NULL, + PLATFORM_ID INT NOT NULL, + PRIMARY KEY (PLATFORM_ID, NAME), + CONSTRAINT fk_APPM_PLATFORM_TAG_APPM_APPLICATION1 + FOREIGN KEY (PLATFORM_ID) + REFERENCES APPM_PLATFORM (ID) + ON DELETE CASCADE + ON UPDATE CASCADE); + DROP TABLE IF EXISTS APPM_APPLICATION_RELEASE; DROP SEQUENCE IF EXISTS APPM_APPLICATION_RELEASE_PK_SEQ; CREATE SEQUENCE APPM_APPLICATION_RELEASE_PK_SEQ;