forked from community/device-mgt-core
parent
ec0be0183e
commit
612905bc5f
@ -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<String> 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<Platform> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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 = ?";
|
||||||
|
}
|
@ -1,44 +1,80 @@
|
|||||||
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_TYPE (
|
-- -----------------------------------------------------
|
||||||
ID INTEGER AUTO_INCREMENT,
|
-- Schema WSO2DM_APPM_DB
|
||||||
NAME VARCHAR (255),
|
-- -----------------------------------------------------
|
||||||
DESCRIPTION TEXT,
|
|
||||||
CODE VARCHAR (255),
|
-- -----------------------------------------------------
|
||||||
PARAMTERS LONGTEXT,
|
-- Table APPM_PLATFORM
|
||||||
PRIMARY KEY (ID)
|
-- -----------------------------------------------------
|
||||||
)ENGINE INNODB;
|
CREATE TABLE APPM_PLATFORM (
|
||||||
|
ID INT UNIQUE,
|
||||||
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY (
|
IDENTIFIER VARCHAR (100) NOT NULL,
|
||||||
ID INTEGER AUTO_INCREMENT,
|
TENANT_ID INT NOT NULL ,
|
||||||
NAME VARCHAR (255),
|
NAME VARCHAR (255),
|
||||||
DESCRIPTION TEXT,
|
FILE_BASED NUMBER (1),
|
||||||
PRIMARY KEY (ID)
|
DESCRIPTION VARCHAR (2048),
|
||||||
)ENGINE INNODB;
|
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 IF NOT EXISTS APPM_APPLICATION (
|
|
||||||
ID INTEGER AUTO_INCREMENT,
|
CREATE TABLE APPM_PLATFORM_PROPERTIES (
|
||||||
NAME VARCHAR (255),
|
ID INT,
|
||||||
UUID VARCHAR (255),
|
PLATFORM_ID INT NOT NULL,
|
||||||
DESCRIPTION MEDIUMTEXT,
|
PROP_NAME VARCHAR (100) NOT NULL,
|
||||||
ICON_NAME VARCHAR (255),
|
OPTIONAL NUMBER (1),
|
||||||
BANNER_NAME VARCHAR (255),
|
DEFAUL_VALUE VARCHAR (255),
|
||||||
VIDEO_NAME VARCHAR (255),
|
FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE,
|
||||||
SCREENSHOTS TEXT,
|
PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME)
|
||||||
TAGS TEXT,
|
)
|
||||||
APPLICATION_TYPE_ID INTEGER,
|
/
|
||||||
CATEGORY_ID INTEGER,
|
|
||||||
CREATED_AT DATETIME,
|
CREATE SEQUENCE APPM_PLATFORM_PROPERTIES_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
|
||||||
MODIFIED_AT DATETIME,
|
/
|
||||||
PRIMARY KEY (ID),
|
CREATE OR REPLACE TRIGGER APPM_PLATFORM_PROPERTIES_TRIG
|
||||||
FOREIGN KEY (CATEGORY_ID) REFERENCES APPM_APPLICATION_CATEGORY(ID),
|
BEFORE INSERT
|
||||||
FOREIGN KEY (APPLICATION_TYPE_ID) REFERENCES APPM_APPLICATION_TYPE(ID)
|
ON APPM_PLATFORM_PROPERTIES
|
||||||
)ENGINE INNODB;
|
REFERENCING NEW AS NEW
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_PROPERTIES (
|
SELECT APPM_PLATFORM_PROPERTIES_SEQ.nextval INTO :NEW.ID FROM dual;
|
||||||
PROP_KEY VARCHAR (255),
|
END;
|
||||||
PROP_VAL MEDIUMTEXT,
|
/
|
||||||
APPLICATION_ID INTEGER,
|
|
||||||
PRIMARY KEY (APPLICATION_ID, PROP_KEY),
|
CREATE TABLE APPM_PLATFORM_TENANT_MAPPING (
|
||||||
FOREIGN KEY (APPLICATION_ID) REFERENCES APPM_APPLICATION(ID)
|
ID INT,
|
||||||
)ENGINE INNODB;
|
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)
|
||||||
|
/
|
||||||
|
Loading…
Reference in new issue