View Javadoc
1   /*
2    * Copyright (c) 2022-2023. Roland T. Lichti, Kaiserpfalz EDV-Service.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16   */
17  
18  package de.kaiserpfalzedv.commons.jpa;
19  
20  import java.io.Serializable;
21  import java.time.OffsetDateTime;
22  
23  import org.hibernate.envers.RevisionEntity;
24  import org.hibernate.envers.RevisionNumber;
25  import org.hibernate.envers.RevisionTimestamp;
26  
27  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
28  import jakarta.persistence.Column;
29  import jakarta.persistence.MappedSuperclass;
30  import lombok.AllArgsConstructor;
31  import lombok.EqualsAndHashCode;
32  import lombok.Getter;
33  import lombok.NoArgsConstructor;
34  import lombok.Setter;
35  import lombok.experimental.SuperBuilder;
36  
37  @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "lombok provided SuperBuilder constructor.")
38  @MappedSuperclass
39  @RevisionEntity
40  @SuperBuilder(toBuilder = true)
41  @AllArgsConstructor
42  @NoArgsConstructor
43  @Getter
44  @Setter
45  @EqualsAndHashCode(callSuper = true, of = {"revId"})
46  public abstract class AbstractRevisionedJPAEntity<T extends Serializable> extends AbstractJPAEntity<T> {
47      @RevisionNumber
48      protected int revId;
49  
50      @RevisionTimestamp
51      @Column(name = "REVISIONED", insertable = true, updatable = false)
52      protected OffsetDateTime revisioned;
53  
54  
55      @SuppressWarnings("java:S2975")
56      @Override
57      public AbstractRevisionedJPAEntity<T> clone() throws CloneNotSupportedException {
58          final AbstractRevisionedJPAEntity<T> result = (AbstractRevisionedJPAEntity<T>) super.clone();
59  
60          result.revId = this.revId;
61          result.revisioned = this.revisioned;
62  
63          return result;
64      }
65  }