Skip to content

Package: ManagedFileEntity

ManagedFileEntity

nameinstructionbranchcomplexitylinemethod
equals(Object)
M: 1 C: 23
96%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 0 C: 5
100%
M: 0 C: 1
100%
hashCode()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isInitialized()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
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.ArrayList;
31: import java.util.List;
32: import java.util.Objects;
33: import jakarta.persistence.Column;
34: import jakarta.persistence.Entity;
35: import jakarta.persistence.FetchType;
36: import jakarta.persistence.Id;
37: import jakarta.persistence.Index;
38: import jakarta.persistence.OneToMany;
39: import jakarta.persistence.OrderBy;
40: import jakarta.persistence.Table;
41: import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
42: import org.hibernate.Hibernate;
43: import lombok.AllArgsConstructor;
44: import lombok.Getter;
45: import lombok.NoArgsConstructor;
46: import lombok.Setter;
47: import static jakarta.persistence.CascadeType.PERSIST;
48:
49: /***********************************************************************************************************************
50: *
51: * A JPA Entity for {@link ManagedFileEntity}.
52: *
53: * @stereotype JPA Entity
54: * @author Fabrizio Giudici
55: *
56: **********************************************************************************************************************/
57: @Entity
58: @Table(name="files", indexes = { @Index(name = "files__id", columnList = "id"),
59: @Index(name = "files__path", columnList = "path")})
60: @NoArgsConstructor @AllArgsConstructor @Getter
61: @SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
62: public class ManagedFileEntity
63: {
64: @Id
65: @Column(length = 36)
66:
67: private String id;
68:
69: @Column(nullable = false, columnDefinition = "text")
70: private String path;
71:
72: @Setter
73: @OneToMany(mappedBy = "fileId", fetch = FetchType.LAZY, cascade = PERSIST)
74: @OrderBy("timestamp asc")
75: private List<FingerprintEntity> fingerprints = new ArrayList<>();
76:
77: public boolean isInitialized()
78: {
79: return Hibernate.isInitialized(fingerprints);
80: }
81:
82: @Override @Nonnull
83: public String toString()
84: {
85: return "ManagedFileEntity@%x(id=%s, path=%s, fingerprints=%s)".formatted(
86: System.identityHashCode(this),
87:• id, path, Hibernate.isInitialized(fingerprints) ? fingerprints : "not initialized");
88: }
89:
90: // See https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
91: @Override
92: public boolean equals (final Object other)
93: {
94:• if (this == other)
95: {
96: return true;
97: }
98:
99:• if (!(other instanceof ManagedFileEntity))
100: {
101: return false;
102: }
103:
104:• return id != null && Objects.equals(id, ((ManagedFileEntity)other).getId());
105: }
106:
107: @Override
108: public int hashCode()
109: {
110: return getClass().hashCode();
111: }
112: }