Removed unnecessary transaction exceptions.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transaction;
|
||||
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -38,38 +37,31 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager {
|
||||
protected void doBegin(final Object transaction, final TransactionDefinition definition) {
|
||||
super.doBegin(transaction, definition);
|
||||
|
||||
// ignore transactions on tenant independent calls
|
||||
if (isTenantManagement(definition) && isCurrentTenantKeyGenerator(definition)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
|
||||
.getResource(getEntityManagerFactory());
|
||||
final EntityManager em = emHolder.getEntityManager();
|
||||
|
||||
if (notTenantManagement(definition) && notCurrentTenantKeyGenerator(definition)
|
||||
&& notRolloutScheduler(definition) && notGetOrCreateTenantMetadata(definition)) {
|
||||
|
||||
final String currentTenant = tenantAware.getCurrentTenant();
|
||||
if (currentTenant == null) {
|
||||
throw new TenantNotExistException("Tenant Unknown. Canceling transaction.");
|
||||
}
|
||||
|
||||
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
|
||||
final String currentTenant = tenantAware.getCurrentTenant();
|
||||
if (currentTenant == null) {
|
||||
throw new TenantNotExistException("Tenant Unknown. Canceling transaction.");
|
||||
}
|
||||
|
||||
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
|
||||
|
||||
}
|
||||
|
||||
private boolean notGetOrCreateTenantMetadata(final TransactionDefinition definition) {
|
||||
return !definition.getName()
|
||||
.startsWith(SystemManagement.class.getCanonicalName() + ".getOrCreateTenantMetadata");
|
||||
}
|
||||
|
||||
private boolean notRolloutScheduler(final TransactionDefinition definition) {
|
||||
return !definition.getName().startsWith(RolloutManagement.class.getCanonicalName() + ".rolloutScheduler");
|
||||
}
|
||||
|
||||
private boolean notCurrentTenantKeyGenerator(final TransactionDefinition definition) {
|
||||
return !definition.getName()
|
||||
private boolean isCurrentTenantKeyGenerator(final TransactionDefinition definition) {
|
||||
return definition.getName()
|
||||
.startsWith(SystemManagement.class.getCanonicalName() + ".currentTenantKeyGenerator");
|
||||
}
|
||||
|
||||
private boolean notTenantManagement(final TransactionDefinition definition) {
|
||||
return !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant")
|
||||
private boolean isTenantManagement(final TransactionDefinition definition) {
|
||||
return definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant")
|
||||
&& !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user