diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 8ee3b7600..039e4ae13 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -18,8 +18,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.context.annotation.Bean; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -67,10 +65,6 @@ public interface SystemManagement { */ TenantMetaData getTenantMetadata(); - // TODO figure out why this is necessary and clean this up - @Bean - KeyGenerator currentTenantKeyGenerator(); - /** * Returns {@link TenantMetaData} of given and current tenant. Creates for * new tenants also two {@link SoftwareModuleType} (os and app) and diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java new file mode 100644 index 000000000..029246d2d --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Service; + +/** + * Defines the interfaces to register the {@link KeyGenerator} as bean which is + * used by spring caching framework to resolve the key-generator. The + * key-generator must registered as bean so spring can resolve the key-generator + * by its name. + * + * When using the {@link Service} annotation e.g. by {@link JpaSystemManagement} + * the bean registration must be declared by the interface due spring registers + * the bean by the implemented interfaces. So introduce a single interface for + * the {@link JpaSystemManagement} implementation to allow it to register the + * key-generator bean. + * + */ +@FunctionalInterface +public interface CurrentTenantCacheKeyGenerator { + + /** + * Bean declaration to register a {@code currentTenantKeyGenerator} bean + * which is used by the caching framework. + * + * @return the {@link KeyGenerator} to be used to cache the values of the + * current used tenant in the {@link JpaSystemManagement} + */ + @Bean + KeyGenerator currentTenantKeyGenerator(); +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index be46362a5..8f9e8c5f9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -49,7 +49,7 @@ import org.springframework.validation.annotation.Validated; @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class JpaSystemManagement implements SystemManagement { +public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, SystemManagement { @Autowired private EntityManager entityManager;