Remove UPPER from delete queries. (#494)
* Remove UPPER from delete queries. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Typos. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix case issue in sp_tenant table. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -12,6 +12,8 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -144,13 +146,16 @@ public interface DistributionSetRepository
|
||||
List<JpaDistributionSet> findAll(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaDistributionSet t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaDistributionSet t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -58,13 +60,16 @@ public interface DistributionSetTagRepository
|
||||
List<JpaDistributionSetTag> findAll();
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaDistributionSetTag t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaDistributionSetTag t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
@@ -61,13 +63,16 @@ public interface DistributionSetTypeRepository
|
||||
Long countByElementsSmType(JpaSoftwareModuleType softwareModuleType);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaDistributionSetType t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaDistributionSetType t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -198,21 +198,22 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteTenant(final String tenant) {
|
||||
public void deleteTenant(final String t) {
|
||||
final String tenant = t.toUpperCase();
|
||||
cacheManager.evictCaches(tenant);
|
||||
tenantAware.runAsTenant(tenant, () -> {
|
||||
entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant.toUpperCase());
|
||||
entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
|
||||
tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
|
||||
tenantConfigurationRepository.deleteByTenantIgnoreCase(tenant);
|
||||
targetRepository.deleteByTenantIgnoreCase(tenant);
|
||||
targetFilterQueryRepository.deleteByTenantIgnoreCase(tenant);
|
||||
rolloutRepository.deleteByTenantIgnoreCase(tenant);
|
||||
targetTagRepository.deleteByTenantIgnoreCase(tenant);
|
||||
distributionSetTagRepository.deleteByTenantIgnoreCase(tenant);
|
||||
distributionSetRepository.deleteByTenantIgnoreCase(tenant);
|
||||
distributionSetTypeRepository.deleteByTenantIgnoreCase(tenant);
|
||||
softwareModuleRepository.deleteByTenantIgnoreCase(tenant);
|
||||
softwareModuleTypeRepository.deleteByTenantIgnoreCase(tenant);
|
||||
tenantConfigurationRepository.deleteByTenant(tenant);
|
||||
targetRepository.deleteByTenant(tenant);
|
||||
targetFilterQueryRepository.deleteByTenant(tenant);
|
||||
rolloutRepository.deleteByTenant(tenant);
|
||||
targetTagRepository.deleteByTenant(tenant);
|
||||
distributionSetTagRepository.deleteByTenant(tenant);
|
||||
distributionSetRepository.deleteByTenant(tenant);
|
||||
distributionSetTypeRepository.deleteByTenant(tenant);
|
||||
softwareModuleRepository.deleteByTenant(tenant);
|
||||
softwareModuleTypeRepository.deleteByTenant(tenant);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus;
|
||||
@@ -50,13 +52,16 @@ public interface RolloutRepository
|
||||
Optional<Rollout> findByName(String name);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaRollout t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaRollout t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
@@ -110,13 +112,16 @@ public interface SoftwareModuleRepository
|
||||
List<JpaSoftwareModule> findByIdIn(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaSoftwareModule t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaSoftwareModule t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
@@ -79,13 +81,16 @@ public interface SoftwareModuleTypeRepository
|
||||
List<JpaSoftwareModuleType> findByIdIn(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaSoftwareModuleType t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaSoftwareModuleType t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
@@ -54,14 +56,17 @@ public interface TargetFilterQueryRepository
|
||||
void unsetAutoAssignDistributionSet(@Param("ids") Long... dsIds);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaTargetFilterQuery t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaTargetFilterQuery t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -211,13 +213,16 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
Page<Target> findByActionsRolloutGroupId(Long rolloutGroupId, Pageable page);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaTarget t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaTarget t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
@@ -57,13 +59,16 @@ public interface TargetTagRepository
|
||||
List<JpaTargetTag> findAll();
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaTargetTag t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaTargetTag t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTenantConfiguration;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
|
||||
@@ -43,14 +45,17 @@ public interface TenantConfigurationRepository extends BaseEntityRepository<JpaT
|
||||
void deleteByKey(String keyName);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant manually to
|
||||
* query even if this will by done by {@link EntityManager} anyhow. The DB
|
||||
* should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant
|
||||
* to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaTenantConfiguration t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
@Query("DELETE FROM JpaTenantConfiguration t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.persistence.EntityManager;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManager;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
Reference in New Issue
Block a user