Fixing minor issues in closing the database statements and resultsets

4.x.x
megala21 7 years ago
parent 149719d64c
commit f16b03ffee

@ -91,4 +91,4 @@ public class ErrorResponse {
public void setErrorItems(List<ErrorListItem> error) { public void setErrorItems(List<ErrorListItem> error) {
this.errorItems = error; this.errorItems = error;
} }
} }

@ -66,13 +66,16 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
String insertPlatformProps = String insertPlatformProps =
"INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, " "INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, "
+ "DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)"; + "DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
for (Platform.Property property : platform.getProperties()) {
preparedStatement = connection.prepareStatement(insertPlatformProps); if (platform.getProperties() != null) {
preparedStatement.setInt(1, platformId); for (Platform.Property property : platform.getProperties()) {
preparedStatement.setString(2, property.getName()); preparedStatement = connection.prepareStatement(insertPlatformProps);
preparedStatement.setBoolean(3, property.isOptional()); preparedStatement.setInt(1, platformId);
preparedStatement.setString(4, property.getDefaultValue()); preparedStatement.setString(2, property.getName());
preparedStatement.execute(); preparedStatement.setBoolean(3, property.isOptional());
preparedStatement.setString(4, property.getDefaultValue());
preparedStatement.execute();
}
} }
} else { } else {
String insertToPlatform = String insertToPlatform =
@ -105,12 +108,14 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
throw ex; throw ex;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackTransaction(); ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - " throw new PlatformManagementDAOException(
+ platform.getIdentifier() + " for tenant - " + tenantId, e); "Unable to obtain the connection while trying to register the platform - " + platform
.getIdentifier() + " for tenant - " + tenantId, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackTransaction(); ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementDAOException("Error occurred while performing the transaction on the database " + throw new PlatformManagementDAOException(
"for adding the platform - " + platform.getIdentifier() + " , tenant domain - " + tenantId); "Error occurred while performing the transaction on the database " + "for adding the platform - "
+ platform.getIdentifier() + " , tenant domain - " + tenantId);
} finally { } finally {
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
@ -119,6 +124,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
@Override @Override
public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws
PlatformManagementDAOException { PlatformManagementDAOException {
PreparedStatement preparedStatement = null;
try { try {
ConnectionManagerUtil.beginTransaction(); ConnectionManagerUtil.beginTransaction();
int platformId = getPlatformId(tenantId, oldPlatformIdentifier); int platformId = getPlatformId(tenantId, oldPlatformIdentifier);
@ -127,7 +133,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
if (!platform.isFileBased()) { if (!platform.isFileBased()) {
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, " String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, "
+ "IS_SHARED=?, ICON_NAME=? WHERE ID = ?"; + "IS_SHARED=?, ICON_NAME=? WHERE ID = ?";
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform); preparedStatement = connection.prepareStatement(insertToPlatform);
preparedStatement.setString(1, platform.getIdentifier()); preparedStatement.setString(1, platform.getIdentifier());
preparedStatement.setString(2, platform.getName()); preparedStatement.setString(2, platform.getName());
preparedStatement.setString(3, platform.getDescription()); preparedStatement.setString(3, platform.getDescription());
@ -154,7 +160,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
} }
} else { } else {
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ? WHERE ID = ?"; String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ? WHERE ID = ?";
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform); preparedStatement = connection.prepareStatement(insertToPlatform);
preparedStatement.setInt(1, platformId); preparedStatement.setInt(1, platformId);
preparedStatement.execute(); preparedStatement.execute();
} }
@ -181,20 +187,23 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
"Error occurred while performing the transaction on the database " + "for adding the platform - " "Error occurred while performing the transaction on the database " + "for adding the platform - "
+ platform.getIdentifier() + " , tenant domain - " + tenantId); + platform.getIdentifier() + " , tenant domain - " + tenantId);
} finally { } finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, null);
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
} }
private int getPlatformId(int tenantId, String platformIdentifier) throws PlatformManagementDAOException { 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 " String query = "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND "
+ "IDENTIFIER=?)"; + "IDENTIFIER=?)";
try { try {
Connection connection = ConnectionManagerUtil.getConnection(); Connection connection = ConnectionManagerUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, tenantId); preparedStatement.setInt(1, tenantId);
preparedStatement.setString(2, platformIdentifier); preparedStatement.setString(2, platformIdentifier);
preparedStatement.setString(3, platformIdentifier); preparedStatement.setString(3, platformIdentifier);
ResultSet resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
return resultSet.getInt("ID"); return resultSet.getInt("ID");
} }
@ -203,19 +212,22 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
throw new PlatformManagementDAOException("Error when trying to obtaining the database connection.", e); throw new PlatformManagementDAOException("Error when trying to obtaining the database connection.", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PlatformManagementDAOException("Error in executing the query - " + query, e); throw new PlatformManagementDAOException("Error in executing the query - " + query, e);
} finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, resultSet);
} }
} }
@Override @Override
public void unregister(int tenantId, String platformIdenfier) throws PlatformManagementDAOException { public void unregister(int tenantId, String platformIdenfier) throws PlatformManagementDAOException {
PreparedStatement preparedStatement = null;
try { try {
ConnectionManagerUtil.beginTransaction(); ConnectionManagerUtil.beginTransaction();
int platformId = getPlatformId(tenantId, platformIdenfier); int platformId = getPlatformId(tenantId, platformIdenfier);
if (platformId != -1) { if (platformId != -1) {
Connection connection = ConnectionManagerUtil.getConnection(); Connection connection = ConnectionManagerUtil.getConnection();
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?"; String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
PreparedStatement preparedStatement = connection.prepareStatement(deletePlatform); preparedStatement = connection.prepareStatement(deletePlatform);
preparedStatement.setInt(1, platformId); preparedStatement.setInt(1, platformId);
preparedStatement.execute(); preparedStatement.execute();
ConnectionManagerUtil.commitTransaction(); ConnectionManagerUtil.commitTransaction();
@ -240,25 +252,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
ConnectionManagerUtil.rollbackTransaction(); ConnectionManagerUtil.rollbackTransaction();
throw ex; throw ex;
} finally { } finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, null);
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
} }
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException { public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException {
String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_ID, PLATFORM_ID) VALUES (?, ?)"; String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_ID, PLATFORM_ID) VALUES (?, ?)";
PreparedStatement preparedStatement = null;
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 = connection.prepareStatement(insertMapping);
preparedStatement.setInt(1, tenantId); preparedStatement.setInt(1, tenantId);
preparedStatement.setInt(2, platformId); preparedStatement.setInt(2, platformId);
preparedStatement.execute(); preparedStatement.execute();
} else { } else {
throw new PlatformManagementDAOException("Platform identifier - " + platformIdentifier + " is " log.error("Platform identifier - " + platformIdentifier + " is already assigned to tenant domain"
+ "already assigned to tenant domain - " + tenantId); + " - " + tenantId);
} }
} }
ConnectionManagerUtil.commitTransaction(); ConnectionManagerUtil.commitTransaction();
@ -279,6 +293,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
ConnectionManagerUtil.rollbackTransaction(); ConnectionManagerUtil.rollbackTransaction();
throw ex; throw ex;
} finally { } finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, null);
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
} }
@ -310,12 +325,13 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
@Override @Override
public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException { public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException {
String deleteMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE ID = ?"; String deleteMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE ID = ?";
PreparedStatement preparedStatement = null;
try { try {
ConnectionManagerUtil.beginTransaction(); ConnectionManagerUtil.beginTransaction();
int mappingId = getTenantPlatformMapping(tenantId, platformIdentifier); int mappingId = getTenantPlatformMapping(tenantId, platformIdentifier);
if (mappingId != -1) { if (mappingId != -1) {
Connection connection = ConnectionManagerUtil.getConnection(); Connection connection = ConnectionManagerUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(deleteMapping); preparedStatement = connection.prepareStatement(deleteMapping);
preparedStatement.setInt(1, mappingId); preparedStatement.setInt(1, mappingId);
preparedStatement.execute(); preparedStatement.execute();
ConnectionManagerUtil.commitTransaction(); ConnectionManagerUtil.commitTransaction();
@ -335,28 +351,31 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
ConnectionManagerUtil.rollbackTransaction(); ConnectionManagerUtil.rollbackTransaction();
throw ex; throw ex;
} finally { } finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, null);
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
} }
@Override @Override
public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException { public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException {
PreparedStatement preparedStatement = null;
int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_ID, platformIdentifier); int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_ID, platformIdentifier);
String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_ID != ? AND PLATFORM_ID=?"; String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_ID != ? AND PLATFORM_ID=?";
try { try {
ConnectionManagerUtil.openConnection(); ConnectionManagerUtil.openConnection();
Connection connection = ConnectionManagerUtil.getConnection(); Connection connection = ConnectionManagerUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(getMapping); preparedStatement = connection.prepareStatement(getMapping);
preparedStatement.setInt(1, MultitenantConstants.SUPER_TENANT_ID); preparedStatement.setInt(1, MultitenantConstants.SUPER_TENANT_ID);
preparedStatement.setInt(2, platformId); preparedStatement.setInt(2, platformId);
preparedStatement.execute(); preparedStatement.execute();
} 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 occurred while executing the SQL query - " + getMapping, e);
} finally { } finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, null);
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
} }
@ -364,6 +383,9 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
@Override @Override
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException { public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("GetPlaforms request received for the tenant ID " + tenantId); log.debug("GetPlaforms request received for the tenant ID " + tenantId);
} }
@ -373,9 +395,9 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID"; + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
try { try {
Connection connection = ConnectionManagerUtil.openConnection(); Connection connection = ConnectionManagerUtil.openConnection();
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery); preparedStatement = connection.prepareStatement(selectQuery);
preparedStatement.setInt(1, tenantId); preparedStatement.setInt(1, tenantId);
ResultSet resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
List<Platform> platforms = new ArrayList<>(); List<Platform> platforms = new ArrayList<>();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Platform retrieved for the tenant Id " + tenantId); log.debug("Platform retrieved for the tenant Id " + tenantId);
@ -401,30 +423,33 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
return platforms; return platforms;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new PlatformManagementDAOException( throw new PlatformManagementDAOException(
"Error occured when loading the platforms for tenant - " + tenantId, e); "Error occurred when loading the platforms for tenant - " + tenantId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e); throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e);
} finally { } finally {
ConnectionManagerUtil.cleanupResources(preparedStatement,resultSet);
ConnectionManagerUtil.closeConnection(); ConnectionManagerUtil.closeConnection();
} }
} }
public Platform getPlatform(String tenantDomain, String platformIdenfier) throws PlatformManagementDAOException { public Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) " + String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) " +
"OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM " + "OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM " +
"LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID"; "LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID";
try { try {
ConnectionManagerUtil.openConnection(); ConnectionManagerUtil.openConnection();
Connection connection = ConnectionManagerUtil.getConnection(); Connection connection = ConnectionManagerUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(platformQuery); preparedStatement = connection.prepareStatement(platformQuery);
preparedStatement.setString(1, tenantDomain); preparedStatement.setString(1, tenantDomain);
preparedStatement.setString(2, platformIdenfier); preparedStatement.setString(2, platformIdentifier);
preparedStatement.setString(3, platformIdenfier); preparedStatement.setString(3, platformIdentifier);
ResultSet resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
Platform platform = new Platform(); Platform platform = new Platform();
if (resultSet.next()) { if (resultSet.next()) {
platform.setId(resultSet.getInt("PLATFORM.ID")); platform.setId(resultSet.getInt("PLATFORM.ID"));
platform.setIdentifier(platformIdenfier); platform.setIdentifier(platformIdentifier);
platform.setName(resultSet.getString("PLATFORM.NAME")); platform.setName(resultSet.getString("PLATFORM.NAME"));
platform.setIconName(resultSet.getString("PLATFORM.DESCRIPTION")); platform.setIconName(resultSet.getString("PLATFORM.DESCRIPTION"));
platform.setIconName(resultSet.getString("PLATFORM.ICON_NAME")); platform.setIconName(resultSet.getString("PLATFORM.ICON_NAME"));
@ -442,27 +467,29 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
} while (resultSet.next()); } while (resultSet.next());
platform.setProperties(properties); platform.setProperties(properties);
} else { } else {
platform.setIdentifier(platformIdenfier); platform.setIdentifier(platformIdentifier);
platform.setFileBased(true); platform.setFileBased(true);
} }
return platform; return platform;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new PlatformManagementDAOException("Error when loading the platform - " + platformIdenfier, e); throw new PlatformManagementDAOException("Error when loading the platform - " + platformIdentifier, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PlatformManagementDAOException("Error in executing the query - " + platformQuery, e); throw new PlatformManagementDAOException("Error in executing the query - " + platformQuery, e);
} finally {
ConnectionManagerUtil.cleanupResources(preparedStatement, resultSet);
ConnectionManagerUtil.closeConnection();
} }
} }
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException { public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException {
Connection conn;
Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = ""; String sql = "";
try { try {
conn = this.getConnection(); conn = this.getConnection();
sql += "SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER = ? AND TENANT_ID = ?"; sql = "SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier); stmt.setString(1, identifier);
@ -484,14 +511,14 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
platform.setShared(rs.getBoolean("IS_SHARED")); platform.setShared(rs.getBoolean("IS_SHARED"));
} }
} }
return platform; return platform;
} catch (SQLException e) { } catch (SQLException e) {
throw new PlatformManagementDAOException("Error occurred while getting application List", e); throw new PlatformManagementDAOException("Error occurred while getting platform with the identifier " +
identifier + ", for the tenant : " + tenantId, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new PlatformManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new PlatformManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
ConnectionManagerUtil.cleanupResources(stmt, rs);
} }
} }
} }

@ -37,6 +37,10 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
/**
* PlatformDeployer is responsible for deploying platforms that are added in the filesystem.
* This will deploy the platforms that are added in <IOT_HOME>/repository/deployment/server/platforms directory.
*/
public class PlatformDeployer extends AbstractDeployer { public class PlatformDeployer extends AbstractDeployer {
private static final Log log = LogFactory.getLog(PlatformDeployer.class); private static final Log log = LogFactory.getLog(PlatformDeployer.class);
@ -53,6 +57,7 @@ public class PlatformDeployer extends AbstractDeployer {
} }
} }
@Override
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException { public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
File deploymentFile = new File(deploymentFileData.getAbsolutePath()); File deploymentFile = new File(deploymentFileData.getAbsolutePath());
try { try {
@ -63,6 +68,7 @@ public class PlatformDeployer extends AbstractDeployer {
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);
log.info("Platform configuration : " + deploymentFile.getName() + " deployed successfully");
} else { } else {
log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath() log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath()
+ "!. Platform config file name - " + deploymentFile.getName() + "!. Platform config file name - " + deploymentFile.getName()
@ -75,13 +81,15 @@ public class PlatformDeployer extends AbstractDeployer {
} }
} }
@Override
public void undeploy(String fileName) throws DeploymentException { public void undeploy(String fileName) throws DeploymentException {
String platformId = getPlatformID(fileName); String platformId = getPlatformID(fileName);
try { try {
DataHolder.getInstance().getPlatformManager() DataHolder.getInstance().getPlatformManager()
.unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true); .unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true);
log.info("Platform configuration : " + fileName + " un-deployed successfully");
} catch (PlatformManagementException e) { } catch (PlatformManagementException e) {
log.error("Error occurred while undeploying the platform - " + fileName); log.error("Error occurred while un-deploying the platform - " + fileName);
} }
} }

@ -226,9 +226,8 @@ public class PlatformManagerImpl implements PlatformManager {
if (tenantPlatforms != null) { if (tenantPlatforms != null) {
this.inMemoryStore.remove(identifier); this.inMemoryStore.remove(identifier);
} }
} else {
DAOFactory.getPlatformDAO().unregister(tenantId, identifier);
} }
DAOFactory.getPlatformDAO().unregister(tenantId, identifier);
} }
@Override @Override

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -18,14 +18,13 @@
package org.wso2.carbon.device.application.mgt.core.util; package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.logging.Log; import java.io.File;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.dbcreator.DatabaseCreator; import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
import javax.sql.DataSource;
import java.io.File;
/** /**
* ApplicationMgtDatabaseCreator is responsible for creating the Application Management related tables. * ApplicationMgtDatabaseCreator is responsible for creating the Application Management related tables.
*/ */

@ -27,6 +27,8 @@ import org.wso2.carbon.device.application.mgt.common.exception.TransactionManage
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
public class ConnectionManagerUtil { public class ConnectionManagerUtil {
@ -185,4 +187,27 @@ public class ConnectionManagerUtil {
return null; return null;
} }
/**
* Cleanup resources used to transaction
*
* @param stmt Prepared statement used
* @param rs Obtained results set
*/
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
log.warn("Error occurred while closing result set", e);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
log.warn("Error occurred while closing prepared statement", e);
}
}
}
} }

Loading…
Cancel
Save