Adding oracle scripts and impl for PlatformManagement

feature/appm-store/pbac
megala21 7 years ago
parent ec0be0183e
commit 612905bc5f

@ -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) {

@ -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<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
@Override
public List<Platform> 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;

@ -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 = ?";
}

@ -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();
}
}

@ -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;
-- -----------------------------------------------------
-- 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)
/

Loading…
Cancel
Save