Sync: code local unifié
Synchronisation du code source local (fait foi). Signed-off-by: lions dev Team
This commit is contained in:
@@ -1,111 +1,79 @@
|
||||
package dev.lions.unionflow.server.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import dev.lions.unionflow.server.entity.listener.AuditEntityListener;
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.PrePersist;
|
||||
import jakarta.persistence.PreUpdate;
|
||||
import jakarta.persistence.Version;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Classe de base pour les entités UnionFlow utilisant UUID comme identifiant
|
||||
*
|
||||
* <p>Remplace PanacheEntity pour utiliser UUID au lieu de Long comme ID.
|
||||
* Fournit les fonctionnalités de base de Panache avec UUID.
|
||||
*
|
||||
* Classe de base pour toutes les entités UnionFlow.
|
||||
*
|
||||
* <p>
|
||||
* Étend PanacheEntityBase pour bénéficier du pattern Active Record et résoudre
|
||||
* les warnings Hibernate.
|
||||
* Fournit les champs communs d'audit et le versioning optimistic.
|
||||
*
|
||||
* @author UnionFlow Team
|
||||
* @version 2.0
|
||||
* @since 2025-01-16
|
||||
* @version 4.0
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public abstract class BaseEntity {
|
||||
@EntityListeners(AuditEntityListener.class)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public abstract class BaseEntity extends PanacheEntityBase {
|
||||
|
||||
/** Identifiant unique auto-généré. */
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
@Column(name = "id", updatable = false, nullable = false)
|
||||
private UUID id;
|
||||
|
||||
/**
|
||||
* Date de création.
|
||||
*/
|
||||
@Column(name = "date_creation", nullable = false, updatable = false)
|
||||
protected LocalDateTime dateCreation;
|
||||
private LocalDateTime dateCreation;
|
||||
|
||||
/**
|
||||
* Date de dernière modification.
|
||||
*/
|
||||
@Column(name = "date_modification")
|
||||
protected LocalDateTime dateModification;
|
||||
private LocalDateTime dateModification;
|
||||
|
||||
/**
|
||||
* Email de l'utilisateur ayant créé l'entité.
|
||||
*/
|
||||
@Column(name = "cree_par", length = 255)
|
||||
protected String creePar;
|
||||
private String creePar;
|
||||
|
||||
/**
|
||||
* Email du dernier utilisateur ayant modifié l'entité.
|
||||
*/
|
||||
@Column(name = "modifie_par", length = 255)
|
||||
protected String modifiePar;
|
||||
private String modifiePar;
|
||||
|
||||
/** Version pour l'optimistic locking JPA. */
|
||||
@Version
|
||||
@Column(name = "version")
|
||||
protected Long version;
|
||||
private Long version;
|
||||
|
||||
/**
|
||||
* État actif/inactif pour le soft-delete.
|
||||
*/
|
||||
@Column(name = "actif", nullable = false)
|
||||
protected Boolean actif = true;
|
||||
private Boolean actif;
|
||||
|
||||
// Constructeur par défaut
|
||||
public BaseEntity() {
|
||||
this.dateCreation = LocalDateTime.now();
|
||||
this.actif = true;
|
||||
this.version = 0L;
|
||||
}
|
||||
|
||||
// Getters et Setters
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateTime getDateCreation() {
|
||||
return dateCreation;
|
||||
}
|
||||
|
||||
public void setDateCreation(LocalDateTime dateCreation) {
|
||||
this.dateCreation = dateCreation;
|
||||
}
|
||||
|
||||
public LocalDateTime getDateModification() {
|
||||
return dateModification;
|
||||
}
|
||||
|
||||
public void setDateModification(LocalDateTime dateModification) {
|
||||
this.dateModification = dateModification;
|
||||
}
|
||||
|
||||
public String getCreePar() {
|
||||
return creePar;
|
||||
}
|
||||
|
||||
public void setCreePar(String creePar) {
|
||||
this.creePar = creePar;
|
||||
}
|
||||
|
||||
public String getModifiePar() {
|
||||
return modifiePar;
|
||||
}
|
||||
|
||||
public void setModifiePar(String modifiePar) {
|
||||
this.modifiePar = modifiePar;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Boolean getActif() {
|
||||
return actif;
|
||||
}
|
||||
|
||||
public void setActif(Boolean actif) {
|
||||
this.actif = actif;
|
||||
}
|
||||
|
||||
// Callbacks JPA
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
if (this.dateCreation == null) {
|
||||
@@ -114,9 +82,6 @@ public abstract class BaseEntity {
|
||||
if (this.actif == null) {
|
||||
this.actif = true;
|
||||
}
|
||||
if (this.version == null) {
|
||||
this.version = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
@@ -124,18 +89,13 @@ public abstract class BaseEntity {
|
||||
this.dateModification = LocalDateTime.now();
|
||||
}
|
||||
|
||||
// Méthodes utilitaires Panache-like
|
||||
public void persist() {
|
||||
// Cette méthode sera implémentée par les repositories ou services
|
||||
// Pour l'instant, elle est là pour compatibilité avec le code existant
|
||||
throw new UnsupportedOperationException(
|
||||
"Utilisez le repository approprié pour persister cette entité");
|
||||
}
|
||||
|
||||
public static <T extends BaseEntity> T findById(UUID id) {
|
||||
// Cette méthode sera implémentée par les repositories
|
||||
throw new UnsupportedOperationException(
|
||||
"Utilisez le repository approprié pour rechercher par ID");
|
||||
/**
|
||||
* Marque l'entité comme modifiée par un utilisateur donné.
|
||||
*
|
||||
* @param utilisateur email de l'utilisateur
|
||||
*/
|
||||
public void marquerCommeModifie(String utilisateur) {
|
||||
this.dateModification = LocalDateTime.now();
|
||||
this.modifiePar = utilisateur;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user