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.persistence.EntityManager;
|
||||||
import javax.transaction.Transaction;
|
import javax.transaction.Transaction;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
|
||||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||||
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
|
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
@@ -38,38 +37,31 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager {
|
|||||||
protected void doBegin(final Object transaction, final TransactionDefinition definition) {
|
protected void doBegin(final Object transaction, final TransactionDefinition definition) {
|
||||||
super.doBegin(transaction, definition);
|
super.doBegin(transaction, definition);
|
||||||
|
|
||||||
|
// ignore transactions on tenant independent calls
|
||||||
|
if (isTenantManagement(definition) && isCurrentTenantKeyGenerator(definition)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
|
final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
|
||||||
.getResource(getEntityManagerFactory());
|
.getResource(getEntityManagerFactory());
|
||||||
final EntityManager em = emHolder.getEntityManager();
|
final EntityManager em = emHolder.getEntityManager();
|
||||||
|
|
||||||
if (notTenantManagement(definition) && notCurrentTenantKeyGenerator(definition)
|
final String currentTenant = tenantAware.getCurrentTenant();
|
||||||
&& notRolloutScheduler(definition) && notGetOrCreateTenantMetadata(definition)) {
|
if (currentTenant == null) {
|
||||||
|
throw new TenantNotExistException("Tenant Unknown. Canceling transaction.");
|
||||||
final String currentTenant = tenantAware.getCurrentTenant();
|
|
||||||
if (currentTenant == null) {
|
|
||||||
throw new TenantNotExistException("Tenant Unknown. Canceling transaction.");
|
|
||||||
}
|
|
||||||
|
|
||||||
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean notGetOrCreateTenantMetadata(final TransactionDefinition definition) {
|
private boolean isCurrentTenantKeyGenerator(final TransactionDefinition definition) {
|
||||||
return !definition.getName()
|
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()
|
|
||||||
.startsWith(SystemManagement.class.getCanonicalName() + ".currentTenantKeyGenerator");
|
.startsWith(SystemManagement.class.getCanonicalName() + ".currentTenantKeyGenerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean notTenantManagement(final TransactionDefinition definition) {
|
private boolean isTenantManagement(final TransactionDefinition definition) {
|
||||||
return !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant")
|
return definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant")
|
||||||
&& !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants");
|
&& !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user