From 612905bc5f2cdacfd9dd98576bed82e3fb2737d5 Mon Sep 17 00:00:00 2001 From: megala21 Date: Sun, 6 Aug 2017 00:26:41 +0530 Subject: [PATCH] Adding oracle scripts and impl for PlatformManagement --- .../mgt/core/dao/common/DAOFactory.java | 9 +- .../impl/platform/GenericPlatformDAOImpl.java | 48 +++---- .../impl/platform/OraclePlatformDAOImpl.java | 87 ++++++++++++ .../core/dao/impl/platform/SQLQueries.java | 40 ++++++ .../mgt/core/impl/PlatformManagerImpl.java | 2 +- .../dbscripts/cdm/application-mgt/oracle.sql | 124 +++++++++++------- 6 files changed, 238 insertions(+), 72 deletions(-) create mode 100644 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 create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/SQLQueries.java 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 027067a1864..d1f675c8388 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,6 +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.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; @@ -73,6 +74,8 @@ public class DAOFactory { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: return new GenericPlatformDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OraclePlatformDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } @@ -111,9 +114,9 @@ public class DAOFactory { DatabaseCreator databaseCreator = new ApplicationMgtDatabaseCreator(dataSourceName); if (!databaseCreator.isDatabaseStructureCreated(validationQuery)) { databaseCreator.createRegistryDatabase(); - if (log.isDebugEnabled()) { - log.debug("Application Management tables are created in the database"); - } + log.info("Application Management tables are created in the database"); + } else { + log.info("Application Management Database structure already exists. Not creating the database."); } } } catch (SQLException e) { 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 cb98c1fb297..4cc2a8f67aa 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 @@ -41,7 +41,8 @@ import java.util.List; public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO { private static Log log = LogFactory.getLog(GenericPlatformDAOImpl.class); - @Override public int register(int tenantId, Platform platform) throws PlatformManagementDAOException { + @Override + public int register(int tenantId, Platform platform) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; try { int platformId = getPlatformId(tenantId, platform.getIdentifier()); @@ -113,7 +114,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public void update(int tenantId, String oldPlatformIdentifier, Platform platform) + @Override + public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; try { @@ -200,8 +202,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD private int getPlatformId(int tenantId, String platformIdentifier) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; ResultSet resultSet = null; - String query = "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND " - + "IDENTIFIER=?)"; + String query = SQLQueries.queryToGetPlatformId; try { Connection connection = this.getDBConnection(); preparedStatement = connection.prepareStatement(query); @@ -222,7 +223,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public void unregister(int tenantId, String platformIdenfier, boolean isFileBased) + @Override + public void unregister(int tenantId, String platformIdenfier, boolean isFileBased) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; try { @@ -315,7 +317,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException { + @Override + public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException { String deleteMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE ID = ?"; PreparedStatement preparedStatement = null; try { @@ -340,7 +343,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException { + @Override + public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_ID, platformIdentifier); String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_ID != ? AND PLATFORM_ID=?"; @@ -361,16 +365,15 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public List getPlatforms(int tenantId) throws PlatformManagementDAOException { + @Override + public List getPlatforms(int tenantId) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; ResultSet resultSet = null; if (log.isDebugEnabled()) { log.debug("GetPlaforms request received for the tenant ID " + tenantId); } - String selectQuery = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM " - + "WHERE TENANT_ID=? OR IS_SHARED = TRUE ) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING " - + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?"; + String selectQuery = SQLQueries.queryToGetPlatforms; try { Connection connection = this.getDBConnection(); preparedStatement = connection.prepareStatement(selectQuery); @@ -456,7 +459,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException { + @Override + public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; @@ -464,12 +468,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD try { conn = this.getDBConnection(); - sql = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER, PLATFORM.FILE_BASED, PLATFORM.ID, PLATFORM.NAME, PLATFORM" - + ".DESCRIPTION, PLATFORM.ICON_NAME, PLATFORM.IS_SHARED, PLATFORM.IS_DEFAULT_TENANT_MAPPING FROM " - + "(SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER= ? AND (TENANT_ID=? OR IS_SHARED = TRUE)) " - + "PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID " - + "AND MAPPING.TENANT_ID = ?"; - + sql = SQLQueries.queryToGetPlatform; stmt = conn.prepareStatement(sql); stmt.setString(1, identifier); stmt.setInt(2, tenantId); @@ -509,7 +508,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public void removePlatforms(int tenantId) throws PlatformManagementDAOException { + @Override + public void removePlatforms(int tenantId) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; String sql = "DELETE FROM APPM_PLATFORM WHERE TENANT_ID = ?"; @@ -529,12 +529,12 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } - @Override public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId) + @Override + public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId) throws PlatformManagementDAOException { PreparedStatement preparedStatement = null; ResultSet resultSet = null; - String sql = "SELECT ID from APPM_PLATFORM where IDENTIFIER = ? AND (TENANT_ID = ? OR (TENANT_ID = ? AND " - + "IS_SHARED = true)"; + String sql = SQLQueries.queryToGetSupertenantAndOwnPlatforms; try { Connection connection = this.getDBConnection(); @@ -558,10 +558,10 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } finally { Util.cleanupResources(preparedStatement, resultSet); } - } - @Override public Platform getTenantOwnedPlatform(int tenantId, String platformIdentifier) + @Override + public Platform getTenantOwnedPlatform(int tenantId, String platformIdentifier) throws PlatformManagementDAOException { Connection conn; PreparedStatement stmt = null; 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/OraclePlatformDAOImpl.java new file mode 100644 index 00000000000..1d6cf0d8588 --- /dev/null +++ b/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 @@ -0,0 +1,87 @@ +/* + * 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.application.mgt.core.dao.impl.platform; + +import org.wso2.carbon.device.application.mgt.common.Platform; +import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException; + +import java.util.List; + +/** + * Oracle specific implementation for Platform DAO. + */ +public class OraclePlatformDAOImpl extends GenericPlatformDAOImpl { + + @Override + public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId) + throws PlatformManagementDAOException { + SQLQueries.queryToGetSupertenantAndOwnPlatforms = "SELECT ID from APPM_PLATFORM where IDENTIFIER " + + "= ? AND (TENANT_ID = ? OR (TENANT_ID = ? AND IS_SHARED = 1))"; + return super.getSuperTenantAndOwnPlatforms(platformIdentifier, tenantId); + } + + @Override + public int register(int tenantId, Platform platform) throws PlatformManagementDAOException { + SQLQueries.queryToGetPlatformId = + "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND " + + "IDENTIFIER=?)"; + return super.register(tenantId, platform); + } + + @Override + public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException { + SQLQueries.queryToGetPlatform = + "SELECT MAPPING.ID, PLATFORM.IDENTIFIER, PLATFORM.FILE_BASED, PLATFORM.ID, PLATFORM.NAME, " + + "PLATFORM.DESCRIPTION, PLATFORM.ICON_NAME, PLATFORM.IS_SHARED, " + + "PLATFORM.IS_DEFAULT_TENANT_MAPPING FROM (SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER= ? " + + "AND (TENANT_ID=? OR IS_SHARED = 1)) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING " + + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?"; + return super.getPlatform(tenantId, identifier); + } + + public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException { + SQLQueries.queryToGetPlatformId = + "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND " + + "IDENTIFIER=?)"; + super.removeMappingTenants(platformIdentifier); + } + + public void update(int tenantId, String oldPlatformIdentifier, Platform platform) + throws PlatformManagementDAOException { + SQLQueries.queryToGetPlatformId = + "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND " + + "IDENTIFIER=?)"; + super.update(tenantId, oldPlatformIdentifier, platform); + } + + public void addMapping(int tenantId, List platformIdentifiers) throws PlatformManagementDAOException { + SQLQueries.queryToGetPlatformId = + "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND " + + "IDENTIFIER=?)"; + super.addMapping(tenantId, platformIdentifiers); + } + + public List getPlatforms(int tenantId) throws PlatformManagementDAOException { + SQLQueries.queryToGetPlatforms = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM " + + "WHERE TENANT_ID=? OR IS_SHARED = 1) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING " + + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?"; + return super.getPlatforms(tenantId); + } +} 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/SQLQueries.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/SQLQueries.java new file mode 100644 index 00000000000..73eab98ac4e --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/SQLQueries.java @@ -0,0 +1,40 @@ +/* + * 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.application.mgt.core.dao.impl.platform; + +/** + * SQL Queries specific to Platform. + */ +public class SQLQueries { + static String queryToGetSupertenantAndOwnPlatforms = "SELECT ID from APPM_PLATFORM where IDENTIFIER " + + "= ? AND (TENANT_ID = ? OR (TENANT_ID = ? AND IS_SHARED = true))"; + static String queryToGetPlatformId = + "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND " + + "IDENTIFIER=?)"; + static String queryToGetPlatform = + "SELECT MAPPING.ID, PLATFORM.IDENTIFIER, PLATFORM.FILE_BASED, PLATFORM.ID, PLATFORM.NAME, PLATFORM" + + ".DESCRIPTION, PLATFORM.ICON_NAME, PLATFORM.IS_SHARED, PLATFORM.IS_DEFAULT_TENANT_MAPPING FROM " + + "(SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER= ? AND (TENANT_ID=? OR IS_SHARED = TRUE)) " + + "PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID " + + "AND MAPPING.TENANT_ID = ?"; + static String queryToGetPlatforms = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM " + + "WHERE TENANT_ID=? OR IS_SHARED = TRUE ) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING " + + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?"; +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java index c9d7546a93f..44e516217c5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java @@ -548,7 +548,7 @@ public class PlatformManagerImpl implements PlatformManager { "Error while checking platform sharing conditions for " + " platform identifier '" + platform .getIdentifier() + "' for the tenant :" + tenantId); } finally { - ConnectionManagerUtil.rollbackDBTransaction(); + ConnectionManagerUtil.closeDBConnection(); } } 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 d512eafa36f..b4b845e77c7 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 @@ -1,44 +1,80 @@ -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; - -CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY ( - ID INTEGER AUTO_INCREMENT, - NAME VARCHAR (255), - DESCRIPTION TEXT, - PRIMARY KEY (ID) -)ENGINE INNODB; - - -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 +-- ----------------------------------------------------- +-- Schema WSO2DM_APPM_DB +-- ----------------------------------------------------- + +-- ----------------------------------------------------- +-- Table APPM_PLATFORM +-- ----------------------------------------------------- +CREATE TABLE APPM_PLATFORM ( +ID INT UNIQUE, +IDENTIFIER VARCHAR (100) NOT NULL, +TENANT_ID INT NOT NULL , +NAME VARCHAR (255), +FILE_BASED NUMBER (1), +DESCRIPTION VARCHAR (2048), +IS_SHARED NUMBER (1), +IS_DEFAULT_TENANT_MAPPING NUMBER (1), +ICON_NAME VARCHAR (100), +PRIMARY KEY (IDENTIFIER, TENANT_ID) +) +/ + +CREATE SEQUENCE APPM_PLATFORM_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ +CREATE OR REPLACE TRIGGER APPM_PLATFORM_TRIG + BEFORE INSERT + ON APPM_PLATFORM + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APPM_PLATFORM_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + + +CREATE TABLE APPM_PLATFORM_PROPERTIES ( +ID INT, +PLATFORM_ID INT NOT NULL, +PROP_NAME VARCHAR (100) NOT NULL, +OPTIONAL NUMBER (1), +DEFAUL_VALUE VARCHAR (255), +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME) +) +/ + +CREATE SEQUENCE APPM_PLATFORM_PROPERTIES_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ +CREATE OR REPLACE TRIGGER APPM_PLATFORM_PROPERTIES_TRIG + BEFORE INSERT + ON APPM_PLATFORM_PROPERTIES + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APPM_PLATFORM_PROPERTIES_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + +CREATE TABLE APPM_PLATFORM_TENANT_MAPPING ( +ID INT, +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 SEQUENCE APPM_TENANT_MAPPING_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ +CREATE OR REPLACE TRIGGER APPM_TENANT_MAPPING_TRIG + BEFORE INSERT + ON APPM_PLATFORM_TENANT_MAPPING + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APPM_TENANT_MAPPING_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + +CREATE INDEX FK_PLATFROM_TENANT_MAPPING ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC) +/