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.time.OffsetDateTime;
21  
22  import org.hibernate.envers.RevisionEntity;
23  import org.hibernate.envers.RevisionNumber;
24  import org.hibernate.envers.RevisionTimestamp;
25  
26  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27  import jakarta.persistence.Column;
28  import jakarta.persistence.GeneratedValue;
29  import jakarta.persistence.GenerationType;
30  import jakarta.persistence.MappedSuperclass;
31  import jakarta.persistence.SequenceGenerator;
32  import lombok.AllArgsConstructor;
33  import lombok.Getter;
34  import lombok.NoArgsConstructor;
35  import lombok.NonNull;
36  import lombok.Setter;
37  import lombok.experimental.SuperBuilder;
38  
39  @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "lombok provided superbuilder constructor.")
40  @MappedSuperclass
41  @RevisionEntity
42  @SuperBuilder(toBuilder = true)
43  @AllArgsConstructor
44  @NoArgsConstructor
45  @Getter
46  @Setter
47  public abstract class AbstractRevisionedJPAEntity extends AbstractJPAEntity {
48      @RevisionNumber
49      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DbSequence")
50      @SequenceGenerator(name = "DbSequence", sequenceName = "hibernate_sequence")
51      @Column(name = "REVID", nullable = false, updatable = false)
52      protected int revId;
53  
54      @RevisionTimestamp
55      @Column(name = "REVISIONED", insertable = true, updatable = false)
56      @NonNull
57      protected OffsetDateTime revisioned;
58  
59  
60      @Override
61      public AbstractRevisionedJPAEntity clone() throws CloneNotSupportedException {
62          final AbstractRevisionedJPAEntity result = (AbstractRevisionedJPAEntity) super.clone();
63  
64          result.revId = this.revId;
65          result.revisioned = this.revisioned;
66  
67          return result;
68      }
69  }