@Getter
@Entity
@ToString(onlyExplicitlyIncluded = true)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@NoArgsConstructor(access = PROTECTED)
@Table(name = "OPERATORS")
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@DynamicUpdate
@Cacheable
@Cache(usage = READ_WRITE)
public class Operator {
public Operator(String operatorId) {
this.operatorId = operatorId;
this.tagPolicy = new OperatorTagPolicy(Set.of(), ALL);
}
@EqualsAndHashCode.Include
@ToString.Include
@Id
@Column(name = "OPERATOR_ID", nullable = false)
private String operatorId;
@Embedded
private OperatorTagPolicy tagPolicy;
@OneToMany(mappedBy = "operator", cascade = {CascadeType.ALL}, orphanRemoval = true, fetch = FetchType.LAZY)
private List<Product> products = new ArrayList<>();
public void setProducts(List<Product> products) {
this.products = products;
}
@Value
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
@Embeddable
public static class OperatorTagPolicy {
@NonFinal
@ManyToMany(fetch = LAZY)
@JoinTable(
name = "OPERATOR_TO_TAG",
joinColumns = {
@JoinColumn(name = "OPERATOR_ID", referencedColumnName = "OPERATOR_ID")
},
inverseJoinColumns = @JoinColumn(name = "TAG_NAME"))
@Cache(usage = READ_WRITE)
Set<Tag> exceptions;
@NonFinal
@Column(name = "TAG_POLICY_TYPE", nullable = false)
@Enumerated(EnumType.STRING)
PolicyType type;
}
}