mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing minor issues with database queries
This commit is contained in:
parent
b1fc0fcfdb
commit
e79c9b4919
@ -249,7 +249,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|||||||
try {
|
try {
|
||||||
ConnectionManagerUtil.beginTransaction();
|
ConnectionManagerUtil.beginTransaction();
|
||||||
for (String platformIdentifier : platformIdentifiers) {
|
for (String platformIdentifier : platformIdentifiers) {
|
||||||
if (getTenantPlatformMapping(tenantId, platformIdentifier) != -1) {
|
if (getTenantPlatformMapping(tenantId, platformIdentifier) == -1) {
|
||||||
int platformId = getPlatformId(tenantId, platformIdentifier);
|
int platformId = getPlatformId(tenantId, platformIdentifier);
|
||||||
Connection connection = ConnectionManagerUtil.getConnection();
|
Connection connection = ConnectionManagerUtil.getConnection();
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(insertMapping);
|
PreparedStatement preparedStatement = connection.prepareStatement(insertMapping);
|
||||||
@ -285,8 +285,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|||||||
|
|
||||||
private int getTenantPlatformMapping(int tenantId, String platformIdentifier) throws
|
private int getTenantPlatformMapping(int tenantId, String platformIdentifier) throws
|
||||||
PlatformManagementDAOException {
|
PlatformManagementDAOException {
|
||||||
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE "
|
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID, PLATFORM_ID FROM APPM_PLATFORM_TENANT_MAPPING "
|
||||||
+ "TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
|
+ "WHERE TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
|
||||||
+ "PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
+ "PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
||||||
try {
|
try {
|
||||||
Connection connection = ConnectionManagerUtil.getConnection();
|
Connection connection = ConnectionManagerUtil.getConnection();
|
||||||
@ -300,7 +300,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|||||||
return -1;
|
return -1;
|
||||||
} catch (DBConnectionException e) {
|
} catch (DBConnectionException e) {
|
||||||
throw new PlatformManagementDAOException(
|
throw new PlatformManagementDAOException(
|
||||||
"Error occured while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
|
"Error occurred while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
|
||||||
e);
|
e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
||||||
@ -462,21 +462,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
sql += "SELECT * ";
|
sql += "SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER = ? AND TENANT_ID = ?";
|
||||||
sql += "FROM APPM_PLATFORM ";
|
|
||||||
sql += "WHERE IDENTIFIER = ? ";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, identifier);
|
stmt.setString(1, identifier);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
Platform platform = null;
|
Platform platform = null;
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
platform = new Platform();
|
platform = new Platform();
|
||||||
|
platform.setFileBased(rs.getBoolean("FILE_BASED"));
|
||||||
|
|
||||||
|
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
||||||
|
if (!platform.isFileBased()) {
|
||||||
platform.setId(rs.getInt("ID"));
|
platform.setId(rs.getInt("ID"));
|
||||||
platform.setName(rs.getString("NAME"));
|
platform.setName(rs.getString("NAME"));
|
||||||
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
platform.setDescription(rs.getString("DESCRIPTION"));
|
||||||
|
platform.setIconName(rs.getString("ICON_NAME"));
|
||||||
|
platform.setShared(rs.getBoolean("IS_SHARED"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return platform;
|
return platform;
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public class PlatformDeployer extends AbstractDeployer {
|
|||||||
JAXBContext jaxbContext = JAXBContext.newInstance(Platform.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(Platform.class);
|
||||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile);
|
Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile);
|
||||||
if (platformConf.getName().contentEquals(getPlatformID(deploymentFile.getName()))) {
|
if (platformConf.getId().contentEquals(getPlatformID(deploymentFile.getName()))) {
|
||||||
org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf);
|
org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf);
|
||||||
DataHolder.getInstance().getPlatformManager()
|
DataHolder.getInstance().getPlatformManager()
|
||||||
.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform);
|
.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform);
|
||||||
@ -105,6 +105,8 @@ public class PlatformDeployer extends AbstractDeployer {
|
|||||||
platform.setDefaultTenantMapping(platformConfig.isTenantMapping());
|
platform.setDefaultTenantMapping(platformConfig.isTenantMapping());
|
||||||
platform.setEnabled(false);
|
platform.setEnabled(false);
|
||||||
List<org.wso2.carbon.device.application.mgt.common.Platform.Property> properties = new ArrayList<>();
|
List<org.wso2.carbon.device.application.mgt.common.Platform.Property> properties = new ArrayList<>();
|
||||||
|
|
||||||
|
if (platformConfig.getProperties() != null) {
|
||||||
for (Property propertyConfig : platformConfig.getProperties()) {
|
for (Property propertyConfig : platformConfig.getProperties()) {
|
||||||
org.wso2.carbon.device.application.mgt.common.Platform.Property property =
|
org.wso2.carbon.device.application.mgt.common.Platform.Property property =
|
||||||
new org.wso2.carbon.device.application.mgt.common.Platform.Property();
|
new org.wso2.carbon.device.application.mgt.common.Platform.Property();
|
||||||
@ -113,6 +115,7 @@ public class PlatformDeployer extends AbstractDeployer {
|
|||||||
property.setOptional(propertyConfig.isOptional());
|
property.setOptional(propertyConfig.isOptional());
|
||||||
properties.add(property);
|
properties.add(property);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
platform.setProperties(properties);
|
platform.setProperties(properties);
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,18 +6,37 @@
|
|||||||
-- Table APPM_PLATFORM
|
-- Table APPM_PLATFORM
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
|
CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
|
||||||
ID INT NOT NULL,
|
ID INT NOT NULL AUTO_INCREMENT UNIQUE,
|
||||||
NAME VARCHAR(100) NOT NULL,
|
IDENTIFIER VARCHAR (100) NOT NULL,
|
||||||
DESCRIPTION TEXT NULL,
|
TENANT_ID INT NOT NULL ,
|
||||||
IDENTIFIER VARCHAR(100) NOT NULL,
|
NAME VARCHAR (255),
|
||||||
ICON_NAME VARCHAR(100) NULL,
|
FILE_BASED BOOLEAN,
|
||||||
DESCRIPTOR LONGTEXT NOT NULL,
|
DESCRIPTION LONGVARCHAR,
|
||||||
PUBLISHED TINYINT NULL,
|
IS_SHARED BOOLEAN,
|
||||||
IS_SHARED BOOLEAN DEFAULT FALSE,
|
ICON_NAME VARCHAR (100),
|
||||||
FILE_BASED BOOLEAN DEFAULT FALSE,
|
PRIMARY KEY (IDENTIFIER, TENANT_ID)
|
||||||
TENANT_ID INT,
|
);
|
||||||
PRIMARY KEY (ID),
|
|
||||||
UNIQUE INDEX IDENTIFIER_UNIQUE (IDENTIFIER ASC));
|
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_PROPERTIES (
|
||||||
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
|
PLATFORM_ID VARCHAR (100) NOT NULL,
|
||||||
|
PROP_NAME VARCHAR (100) NOT NULL,
|
||||||
|
OPTIONAL BOOLEAN,
|
||||||
|
DEFAUL_VALUE VARCHAR (255),
|
||||||
|
TENANT_ID INT NOT NULL ,
|
||||||
|
FOREIGN KEY(PLATFORM_ID, TENANT_ID) REFERENCES APPM_PLATFORM(IDENTIFIER, TENANT_ID) ON DELETE CASCADE,
|
||||||
|
PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME, TENANT_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TENANT_MAPPING (
|
||||||
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
|
TENANT_ID INT NOT NULL ,
|
||||||
|
PLATFORM_ID VARCHAR (100) NOT NULL,
|
||||||
|
FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(IDENTIFIER) 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);
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
-- Table APPM_APPLICATION_CATEGORY
|
-- Table APPM_APPLICATION_CATEGORY
|
||||||
@ -29,21 +48,6 @@ CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY (
|
|||||||
PUBLISHED TINYINT NULL,
|
PUBLISHED TINYINT NULL,
|
||||||
PRIMARY KEY (ID));
|
PRIMARY KEY (ID));
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
|
||||||
-- Table APPM_PLATFORM_TENANT_MAPPING
|
|
||||||
-- -----------------------------------------------------
|
|
||||||
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TENANT_MAPPING (
|
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
|
||||||
PLATFORM_ID INT NOT NULL,
|
|
||||||
TENANT_ID INT NOT NULL,
|
|
||||||
PRIMARY KEY (ID, PLATFORM_ID),
|
|
||||||
CONSTRAINT fk_APPM_PLATFORM_TENANT_MAPPING_APPM_SUPPORTED_PLATFORM1
|
|
||||||
FOREIGN KEY (PLATFORM_ID)
|
|
||||||
REFERENCES APPM_PLATFORM (ID)
|
|
||||||
ON DELETE NO ACTION
|
|
||||||
ON UPDATE NO ACTION);
|
|
||||||
|
|
||||||
CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC);
|
|
||||||
|
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
|
|||||||
@ -14,18 +14,28 @@ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
|
|||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
-- Table `APPM_PLATFORM`
|
-- Table `APPM_PLATFORM`
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS `APPM_PLATFORM` (
|
CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
|
||||||
`ID` INT NOT NULL,
|
ID INT NOT NULL AUTO_INCREMENT UNIQUE,
|
||||||
`NAME` VARCHAR(100) NOT NULL,
|
IDENTIFIER VARCHAR (100) NOT NULL,
|
||||||
`DESCRIPTION` TEXT NULL,
|
TENANT_ID INT NOT NULL ,
|
||||||
`IDENTIFIER` VARCHAR(100) NOT NULL,
|
NAME VARCHAR (255),
|
||||||
`DESCRIPTOR` LONGTEXT NOT NULL,
|
FILE_BASED BOOLEAN,
|
||||||
IS_SHARED BOOLEAN DEFAULT FALSE,
|
DESCRIPTION VARCHAR(2048),
|
||||||
FILE_BASED BOOLEAN DEFAULT FALSE,
|
IS_SHARED BOOLEAN,
|
||||||
PRIMARY KEY (`ID`),
|
ICON_NAME VARCHAR (100),
|
||||||
UNIQUE INDEX `IDENTIFIER_UNIQUE` (`IDENTIFIER` ASC))
|
PRIMARY KEY (IDENTIFIER, TENANT_ID)
|
||||||
ENGINE = InnoDB
|
);
|
||||||
COMMENT = 'This table contains the data related to the application platform';
|
|
||||||
|
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_PROPERTIES (
|
||||||
|
ID INT NOT NULL AUTO_INCREMENT UNIQUE,
|
||||||
|
PLATFORM_ID VARCHAR (100) NOT NULL,
|
||||||
|
TENANT_ID INT NOT NULL ,
|
||||||
|
PROP_NAME VARCHAR (100) NOT NULL,
|
||||||
|
OPTIONAL BOOLEAN,
|
||||||
|
DEFAUL_VALUE VARCHAR (255),
|
||||||
|
PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME, TENANT_ID),
|
||||||
|
FOREIGN KEY(PLATFORM_ID, TENANT_ID) REFERENCES APPM_PLATFORM(IDENTIFIER, TENANT_ID) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user