Skip to contentPackage: BackupFileEntity
BackupFileEntity
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.Objects;
31: import jakarta.persistence.Column;
32: import jakarta.persistence.Entity;
33: import jakarta.persistence.FetchType;
34: import jakarta.persistence.Id;
35: import jakarta.persistence.Index;
36: import jakarta.persistence.JoinColumn;
37: import jakarta.persistence.ManyToOne;
38: import jakarta.persistence.Table;
39: import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
40: import lombok.AllArgsConstructor;
41: import lombok.Getter;
42: import lombok.NoArgsConstructor;
43:
44: /***********************************************************************************************************************
45: *
46: * @stereotype JPA Entity
47: * @author Fabrizio Giudici
48: *
49: **********************************************************************************************************************/
50: @Entity
51: @Table(name="backup_files", indexes = { @Index(name = "backup_files__id", columnList = "id"),
52: @Index(name = "backup_files__file_id", columnList = "file_id")})
53: @NoArgsConstructor @AllArgsConstructor @Getter
54: @SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
55: public class BackupFileEntity
56: {
57: @Id
58: @Column(length = 36)
59: private String id;
60:
61: @ManyToOne(optional = false, fetch = FetchType.EAGER)
62: @JoinColumn(name = "backup_id", nullable = false)
63: private BackupEntity backup;
64:
65: @ManyToOne(optional = false, fetch = FetchType.EAGER)
66: @JoinColumn(name = "file_id", nullable = false)
67: private ManagedFileEntity managedFile;
68:
69: @Column(name = "path", nullable = false, columnDefinition = "text")
70: private String path;
71:
72: @Override @Nonnull
73: public String toString()
74: {
75: return "BackupFileEntity@%x(id=%s, backupId=%s, path=%s, file=%s)".formatted(
76: System.identityHashCode(this),
77:• id, backup == null ? null : backup.getId(), path, managedFile);
78: }
79:
80: // See https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
81: @Override
82: public boolean equals (final Object other)
83: {
84:• if (this == other)
85: {
86: return true;
87: }
88:
89:• if (!(other instanceof BackupFileEntity))
90: {
91: return false;
92: }
93:
94:• return id != null && Objects.equals(id, ((BackupFileEntity)other).getId());
95: }
96:
97: @Override
98: public int hashCode()
99: {
100: return getClass().hashCode();
101: }
102: }