Fix AutoCommit issue in Tenant Deletion

fix-access-authorization
Lasantha Dharmakeerthi 8 months ago
commit f3974c2cb4

@ -1891,7 +1891,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
String sql = "DELETE FROM AP_APP_FAVOURITES " String sql = "DELETE FROM AP_APP_FAVOURITES "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1917,7 +1918,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
String sql = "DELETE FROM AP_APP_CATEGORY_MAPPING " String sql = "DELETE FROM AP_APP_CATEGORY_MAPPING "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1943,7 +1945,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
String sql = "DELETE FROM AP_APP_CATEGORY " String sql = "DELETE FROM AP_APP_CATEGORY "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1969,7 +1972,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
String sql = "DELETE FROM AP_APP_TAG_MAPPING " String sql = "DELETE FROM AP_APP_TAG_MAPPING "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1995,7 +1999,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
String sql = "DELETE FROM AP_APP_TAG " String sql = "DELETE FROM AP_APP_TAG "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -2021,7 +2026,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
String sql = "DELETE FROM AP_APP " String sql = "DELETE FROM AP_APP "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -632,7 +632,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
String sql = "DELETE FROM AP_APP_RELEASE " String sql = "DELETE FROM AP_APP_RELEASE "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -491,7 +491,8 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
} }
String sql = "DELETE FROM AP_IDENTITY_SERVER " + String sql = "DELETE FROM AP_IDENTITY_SERVER " +
"WHERE TENANT_ID = ?"; "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -121,7 +121,8 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
} }
String sql = "DELETE FROM AP_APP_LIFECYCLE_STATE " String sql = "DELETE FROM AP_APP_LIFECYCLE_STATE "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try ( Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -610,7 +610,8 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
String sql = "DELETE FROM AP_APP_REVIEW " String sql = "DELETE FROM AP_APP_REVIEW "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -1484,7 +1484,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
String sql = "DELETE FROM AP_APP_SUB_OP_MAPPING " + String sql = "DELETE FROM AP_APP_SUB_OP_MAPPING " +
"WHERE TENANT_ID = ?"; "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1509,7 +1510,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
String sql = "DELETE FROM AP_ROLE_SUBSCRIPTION " + String sql = "DELETE FROM AP_ROLE_SUBSCRIPTION " +
"WHERE TENANT_ID = ?"; "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1535,7 +1537,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
String sql = "DELETE FROM AP_USER_SUBSCRIPTION " + String sql = "DELETE FROM AP_USER_SUBSCRIPTION " +
"WHERE TENANT_ID = ?"; "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1561,7 +1564,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
String sql = "DELETE FROM AP_GROUP_SUBSCRIPTION " + String sql = "DELETE FROM AP_GROUP_SUBSCRIPTION " +
"WHERE TENANT_ID = ?"; "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -1587,7 +1591,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
String sql = "DELETE FROM AP_SCHEDULED_SUBSCRIPTION " + String sql = "DELETE FROM AP_SCHEDULED_SUBSCRIPTION " +
"WHERE APPLICATION_UUID IN " + "WHERE APPLICATION_UUID IN " +
"(SELECT UUID FROM AP_APP_RELEASE WHERE TENANT_ID = ?)"; "(SELECT UUID FROM AP_APP_RELEASE WHERE TENANT_ID = ?)";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeBatch(); stmt.executeBatch();
@ -1612,7 +1617,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
String sql = "DELETE FROM AP_DEVICE_SUBSCRIPTION " + String sql = "DELETE FROM AP_DEVICE_SUBSCRIPTION " +
"WHERE TENANT_ID = ?"; "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -186,7 +186,8 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
String sql = "DELETE " String sql = "DELETE "
+ "FROM AP_UNRESTRICTED_ROLE " + "FROM AP_UNRESTRICTED_ROLE "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -514,7 +514,8 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
} }
String sql = "DELETE FROM AP_ASSETS " String sql = "DELETE FROM AP_ASSETS "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -539,7 +540,8 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
} }
String sql = "DELETE FROM AP_VPP_USER " String sql = "DELETE FROM AP_VPP_USER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -565,7 +567,8 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
} }
String sql = "DELETE FROM AP_VPP_ASSOCIATION " String sql = "DELETE FROM AP_VPP_ASSOCIATION "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try (Connection conn = this.getDBConnection()) { try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();

@ -66,6 +66,7 @@
io.entgra.device.mgt.core.device.mgt.common.roles.config, io.entgra.device.mgt.core.device.mgt.common.roles.config,
io.entgra.device.mgt.core.device.mgt.core.metadata.mgt, io.entgra.device.mgt.core.device.mgt.core.metadata.mgt,
io.entgra.device.mgt.core.device.mgt.core.config, io.entgra.device.mgt.core.device.mgt.core.config,
io.entgra.device.mgt.core.device.mgt.core.dao.*,
org.wso2.carbon.user.core.service, org.wso2.carbon.user.core.service,
org.wso2.carbon.context org.wso2.carbon.context
</Import-Package> </Import-Package>

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.tenant.mgt.core.impl;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager; import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager; import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.TenantDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.TenantDAO;
@ -200,13 +201,13 @@ public class TenantManagerImpl implements TenantManager {
tenantDao.deleteDeviceCertificateByTenantId(tenantId); tenantDao.deleteDeviceCertificateByTenantId(tenantId);
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
} catch (SQLException e){ } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error accessing the database when trying to delete tenant info of '" + tenantId + "'"; String msg = "Error deleting data of tenant of ID: '" + tenantId + "'";
log.error(msg); log.error(msg);
throw new TenantMgtException(msg, e); throw new TenantMgtException(msg, e);
} catch (DeviceManagementDAOException e) { } catch (SQLException e) {
String msg = "Error deleting data of tenant of ID: '" + tenantId + "'"; String msg = "Error accessing the database when trying to delete tenant info of '" + tenantId + "'";
log.error(msg); log.error(msg);
throw new TenantMgtException(msg, e); throw new TenantMgtException(msg, e);
} finally { } finally {

Loading…
Cancel
Save