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:
Kai Zimmermann
2017-04-21 08:34:44 +02:00
committed by GitHub
parent d96ef9e937
commit a19364c635
14 changed files with 94 additions and 45 deletions

View File

@@ -12,6 +12,8 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -144,13 +146,16 @@ public interface DistributionSetRepository
List<JpaDistributionSet> findAll(Iterable<Long> ids); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaDistributionSet t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaDistributionSet t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
@@ -58,13 +60,16 @@ public interface DistributionSetTagRepository
List<JpaDistributionSetTag> findAll(); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaDistributionSetTag t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaDistributionSetTag t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -8,6 +8,8 @@
*/ */
package org.eclipse.hawkbit.repository.jpa; 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.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -61,13 +63,16 @@ public interface DistributionSetTypeRepository
Long countByElementsSmType(JpaSoftwareModuleType softwareModuleType); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaDistributionSetType t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaDistributionSetType t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -198,21 +198,22 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
@Override @Override
@Transactional @Transactional
public void deleteTenant(final String tenant) { public void deleteTenant(final String t) {
final String tenant = t.toUpperCase();
cacheManager.evictCaches(tenant); cacheManager.evictCaches(tenant);
tenantAware.runAsTenant(tenant, () -> { tenantAware.runAsTenant(tenant, () -> {
entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant.toUpperCase()); entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant); tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
tenantConfigurationRepository.deleteByTenantIgnoreCase(tenant); tenantConfigurationRepository.deleteByTenant(tenant);
targetRepository.deleteByTenantIgnoreCase(tenant); targetRepository.deleteByTenant(tenant);
targetFilterQueryRepository.deleteByTenantIgnoreCase(tenant); targetFilterQueryRepository.deleteByTenant(tenant);
rolloutRepository.deleteByTenantIgnoreCase(tenant); rolloutRepository.deleteByTenant(tenant);
targetTagRepository.deleteByTenantIgnoreCase(tenant); targetTagRepository.deleteByTenant(tenant);
distributionSetTagRepository.deleteByTenantIgnoreCase(tenant); distributionSetTagRepository.deleteByTenant(tenant);
distributionSetRepository.deleteByTenantIgnoreCase(tenant); distributionSetRepository.deleteByTenant(tenant);
distributionSetTypeRepository.deleteByTenantIgnoreCase(tenant); distributionSetTypeRepository.deleteByTenant(tenant);
softwareModuleRepository.deleteByTenantIgnoreCase(tenant); softwareModuleRepository.deleteByTenant(tenant);
softwareModuleTypeRepository.deleteByTenantIgnoreCase(tenant); softwareModuleTypeRepository.deleteByTenant(tenant);
return null; return null;
}); });
} }

View File

@@ -12,6 +12,8 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus;
@@ -50,13 +52,16 @@ public interface RolloutRepository
Optional<Rollout> findByName(String name); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaRollout t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaRollout t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
@@ -110,13 +112,16 @@ public interface SoftwareModuleRepository
List<JpaSoftwareModule> findByIdIn(Iterable<Long> ids); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaSoftwareModule t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaSoftwareModule t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -79,13 +81,16 @@ public interface SoftwareModuleTypeRepository
List<JpaSoftwareModuleType> findByIdIn(Iterable<Long> ids); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaSoftwareModuleType t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaSoftwareModuleType t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
@@ -54,14 +56,17 @@ public interface TargetFilterQueryRepository
void unsetAutoAssignDistributionSet(@Param("ids") Long... dsIds); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaTargetFilterQuery t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaTargetFilterQuery t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -13,6 +13,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.DistributionSet; 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); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaTarget t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaTarget t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
@@ -57,13 +59,16 @@ public interface TargetTagRepository
List<JpaTargetTag> findAll(); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaTargetTag t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaTargetTag t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -8,6 +8,8 @@
*/ */
package org.eclipse.hawkbit.repository.jpa; package org.eclipse.hawkbit.repository.jpa;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaTenantConfiguration; import org.eclipse.hawkbit.repository.jpa.model.JpaTenantConfiguration;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfiguration;
@@ -43,14 +45,17 @@ public interface TenantConfigurationRepository extends BaseEntityRepository<JpaT
void deleteByKey(String keyName); 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 * @param tenant
* to delete data from * to delete data from
*/ */
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaTenantConfiguration t WHERE UPPER(t.tenant) = UPPER(:tenant)") @Query("DELETE FROM JpaTenantConfiguration t WHERE t.tenant = :tenant")
void deleteByTenantIgnoreCase(@Param("tenant") String tenant); void deleteByTenant(@Param("tenant") String tenant);
} }

View File

@@ -13,7 +13,6 @@ import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.event.remote.EventEntityManager; import org.eclipse.hawkbit.repository.event.remote.EventEntityManager;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**

View File

@@ -8,8 +8,8 @@
*/ */
package org.eclipse.hawkbit.repository.event.remote.entity; 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.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.UUID; import java.util.UUID;

View File

@@ -31,7 +31,6 @@ import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;