2024-04-26 12:50:56 +02:00
|
|
|
package org.opencdmp.data.tenant;
|
2023-12-06 12:08:49 +01:00
|
|
|
|
2024-05-02 09:46:36 +02:00
|
|
|
import jakarta.persistence.Column;
|
2024-05-02 11:38:36 +02:00
|
|
|
import jakarta.persistence.EntityListeners;
|
2024-05-02 09:46:36 +02:00
|
|
|
import jakarta.persistence.MappedSuperclass;
|
2023-12-06 12:08:49 +01:00
|
|
|
import org.hibernate.annotations.Filter;
|
|
|
|
import org.hibernate.annotations.FilterDef;
|
|
|
|
import org.hibernate.annotations.ParamDef;
|
2024-05-02 09:46:36 +02:00
|
|
|
import org.opencdmp.commons.scope.tenant.TenantScoped;
|
2023-12-06 12:08:49 +01:00
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
@MappedSuperclass
|
|
|
|
//@Getter
|
|
|
|
//@Setter
|
|
|
|
//@NoArgsConstructor
|
2024-05-02 09:46:36 +02:00
|
|
|
@FilterDef(name = TenantScopedBaseEntity.TENANT_FILTER, parameters = @ParamDef(name = TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, type = String.class))
|
2024-04-02 12:07:00 +02:00
|
|
|
@FilterDef(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER)
|
|
|
|
@Filter(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER, condition = "(tenant = tenant is null)")
|
|
|
|
@Filter(name = TenantScopedBaseEntity.TENANT_FILTER, condition = "(tenant = (cast(:tenantId as uuid)) or tenant is null)")
|
2024-05-02 11:38:36 +02:00
|
|
|
@EntityListeners(TenantListener.class)
|
2023-12-06 12:08:49 +01:00
|
|
|
public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable {
|
|
|
|
private static final long serialVersionUID = 1L;
|
2024-04-02 12:07:00 +02:00
|
|
|
public static final String TENANT_FILTER = "tenantFilter";
|
|
|
|
public static final String DEFAULT_TENANT_FILTER = "defaultTenantFilter";
|
|
|
|
public static final String TENANT_FILTER_TENANT_PARAM = "tenantId";
|
2023-12-06 12:08:49 +01:00
|
|
|
|
2023-12-06 13:21:25 +01:00
|
|
|
@Column(name = "tenant", columnDefinition = "uuid", nullable = true)
|
2023-12-06 12:08:49 +01:00
|
|
|
private UUID tenantId;
|
|
|
|
public static final String _tenantId = "tenantId";
|
|
|
|
public UUID getTenantId() {
|
2024-05-02 09:46:36 +02:00
|
|
|
return this.tenantId;
|
2023-12-06 12:08:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTenantId(UUID tenantId) {
|
|
|
|
this.tenantId = tenantId;
|
|
|
|
}
|
|
|
|
}
|