Skip to content

Package: JpaBackupFinder

JpaBackupFinder

nameinstructionbranchcomplexitylinemethod
JpaBackupFinder(BackupEntityJpaRepository, Function)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
JpaBackupFinder(BackupEntityJpaRepository, Function, Optional, Optional, Optional)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
JpaBackupFinder(JpaBackupFinder, Object)
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
composeSpecification(Root, CriteriaBuilder, List)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$composeSpecification$0(List, CriteriaBuilder, Root, String)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$composeSpecification$1(List, CriteriaBuilder, Root, String)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$composeSpecification$2(List, CriteriaBuilder, Root, String)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
withFileId(Optional)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
withLabel(Optional)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
withVolumeId(Optional)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * SolidBlue 3: Data safety
5: * http://tidalwave.it/projects/solidblue3
6: *
7: * Copyright (C) 2023 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/solidblue3j-src
23: * git clone https://github.com/tidalwave-it/solidblue3j-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.datamanager.dao.impl.jpa;
28:
29: import jakarta.annotation.Nonnull;
30: import java.util.List;
31: import java.util.Optional;
32: import java.util.function.Function;
33: import java.io.Serial;
34: import jakarta.persistence.criteria.CriteriaBuilder;
35: import jakarta.persistence.criteria.Predicate;
36: import jakarta.persistence.criteria.Root;
37: import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
38: import it.tidalwave.util.spring.jpa.JpaSpecificationFinder;
39: import it.tidalwave.datamanager.model.Backup;
40: import it.tidalwave.datamanager.model.DataManager.BackupFinder;
41:
42: /***********************************************************************************************************************
43: *
44: * A specialised {@link it.tidalwave.util.Finder} for {@link ManagedFileEntity}.
45: *
46: * @stereotype Finder
47: * @author Fabrizio Giudici
48: *
49: **********************************************************************************************************************/
50: @SuppressFBWarnings("SE_BAD_FIELD")
51: public class JpaBackupFinder
52: extends JpaSpecificationFinder<Backup, BackupEntity, BackupFinder, BackupEntityJpaRepository>
53: implements BackupFinder
54: {
55: @Serial private static final long serialVersionUID = 0L;
56:
57: private final Optional<String> label;
58:
59: private final Optional<String> volumeId;
60:
61: private final Optional<String> fileId;
62:
63: /*******************************************************************************************************************
64: *
65: ******************************************************************************************************************/
66: public JpaBackupFinder (@Nonnull final BackupEntityJpaRepository repository,
67: @Nonnull final Function<BackupEntity, Backup> transformer)
68: {
69: this(repository, transformer, Optional.empty(), Optional.empty(), Optional.empty());
70: }
71:
72: /*******************************************************************************************************************
73: *
74: ******************************************************************************************************************/
75: public JpaBackupFinder (@Nonnull final BackupEntityJpaRepository repository,
76: @Nonnull final Function<BackupEntity, Backup> transformer,
77: @Nonnull final Optional<String> label,
78: @Nonnull final Optional<String> volumeId,
79: @Nonnull final Optional<String> fileId)
80: {
81: super(repository, transformer);
82: this.label = label;
83: this.volumeId = volumeId;
84: this.fileId = fileId;
85: }
86:
87: /*******************************************************************************************************************
88: * The copy constructor required by {@link it.tidalwave.util.spi.HierarchicFinderSupport}.
89: ******************************************************************************************************************/
90: public JpaBackupFinder (@Nonnull final JpaBackupFinder other, @Nonnull final Object override)
91: {
92: super(other, override);
93: final var source = getSource(JpaBackupFinder.class, other, override);
94: this.label = source.label;
95: this.volumeId = source.volumeId;
96: this.fileId = source.fileId;
97: }
98:
99: /*******************************************************************************************************************
100: * {@inheritDoc}
101: ******************************************************************************************************************/
102: @Override @Nonnull
103: public BackupFinder withLabel (@Nonnull final Optional<String> label)
104: {
105: return clonedWith(new JpaBackupFinder(repository, entityToModel, label, volumeId, fileId));
106: }
107:
108: /*******************************************************************************************************************
109: * {@inheritDoc}
110: ******************************************************************************************************************/
111: @Override @Nonnull
112: public BackupFinder withVolumeId (@Nonnull final Optional<String> volumeId)
113: {
114: return clonedWith(new JpaBackupFinder(repository, entityToModel, label, volumeId, fileId));
115: }
116:
117: /*******************************************************************************************************************
118: * {@inheritDoc}
119: ******************************************************************************************************************/
120: @Override @Nonnull
121: public BackupFinder withFileId (@Nonnull final Optional<String> fileId)
122: {
123: return clonedWith(new JpaBackupFinder(repository, entityToModel, label, volumeId, fileId));
124: }
125:
126: /*******************************************************************************************************************
127: * {@inheritDoc}
128: ******************************************************************************************************************/
129: protected void composeSpecification (@Nonnull final Root<BackupEntity> root,
130: @Nonnull final CriteriaBuilder criteriaBuilder,
131: @Nonnull final List<? super Predicate> predicates)
132: {
133: label.ifPresent(l -> predicates.add(criteriaBuilder.equal(root.get("label"), l)));
134: volumeId.ifPresent(v -> predicates.add(criteriaBuilder.equal(root.get("volumeId"), v)));
135: fileId.ifPresent(i -> predicates.add(criteriaBuilder.equal(root.join("backupFiles")
136: .join("managedFile")
137: .get("id"), i)));
138: }
139: }