Spring Boot 2.0 (#721)

* Migration to Boot 2.0.

Signed-off-by: Kai Zimmermann <kai.zimmermann@microsoft.com>
This commit is contained in:
Kai Zimmermann
2019-01-31 07:29:27 +01:00
committed by GitHub
parent b42b009f9e
commit d52a720480
263 changed files with 2874 additions and 2692 deletions

View File

@@ -34,7 +34,7 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.CollectionUtils;
@@ -50,19 +50,19 @@ public abstract class AbstractDsAssignmentStrategy {
protected final TargetRepository targetRepository;
protected final AfterTransactionCommitExecutor afterCommit;
protected final ApplicationEventPublisher eventPublisher;
protected final ApplicationContext applicationContext;
protected final BusProperties bus;
private final ActionRepository actionRepository;
private final ActionStatusRepository actionStatusRepository;
private final QuotaManagement quotaManagement;
AbstractDsAssignmentStrategy(final TargetRepository targetRepository,
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
final ApplicationContext applicationContext, final ActionRepository actionRepository,
final BusProperties bus, final ActionRepository actionRepository,
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
this.targetRepository = targetRepository;
this.afterCommit = afterCommit;
this.eventPublisher = eventPublisher;
this.applicationContext = applicationContext;
this.bus = bus;
this.actionRepository = actionRepository;
this.actionStatusRepository = actionStatusRepository;
this.quotaManagement = quotaManagement;
@@ -138,14 +138,12 @@ public abstract class AbstractDsAssignmentStrategy {
return;
}
afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId,
actions, applicationContext.getId(), actions.get(0).isMaintenanceWindowAvailable())));
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
distributionSetId, actions, bus.getId(), actions.get(0).isMaintenanceWindowAvailable())));
}
protected void sendTargetUpdatedEvent(final JpaTarget target) {
afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId())));
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId())));
}
/**
@@ -216,8 +214,8 @@ public abstract class AbstractDsAssignmentStrategy {
* the action id of the assignment
*/
void cancelAssignDistributionSetEvent(final Target target, final Long actionId) {
afterCommit.afterCommit(() -> eventPublisher
.publishEvent(new CancelTargetAssignmentEvent(target, actionId, applicationContext.getId())));
afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new CancelTargetAssignmentEvent(target, actionId, bus.getId())));
}
JpaAction createTargetAction(final Map<String, TargetWithActionType> targetsWithActionMap, final JpaTarget target,

View File

@@ -147,7 +147,7 @@ public interface DistributionSetRepository
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT d FROM JpaDistributionSet d WHERE d.id IN ?1")
List<JpaDistributionSet> findAll(Iterable<Long> ids);
List<JpaDistributionSet> findAllById(Iterable<Long> ids);
/**
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety

View File

@@ -86,5 +86,5 @@ public interface DistributionSetTagRepository
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT d FROM JpaDistributionSetTag d WHERE d.id IN ?1")
List<JpaDistributionSetTag> findAll(Iterable<Long> ids);
List<JpaDistributionSetTag> findAllById(Iterable<Long> ids);
}

View File

@@ -93,7 +93,7 @@ public interface DistributionSetTypeRepository
*/
@Override
@Query("SELECT d FROM JpaDistributionSetType d WHERE d.id IN ?1")
List<JpaDistributionSetType> findAll(Iterable<Long> ids);
List<JpaDistributionSetType> findAllById(Iterable<Long> ids);
/**
* Counts the {@link SoftwareModuleType}s which are associated with the

View File

@@ -193,12 +193,12 @@ public class JpaArtifactManagement implements ArtifactManagement {
((JpaSoftwareModule) existing.getSoftwareModule()).removeArtifact(existing);
softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule());
localArtifactRepository.delete(id);
localArtifactRepository.deleteById(id);
}
@Override
public Optional<Artifact> get(final long id) {
return Optional.ofNullable(localArtifactRepository.findOne(id));
return Optional.ofNullable(localArtifactRepository.findById(id).orElse(null));
}
@Override
@@ -226,7 +226,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) {
if (!softwareModuleRepository.exists(swId)) {
if (!softwareModuleRepository.existsById(swId)) {
throw new EntityNotFoundException(SoftwareModule.class, swId);
}
}
@@ -256,13 +256,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) {
final SoftwareModule softwareModule = softwareModuleRepository.findOne(moduleId);
if (softwareModule == null) {
LOG.debug("no software module with ID {} exists", moduleId);
throw new EntityNotFoundException(SoftwareModule.class, moduleId);
}
return softwareModule;
return softwareModuleRepository.findById(moduleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId));
}
}

View File

@@ -40,10 +40,10 @@ import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.UpdateMode;
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
@@ -76,7 +76,7 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.T
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
@@ -94,7 +94,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.validation.annotation.Validated;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@@ -119,9 +118,6 @@ public class JpaControllerManagement implements ControllerManagement {
@Autowired
private TargetRepository targetRepository;
@Autowired
private TargetManagement targetManagement;
@Autowired
private SoftwareModuleRepository softwareModuleRepository;
@@ -144,7 +140,7 @@ public class JpaControllerManagement implements ControllerManagement {
private ApplicationEventPublisher eventPublisher;
@Autowired
private ApplicationContext applicationContext;
private BusProperties bus;
@Autowired
private AfterTransactionCommitExecutor afterCommit;
@@ -215,7 +211,7 @@ public class JpaControllerManagement implements ControllerManagement {
return getPollingTime();
}
return (new EventTimer(getPollingTime(), getMinPollingTime(), ChronoUnit.SECONDS))
return new EventTimer(getPollingTime(), getMinPollingTime(), ChronoUnit.SECONDS)
.timeToNextEvent(getMaintenanceWindowPollCount(), action.getMaintenanceWindowStartTime().orElse(null));
}
@@ -324,13 +320,13 @@ public class JpaControllerManagement implements ControllerManagement {
}
private void throwExceptionIfTargetDoesNotExist(final Long targetId) {
if (!targetRepository.exists(targetId)) {
if (!targetRepository.existsById(targetId)) {
throw new EntityNotFoundException(Target.class, targetId);
}
}
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long moduleId) {
if (!softwareModuleRepository.exists(moduleId)) {
if (!softwareModuleRepository.existsById(moduleId)) {
throw new EntityNotFoundException(SoftwareModule.class, moduleId);
}
}
@@ -372,21 +368,20 @@ public class JpaControllerManagement implements ControllerManagement {
final Specification<JpaTarget> spec = (targetRoot, query, cb) -> cb
.equal(targetRoot.get(JpaTarget_.controllerId), controllerId);
final JpaTarget target = targetRepository.findOne(spec);
final Optional<JpaTarget> target = targetRepository.findOne(spec);
if (target == null) {
if (!target.isPresent()) {
final Target result = targetRepository.save((JpaTarget) entityFactory.target().create()
.controllerId(controllerId).description("Plug and Play target: " + controllerId).name(controllerId)
.status(TargetUpdateStatus.REGISTERED).lastTargetQuery(System.currentTimeMillis())
.address(Optional.ofNullable(address).map(URI::toString).orElse(null)).build());
afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new TargetPollEvent(result, applicationContext.getId())));
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(result, bus.getId())));
return result;
}
return updateTargetStatus(target, address);
return updateTargetStatus(target.get(), address);
}
/**
@@ -433,8 +428,8 @@ public class JpaControllerManagement implements ControllerManagement {
pollChunks.forEach(chunk -> {
setLastTargetQuery(tenant, System.currentTimeMillis(), chunk);
chunk.forEach(controllerId -> afterCommit.afterCommit(() -> eventPublisher
.publishEvent(new TargetPollEvent(controllerId, tenant, applicationContext.getId()))));
chunk.forEach(controllerId -> afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new TargetPollEvent(controllerId, tenant, bus.getId()))));
});
return null;
@@ -468,7 +463,7 @@ public class JpaControllerManagement implements ControllerManagement {
}
private static String formatQueryInStatementParams(final Collection<String> paramNames) {
return "#" + Joiner.on(",#").join(paramNames);
return "#" + String.join(",#", paramNames);
}
/**
@@ -488,8 +483,7 @@ public class JpaControllerManagement implements ControllerManagement {
toUpdate.setAddress(address.toString());
toUpdate.setLastTargetQuery(System.currentTimeMillis());
afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new TargetPollEvent(toUpdate, applicationContext.getId())));
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(toUpdate, bus.getId())));
return targetRepository.save(toUpdate);
}
@@ -583,7 +577,7 @@ public class JpaControllerManagement implements ControllerManagement {
private boolean actionIsNotActiveButIntermediateFeedbackStillAllowed(final ActionStatus actionStatus,
final boolean actionActive) {
return !actionActive && (repositoryProperties.isRejectActionStatusForClosedAction()
|| (Status.ERROR.equals(actionStatus.getStatus()) || Status.FINISHED.equals(actionStatus.getStatus())));
|| Status.ERROR.equals(actionStatus.getStatus()) || Status.FINISHED.equals(actionStatus.getStatus()));
}
/**
@@ -615,12 +609,23 @@ public class JpaControllerManagement implements ControllerManagement {
final Action savedAction = actionRepository.save(action);
if (controllerId != null) {
targetManagement.requestControllerAttributes(controllerId);
requestControllerAttributes(controllerId);
}
return savedAction;
}
private void requestControllerAttributes(final String controllerId) {
final JpaTarget target = (JpaTarget) getByControllerId(controllerId)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
target.setRequestControllerAttributes(true);
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
JpaTarget.class.getName(), bus.getId()));
}
private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) {
mergedAction.setActive(false);
mergedAction.setStatus(Status.ERROR);
@@ -823,12 +828,12 @@ public class JpaControllerManagement implements ControllerManagement {
@Override
public Optional<Target> get(final long targetId) {
return Optional.ofNullable(targetRepository.findOne(targetId));
return targetRepository.findById(targetId).map(t -> (Target) t);
}
@Override
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final long actionId) {
if (!actionRepository.exists(actionId)) {
if (!actionRepository.existsById(actionId)) {
throw new EntityNotFoundException(Action.class, actionId);
}
@@ -848,7 +853,7 @@ public class JpaControllerManagement implements ControllerManagement {
? RepositoryConstants.MAX_ACTION_HISTORY_MSG_COUNT
: messageCount;
final PageRequest pageable = new PageRequest(0, limit, new Sort(Direction.DESC, "occurredAt"));
final PageRequest pageable = PageRequest.of(0, limit, new Sort(Direction.DESC, "occurredAt"));
final Page<String> messages = actionStatusRepository.findMessagesByActionIdAndMessageNotLike(pageable, actionId,
RepositoryConstants.SERVER_MESSAGE_PREFIX + "%");
@@ -860,7 +865,7 @@ public class JpaControllerManagement implements ControllerManagement {
@Override
public Optional<SoftwareModule> getSoftwareModule(final long id) {
return Optional.ofNullable(softwareModuleRepository.findOne(id));
return softwareModuleRepository.findById(id).map(s -> (SoftwareModule) s);
}
@Override
@@ -868,7 +873,7 @@ public class JpaControllerManagement implements ControllerManagement {
final Collection<Long> moduleId) {
return softwareModuleMetadataRepository
.findBySoftwareModuleIdInAndTargetVisible(new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT),
.findBySoftwareModuleIdInAndTargetVisible(PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT),
moduleId, true)
.getContent().stream().collect(Collectors.groupingBy(o -> (Long) o[0],
Collectors.mapping(o -> (SoftwareModuleMetadata) o[1], Collectors.toList())));
@@ -896,8 +901,8 @@ public class JpaControllerManagement implements ControllerManagement {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((controllerId == null) ? 0 : controllerId.hashCode());
result = prime * result + ((tenant == null) ? 0 : tenant.hashCode());
result = prime * result + (controllerId == null ? 0 : controllerId.hashCode());
result = prime * result + (tenant == null ? 0 : tenant.hashCode());
return result;
}
@@ -980,7 +985,7 @@ public class JpaControllerManagement implements ControllerManagement {
}
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
afterCommit.afterCommit(() -> eventPublisher
.publishEvent(new CancelTargetAssignmentEvent(target, actionId, applicationContext.getId())));
afterCommit.afterCommit(
() -> eventPublisher.publishEvent(new CancelTargetAssignmentEvent(target, actionId, bus.getId())));
}
}

View File

@@ -69,7 +69,7 @@ import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.AuditorAware;
@@ -88,7 +88,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
/**
@@ -125,7 +124,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private final TargetManagement targetManagement;
private final AuditorAware<String> auditorProvider;
private final ApplicationEventPublisher eventPublisher;
private final ApplicationContext applicationContext;
private final BusProperties bus;
private final AfterTransactionCommitExecutor afterCommit;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final PlatformTransactionManager txManager;
@@ -141,7 +140,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository,
final ActionStatusRepository actionStatusRepository, final TargetManagement targetManagement,
final AuditorAware<String> auditorProvider, final ApplicationEventPublisher eventPublisher,
final ApplicationContext applicationContext, final AfterTransactionCommitExecutor afterCommit,
final BusProperties bus, final AfterTransactionCommitExecutor afterCommit,
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final Database database) {
@@ -153,14 +152,14 @@ public class JpaDeploymentManagement implements DeploymentManagement {
this.targetManagement = targetManagement;
this.auditorProvider = auditorProvider;
this.eventPublisher = eventPublisher;
this.applicationContext = applicationContext;
this.bus = bus;
this.afterCommit = afterCommit;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.txManager = txManager;
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher,
applicationContext, actionRepository, actionStatusRepository, quotaManagement);
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher, bus,
actionRepository, actionStatusRepository, quotaManagement);
offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher,
applicationContext, actionRepository, actionStatusRepository, quotaManagement);
bus, actionRepository, actionStatusRepository, quotaManagement);
this.tenantConfigurationManagement = tenantConfigurationManagement;
this.quotaManagement = quotaManagement;
this.systemSecurityContext = systemSecurityContext;
@@ -367,7 +366,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private void setAssignedDistributionSetAndTargetUpdateStatus(final AbstractDsAssignmentStrategy assignmentStrategy,
final JpaDistributionSet set, final List<List<Long>> targetIdsChunks) {
final String currentUser = auditorProvider != null ? auditorProvider.getCurrentAuditor() : null;
final String currentUser = auditorProvider.getCurrentAuditor().orElse(null);
assignmentStrategy.updateTargetStatus(set, targetIdsChunks, currentUser);
}
@@ -385,7 +384,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private void createActionsStatus(final Collection<JpaAction> actions,
final AbstractDsAssignmentStrategy assignmentStrategy, final String actionMessage) {
actionStatusRepository
.save(actions.stream().map(action -> assignmentStrategy.createActionStatus(action, actionMessage))
.saveAll(actions.stream().map(action -> assignmentStrategy.createActionStatus(action, actionMessage))
.collect(Collectors.toList()));
}
@@ -493,7 +492,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
if (!CollectionUtils.isEmpty(targetAssignments)) {
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
distributionSetId, targetAssignments, applicationContext.getId(), maintenanceWindowAvailable)));
distributionSetId, targetAssignments, bus.getId(), maintenanceWindowAvailable)));
}
return rolloutGroupActions.getTotalElements();
@@ -503,7 +502,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private Page<Action> findActionsByRolloutAndRolloutGroupParent(final Long rolloutId,
final Long rolloutGroupParentId, final int limit) {
final PageRequest pageRequest = new PageRequest(0, limit);
final PageRequest pageRequest = PageRequest.of(0, limit);
if (rolloutGroupParentId == null) {
return actionRepository.findByRolloutIdAndRolloutGroupParentIsNullAndStatus(pageRequest, rolloutId,
Action.Status.SCHEDULED);
@@ -577,7 +576,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Override
public Optional<Action> findAction(final long actionId) {
return Optional.ofNullable(actionRepository.findOne(actionId));
return actionRepository.findById(actionId).map(a -> (Action) a);
}
@Override
@@ -644,7 +643,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
private void throwExceptionIfDistributionSetDoesNotExist(final Long dsId) {
if (!distributionSetRepository.exists(dsId)) {
if (!distributionSetRepository.existsById(dsId)) {
throw new EntityNotFoundException(DistributionSet.class, dsId);
}
}
@@ -666,7 +665,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Override
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final long actionId) {
if (!actionRepository.exists(actionId)) {
if (!actionRepository.existsById(actionId)) {
throw new EntityNotFoundException(Action.class, actionId);
}
@@ -690,7 +689,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
final CriteriaQuery<String> selMsgQuery = msgQuery.select(join);
selMsgQuery.where(cb.equal(as.get(JpaActionStatus_.id), actionStatusId));
final List<String> result = entityManager.createQuery(selMsgQuery).setFirstResult(pageable.getOffset())
final List<String> result = entityManager.createQuery(selMsgQuery).setFirstResult((int) pageable.getOffset())
.setMaxResults(pageable.getPageSize()).getResultList().stream().collect(Collectors.toList());
return new PageImpl<>(result, pageable, totalCount);
@@ -777,7 +776,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
private static String formatInClause(final Collection<String> elements) {
return "#" + Joiner.on(",#").join(elements);
return "#" + String.join(",#", elements);
}
protected ActionRepository getActionRepository() {

View File

@@ -57,7 +57,7 @@ import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
@@ -105,7 +105,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private final ApplicationEventPublisher eventPublisher;
private final ApplicationContext applicationContext;
private final BusProperties bus;
private final TenantAware tenantAware;
@@ -126,7 +126,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final DistributionSetMetadataRepository distributionSetMetadataRepository,
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
final NoCountPagingRepository criteriaNoCountDao, final ApplicationEventPublisher eventPublisher,
final ApplicationContext applicationContext, final TenantAware tenantAware,
final BusProperties bus, final TenantAware tenantAware,
final VirtualPropertyReplacer virtualPropertyReplacer,
final SoftwareModuleRepository softwareModuleRepository,
final DistributionSetTagRepository distributionSetTagRepository,
@@ -142,7 +142,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
this.actionRepository = actionRepository;
this.criteriaNoCountDao = criteriaNoCountDao;
this.eventPublisher = eventPublisher;
this.applicationContext = applicationContext;
this.bus = bus;
this.tenantAware = tenantAware;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.softwareModuleRepository = softwareModuleRepository;
@@ -153,7 +153,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public Optional<DistributionSet> getWithDetails(final long distid) {
return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)));
return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid))
.map(d -> (DistributionSet) d);
}
@Override
@@ -242,7 +243,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
private JpaSoftwareModule findSoftwareModuleAndThrowExceptionIfNotFound(final Long moduleId) {
return Optional.ofNullable(softwareModuleRepository.findOne(moduleId))
return softwareModuleRepository.findById(moduleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId));
}
@@ -282,7 +283,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
afterCommit.afterCommit(() -> distributionSetIDs.forEach(
dsId -> eventPublisher.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(),
dsId, JpaDistributionSet.class.getName(), applicationContext.getId()))));
dsId, JpaDistributionSet.class.getName(), bus.getId()))));
}
@Override
@@ -370,12 +371,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
* @return a single DistributionSet which is either installed or assigned to
* a specific target or {@code null}.
*/
private DistributionSet findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
private Optional<JpaDistributionSet> findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
final DistributionSetFilter distributionSetFilter) {
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
distributionSetFilter);
if (CollectionUtils.isEmpty(specList)) {
return null;
return Optional.empty();
}
return distributionSetRepository.findOne(SpecificationsBuilder.combineWithAnd(specList));
}
@@ -400,12 +401,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final DistributionSetFilter filterWithInstalledTargets = distributionSetFilterBuilder
.setInstalledTargetId(assignedOrInstalled).setAssignedTargetId(null).build();
final DistributionSet installedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
final Optional<JpaDistributionSet> installedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
filterWithInstalledTargets);
final DistributionSetFilter filterWithAssignedTargets = distributionSetFilterBuilder.setInstalledTargetId(null)
.setAssignedTargetId(assignedOrInstalled).build();
final DistributionSet assignedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
final Optional<JpaDistributionSet> assignedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
filterWithAssignedTargets);
final DistributionSetFilter dsFilterWithNoTargetLinked = distributionSetFilterBuilder.setInstalledTargetId(null)
@@ -417,20 +418,20 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final List<DistributionSet> resultSet = new ArrayList<>(findDistributionSetsByFilters.getContent());
int orderIndex = 0;
if (installedDS != null) {
final boolean remove = resultSet.remove(installedDS);
if (installedDS.isPresent()) {
final boolean remove = resultSet.remove(installedDS.get());
if (!remove) {
resultSet.remove(resultSet.size() - 1);
}
resultSet.add(orderIndex, installedDS);
resultSet.add(orderIndex, installedDS.get());
orderIndex++;
}
if (assignedDS != null && !assignedDS.equals(installedDS)) {
final boolean remove = resultSet.remove(assignedDS);
if (assignedDS.isPresent() && !assignedDS.equals(installedDS)) {
final boolean remove = resultSet.remove(assignedDS.get());
if (!remove) {
resultSet.remove(resultSet.size() - 1);
}
resultSet.add(orderIndex, assignedDS);
resultSet.add(orderIndex, assignedDS.get());
}
return new PageImpl<>(resultSet, pageable, findDistributionSetsByFilters.getTotalElements());
@@ -440,7 +441,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
public Optional<DistributionSet> getByNameAndVersion(final String distributionName, final String version) {
final Specification<JpaDistributionSet> spec = DistributionSetSpecification
.equalsNameAndVersionIgnoreCase(distributionName, version);
return Optional.ofNullable(distributionSetRepository.findOne(spec));
return distributionSetRepository.findOne(spec).map(d -> (DistributionSet) d);
}
@@ -508,7 +509,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, key));
touch(metadata.getDistributionSet());
distributionSetMetadataRepository.delete(metadata.getId());
distributionSetMetadataRepository.deleteById(metadata.getId());
}
/**
@@ -579,12 +580,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
public Optional<DistributionSetMetadata> getMetaDataByDistributionSetId(final long setId, final String key) {
throwExceptionIfDistributionSetDoesNotExist(setId);
return Optional.ofNullable(distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(setId, key)));
return distributionSetMetadataRepository.findById(new DsMetadataCompositeKey(setId, key))
.map(dmd -> (DistributionSetMetadata) dmd);
}
@Override
public Optional<DistributionSet> getByAction(final long actionId) {
if (!actionRepository.exists(actionId)) {
if (!actionRepository.existsById(actionId)) {
throw new EntityNotFoundException(Action.class, actionId);
}
@@ -676,7 +678,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
private void checkAndThrowIfDistributionSetMetadataAlreadyExists(final DsMetadataCompositeKey metadataId) {
if (distributionSetMetadataRepository.exists(metadataId)) {
if (distributionSetMetadataRepository.existsById(metadataId)) {
throw new EntityAlreadyExistsException(
"Metadata entry with key '" + metadataId.getKey() + "' already exists");
}
@@ -738,14 +740,14 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
private void throwExceptionIfDistributionSetDoesNotExist(final Long setId) {
if (!distributionSetRepository.exists(setId)) {
if (!distributionSetRepository.existsById(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
}
@Override
public List<DistributionSet> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetRepository.findAll(ids));
return Collections.unmodifiableList(distributionSetRepository.findAllById(ids));
}
@Override
@@ -757,7 +759,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
private void throwEntityNotFoundExceptionIfDsTagDoesNotExist(final Long tagId) {
if (!distributionSetTagRepository.exists(tagId)) {
if (!distributionSetTagRepository.existsById(tagId)) {
throw new EntityNotFoundException(DistributionSetTag.class, tagId);
}
}
@@ -791,12 +793,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public Optional<DistributionSet> get(final long id) {
return Optional.ofNullable(distributionSetRepository.findOne(id));
return distributionSetRepository.findById(id).map(d -> (DistributionSet) d);
}
@Override
public boolean exists(final long id) {
return distributionSetRepository.exists(id);
return distributionSetRepository.existsById(id);
}
}

View File

@@ -142,7 +142,7 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override
public Page<DistributionSetTag> findByDistributionSet(final Pageable pageable, final long setId) {
if (!distributionSetRepository.exists(setId)) {
if (!distributionSetRepository.existsById(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
@@ -165,24 +165,24 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) {
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAll(ids);
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAllById(ids);
if (setsFound.size() < ids.size()) {
throw new EntityNotFoundException(DistributionSetTag.class, ids,
setsFound.stream().map(DistributionSetTag::getId).collect(Collectors.toList()));
}
distributionSetTagRepository.delete(setsFound);
distributionSetTagRepository.deleteAll(setsFound);
}
@Override
public List<DistributionSetTag> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetTagRepository.findAll(ids));
return Collections.unmodifiableList(distributionSetTagRepository.findAllById(ids));
}
@Override
public Optional<DistributionSetTag> get(final long id) {
return Optional.ofNullable(distributionSetTagRepository.findOne(id));
return distributionSetTagRepository.findById(id).map(dst -> (DistributionSetTag) dst);
}
@Override
@@ -190,12 +190,12 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) {
distributionSetTagRepository.delete(id);
distributionSetTagRepository.deleteById(id);
}
@Override
public boolean exists(final long id) {
return distributionSetTagRepository.exists(id);
return distributionSetTagRepository.existsById(id);
}
@Override

View File

@@ -99,9 +99,9 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(update.getId());
update.getMandatory().ifPresent(
mand -> softwareModuleTypeRepository.findAll(mand).forEach(type::addMandatoryModuleType));
update.getOptional()
.ifPresent(opt -> softwareModuleTypeRepository.findAll(opt).forEach(type::addOptionalModuleType));
mand -> softwareModuleTypeRepository.findAllById(mand).forEach(type::addMandatoryModuleType));
update.getOptional().ifPresent(
opt -> softwareModuleTypeRepository.findAllById(opt).forEach(type::addOptionalModuleType));
}
return distributionSetTypeRepository.save(type);
@@ -113,7 +113,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignMandatorySoftwareModuleTypes(final long dsTypeId,
final Collection<Long> softwareModulesTypeIds) {
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds);
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
.findAllById(softwareModulesTypeIds);
if (modules.size() < softwareModulesTypeIds.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
@@ -136,7 +137,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
public DistributionSetType assignOptionalSoftwareModuleTypes(final long dsTypeId,
final Collection<Long> softwareModulesTypeIds) {
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds);
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
.findAllById(softwareModulesTypeIds);
if (modules.size() < softwareModulesTypeIds.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
@@ -206,13 +208,14 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override
public Optional<DistributionSetType> getByName(final String name) {
return Optional
.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)));
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name))
.map(dst -> (DistributionSetType) dst);
}
@Override
public Optional<DistributionSetType> getByKey(final String key) {
return Optional.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)));
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key))
.map(dst -> (DistributionSetType) dst);
}
@Override
@@ -238,7 +241,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
toDelete.setDeleted(true);
distributionSetTypeRepository.save(toDelete);
} else {
distributionSetTypeRepository.delete(typeId);
distributionSetTypeRepository.deleteById(typeId);
}
}
@@ -291,29 +294,29 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) {
final List<JpaDistributionSetType> setsFound = distributionSetTypeRepository.findAll(ids);
final List<JpaDistributionSetType> setsFound = distributionSetTypeRepository.findAllById(ids);
if (setsFound.size() < ids.size()) {
throw new EntityNotFoundException(DistributionSetType.class, ids,
setsFound.stream().map(DistributionSetType::getId).collect(Collectors.toList()));
}
distributionSetTypeRepository.delete(setsFound);
distributionSetTypeRepository.deleteAll(setsFound);
}
@Override
public List<DistributionSetType> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetTypeRepository.findAll(ids));
return Collections.unmodifiableList(distributionSetTypeRepository.findAllById(ids));
}
@Override
public Optional<DistributionSetType> get(final long id) {
return Optional.ofNullable(distributionSetTypeRepository.findOne(id));
return distributionSetTypeRepository.findById(id).map(dst -> (DistributionSetType) dst);
}
@Override
public boolean exists(final long id) {
return distributionSetTypeRepository.exists(id);
return distributionSetTypeRepository.existsById(id);
}
}

View File

@@ -96,7 +96,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
@Override
public Optional<RolloutGroup> get(final long rolloutGroupId) {
return Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId));
return rolloutGroupRepository.findById(rolloutGroupId).map(rg -> (RolloutGroup) rg);
}
@Override
@@ -128,7 +128,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
private void throwEntityNotFoundExceptionIfRolloutDoesNotExist(final Long rolloutId) {
if (!rolloutRepository.exists(rolloutId)) {
if (!rolloutRepository.existsById(rolloutId)) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
}
}
@@ -265,7 +265,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
.where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id),
rolloutGroupId));
final List<TargetWithActionStatus> targetWithActionStatus = entityManager.createQuery(multiselect)
.setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList()
.setFirstResult((int) pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList()
.stream().map(o -> new TargetWithActionStatus((Target) o[0], (Action.Status) o[1]))
.collect(Collectors.toList());
@@ -285,7 +285,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
private void throwExceptionIfRolloutGroupDoesNotExist(final Long rolloutGroupId) {
if (!rolloutGroupRepository.exists(rolloutGroupId)) {
if (!rolloutGroupRepository.existsById(rolloutGroupId)) {
throw new EntityNotFoundException(RolloutGroup.class, rolloutGroupId);
}
}

View File

@@ -77,6 +77,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.dao.ConcurrencyFailureException;
@@ -149,20 +150,21 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Autowired
private RolloutStatusCache rolloutStatusCache;
@Autowired
private ApplicationContext applicationContext;
private final BusProperties bus;
private final Database database;
JpaRolloutManagement(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
final RolloutGroupManagement rolloutGroupManagement,
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
final ApplicationEventPublisher eventPublisher, final VirtualPropertyReplacer virtualPropertyReplacer,
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
final Database database, final RolloutApprovalStrategy rolloutApprovalStrategy) {
final BusProperties bus, final ApplicationEventPublisher eventPublisher,
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
final TenantAware tenantAware, final LockRegistry lockRegistry, final Database database,
final RolloutApprovalStrategy rolloutApprovalStrategy) {
super(targetManagement, deploymentManagement, rolloutGroupManagement, distributionSetManagement, context,
eventPublisher, virtualPropertyReplacer, txManager, tenantAware, lockRegistry, rolloutApprovalStrategy);
this.database = database;
this.bus = bus;
}
@Override
@@ -194,7 +196,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Override
public Optional<Rollout> get(final long rolloutId) {
return Optional.ofNullable(rolloutRepository.findOne(rolloutId));
return rolloutRepository.findById(rolloutId).map(r -> (Rollout) r);
}
@Override
@@ -337,7 +339,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId());
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(
new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")),
PageRequest.of(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")),
rollout.getId()).getContent();
int readyGroups = 0;
@@ -431,7 +433,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
final String targetFilter, final long limit) {
return DeploymentHelper.runInNewTransaction(txManager, "assignTargetsToRolloutGroup", status -> {
final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit));
final PageRequest pageRequest = PageRequest.of(0, Math.toIntExact(limit));
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(),
RolloutGroupStatus.READY, group);
final Page<Target> targets = targetManagement.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest,
@@ -582,9 +584,11 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
private Long createActionsForTargetsInNewTransaction(final long rolloutId, final long groupId, final int limit) {
return DeploymentHelper.runInNewTransaction(txManager, "createActionsForTargets", status -> {
final PageRequest pageRequest = new PageRequest(0, limit);
final Rollout rollout = rolloutRepository.findOne(rolloutId);
final RolloutGroup group = rolloutGroupRepository.findOne(groupId);
final PageRequest pageRequest = PageRequest.of(0, limit);
final Rollout rollout = rolloutRepository.findById(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
final RolloutGroup group = rolloutGroupRepository.findById(groupId)
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, groupId));
final DistributionSet distributionSet = rollout.getDistributionSet();
final ActionType actionType = rollout.getActionType();
@@ -832,9 +836,10 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
}
private long executeFittingHandler(final Long rolloutId) {
private long executeFittingHandler(final long rolloutId) {
LOGGER.debug("handle rollout {}", rolloutId);
final JpaRollout rollout = rolloutRepository.findOne(rolloutId);
final JpaRollout rollout = rolloutRepository.findById(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
switch (rollout.getStatus()) {
case CREATING:
@@ -882,7 +887,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long rolloutId) {
final JpaRollout jpaRollout = rolloutRepository.findOne(rolloutId);
final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
if (jpaRollout == null) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
@@ -945,7 +951,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
afterCommit.afterCommit(() -> groupIds.forEach(rolloutGroupId -> eventPublisher
.publishEvent(new RolloutGroupDeletedEvent(tenantAware.getCurrentTenant(), rolloutGroupId,
JpaRolloutGroup.class.getName(), applicationContext.getId()))));
JpaRolloutGroup.class.getName(), bus.getId()))));
}
private void hardDeleteRollout(final JpaRollout rollout) {
@@ -971,7 +977,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
private Slice<JpaAction> findScheduledActionsByRollout(final JpaRollout rollout) {
return actionRepository.findByRolloutIdAndStatus(new PageRequest(0, TRANSACTION_ACTIONS), rollout.getId(),
return actionRepository.findByRolloutIdAndStatus(PageRequest.of(0, TRANSACTION_ACTIONS), rollout.getId(),
Status.SCHEDULED);
}
@@ -1071,7 +1077,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Override
public boolean exists(final long rolloutId) {
return rolloutRepository.exists(rolloutId);
return rolloutRepository.existsById(rolloutId);
}
private Map<Long, List<TotalTargetCountActionStatus>> getStatusCountItemForRollout(final List<Long> rollouts) {

View File

@@ -180,7 +180,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
private void throwExceptionIfSoftwareModuleTypeDoesNotExist(final Long typeId) {
if (!softwareModuleTypeRepository.exists(typeId)) {
if (!softwareModuleTypeRepository.existsById(typeId)) {
throw new EntityNotFoundException(SoftwareModuleType.class, typeId);
}
}
@@ -201,7 +201,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override
public Optional<SoftwareModule> get(final long id) {
return Optional.ofNullable(softwareModuleRepository.findOne(id));
return softwareModuleRepository.findById(id).map(sm -> (SoftwareModule) sm);
}
@Override
@@ -252,7 +252,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
deleteGridFsArtifacts(swModule);
if (isUnassigned(swModule.getId())) {
softwareModuleRepository.delete(swModule.getId());
softwareModuleRepository.deleteById(swModule.getId());
} else {
assignedModuleIds.add(swModule.getId());
}
@@ -261,7 +261,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
if (!assignedModuleIds.isEmpty()) {
String currentUser = null;
if (auditorProvider != null) {
currentUser = auditorProvider.getCurrentAuditor();
currentUser = auditorProvider.getCurrentAuditor().orElse(null);
}
softwareModuleRepository.deleteSoftwareModule(System.currentTimeMillis(), currentUser,
assignedModuleIds.toArray(new Long[0]));
@@ -374,7 +374,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
// map result
if (pageable.getOffset() < assignedSoftwareModules.size()) {
assignedSoftwareModules
.subList(pageable.getOffset(), Math.min(assignedSoftwareModules.size(), pageable.getPageSize()))
.subList((int) pageable.getOffset(),
Math.min(assignedSoftwareModules.size(), pageable.getPageSize()))
.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, true)));
}
@@ -401,7 +402,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
unassignedQuery.orderBy(cb.asc(unassignedRoot.get(JpaSoftwareModule_.name)),
cb.asc(unassignedRoot.get(JpaSoftwareModule_.version)));
final List<JpaSoftwareModule> unassignedSoftwareModules = entityManager.createQuery(unassignedQuery)
.setFirstResult(Math.max(0, pageable.getOffset() - assignedSoftwareModules.size()))
.setFirstResult((int) Math.max(0, pageable.getOffset() - assignedSoftwareModules.size()))
.setMaxResults(pageSize).getResultList();
// map result
unassignedSoftwareModules.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, false)));
@@ -456,7 +457,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override
public Page<SoftwareModule> findByAssignedTo(final Pageable pageable, final long setId) {
if (!distributionSetRepository.exists(setId)) {
if (!distributionSetRepository.existsById(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
@@ -527,7 +528,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
private void assertSoftwareModuleMetadataDoesNotExist(final Long moduleId,
final JpaSoftwareModuleMetadataCreate md) {
if (softwareModuleMetadataRepository.exists(new SwMetadataCompositeKey(moduleId, md.getKey()))) {
if (softwareModuleMetadataRepository.existsById(new SwMetadataCompositeKey(moduleId, md.getKey()))) {
throwMetadataKeyAlreadyExists(md.getKey());
}
}
@@ -607,11 +608,11 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key));
touch(metadata.getSoftwareModule());
softwareModuleMetadataRepository.delete(metadata.getId());
softwareModuleMetadataRepository.deleteById(metadata.getId());
}
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) {
if (!softwareModuleRepository.exists(swId)) {
if (!softwareModuleRepository.existsById(swId)) {
throw new EntityNotFoundException(SoftwareModule.class, swId);
}
}
@@ -654,7 +655,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
public Optional<SoftwareModuleMetadata> getMetaDataBySoftwareModuleId(final long moduleId, final String key) {
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
return Optional.ofNullable(softwareModuleMetadataRepository.findOne(new SwMetadataCompositeKey(moduleId, key)));
return softwareModuleMetadataRepository.findById(new SwMetadataCompositeKey(moduleId, key))
.map(smmd -> (SoftwareModuleMetadata) smmd);
}
private static void throwMetadataKeyAlreadyExists(final String metadataKey) {
@@ -671,7 +673,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override
public boolean exists(final long id) {
return softwareModuleRepository.exists(id);
return softwareModuleRepository.existsById(id);
}
@Override
@@ -680,7 +682,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
return convertMdPage(softwareModuleMetadataRepository.findBySoftwareModuleIdAndTargetVisible(
new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT), moduleId, true), pageable);
PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT), moduleId, true), pageable);
}
}

View File

@@ -168,29 +168,29 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) {
final List<JpaSoftwareModuleType> setsFound = softwareModuleTypeRepository.findAll(ids);
final List<JpaSoftwareModuleType> setsFound = softwareModuleTypeRepository.findAllById(ids);
if (setsFound.size() < ids.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, ids,
setsFound.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
}
softwareModuleTypeRepository.delete(setsFound);
softwareModuleTypeRepository.deleteAll(setsFound);
}
@Override
public List<SoftwareModuleType> get(final Collection<Long> ids) {
return Collections.unmodifiableList(softwareModuleTypeRepository.findAll(ids));
return Collections.unmodifiableList(softwareModuleTypeRepository.findAllById(ids));
}
@Override
public Optional<SoftwareModuleType> get(final long id) {
return Optional.ofNullable(softwareModuleTypeRepository.findOne(id));
return softwareModuleTypeRepository.findById(id).map(smt -> (SoftwareModuleType) smt);
}
@Override
public boolean exists(final long id) {
return softwareModuleTypeRepository.exists(id);
return softwareModuleTypeRepository.existsById(id);
}
}

View File

@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.cache.TenancyCacheManager;
import org.eclipse.hawkbit.repository.RolloutStatusCache;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantStatsManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
@@ -160,7 +161,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
}
private void usageStatsPerTenant(final SystemUsageReportWithTenants report) {
final List<String> tenants = findTenants(new PageRequest(0, MAX_TENANTS_QUERY)).getContent();
final List<String> tenants = findTenants(PageRequest.of(0, MAX_TENANTS_QUERY)).getContent();
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
report.addTenantData(systemStatsManagement.getStatsOfTenant());
@@ -276,7 +277,8 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
public TenantMetaData updateTenantMetadata(final long defaultDsType) {
final JpaTenantMetaData data = (JpaTenantMetaData) getTenantMetadata();
data.setDefaultDsType(distributionSetTypeRepository.findOne(defaultDsType));
data.setDefaultDsType(distributionSetTypeRepository.findById(defaultDsType)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, defaultDsType)));
return tenantMetaDataRepository.save(data);
}
@@ -312,15 +314,19 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
@Override
public TenantMetaData getTenantMetadata(final long tenantId) {
return tenantMetaDataRepository.findOne(tenantId);
return tenantMetaDataRepository.findById(tenantId)
.orElseThrow(() -> new EntityNotFoundException(TenantMetaData.class, tenantId));
}
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
// Exception squid:S2229 - calling findTenants without transaction is
// intended in this case
@SuppressWarnings("squid:S2229")
public void forEachTenant(final Consumer<String> consumer) {
Page<String> tenants;
Pageable query = new PageRequest(0, MAX_TENANTS_QUERY);
Pageable query = PageRequest.of(0, MAX_TENANTS_QUERY);
do {
tenants = findTenants(query);
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {

View File

@@ -39,7 +39,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
@@ -99,11 +98,11 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long targetFilterQueryId) {
if (!targetFilterQueryRepository.exists(targetFilterQueryId)) {
if (!targetFilterQueryRepository.existsById(targetFilterQueryId)) {
throw new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId);
}
targetFilterQueryRepository.delete(targetFilterQueryId);
targetFilterQueryRepository.deleteById(targetFilterQueryId);
}
@Override
@@ -178,7 +177,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
return targetFilterQueryRepository.findAll(pageable);
}
final Specifications<JpaTargetFilterQuery> specs = SpecificationsBuilder.combineWithAnd(specList);
final Specification<JpaTargetFilterQuery> specs = SpecificationsBuilder.combineWithAnd(specList);
return targetFilterQueryRepository.findAll(specs, pageable);
}
@@ -189,7 +188,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override
public Optional<TargetFilterQuery> get(final long targetFilterQueryId) {
return Optional.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId));
return targetFilterQueryRepository.findById(targetFilterQueryId).map(tfq -> (TargetFilterQuery) tfq);
}
@Override

View File

@@ -64,7 +64,7 @@ import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
@@ -111,7 +111,7 @@ public class JpaTargetManagement implements TargetManagement {
private final ApplicationEventPublisher eventPublisher;
private final ApplicationContext applicationContext;
private final BusProperties bus;
private final TenantAware tenantAware;
@@ -127,9 +127,9 @@ public class JpaTargetManagement implements TargetManagement {
final DistributionSetRepository distributionSetRepository,
final TargetFilterQueryRepository targetFilterQueryRepository,
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext,
final TenantAware tenantAware, final AfterTransactionCommitExecutor afterCommit,
final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
final ApplicationEventPublisher eventPublisher, final BusProperties bus, final TenantAware tenantAware,
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
final Database database) {
this.entityManager = entityManager;
this.quotaManagement = quotaManagement;
this.targetRepository = targetRepository;
@@ -140,7 +140,7 @@ public class JpaTargetManagement implements TargetManagement {
this.targetTagRepository = targetTagRepository;
this.criteriaNoCountDao = criteriaNoCountDao;
this.eventPublisher = eventPublisher;
this.applicationContext = applicationContext;
this.bus = bus;
this.tenantAware = tenantAware;
this.afterCommit = afterCommit;
this.virtualPropertyReplacer = virtualPropertyReplacer;
@@ -190,13 +190,13 @@ public class JpaTargetManagement implements TargetManagement {
// TargetUpdatedEvent is not sent within the touch() method due to the
// "lastModifiedAt" field being ignored in JpaTarget
eventPublisher.publishEvent(new TargetUpdatedEvent(updatedTarget, applicationContext.getId()));
eventPublisher.publishEvent(new TargetUpdatedEvent(updatedTarget, bus.getId()));
return createdMetadata;
}
private void checkAndThrowIfTargetMetadataAlreadyExists(final TargetMetadataCompositeKey metadataId) {
if (targetMetadataRepository.exists(metadataId)) {
if (targetMetadataRepository.existsById(metadataId)) {
throw new EntityAlreadyExistsException(
"Metadata entry with key '" + metadataId.getKey() + "' already exists");
}
@@ -230,8 +230,8 @@ public class JpaTargetManagement implements TargetManagement {
// check if exists otherwise throw entity not found exception
final JpaTargetMetadata updatedMetadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId,
md.getKey())
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, md.getKey()));
md.getKey()).orElseThrow(
() -> new EntityNotFoundException(TargetMetadata.class, controllerId, md.getKey()));
updatedMetadata.setValue(md.getValue());
// touch it to update the lock revision because we are modifying the
// target indirectly
@@ -239,7 +239,7 @@ public class JpaTargetManagement implements TargetManagement {
final JpaTargetMetadata matadata = targetMetadataRepository.save(updatedMetadata);
// target update event is set to ignore "lastModifiedAt" field so it is
// not send automatically within the touch() method
eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId()));
eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId()));
return matadata;
}
@@ -252,10 +252,10 @@ public class JpaTargetManagement implements TargetManagement {
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, key));
final JpaTarget target = touch(controllerId);
targetMetadataRepository.delete(metadata.getId());
targetMetadataRepository.deleteById(metadata.getId());
// target update event is set to ignore "lastModifiedAt" field so it is
// not send automatically within the touch() method
eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId()));
eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId()));
}
@Override
@@ -294,7 +294,8 @@ public class JpaTargetManagement implements TargetManagement {
public Optional<TargetMetadata> getMetaDataByControllerId(final String controllerId, final String key) {
final Long targetId = getByControllerIdAndThrowIfNotFound(controllerId).getId();
return Optional.ofNullable(targetMetadataRepository.findOne(new TargetMetadataCompositeKey(targetId, key)));
return targetMetadataRepository.findById(new TargetMetadataCompositeKey(targetId, key))
.map(t -> (TargetMetadata) t);
}
@Override
@@ -344,7 +345,7 @@ public class JpaTargetManagement implements TargetManagement {
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> targetIDs) {
final List<JpaTarget> targets = targetRepository.findAll(targetIDs);
final List<JpaTarget> targets = targetRepository.findAllById(targetIDs);
if (targets.size() < targetIDs.size()) {
throw new EntityNotFoundException(Target.class, targetIDs,
@@ -356,7 +357,7 @@ public class JpaTargetManagement implements TargetManagement {
afterCommit.afterCommit(() -> targets.forEach(target -> eventPublisher.publishEvent(
new TargetDeletedEvent(tenantAware.getCurrentTenant(), target.getId(), target.getControllerId(),
Optional.ofNullable(target.getAddress()).map(URI::toString).orElse(null),
JpaTarget.class.getName(), applicationContext.getId()))));
JpaTarget.class.getName(), bus.getId()))));
}
@Override
@@ -366,7 +367,7 @@ public class JpaTargetManagement implements TargetManagement {
public void deleteByControllerID(final String controllerID) {
final Target target = getByControllerIdAndThrowIfNotFound(controllerID);
targetRepository.delete(target.getId());
targetRepository.deleteById(target.getId());
}
@Override
@@ -394,7 +395,7 @@ public class JpaTargetManagement implements TargetManagement {
}
private void throwEntityNotFoundIfDsDoesNotExist(final Long distributionSetID) {
if (!distributionSetRepository.exists(distributionSetID)) {
if (!distributionSetRepository.existsById(distributionSetID)) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetID);
}
}
@@ -452,7 +453,7 @@ public class JpaTargetManagement implements TargetManagement {
private List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams) {
final List<Specification<JpaTarget>> specList = new ArrayList<>();
if (filterParams.getFilterByStatus() != null && !filterParams.getFilterByStatus().isEmpty()) {
if ((filterParams.getFilterByStatus() != null) && !filterParams.getFilterByStatus().isEmpty()) {
specList.add(TargetSpecifications.hasTargetUpdateStatus(filterParams.getFilterByStatus()));
}
if (filterParams.getOverdueState() != null) {
@@ -475,8 +476,8 @@ public class JpaTargetManagement implements TargetManagement {
}
private static boolean isHasTagsFilterActive(final FilterParams filterParams) {
return filterParams.getSelectTargetWithNoTag() != null && (filterParams.getSelectTargetWithNoTag()
|| (filterParams.getFilterByTagNames() != null && filterParams.getFilterByTagNames().length > 0));
return ((filterParams.getSelectTargetWithNoTag() != null) && filterParams.getSelectTargetWithNoTag())
|| ((filterParams.getFilterByTagNames() != null) && (filterParams.getFilterByTagNames().length > 0));
}
private Slice<Target> findByCriteriaAPI(final Pageable pageable, final List<Specification<JpaTarget>> specList) {
@@ -617,7 +618,7 @@ public class JpaTargetManagement implements TargetManagement {
// index of the array and
// the 2nd contains the selectCase int value.
final int pageSize = pageable.getPageSize();
final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset())
final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult((int) pageable.getOffset())
.setMaxResults(pageSize + 1).getResultList();
final boolean hasNext = resultList.size() > pageSize;
return new SliceImpl<>(Collections.unmodifiableList(resultList), pageable, hasNext);
@@ -676,7 +677,7 @@ public class JpaTargetManagement implements TargetManagement {
@Override
public Page<Target> findByInRolloutGroupWithoutAction(final Pageable pageRequest, final long group) {
if (!rolloutGroupRepository.exists(group)) {
if (!rolloutGroupRepository.existsById(group)) {
throw new EntityNotFoundException(RolloutGroup.class, group);
}
@@ -733,7 +734,7 @@ public class JpaTargetManagement implements TargetManagement {
}
private void throwEntityNotFoundExceptionIfTagDoesNotExist(final Long tagId) {
if (!targetTagRepository.exists(tagId)) {
if (!targetTagRepository.existsById(tagId)) {
throw new EntityNotFoundException(TargetTag.class, tagId);
}
}
@@ -773,12 +774,12 @@ public class JpaTargetManagement implements TargetManagement {
@Override
public Optional<Target> get(final long id) {
return Optional.ofNullable(targetRepository.findOne(id));
return targetRepository.findById(id).map(t -> (Target) t);
}
@Override
public List<Target> get(final Collection<Long> ids) {
return Collections.unmodifiableList(targetRepository.findAll(ids));
return Collections.unmodifiableList(targetRepository.findAllById(ids));
}
@Override
@@ -796,7 +797,7 @@ public class JpaTargetManagement implements TargetManagement {
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
JpaTarget.class.getName(), applicationContext.getId()));
JpaTarget.class.getName(), bus.getId()));
}
@Override
@@ -806,4 +807,14 @@ public class JpaTargetManagement implements TargetManagement {
return target.isRequestControllerAttributes();
}
@Override
public boolean existsByControllerId(final String controllerId) {
return targetRepository.existsByControllerId(controllerId);
}
@Override
public Page<Target> findByControllerAttributesRequested(final Pageable pageReq) {
return targetRepository.findByRequestControllerAttributesIsTrue(pageReq);
}
}

View File

@@ -138,7 +138,7 @@ public class JpaTargetTagManagement implements TargetTagManagement {
@Override
public Optional<TargetTag> get(final long id) {
return Optional.ofNullable(targetTagRepository.findOne(id));
return targetTagRepository.findById(id).map(tt -> (TargetTag) tt);
}
@Override

View File

@@ -103,7 +103,7 @@ public class NoCountPagingRepository {
@Override
protected Page<T> readPage(final TypedQuery<T> query, final Pageable pageable, final Specification<T> spec) {
query.setFirstResult(pageable.getOffset());
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
final List<T> content = query.getResultList();

View File

@@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import com.google.common.collect.Lists;
@@ -43,10 +43,10 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
OfflineDsAssignmentStrategy(final TargetRepository targetRepository,
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
final ApplicationContext applicationContext, final ActionRepository actionRepository,
final BusProperties bus, final ActionRepository actionRepository,
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
super(targetRepository, afterCommit, eventPublisher, applicationContext, actionRepository,
actionStatusRepository, quotaManagement);
super(targetRepository, afterCommit, eventPublisher, bus, actionRepository, actionStatusRepository,
quotaManagement);
}
@Override

View File

@@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import com.google.common.collect.Lists;
@@ -41,10 +41,10 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
OnlineDsAssignmentStrategy(final TargetRepository targetRepository,
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
final ApplicationContext applicationContext, final ActionRepository actionRepository,
final BusProperties bus, final ActionRepository actionRepository,
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
super(targetRepository, afterCommit, eventPublisher, applicationContext, actionRepository,
actionStatusRepository, quotaManagement);
super(targetRepository, afterCommit, eventPublisher, bus, actionRepository, actionStatusRepository,
quotaManagement);
}
@Override

View File

@@ -63,6 +63,7 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataBuild
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetFilterQueryBuilder;
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager;
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitDefaultServiceExecutor;
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
@@ -70,6 +71,10 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHol
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder;
import org.eclipse.hawkbit.repository.jpa.rollout.RolloutScheduler;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.PauseRolloutGroupAction;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.StartNextGroupRolloutGroupSuccessAction;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupErrorCondition;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupSuccessCondition;
import org.eclipse.hawkbit.repository.jpa.rsql.RsqlParserValidationOracle;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -87,16 +92,18 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
@@ -123,23 +130,71 @@ import com.google.common.collect.Maps;
* General configuration for hawkBit's Repository.
*
*/
@EnableJpaRepositories(basePackages = { "org.eclipse.hawkbit.repository.jpa" })
@EnableJpaRepositories("org.eclipse.hawkbit.repository.jpa")
@EnableTransactionManagement
@EnableJpaAuditing
@EnableAspectJAutoProxy
@Configuration
@ComponentScan
@EnableScheduling
@EnableRetry
@EntityScan("org.eclipse.hawkbit.repository.jpa.model")
@PropertySource("classpath:/hawkbit-jpa-defaults.properties")
@Import({ RepositoryDefaultConfiguration.class })
@Import({ RepositoryDefaultConfiguration.class, DataSourceAutoConfiguration.class,
SystemManagementCacheKeyGenerator.class })
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
@Autowired
RepositoryApplicationConfiguration(final DataSource dataSource, final JpaProperties jpaProperties,
final ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) {
super(dataSource, jpaProperties, jtaTransactionManagerProvider);
protected RepositoryApplicationConfiguration(final DataSource dataSource, final JpaProperties properties,
final ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider,
final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
super(dataSource, properties, jtaTransactionManagerProvider, transactionManagerCustomizers);
}
@Bean
@ConditionalOnMissingBean
PauseRolloutGroupAction pauseRolloutGroupAction(final RolloutManagement rolloutManagement,
final RolloutGroupRepository rolloutGroupRepository, final SystemSecurityContext systemSecurityContext) {
return new PauseRolloutGroupAction(rolloutManagement, rolloutGroupRepository, systemSecurityContext);
}
@Bean
@ConditionalOnMissingBean
StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction(
final RolloutGroupRepository rolloutGroupRepository, final DeploymentManagement deploymentManagement,
final SystemSecurityContext systemSecurityContext) {
return new StartNextGroupRolloutGroupSuccessAction(rolloutGroupRepository, deploymentManagement,
systemSecurityContext);
}
@Bean
@ConditionalOnMissingBean
ThresholdRolloutGroupErrorCondition thresholdRolloutGroupErrorCondition(final ActionRepository actionRepository) {
return new ThresholdRolloutGroupErrorCondition(actionRepository);
}
@Bean
@ConditionalOnMissingBean
ThresholdRolloutGroupSuccessCondition thresholdRolloutGroupSuccessCondition(
final ActionRepository actionRepository) {
return new ThresholdRolloutGroupSuccessCondition(actionRepository);
}
@Bean
@ConditionalOnMissingBean
SystemManagementCacheKeyGenerator systemManagementCacheKeyGenerator() {
return new SystemManagementCacheKeyGenerator();
}
@Bean
@ConditionalOnMissingBean
AfterTransactionCommitDefaultServiceExecutor afterTransactionCommitDefaultServiceExecutor() {
return new AfterTransactionCommitDefaultServiceExecutor();
}
@Bean
@ConditionalOnMissingBean
NoCountPagingRepository noCountPagingRepository() {
return new NoCountPagingRepository();
}
@Bean
@@ -163,7 +218,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
@Bean
@ConditionalOnMissingBean
ApplicationEventFilter applicationEventFilter(final RepositoryProperties repositoryProperties) {
return e -> (e instanceof TargetPollEvent) && !repositoryProperties.isPublishTargetPollEvent();
return e -> e instanceof TargetPollEvent && !repositoryProperties.isPublishTargetPollEvent();
}
/**
@@ -389,16 +444,16 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
final DistributionSetMetadataRepository distributionSetMetadataRepository,
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
final NoCountPagingRepository criteriaNoCountDao, final ApplicationEventPublisher eventPublisher,
final ApplicationContext applicationContext, final TenantAware tenantAware,
final BusProperties bus, final TenantAware tenantAware,
final VirtualPropertyReplacer virtualPropertyReplacer,
final SoftwareModuleRepository softwareModuleRepository,
final DistributionSetTagRepository distributionSetTagRepository,
final AfterTransactionCommitExecutor afterCommit, final JpaProperties properties) {
return new JpaDistributionSetManagement(entityManager, distributionSetRepository, distributionSetTagManagement,
systemManagement, distributionSetTypeManagement, quotaManagement, distributionSetMetadataRepository,
targetFilterQueryRepository, actionRepository, criteriaNoCountDao, eventPublisher, applicationContext,
tenantAware, virtualPropertyReplacer, softwareModuleRepository, distributionSetTagRepository,
afterCommit, properties.getDatabase());
targetFilterQueryRepository, actionRepository, criteriaNoCountDao, eventPublisher, bus, tenantAware,
virtualPropertyReplacer, softwareModuleRepository, distributionSetTagRepository, afterCommit,
properties.getDatabase());
}
@@ -455,13 +510,13 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
final DistributionSetRepository distributionSetRepository,
final TargetFilterQueryRepository targetFilterQueryRepository,
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext,
final TenantAware tenantAware, final AfterTransactionCommitExecutor afterCommit,
final VirtualPropertyReplacer virtualPropertyReplacer, final JpaProperties properties) {
final ApplicationEventPublisher eventPublisher, final BusProperties bus, final TenantAware tenantAware,
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
final JpaProperties properties) {
return new JpaTargetManagement(entityManager, quotaManagement, targetRepository, targetMetadataRepository,
rolloutGroupRepository, distributionSetRepository, targetFilterQueryRepository, targetTagRepository,
criteriaNoCountDao, eventPublisher, applicationContext, tenantAware, afterCommit,
virtualPropertyReplacer, properties.getDatabase());
criteriaNoCountDao, eventPublisher, bus, tenantAware, afterCommit, virtualPropertyReplacer,
properties.getDatabase());
}
/**
@@ -565,12 +620,13 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
RolloutManagement rolloutManagement(final TargetManagement targetManagement,
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
final ApplicationEventPublisher eventPublisher, final VirtualPropertyReplacer virtualPropertyReplacer,
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
final JpaProperties properties, final RolloutApprovalStrategy rolloutApprovalStrategy) {
final BusProperties bus, final ApplicationEventPublisher eventPublisher,
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
final TenantAware tenantAware, final LockRegistry lockRegistry, final JpaProperties properties,
final RolloutApprovalStrategy rolloutApprovalStrategy) {
return new JpaRolloutManagement(targetManagement, deploymentManagement, rolloutGroupManagement,
distributionSetManagement, context, eventPublisher, virtualPropertyReplacer, txManager, tenantAware,
lockRegistry, properties.getDatabase(), rolloutApprovalStrategy);
distributionSetManagement, context, bus, eventPublisher, virtualPropertyReplacer, txManager,
tenantAware, lockRegistry, properties.getDatabase(), rolloutApprovalStrategy);
}
/**
@@ -614,15 +670,15 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository,
final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository,
final TargetManagement targetManagement, final AuditorAware<String> auditorProvider,
final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext,
final ApplicationEventPublisher eventPublisher, final BusProperties bus,
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
final PlatformTransactionManager txManager,
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware,
final JpaProperties properties) {
return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository,
actionStatusRepository, targetManagement, auditorProvider, eventPublisher, applicationContext,
afterCommit, virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
actionStatusRepository, targetManagement, auditorProvider, eventPublisher, bus, afterCommit,
virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
systemSecurityContext, tenantAware, properties.getDatabase());
}

View File

@@ -84,5 +84,5 @@ public interface SoftwareModuleTypeRepository
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT d FROM JpaSoftwareModuleType d WHERE d.id IN ?1")
List<JpaSoftwareModuleType> findAll(Iterable<Long> ids);
List<JpaSoftwareModuleType> findAllById(Iterable<Long> ids);
}

View File

@@ -15,13 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
/**
* Implementation of {@link CurrentTenantCacheKeyGenerator}.
*
*/
@Service
public class SystemManagementCacheKeyGenerator implements CurrentTenantCacheKeyGenerator {
@Autowired

View File

@@ -177,6 +177,18 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
*/
Page<Target> findByAssignedDistributionSetId(Pageable pageable, Long setID);
/**
* retrieves {@link Target}s where
* {@link JpaTarget#isRequestControllerAttributes()}.
*
* @param pageReq
* page parameter
*
* @return the found {@link Target}s
*
*/
Page<Target> findByRequestControllerAttributesIsTrue(Pageable pageable);
/**
* Counts number of targets with given distribution set Id.
*
@@ -209,7 +221,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT t FROM JpaTarget t WHERE t.id IN ?1")
List<JpaTarget> findAll(Iterable<Long> ids);
List<JpaTarget> findAllById(Iterable<Long> ids);
/**
*

View File

@@ -102,7 +102,7 @@ public class AutoAssignChecker {
public void check() {
LOGGER.debug("Auto assigned check call");
final PageRequest pageRequest = new PageRequest(0, PAGE_SIZE);
final PageRequest pageRequest = PageRequest.of(0, PAGE_SIZE);
final Page<TargetFilterQuery> filterQueries = targetFilterQueryManagement
.findWithAutoAssignDS(pageRequest);
@@ -176,7 +176,7 @@ public class AutoAssignChecker {
private List<TargetWithActionType> getTargetsWithActionType(final String targetFilterQuery, final Long dsId,
final int count) {
final Page<Target> targets = targetManagement
.findByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery);
.findByTargetFilterQueryAndNonDS(PageRequest.of(0, count), dsId, targetFilterQuery);
return targets.getContent().stream().map(t -> new TargetWithActionType(t.getControllerId(),
Action.ActionType.FORCED, RepositoryModelConstants.NO_FORCE_TIME)).collect(Collectors.toList());

View File

@@ -13,7 +13,6 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -22,7 +21,6 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* A Service which calls register runnable. This runnables will executed after a
* successful spring transaction commit.The class is thread safe.
*/
@Service
public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSynchronizationAdapter
implements AfterTransactionCommitExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(AfterTransactionCommitDefaultServiceExecutor.class);

View File

@@ -77,8 +77,8 @@ public class JpaTenantMetaData extends AbstractJpaBaseEntity implements TenantMe
return defaultDsType;
}
public void setDefaultDsType(final DistributionSetType defaultDsType) {
this.defaultDsType = (JpaDistributionSetType) defaultDsType;
public void setDefaultDsType(final JpaDistributionSetType defaultDsType) {
this.defaultDsType = defaultDsType;
}
@Override

View File

@@ -15,24 +15,25 @@ import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Error action evaluator which pauses the whole {@link Rollout} and sets the
* current {@link RolloutGroup} to error.
*/
@Component("pauseRolloutGroupAction")
public class PauseRolloutGroupAction implements RolloutGroupActionEvaluator {
@Autowired
private RolloutManagement rolloutManagement;
private final RolloutManagement rolloutManagement;
@Autowired
private RolloutGroupRepository rolloutGroupRepository;
private final RolloutGroupRepository rolloutGroupRepository;
@Autowired
private SystemSecurityContext systemSecurityContext;
private final SystemSecurityContext systemSecurityContext;
public PauseRolloutGroupAction(final RolloutManagement rolloutManagement,
final RolloutGroupRepository rolloutGroupRepository, final SystemSecurityContext systemSecurityContext) {
this.rolloutManagement = rolloutManagement;
this.rolloutGroupRepository = rolloutGroupRepository;
this.systemSecurityContext = systemSecurityContext;
}
@Override
public boolean verifyExpression(final String expression) {

View File

@@ -19,25 +19,26 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Success action which starts the next following {@link RolloutGroup}.
*/
@Component("startNextRolloutGroupAction")
public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActionEvaluator {
private static final Logger logger = LoggerFactory.getLogger(StartNextGroupRolloutGroupSuccessAction.class);
@Autowired
private RolloutGroupRepository rolloutGroupRepository;
private final RolloutGroupRepository rolloutGroupRepository;
@Autowired
private DeploymentManagement deploymentManagement;
private final DeploymentManagement deploymentManagement;
@Autowired
private SystemSecurityContext systemSecurityContext;
private final SystemSecurityContext systemSecurityContext;
public StartNextGroupRolloutGroupSuccessAction(final RolloutGroupRepository rolloutGroupRepository,
final DeploymentManagement deploymentManagement, final SystemSecurityContext systemSecurityContext) {
this.rolloutGroupRepository = rolloutGroupRepository;
this.deploymentManagement = deploymentManagement;
this.systemSecurityContext = systemSecurityContext;
}
@Override
public boolean verifyExpression(final String expression) {

View File

@@ -16,19 +16,19 @@ import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
*
*/
@Component("thresholdRolloutGroupErrorCondition")
public class ThresholdRolloutGroupErrorCondition implements RolloutGroupConditionEvaluator {
private static final Logger LOGGER = LoggerFactory.getLogger(ThresholdRolloutGroupErrorCondition.class);
@Autowired
private ActionRepository actionRepository;
private final ActionRepository actionRepository;
public ThresholdRolloutGroupErrorCondition(final ActionRepository actionRepository) {
this.actionRepository = actionRepository;
}
@Override
public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) {

View File

@@ -14,19 +14,19 @@ import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Threshold to calculate if rollout group success condition is reached and the
* next rollout group can get started.
*/
@Component("thresholdRolloutGroupSuccessCondition")
public class ThresholdRolloutGroupSuccessCondition implements RolloutGroupConditionEvaluator {
private static final Logger LOGGER = LoggerFactory.getLogger(ThresholdRolloutGroupSuccessCondition.class);
@Autowired
private ActionRepository actionRepository;
private final ActionRepository actionRepository;
public ThresholdRolloutGroupSuccessCondition(final ActionRepository actionRepository) {
this.actionRepository = actionRepository;
}
@Override
public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) {

View File

@@ -159,6 +159,8 @@ public final class RSQLUtility {
private static final class RSQLSpecification<A extends Enum<A> & FieldNameProvider, T> implements Specification<T> {
private static final long serialVersionUID = 1L;
private final String rsql;
private final Class<A> enumType;
private final VirtualPropertyReplacer virtualPropertyReplacer;

View File

@@ -76,7 +76,7 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
context.setSyntaxErrorContext(errorContext);
try {
targetManagement.findByRsql(new PageRequest(0, 1), rsqlQuery);
targetManagement.findByRsql(PageRequest.of(0, 1), rsqlQuery);
context.setSyntaxError(false);
suggestionContext.getSuggestions().addAll(getLogicalOperatorSuggestion(rsqlQuery));
} catch (final RSQLParameterSyntaxException | RSQLParserException ex) {

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
import java.util.List;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
/**
* Helper class to easily combine {@link Specification} instances.
@@ -31,11 +30,11 @@ public final class SpecificationsBuilder {
* all specification which will combine
* @return <null> if the given specification list is empty
*/
public static <T> Specifications<T> combineWithAnd(final List<Specification<T>> specList) {
public static <T> Specification<T> combineWithAnd(final List<Specification<T>> specList) {
if (specList.isEmpty()) {
return null;
}
Specifications<T> specs = Specifications.where(specList.get(0));
Specification<T> specs = Specification.where(specList.get(0));
for (final Specification<T> specification : specList.subList(1, specList.size())) {
specs = specs.and(specification);
}

View File

@@ -7,6 +7,8 @@
# http://www.eclipse.org/legal/epl-v10.html
#
spring.main.allow-bean-definition-overriding=true
### JPA / Datasource - START
spring.jpa.database=H2
spring.jpa.show-sql=false
@@ -17,8 +19,9 @@ spring.jpa.properties.eclipselink.logging.level=off
spring.datasource.eclipselink.query-results-cache=false
spring.datasource.eclipselink.cache.shared.default=false
# Flyway DDL
flyway.enabled=true
flyway.initOnMigrate=true
flyway.cleanDisabled=true
flyway.sqlMigrationSuffix=${spring.jpa.database}.sql
spring.flyway.enabled=true
spring.flyway.init-on-migrate=true
spring.flyway.clean-disabled=true
spring.flyway.sql-migration-suffixes=${spring.jpa.database}.sql
spring.flyway.table=schema_version
### JPA / Datasource - END