Improve target management (#1260)
* Fix join type for targets with their assignedDs Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Override saveAll method and make use of it in the JpaTargetManagement Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Use unmodifiable list and flip transactional logic Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Initialize new list instead of an unmodifiable list. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Fix testdata factory Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTenantAwareBaseEntity;
|
||||
@@ -40,4 +41,18 @@ public interface BaseEntityRepository<T extends AbstractJpaTenantAwareBaseEntity
|
||||
*/
|
||||
Optional<T> findById(I id);
|
||||
|
||||
/**
|
||||
* Overrides
|
||||
* {@link org.springframework.data.repository.CrudRepository#saveAll(Iterable)}
|
||||
* to return a list of created entities instead of an instance of
|
||||
* {@link Iterable} to be able to work with it directly in further code
|
||||
* processing instead of converting the {@link Iterable}.
|
||||
*
|
||||
* @param entities
|
||||
* to persist in the database
|
||||
* @return the created entities
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
<S extends T> List<S> saveAll(Iterable<S> entities);
|
||||
}
|
||||
|
||||
@@ -748,7 +748,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public List<Target> create(final Collection<TargetCreate> targets) {
|
||||
return targets.stream().map(this::create).collect(Collectors.toList());
|
||||
final List<JpaTarget> targetList = targets.stream().map(JpaTargetCreate.class::cast).map(JpaTargetCreate::build)
|
||||
.collect(Collectors.toList());
|
||||
return Collections.unmodifiableList(targetRepository.saveAll(targetList));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
@@ -148,7 +148,7 @@ public final class TargetSpecifications {
|
||||
return (targetRoot, query, cb) -> {
|
||||
|
||||
final Predicate predicate = targetRoot.get(JpaTarget_.controllerId).in(controllerIDs);
|
||||
targetRoot.fetch(JpaTarget_.assignedDistributionSet);
|
||||
targetRoot.fetch(JpaTarget_.assignedDistributionSet, JoinType.LEFT);
|
||||
return predicate;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user